Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python3
#
# This script prepares fonts for use for embedded software. It minimizes them
# (to reduce size and increase performance), encodes them into C files (needed
# by devices without file systems), and prints debug info.
#
# When minimizing, it subsets the glyphs (to a latin set as-is here) and strips
# out layout features. It provides options for whether to keep kerning and in
# which format.
#
@anthrotype
anthrotype / scale_ufo.py
Last active June 4, 2020 14:39
Script that uses ufo2ft (>= 2.14) TransformationsFilter to scale the UPEM of a UFO
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@khaledhosny
khaledhosny / cldr-coverage.py
Last active May 8, 2020 15:49
Calculate font script and language coverage based on ICU exemplar data
# Copyright 2020 Khaled Hosny
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
@kylehowells
kylehowells / ast2text.py
Last active April 8, 2021 22:10
Extract the plain text from markdown, for plain text search.
import commonmark
with open('test.md', 'r') as myfile:
text = myfile.read()
parser = commonmark.Parser()
ast = parser.parse(text)
# Returns the text from markdown, stripped of the markdown syntax itself
def ast2text(astNode):
@arrowtype
arrowtype / README.md
Last active July 28, 2022 05:38
This is a set of Python I use many times I wish to make an animation or multipage doc with Drawbot, but coded in my preferred editor (currently, VS Code)

Using Drawbot in an external editor

This is a set of Python I use many times I wish to make an animation or multipage doc with Drawbot, but code in my preferred editor (currently, VS Code) rather than in the Drawbot app.

Usage

First, install DrawBot as a module:

pip install git+https://github.com/typemytype/drawbot
@raphlinus
raphlinus / decompose_var.py
Created December 7, 2019 20:01
Script to decompose components with mismatched 2x2 matrix
# Script to decompose components with mismatched 2x2 matrix
# See https://github.com/googlefonts/fontmake/issues/595
for glyph in Glyphs.font.glyphs:
#print glyph
xforms = []
mismatch = []
for (i, layer) in enumerate(glyph.layers):
for (j, component) in enumerate(layer.components):
if i == 0:
xforms.append(component.transform)
@mjlagattuta
mjlagattuta / fixBrackets.py
Last active March 10, 2022 04:31
Setup glyphs file with bracket layers for fontmake build, and generate a python file to run on the final ttf to add the feature vars
# Copyright 2019 Michael LaGattuta
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@gbaman
gbaman / graphql_example.py
Created November 1, 2017 00:18
An example on using the Github GraphQL API with Python 3
# An example to get the remaining rate limit using the Github GraphQL API.
import requests
headers = {"Authorization": "Bearer YOUR API KEY"}
def run_query(query): # A simple function to use requests.post to make the API call. Note the json= section.
request = requests.post('https://api.github.com/graphql', json={'query': query}, headers=headers)
if request.status_code == 200:
@SKempin
SKempin / Git Subtree basics.md
Last active October 23, 2024 04:12
Git Subtree basics

Git Subtree Basics

If you hate git submodule, then you may want to give git subtree a try.

Background

When you want to use a subtree, you add the subtree to an existing repository where the subtree is a reference to another repository url and branch/tag. This add command adds all the code and files into the main repository locally; it's not just a reference to a remote repo.

When you stage and commit files for the main repo, it will add all of the remote files in the same operation. The subtree checkout will pull all the files in one pass, so there is no need to try and connect to another repo to get the portion of subtree files, because they were already included in the main repo.

Adding a subtree

Let's say you already have a git repository with at least one commit. You can add another repository into this respository like this:

@gramian
gramian / hack4tex
Last active April 23, 2017 08:52
A small script to use the hack truetype font in pdflatex
#!/bin/sh
# hack4tex 0.1
# Copyright (c) 2016 Christian Himpe
# released under BSD 2-Clause License ( opensource.org/licenses/BSD-2-Clause )
# based on Stephan Lehmke's answer to "How do I use TrueType Fonts with PDFTeX
# using otftotfm?" on tex.stackexchange.com/a/52902
#
# requires otftotfm which is part of lcdf-typetools
#