Skip to content

Instantly share code, notes, and snippets.

Avatar
:electron:
Never stop learning!

Bahman Eslami typoman

:electron:
Never stop learning!
View GitHub Profile
View createGlyphConstructionFromComposites.py
from mojo.UI import *
"""
RoboFont Script
- Type: Composites
- Purpose: To create RoboFont glyph construction syntax out of the exisiting
composites inside a font using the anchor names.
- Specifications:
- Determines the base letter and marks according to anchor names.
- Reconstruct the glyphConstruction syntax from the anchor names.
- Publish Date: 7 Dec 2020
@typoman
typoman / append_glyphs.py
Last active Nov 23, 2021
Append (transfer) a set of glyphs from one TTF font to another.
View append_glyphs.py
from fontTools.ttLib import TTFont
import argparse
import os
import sys
"""
Transfer glyphs from one set of fonts from soucre dir to target dir.
The file names should match and fonts should be ttf. This script does
not transfer kerning, marks or substitutions in the features. Usage:
python append_glyphs.py -h
"""
@typoman
typoman / getIncludedFeautreFilesPaths.py
Last active Nov 5, 2021
Get paths of included feature files in a ufo file.
View getIncludedFeautreFilesPaths.py
from fontTools.feaLib.ast import IncludeStatement
from fontTools.feaLib.parser import Parser
from io import StringIO
import os
from pathlib import PurePath
"""
Get paths of included feature files in a ufo file.
This script makes an assumption feature are written inside the `ufo.features.text`.
Features could be written inside another file that could exist next to the UFO
package (instead of inside the UFO package). This script doesn't support that yet.
@typoman
typoman / findLigaturesInGsub.py
Last active Aug 10, 2021
Find ligature glyph names by parsing the GSUB using fonttools.feaLib
View findLigaturesInGsub.py
from fontTools.feaLib.parser import Parser
from fontTools.feaLib.ast import *
from io import StringIO
"""
RoboFont Script
- Type: Mastering
- Purpose: To find ligature by parsing the features.
- Specifications:
- Parse the substitutions in the current font features using fontTools.feaLib
- Find lookup references in the provided feature tags
View expand-stroke.py
from fontParts.fontshell.font import RFont
from fontTools.pens.cocoaPen import CocoaPen
f = RFont("expand-stroke.ufo") # a ufo with one line path for a glyph (no closed contours)
canvasSize = 800
numFrames = 200
def getGlyphPath(glyph):
pen = CocoaPen(glyph.font)
@typoman
typoman / currentSelection.py
Created Apr 20, 2021
RoboFont CurrentSelection
View currentSelection.py
"""
RoboFont Script
- Type: UI/start up
- Purpose: Runs on RF start up and adds a function to mojo.UI module:
CurrentSelection() which returns the selected RGlyph object(s)
based on what window is active.
- Specifications:
- Find which window is active using mojo.UI.CurrentWindow then return the Glyph(s)
- Publish Date: 20 April 2020
- Author: Bahman Eslami
@typoman
typoman / metric-math.py
Last active Dec 9, 2021
RoboFont Metrics Math
View metric-math.py
from glyphConstruction import *
from mojo.UI import CurrentWindow
"""
RoboFont Script
- Type: Metrics
- Purpose: Fix metrics of selected glyphs according to a formula.
- Specifications:
- Uses RoboFont GlyphConstruction syntax to change metrics of glyphs.
- Publish Date: 18 April 2021
@typoman
typoman / expand-groups-to-components.py
Last active Jan 26, 2021
A RoboFont script to expand kerning groups from base glyph to their composites.
View expand-groups-to-components.py
from mojo.UI import CurrentWindow
from simpleKerning import *
"""
A RoboFont script to expand kerning groups from base glyph to their composites.
You need the simple kerning extension installed for this to work.
1. Select base glyph(s) (with contours) which are already grouped
2. Run the script
3. The groups will be expanded to the composites, if:
- Their width is same as the base glyph
@typoman
typoman / simpleRFobserver.py
Created Sep 7, 2020
simple objective C observer inside RoboFont
View simpleRFobserver.py
"""
You can use this to get the window name if it has become the key window in
RoboFont. But the same data model can be used to create notifications inside
objc apps.
"""
from objc import python_method
import AppKit
from vanilla import FloatingWindow
from lib.tools.debugTools import ClassNameIncrementer
@typoman
typoman / osxKeyboardInputSources.py
Last active Sep 5, 2020
Finds currently availabe keyboard layout input sources in Mac OSX using pyobjc.
View osxKeyboardInputSources.py
import ctypes
import ctypes.util
import objc
import CoreFoundation
"""
Find currently availabe keyboard layout input sources in Mac OSX using pyobjc. Based on:
https://gist.github.com/tiann/f85e89bef4b6e9b83f2a
"""