-- FIND FONTS HANDLERS -- -- -- © March 2002, OpenSpark Interactive Ltd -- Revised August 2002 -- james.newton@openspark.com -- -- This set of four handlers is useful for checking where a "Missing -- Font" is used in a given movie. -- -- Syntax: -- * FindFonts("font name") -- returns a list of all members in the current movie which use a -- given font. -- * FindFonts([list of fonts]) -- returns a list of all members in the current movie which use any -- of the given fonts. -- * CheckForFonts(aMember, aFontNameOrList) -- returns the name of one of the fonts in aFontNameOrList which -- appears in aMember. If more than one of the given fonts appears, -- only the last of the given fonts in the member will be returned. -- -- * FindMissingFonts() - ONLY WORKS FOR TEXT MEMBERS -- returns a list of all missing fonts and the affected text members on FindFonts(aFontList, aFullSearch, aMemberList, aResultList) ------- -- INPUT: can be a string font name or a list of fonts. -- Font names are case-sensitive. -- only has any effect if it is 1 (TRUE). In -- this case, each character of each possible member is -- checked to see if its font is one of those looked for. -- may be a list of members or a list of lists -- of members such as the one returned by this handler. If -- such a list is provided then only the members in the -- list are checked, not all those in the movie. During a -- full search, this handler stops checking characters once -- one of the fonts has been found. Running the handler -- again after removing the offending fonts ensures that -- any other suspect fonts in the same members will also -- be detected. -- is used by this handler if it calls itself -- recursively. -- OUTPUT: a nested list of all the members in the current movie -- that are set to use one of the fonts in aFontList. If -- a member uses one of the fonts elsewhere but in the first -- character, this will not be reported unless -- is TRUE. Running a full search can be very time- -- consuming. A full search is particularly useful when -- checking for missing fonts. --------------------------------------------------------------------- if ilk(aResultList) <> #propList then aResultList = [:] end if case ilk(aFontList) of #list, #propList: -- continue #string: aFontList = list(aFontList) otherwise: return aResultList end case if listP(aMemberList) then i = aMemberList.count repeat while i tMember = aMemberList[i] if listP(tMember) then -- Call this handler recursively return FindFonts(aFontList, aFullSearch, tMember, aResultList) end if tFoundFont = CheckForFonts(tMember, aFontList, not aFullSearch) if stringP(tFoundFont) then AddToList(aResultList, tFoundFont, tMember) end if i = i - 1 end repeat else -- Cycle through the members of each castLib for members with the -- chosen font tCastCount = the number of castLibs repeat with tCastNum = 1 to tCastCount tMemberCount = the number of members of castLib(tCastNum) repeat with tMemberNum = 1 to tMemberCount tMember = member(tMemberNum, tCastNum) case tMember.type of #button, #field, #text: -- Here's a member which may have one of the fonts tFoundFont = CheckForFonts(tMember,aFontList,aFullSearch) if stringP(tFoundFont) then AddToList(aResultList, tFoundFont, tMember) end if end case end repeat end repeat end if return aResultList end FindFonts on CheckForFonts(aMember, aFontList, aCursorySearch) ----------------- -- CALLED by FindFonts() -- INPUT: is a button, field or text member -- is a list of string font names -- can be 1 or 0 -- OUTPUT: the first string font name from that is -- encountered in . If is TRUE, -- only the first character in the member is checked. If it -- is FALSE, every character is checked, starting from the -- end. -------------------------------------------------------------------- tFont = aMember.font if aCursorySearch then if aFontList.getPos(tFont) then return tFont end if else case aMember.type of #button, #field: i = aMember.char.count repeat while i tFont = the font of char i of field aMember if aFontList.getPos(tFont) then return tFont end if i = i - 1 end repeat #text: i = aMember.char.count repeat while i tFont = aMember.char[i].ref.font if aFontList.getPos(tFont) then return tFont end if i = i - 1 end repeat end case end if end CheckForFonts on AddToList(aResultList, aFont, aMember) ---------------------------- -- SENT BY FindFonts() -- ACTION: Adds the given member to the sub-list of members that use -- the given font. -------------------------------------------------------------------- tFontList = aResultList[aFont] if ilk(tFontList) <> #list then -- This is the first member that uses this font tFontList = [] aResultList[aFont] = tFontList end if tFontList.append(aMember) end AddToList on FindMissingFonts() ------------------------------------------------ -- ONLY WORKS FOR TEXT MEMBERS -- OUTPUT: a property list with the structure: -- [: [affected text members], ...] -------------------------------------------------------------------- tMissingFontList = [:] tMissingFontList.sort() tCastLibNum = the number of castLibs repeat while tCastLibNum tMemberNum = the number of members of castLib(tCastLibNum) repeat while tMemberNum tMember = member(tMemberNum, tCastLibNum) if tMember.type = #text then tMissingFonts = tMember.missingFonts i = tMissingFonts.count repeat while i tFont = tMissingFonts[i] tMembers = tMissingFontList[tFont] if ilk(tMembers) <> #list then tMembers = [] tMembers.sort() tMissingFontList[tFont] = tMembers end if tMembers.add(tMember) i = i - 1 end repeat end if tMemberNum = tMemberNum - 1 end repeat tCastLibNum = tCastLibNum - 1 end repeat return tMissingFontList end FindMissingFonts on _FindMissingFonts(aCastLibNum) ------------------------------------- -- ONLY WORKS FOR TEXT MEMBERS -- INPUT: can be the integer number of a castLib. If -- so, searching for missing fonts is limited to that -- castLib. -- OUTPUT: a property list with the structure: -- [: [affected text members], ...] -------------------------------------------------------------------- tMissingFontList = [:] tMissingFontList.sort() tFirstLibNum = 1 tLastLibNum = the number of castLibs if integerP(aCastLibNum) then if aCastLibNum > 0 then if aCastLibNum <= tLastLibNum then tFirstLibNum = aCastLibNum tLastLibNum = aCastLibNum end if end if end if repeat with tCastLibNum = tFirstLibNum to tLastLibNum tMemberNum = the number of members of castLib(tCastLibNum) repeat while tMemberNum tMember = member(tMemberNum, tCastLibNum) if tMember.type = #text then tMissingFonts = tMember.missingFonts i = tMissingFonts.count repeat while i tFont = tMissingFonts[i] tMembers = tMissingFontList[tFont] if ilk(tMembers) <> #list then tMembers = [] tMembers.sort() tMissingFontList[tFont] = tMembers end if tMembers.add(tMember) i = i - 1 end repeat end if tMemberNum = tMemberNum - 1 end repeat end repeat return tMissingFontList end FindMissingFonts