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 / intersectPen.py
Created February 7, 2024 16:58
Get intersection points of list of lines with a glyph in a font
from fontTools.pens.basePen import BasePen
from fontTools.misc.bezierTools import calcCubicParameters, solveCubic, _alignment_transformation, cubicPointAtT, _line_t_of_pt, linePointAtT
def _curve_line_intersections_t(curve, line):
aligned_curve = _alignment_transformation(line).transformPoints(curve)
a, b, c, d = calcCubicParameters(*aligned_curve)
intersections = solveCubic(a[1], b[1], c[1], d[1])
return sorted(i for i in intersections if 0.0 <= i <= 1)
def curveLineIntersections(curve, line):

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?

@typoman
typoman / robofont-key-binding-doom-emacs-config.el
Last active April 14, 2023 17:07
Run the script from doom emacs inside RoboFont using the key sequence "leader r f"
(defun run-robofont ()
"Run current python file inside roboFont."
(interactive)
(when (eq major-mode 'python-mode)
(let ((file-path (buffer-file-name)))
(when file-path
(shell-command (concat "roboFont '" file-path "';open '/Applications/RoboFont.app'"))))))
(map! :map python-mode-map
:leader
@typoman
typoman / addSnippet.py
Last active September 21, 2023 16:28
UI form for adding snippets to espanso
import os
import sys
"""
Add {cb} anywhere inside the replacement to make it replaced with the contents
of the clipboard.
"""
transMap = str.maketrans({
"\n": '\\n',
"\\": '\\\\',
"\"": '\\"',
@typoman
typoman / toggle_nonExport.py
Created January 24, 2023 15:23 — forked from ryanbugden/toggle_nonExport.py
Go through all selected glyphs, and change whether they are set to export or non-export, based on the opposite of the state of the first glyph.
# menuTitle: Skip Export - Mass Toggle Selected
# source: https://gist.github.com/ryanbugden/7f20d42ef45ed0d657ad4f744bf9a373#file-toggle_nonexport-py
'''
Go through all selected glyphs, and change whether they are set to export or non-export, based on the opposite of the state of the first glyph.
2021.10.28
'''
f = CurrentFont()
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 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)