Skip to content

Instantly share code, notes, and snippets.

Avatar
:electron:
Never stop learning!

Bahman Eslami typoman

:electron:
Never stop learning!
View GitHub Profile
@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 Apr 18, 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
"""
@typoman
typoman / pythonTestingUsingUnitTestCheatSheet.md
Created Aug 19, 2020
Python Testing Using UnitTest Cheatsheet
View pythonTestingUsingUnitTestCheatSheet.md

Unittest structure

import unittest

class TestAModule(unittest.TestCase):

    def setUp(self):
        # create test data
        pass
@typoman
typoman / pythonSimpleRegexLexer.py
Last active Apr 16, 2021
Simple Lexer using regex in python
View pythonSimpleRegexLexer.py
```
import re
from collections import namedtuple
Token = namedtuple('Token', ['type', 'value', 'line', 'column'])
class Lexer(object):
_KEYWORDS = {
'if': 'IF_CONDITION',
'while': 'WHILE_LOOP',
@typoman
typoman / overrideRFKeys.py
Created Jul 31, 2020
Override RoboFont keys
View overrideRFKeys.py
import AppKit
from vanilla import *
myHotKeys = {'⌘s', '⇧⌘s', '⌘q', '⇧⌘q'}
MODIFIER_INT_TO_STR = {
1048840: '⌘',
262401: '⌃',
524576: '⌥',
131330: '⇧',