Subset custom font

Hi everyone,

I create a lot of online ads where I create the texts as graphics (PNG) before I load them into HYPE. Now I would like to load a custom font into HYPE, which is no problem. Since the font file is saved with a complete set of glyphs when exported, I thought there might be a way to include "subsetting for fonts" in an export script? The fonts used should only contain the letters that actually appear in the banner. I was thinking of "Glyphhanger" or the Fontsquirrel API. Does anyone have any ideas on how to implement this?
Thank you very much.

Regards
Sebastian

I recently did something like this, Font Forge is your friend here: Download FontForge

  1. Open the TTF font in FontForge.
  2. Go to View > Glyph Window to open the glyph overview.
  3. Select the characters you want to keep (A-Z in your example). You can do this by:
  • Clicking and dragging a selection box.
  • Using the "Select by Range" option in the Edit menu.
  • Entering a wildcard expression like "A-Z" in the "Select by Wildcards" option.
  1. Invert the selection by going to Edit > Selection > Invert Selection . This will select all characters except the ones you want to keep.
  2. Go to Element > Detach and Remove Glyphs . This will delete the selected characters, leaving only the desired subset.
  3. Finally, save the font as a new file.

Here's a starting point to do this in Python which could be run via a Hype Export Script if anyone want to run with this.

# start by installing fontforge with brew install fontforge
import fontforge

# Open the TTF font
font = fontforge.open('/path/to/your/font.ttf')

# Clear current selection
font.selection.none()

# Select glyphs for "My Headline"
for char in "My Headline":
    font.selection.select(('more',), ord(char))

# Invert the selection to select everything but "My Headline"
font.selection.invert()

# Delete the selected glyphs
font.clear()

# Save the font as a new file
font.generate('/path/to/your/modified_font.ttf')

# Close the font
font.close()

You can also use an online service like transfonter to export subsets or specific glyphs as a webfont from a regular font file.

3 Likes

Thank you very much for your answers. I know I could reduce the font characters manually using various tools. Since I will be creating over 100 banners, this is a big (time) effort. I therefore thought that this could be included in the export script.

I will follow Daniel's approach and adapt the export script. In addition, the query for the text used should be made in the index.html so that the letters used do not have to be entered manually each time.

1 Like