Skip to content

Instantly share code, notes, and snippets.

@typoman
typoman / segment symbols pen.py
Last active September 18, 2024 10:54
A pen class for converting glyph outlines into symbolic representations. The resulting string can be used for quick visual comparison or analysis of glyph shapes without rendering the full outline.
from typing import Tuple, Optional
from fontTools.pens.basePen import BasePen
from fontTools.misc.arrayTools import calcBounds
import math
def round_angle_to_step(angle: float, degree: int) -> int:
"""
Rounds an angle to the nearest degree increment.
Args:
@typemytype
typemytype / rotateSubscribers.py
Created April 10, 2024 15:59
RoboFont subscriber to rotate both the glyph view and space center to help out drawing Mongolian, where the letter shapes are stored in binaries 90° rotated.
"""
RoboFont subscriber to rotate both the glyph view and space center to help out drawing Mongolian,
where the letter shapes are stored in binaries 90° rotated.
"""
from AppKit import NSNotificationCenter, NSViewFrameDidChangeNotification
import ezui
from mojo.subscriber import Subscriber, registerSpaceCenterSubscriber, unregisterSpaceCenterSubscriber, registerGlyphEditorSubscriber, unregisterGlyphEditorSubscriber, WindowController
from mojo.tools import CallbackWrapper
@justvanrossum
justvanrossum / rename_fea_glyphs.py
Last active May 21, 2024 13:32
Rename glyph names in OpenType feature files
from functools import singledispatch
from io import StringIO
from fontTools.feaLib import ast
from fontTools.feaLib.error import FeatureLibError
from fontTools.feaLib.parser import Parser
def renameGlyphs(feaSource, renameFunc, glyphNames=()):
features = Parser(StringIO(feaSource), glyphNames=glyphNames).parse()
@connordavenport
connordavenport / RKerning_SmartSet.py
Created February 14, 2024 16:08
An RKerning add on to allow for setting kerning pairs without having to know the group names
def smartSet(self, pair, value, exceptionType=None):
'''
pair must be a tuple, its contents can be a glyphName or a group's name
value must be an integer, why would you even kern on fractions....
exceptionType is the level of searching the function will do
None : use the top level group or glyph names, no exceptions
g2G : glyph to Group exception
g2g : glyph to glyph exception
G2g : Group to glyph exception
@LettError
LettError / responsive_drawbot_animated.py
Created December 4, 2023 11:19
Drawbot output for responsive lettering UFO
#
# script for drawbot extension in robofont
# draws a fitted / interpolating image from a responsive lettering ufo
# [email protected] / 20231204
def ip(a, b, f):
return a + f * (b-a)
page = (659, 500) # image size
margin = 59 # nice to have a margin
@connordavenport
connordavenport / frontAndCenterPopover.py
Last active December 7, 2023 20:27
a simply RF popover to jump between fonts
import ezui
from merz.tools.drawingTools import NSImageDrawingTools
from mojo.UI import AllFontWindows, CurrentFontWindow, AllWindows, CurrentGlyphWindow
class frontAndCenter(ezui.WindowController):
def build(self, parent, viewType):
self.buttonMap = {}
self.parent = parent
@connordavenport
connordavenport / fitTextToWidth_SpaceCenter.py
Created September 16, 2023 16:18
Fit the current space center text to the view width, it measures the longest line (broken up by newlines) and scales it based on that.
from mojo.UI import CurrentSpaceCenter
def measureLine(pointSize, records):
scale = pointSize / window.font.info.unitsPerEm
sublists = []
currentSublist = []
lineBreakChar = "NewLineGlyph"
for item in records:
if item.glyph.objectName == lineBreakChar:
@connordavenport
connordavenport / AutoNaming.py
Last active September 3, 2023 19:29
Subsriber to automatically set font name entries when info has changed
from mojo.subscriber import Subscriber, registerCurrentFontSubscriber
import unicodedata
class AutoNameSetter(Subscriber):
debug = True
def build(self):
pass

OpenType font name table notes

Provided are the name table record ID and instructions on how to fill it out. Arial is used as an example to show how the names records can be filled. You can see the example records here:

https://learn.microsoft.com/en-us/typography/opentype/spec/namesmp

There are also more exmaples added to the bottom of this file.

Why this document?

@typemytype
typemytype / glyphLineController.py
Last active August 28, 2023 11:13
show multiple glyphs in a glyph editor RF4
# this scripts add a input field at the top of your glyph window
# the input text is converted to a list of glyphs objects
# and set into the glyph editor
# jump around with `esc` and select to edit by hitting a glyph
from mojo.UI import GlyphSequenceEditText
from mojo.subscriber import Subscriber, registerGlyphEditorSubscriber
class GlyphLineController(Subscriber):