Skip to content

Instantly share code, notes, and snippets.

View typoman's full-sized avatar
:electron:
Never stop learning!

Bahman Eslami typoman

:electron:
Never stop learning!
View GitHub Profile
@typoman
typoman / append_glyphs.py
Last active November 23, 2021 22:35
Append (transfer) a set of glyphs from one TTF font to another.
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 November 5, 2021 16:43
Get paths of included feature files in a ufo file.
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 August 10, 2021 14:33
Find ligature glyph names by parsing the GSUB using fonttools.feaLib
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
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 April 20, 2021 16:37
RoboFont CurrentSelection
"""
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 December 9, 2021 13:50
RoboFont Metrics Math
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 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 / simpleRFobserver.py
Created September 7, 2020 20:54
simple objective C observer inside RoboFont
"""
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 September 5, 2020 16:16
Finds currently availabe keyboard layout input sources in Mac OSX using pyobjc.
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
"""
@typoman
typoman / pythonTestingUsingUnitTestCheatSheet.md
Created August 19, 2020 17:19
Python Testing Using UnitTest Cheatsheet

Unittest structure

import unittest

class TestAModule(unittest.TestCase):

    def setUp(self):
        # create test data
        pass