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()