SOLVED All Bitmap Font
-
Is it possible to use Robofont to generate a font file that is all from bitmaps?
I have a series of PNGs for each glyph, generated from a 3D program that I'd like to turn into a font file. I can import and see the bitmap in the Glyph Editor (excuse the image quality) but in the preview window I see this symbol, not the bitmap. Then when I generate the font and try to install it, via Fontbook, I don't see the bitmap glyphs in the Fontbook preview.
To be sure, I made some test vector glyphs, for troubleshooting, and these do appear in Fontbook.
I want to know if what I'm trying to do is possible (an all bitmap font file without tracing or vectorizing) and if there are steps unique to generating bitmap fonts that I'm missing.
-
he Matt
It is possible to import an image into a glyph. The image will be visible when you make the font overview cell bigger (see the slider at the bottom)
RF does not generate color fonts. There are already some extensions generating color fonts like RoboChrome. However RoboChrome does not build
SIBX
table from glyph image data.Here is a small script that does generate a .ttf and adds all images in a
SBIX
table.hope this helps:
import os from fontTools.ttLib import TTFont from fontTools.ttLib.tables._s_b_i_x import table__s_b_i_x from fontTools.ttLib.tables.sbixStrike import Strike from fontTools.ttLib.tables.sbixGlyph import Glyph as sbixGlyph from lib.tools.misc import tiff2png import AppKit bitmapSizes = [1000] font = CurrentFont() def getImageData(image): x, y, maxx, maxy = image.bounds w = maxx - x h = maxy - y ciImage, imageRect = glyph.image.getRepresentation("doodle.CIImageFiltered") alpha = 1 if image.color: alpha = image.color.alpha im = AppKit.NSImage.alloc().initWithSize_((w, h)) im.lockFocus() t = AppKit.NSAffineTransform.alloc().init() t.setTransformStruct_(image.transformation) t.concat() ciImage.drawAtPoint_fromRect_operation_fraction_((-x, -y), imageRect, AppKit.NSCompositeSourceOver, alpha) im.unlockFocus() return tiff2png(im.TIFFRepresentation()) if font is not None: ttfpath = os.path.join(os.path.dirname(__file__), f"{font.info.familyName}-{font.info.styleName}.ttf") font.generate(format="ttf", path=ttfpath) ft = TTFont(ttfpath) sbix = table__s_b_i_x("sbix") for ppem in sorted(bitmapSizes): currentStrike = Strike(ppem=ppem) for glyph in font: if glyph.image: imageData = getImageData(glyph.image) originOffsetX, originOffsetY = glyph.image.offset currentStrike.glyphs[glyph.name] = sbixGlyph( glyphName=glyph.name, graphicType="png", originOffsetX=int(round(originOffsetX)), originOffsetY=int(round(originOffsetY)), imageData=imageData ) sbix.strikes[ppem] = currentStrike ft["sbix"] = sbix ft.save(ttfpath) ft.close()