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

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 / pdf-imposer-drawbot.py
Created December 29, 2025 11:51
Tile a PDF for printing or PDF imposer in drawbot app
path = 'file.pdf'
w, h = imageSize(path, pageNumber=1)
points_to_mm = 25.4 / 72
mm_to_points = 72 / 25.4
bleed = 3 * mm_to_points # bleed size of the original PDF
margin = 5 * mm_to_points # margin size in the final export to display the bleed marks
canvas_w = w * 2 + margin * 2
canvas_h = h * 2 + margin * 2
count = numberOfPages(path)
print(f"Number of pages: {count}")
@typoman
typoman / setStartPointPen.py
Last active October 23, 2025 11:38
set start point on a glyph contour in python
from fontTools.pens.pointPen import AbstractPointPen
import defcon
class SetStartPointPen(AbstractPointPen):
"""
A point pen that changes the starting point of a contour.
This pen acts as a filter. It takes another point pen to draw to.
It buffers the points of the specified contour, reorders them
so that the point at `pointIndex` becomes the new starting point,
@typoman
typoman / closestPointPen.py
Last active September 26, 2025 10:16
A pen object that finds the closest point on a glyph's contours to a given target point using analytical method.
from fontgadgets.decorators import font_cached_method, font_method
import fontgadgets; fontgadgets.tools.DEBUG = True
from fontTools.pens.basePen import BasePen, DecomposingPen, MissingComponentError
import math
def bezier_curve(p0, p1, p2, p3, t):
x = (1 - t) ** 3 * p0[0] + 3 * (1 - t) ** 2 * t * p1[0] + 3 * (1 - t) * t ** 2 * p2[0] + t ** 3 * p3[0]
y = (1 - t) ** 3 * p0[1] + 3 * (1 - t) ** 2 * t * p1[1] + 3 * (1 - t) * t ** 2 * p2[1] + t ** 3 * p3[1]
return (x, y)
@typoman
typoman / Fix Contour Directions.py
Last active June 12, 2025 13:34
RoboFont script to fix contour direction for postscript curves (CFF/Cubic/OTF) on selected glyphs.
"""
RoboFont Script
based on:
https://gist.github.com/ryanbugden/a4ddf19cab034f837a51fb9d4f0db015
- Type: Mastering
- Purpose: To fix contour direction for postscript curves (CFF/Cubic/OTF) in selected glyphs.
- Specifications:
- Sorts contours by area and clusters them into contours that contain other contours
- Reverses the direction of contours in clusters where the largest contour is not clockwise
@typoman
typoman / funct-doc-test-decorator.py
Created June 10, 2025 14:37
A python decodator for creating samples for doctests right from the function calls
import inspect
def debug_decorator(func):
"""A decorator that if written behind a function, it prints the function
call and the return value. It's mainly useful for debugging and adding the
test functions calls to the function doctest.
Example:
>>> @debug_decorator
... def my_function(a, b, c=10):
... return a + b + c
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 / 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
@typoman
typoman / pythonSimpleRegexLexer.py
Last active January 22, 2025 13:10
Simple Lexer using regex in python
```
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 / arabic-kashida-in-lualatex-with-babel-with-control-over-the-stretching-using-the-word-spacing.tex
Created January 16, 2025 15:07
Arabic Scirpt kashida in lualatex with babel with control over the stretching using the word spacing
\documentclass{article}
\usepackage{multicol}
\usepackage[bidi = basic]{babel}
\babelprovide[
main,
import,
mapdigits,
justification=kashida,
transforms=kashida.base