Skip to content

Instantly share code, notes, and snippets.

View rbmntjs's full-sized avatar

Robin Mientjes rbmntjs

View GitHub Profile
@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()
IGNORE_ANCHORS = []
# ----------------------------------------
def match_anchor(anchor_source, anchor_targets):
if anchor_source.name.startswith("_"):
target_name = anchor_source.name[1:]
else:
target_name = "_" + anchor_source.name
for a in anchor_targets:
@LettError
LettError / obliqueScale.py
Created October 12, 2021 10:10
Horizontal scaling while preserving the italic angle. (by "unskewing" the geometry to "upright", then scaling, then "reskewing" back to the italic angle)
from fontTools.pens.transformPen import TransformPen
from fontTools.pens.pointPen import AbstractPointPen
from fontTools.misc.transform import Transform
import math
from defcon.objects.glyph import Glyph
class TransformPen2(TransformPen):
# because we don't want to change the transform matrix of the actual components
def addComponent(self, glyphName, transformation):
@typoman
typoman / expand-groups-to-components.py
Last active June 17, 2023 16:07
A RoboFont script to expand kerning groups from base glyph to their composites.
from simpleKerning import *
"""
A RoboFont script to expand kerning groups from base glyph to their composites.
1. Select the composites which are not grouped
2. Run the script
3. The groups will be expanded to the composites, if:
- Their width is same as the base glyph
- They're not already grouped
"""
@typoman
typoman / update-composite-metrics.py
Last active January 28, 2022 14:32
Updates composites margins based on the base letter margins.
"""
RoboFont Script
- Type: Composite/Margins
- Purpose: Updates composites (a glyph which **only** has components e.g accented
letters) margins based on the base letter margins.
- Specifications:
- Determines the base letter according to (in order): unciode,
anchor names, glyph surface area (the darkest shape is the letter),
glyph width (if it's zero then it's accent).
- If the base letter is shifted in the composte (mostly by accident), it
@okay-type
okay-type / interpolated-spacecenter.py
Last active February 25, 2020 12:11
A very simple, very rough interpolated spacecenter window for Robofont
# menuTitle : Interpolated Preview
'''
v 0.2
jackson @ okaytype
to do:
- clean up imports
- better performance
- needs a smarter, cheaper redraw trigger
- only redraw/reinterpolate the current glyph when changed, keep others
import os
import shutil
from mojo.events import addObserver
"""
Goal: Create a UFOZ automatically when a UFO is saved.
Off the top of my head, I can think of a few ways to do this:
1. Make a copy of the font object, save as UFOZ, discard the
@okay-type
okay-type / test-preferences.py
Last active October 22, 2019 15:37
Testing saving/loading preferences in robofont
from vanilla import Window, EditText, Button
from mojo.extensions import setExtensionDefault, getExtensionDefault, registerExtensionDefaults, removeExtensionDefault
class preferenceTest(object):
def __init__(self):
self.windowname = 'pref save / load test'
self.prefKey = 'com.okaytype.toolName'
self.makeWindow()
@nicksherman
nicksherman / screen_info.py
Last active November 12, 2023 17:37 — forked from justvanrossum/screen_info.py
macOS/Python: Get dimension info about active screens
from AppKit import NSScreen, NSDeviceSize, NSDeviceResolution
from Quartz import CGDisplayScreenSize
for i, screen in enumerate(NSScreen.screens(), 1):
description = screen.deviceDescription()
pw, ph = description[NSDeviceSize].sizeValue()
rx, ry = description[NSDeviceResolution].sizeValue()
mmw, mmh = CGDisplayScreenSize(description["NSScreenNumber"])
scaleFactor = screen.backingScaleFactor()
pw *= scaleFactor
@frankrolf
frankrolf / glyph_recompose_according_to_anchor.py
Created April 16, 2019 10:45
Robofont script to reset a composite glyph according to the anchor found in the base glyph.
import math
def largest_component(g):
if not g.components:
return
else:
boxList = []
for c in g.components:
boxList.append(