-- MOVIE SCRIPT - Utility for making 'PixelFonts' -- To Make a font in the message window, type -- MakeFont ("fontName", "regular", 18, 1, #script) -- The resulting fontmap will be saved to the internal cast. To add the -- font to the FontLib, edit the FontMgr script and add this line to -- its "mInit" method: -- LoadFont(#ID, "TheNameOfTheCastMemberCreatedInPreviousStep") -- -- (These scripts are based on the great work by Joel - big thanks!) on MakeFont (aFont, aFontStyle, aFontSize, aAntiAlias, aType) --* aFont: FontName {String} --* aFontStyle: "Regular", "Bold Italic" etc {String} --* aFontSize {integer} --* aAntiAlias {boolean} --* aType: #Script, #vList or #field (default) {symbol} put " Making font >>>" tPixelFont = mInitPixelFont(aFont, aFontStyle, aFontSize, aAntiAlias) -- Working --- pad = "" repeat with i = 1 to 23 pad = pad & " " end repeat step = 1 -------------- tSpc = mConvertChar(tPixelFont.text, " ", false, true, aAntiAlias) tPixelFont.addProp(#lineHeight, tSpc[1].count) tPixelFont.addProp(#spaceWidth, tSpc.count) tTab = mConvertChar(tPixelFont.text, TAB, false, true, aAntiAlias) tPixelFont.addProp(#tabWidth, tTab.count) tPixelFont.addProp(#data, [:]) if (the environment.platform contains "Win") then tNBSP = 160 else tNBSP = 202 end if repeat with tCounter = 33 to 255 if tCounter mod 10 = 0 then step = step + 1 put "." into char step of pad put pad end if if (tCounter <> tNBSP) then tChar = mConvertChar(tPixelFont.text, numToChar(tCounter), true, false, aAntiAlias) if (tChar <> void) then tPixelFont.data.addProp(tCounter, tChar) end if end if end repeat if (the environment.platform contains "Win") then tPixelFont.data = mConvertToMacCodes(tPixelFont.data) end if put " saving... " mSaveFont(tPixelFont, aType) put " Making font >>> DONE! " end ------------------ on mInitPixelFont(aFont, aFontStyle, aFontSize, aAntiAlias) if member("convertFont").type = #Empty then tmp = new(#text) tmp.name = "convertFont" end if tText = member("convertFont") tText.font = aFont tFontStyle = [] case (aFontStyle) of "Regular": tFontStyle.append(#plain) "Bold": tFontStyle.append(#bold) "Bold Italic": tFontStyle.append(#bold) tFontStyle.append(#italic) "Italic": tFontStyle.append(#italic) otherwise tFontStyle.append(#plain) end case tText.fontStyle = tFontStyle tText.fontSize = integer(aFontSize) if (aAntiAlias) then tText.antialias = true tText.antiAliasThreshold = tText.fontSize - 1 tText.kerning = true tText.kerningThreshold = tText.antiAliasThreshold else tText.antialias = false tText.kerning = false end if aPixelFont = [:] aPixelFont.addProp(#font, aFont) aPixelFont.addProp(#fontStyle, aFontStyle) aPixelFont.addProp(#fontSize, aFontSize) aPixelFont.addProp(#antiAlias, aAntiAlias) aPixelFont.addProp(#leading, (member("convertFont").charPosToLoc(2).locV + 1) - tText.fontSize) aPixelFont.addProp(#text, member("convertFont")) return aPixelFont end on mSaveFont(aPixelFont, aType) aPixelFont.deleteProp(#text) tell the stage repeat with tCounter = 1 to the number of members of castlib 1 if (member(tCounter).type = #empty) then exit repeat end repeat if (aType = #script) then tMember = new(#script, member tCounter of castlib 1) tMember.scriptText = "on mGetFontMap(me)" & RETURN & "return " & string(aPixelFont) & RETURN & "end" tMember.scriptType = #score else if (aType = #vList) then tMember = new(#vList, member tCounter of castlib 1) tMember.content = aPixelFont else tMember = new(#field, member tCounter of castlib 1) tMember.text = string(aPixelFont) end if tName = "PIXELFONT" & "." & aPixelFont.font & "." & aPixelFont.fontStyle if (aPixelFont.antiAlias) then tName = tName & ".AntiAlias" tMember.name = tName & "." & aPixelFont.fontSize end tell end on mConvertToMacCodes(aList) rList = [:] myASCIIList = [ \ 196, 197, 199, 201, 209, 214, 220, 225, 224, 226, 228, 227, 229, \ 231, 233, 232, 234, 235, 237, 236, 238, 239, 241, 243, 242, 244, \ 246, 245, 250, 249, 251, 252, 134, 176, 162, 163, 167, 149, 182, \ 223, 174, 169, 153, 180, 168, 141, 198, 216, 144, 177, 143, 142, \ 165, 181, 240, 221, 222, 254, 138, 170, 186, 253, 230, 248, 191, \ 161, 172, 175, 131, 188, 208, 171, 187, 133, 160, 192, 195, 213, \ 140, 156, 173, 151, 147, 148, 145, 146, 247, 215, 255, 159, 158, \ 164, 139, 155, 128, 129, 135, 183, 130, 132, 137, 194, 202, 193, \ 203, 200, 205, 206, 207, 204, 211, 212, 157, 210, 218, 219, 217, \ 166, 136, 152, 150, 154, 178, 190, 184, 189, 179, 185] repeat with i = 1 to aList.count ID = aList.getPropAt(i) if integerP(id) then if ID > 127 and ID < 256 then ID = (127 + myASCIIList.getPos(ID)) end if end if rList.addProp(id, aList[i]) end repeat return rList end on mTrimWhite(aPixelChar) -- Delete beginning white tDeleteList = [] repeat with tColCounter = 1 to aPixelChar.count tColEmpty = true repeat with tRowCounter = 1 to aPixelChar[tColCounter].count if (aPixelChar[tColCounter][tRowCounter] > 0) then tColEmpty = false exit repeat end if end repeat if (tColEmpty) then tDeleteList.append(tColCounter) else exit repeat end if end repeat repeat with tCounter = tDeleteList.count down to 1 aPixelChar.deleteAt(tDeleteList[tCounter]) end repeat -- Delete ending white tDeleteList = [] repeat with tColCounter = aPixelChar.count down to 1 tColEmpty = true repeat with tRowCounter = 1 to aPixelChar[tColCounter].count if (aPixelChar[tColCounter][tRowCounter] > 0) then tColEmpty = false exit repeat end if end repeat if (tColEmpty) then tDeleteList.addAt(1, tColCounter) else exit repeat end if end repeat repeat with tCounter = tDeleteList.count down to 1 aPixelChar.deleteAt(tDeleteList[tCounter]) end repeat end on mRunLengthEncoding(aPixelChar) if (aPixelChar <> []) then tPropName = 0 tRLEPixelChar = [#w:aPixelChar.count,# h:aPixelChar[1].count, #d:[:]] repeat with tCol = 1 to tRLEPixelChar.w tRunStart = -1 tRunEnd = -1 tColor = -1 repeat with tRow = 1 to tRLEPixelChar.h if (aPixelChar[tCol][tRow] <> 0) then if (tRunStart = -1) then tRunStart = tRow - 1 tColor = aPixelChar[tCol][tRow] else if (tRunStart <> -1) then if (aPixelChar[tCol][tRow] <> tColor) then if (tRunStart <> -1 AND tRunEnd <> -1) then tRLEPixelChar.d.addProp(tPropName, [#r:tCol - 1, #s:tRunStart, #e:tRunEnd, #c:tColor]) tPropName = tPropName + 1 tRunStart = tRow - 1 tRunEnd = -1 tColor = aPixelChar[tCol][tRow] else if (tRunStart <> -1) then tRLEPixelChar.d.addProp(tPropName, [#r:tCol - 1, #s:tRunStart, #e:tRunStart, #c:tColor]) tPropName = tPropName + 1 tRunStart = tRow - 1 tColor = aPixelChar[tCol][tRow] end if else tRunEnd = tRow - 1 end if end if else if (tRunStart <> -1 AND tRunEnd <> -1) then tRLEPixelChar.d.addProp(tPropName, [#r:tCol - 1, #s:tRunStart, #e:tRunEnd, #c:tColor]) tPropName = tPropName + 1 tRunStart = -1 tRunEnd = -1 tColor = -1 else if (tRunStart <> -1) then tRLEPixelChar.d.addProp(tPropName, [#r:tCol - 1, #s:tRunStart, #e:tRunStart, #c:tColor]) tPropName = tPropName + 1 tRunStart = -1 tColor = -1 end if end if end repeat if (tRunStart <> -1 AND tRunEnd <> -1) then tRLEPixelChar.d.addProp(tPropName, [#r:tCol - 1, #s:tRunStart, #e:tRunEnd, #c:tColor]) tPropName = tPropName + 1 tRunStart = -1 tRunEnd = -1 end if end repeat return tRLEPixelChar else return void end if end on mConvertChar(aTextMember, aChar, aTrimWhite, aWhite, aAntiAlias) if (aChar <> " " AND aChar <> TAB) then aTextMember.text = " " & aChar tEndPoint = aTextMember.charPosToLoc(3) else aTextMember.text = aChar tEndPoint = aTextMember.charPosToLoc(2) end if tCharImage = aTextMember.image.extractAlpha() if (aChar = " " OR aChar = TAB) then tCropRect = rect(0, 0, tEndPoint.locH, tCharImage.height) else tCropRect = rect(0, 0, 2 * tEndPoint.locH, tCharImage.height) end if tCharImage = tCharImage.crop(tCropRect) tPixelChar = [] repeat with tColCounter = 0 to tCharImage.width tPixelCol = [] repeat with tRowCounter = 0 to tCharImage.height if (aWhite) then tPixelCol.append(0) else if (aAntiAlias) then tPixelCol.append(tCharImage.getPixel(tColCounter, tRowCounter, #integer)) else tPixelCol.append(tCharImage.getPixel(tColCounter, tRowCounter, #integer) = 255) end if end if end repeat tPixelChar.append(tPixelCol) end repeat tCharImage = 0 if (aTrimWhite) then mTrimWhite(tPixelChar) -- if (NOT aAntiAlias and aChar <> " " AND aChar <> TAB) then tPixelChar = mRunLengthEncoding(tPixelChar) if (aChar <> " " AND aChar <> TAB AND aChar <> numToChar(160)) then tPixelChar = mRunLengthEncoding(tPixelChar) return tPixelChar end on mRescaleImage(aImage, aMaxWidth, aMaxHeight, aFillColor) tWidth = aImage.width tHeight = aImage.height tWidthScaler = aMaxWidth / float(tWidth) tHeightScaler = aMaxHeight / float(tHeight) tImage = image(aMaxWidth, aMaxHeight, aImage.depth) tImage.fill(tImage.rect, aFillColor) if (tWidthScaler <= tHeightScaler) then tScaler = tWidthScaler else tScaler = tHeightScaler end if tWidth = tWidth * tScaler tHeight = tHeight * tScaler tLeft = integer((tImage.width / 2) - (tWidth / 2)) tTop = integer((tImage.height / 2) - (tHeight / 2)) tDestRect = rect(tLeft, tTop, tLeft + tWidth, tTop + tHeight) tImage.copyPixels(aImage, tDestRect, aImage.rect) return tImage end