Skip to content

Instantly share code, notes, and snippets.

@anthrotype
Last active March 3, 2020 11:04
Show Gist options
  • Select an option

  • Save anthrotype/8c08eb372df2fb5da311887b32c2b9ac to your computer and use it in GitHub Desktop.

Select an option

Save anthrotype/8c08eb372df2fb5da311887b32c2b9ac to your computer and use it in GitHub Desktop.
import sys
from fontTools import ttLib
from fontTools.ttLib.tables import sbixStrike
from fontTools.ttLib.tables import sbixGlyph
ttfont = ttLib.TTFont()
# https://docs.microsoft.com/en-us/typography/opentype/spec/sbix
sbix = newTable("sbix")
# Apple Color Emoji.ttc has these bitmap strike sizes
# TODO add --bitmap-sizes option
bitmap_sizes = [20, 26, 32, 40, 48, 52, 64, 96, 160]
# Apple Emoji uses this
resolution = 72
# this can be also 'pdf', or special value 'dupe' which indicates that the
# imageData field contains a uint16, big-endian glyph ID.
# The bitmap data for the indicated glyph is used for the current glyph (a bit
# like composite glyphs in glyf table).
graphic_fype = "png"
for ppem in bitmap_sizes:
strike = sbixStrike.Strike(ppem=ppem, resolution=resolution)
# for each glyph...
glyph_name = "a"
# TODO: use cairosvg to rasterize svg to PNG at given sizes
image_data = b"\0\0\0\0"
strike.glyphs[glyph_name] = sbixGlyph.Glyph(
glyphName=glyph_name,
graphicType=graphic_fype,
imageData=image_data,
# these can be used to shift the bitmap image
# originOffsetX=0,
# originOffsetY=0,
)
sbix.strikes[ppem] = strike
ttfont["sbix"] = sbix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment