Skip to content

Commit

Permalink
chore: add glyphs porting utility
Browse files Browse the repository at this point in the history
  • Loading branch information
mishamyrt committed Jul 31, 2024
1 parent d58599d commit 690ebb4
Show file tree
Hide file tree
Showing 18 changed files with 105 additions and 133 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ VENV_DIR = ./venv
VENV = . $(VENV_DIR)/bin/activate;

define build-glyphs
@$(VENV) python $(SCRIPTS_DIR)/lilex.py \
@$(VENV) python $(SCRIPTS_DIR)/font.py \
-i "$(1)" \
-f $(3) \
build $(2)
Expand Down Expand Up @@ -91,7 +91,7 @@ preview: ## show CLI special symbols preview

.PHONY: generate
generate: ## regenerate the font sources with classes and features
@$(VENV) python $(SCRIPTS_DIR)/lilex.py generate
@$(VENV) python $(SCRIPTS_DIR)/font.py generate

.PHONY: build
build: ## build the font
Expand Down
1 change: 1 addition & 0 deletions __snapshots__/missing_glyphs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["Hcedilla", "Oogonek", "hcedilla", "idotless", "oogonek", "germandbls.cv05", "germandbls.cv12", "ge-cy.loclBGR", "ii-cy.loclBGR", "iishort-cy.loclBGR", "iigrave-cy.loclBGR", "pe-cy.loclBGR", "te-cy.loclBGR", "tse-cy.loclBGR", "sha-cy.loclBGR", "shcha-cy.loclBGR", "softsign-cy.loclBGR", "hardsign-cy.loclBGR", "ia-cy.loclBGR", "Alpha", "Beta", "Gamma", "Delta.002", "Epsilon", "Zeta", "Eta", "Theta", "Iota", "Kappa", "Lambda", "Mu", "Nu", "Xi", "Omicron", "Pi", "Rho", "Sigma", "Tau", "Upsilon", "Phi", "Chi", "Psi", "Omega.001", "Alphatonos", "Epsilontonos", "Etatonos", "Iotatonos", "Omicrontonos", "Upsilontonos", "Omegatonos", "Iotadieresis", "Upsilondieresis", "Delta.001", "alpha", "beta", "gamma", "delta", "epsilon", "zeta", "eta", "theta", "iota", "kappa", "lambda", "mu.001", "nu", "xi", "omicron", "rho", "sigmafinal", "sigma", "tau", "upsilon", "phi", "chi", "psi", "omega", "iotatonos", "iotadieresis", "iotadieresistonos", "upsilontonos", "upsilondieresis", "upsilondieresistonos", "omicrontonos", "omegatonos", "alphatonos", "epsilontonos", "etatonos", "alpha.alt01", "alphatonos.alt01", "mu.001.alt", "narrownbspace", "anoteleia", "questiongreek", "colon.valign_eq", "colon.valign_num", "hyphen_hyphen.liga", "parenleft_asterisk.liga", "braceleft_bar.liga", "bracketleft_bar.liga", "bracketright_numbersign.liga", "period_period.liga", "period_period_period.liga", "period_period_equal.liga", "period_period_less.liga", "period_question.liga", "colon_colon.liga", "colon_colon_colon.liga", "colon_colon_equal.liga", "colon_equal.liga", "semicolon_semicolon.liga", "exclam_exclam.liga", "exclam_exclam_period.liga", "exclam_equal.liga", "exclam_equal_equal.liga", "question_period.liga", "question_question.liga", "question_equal.liga", "asterisk_parenright.liga", "asterisk_asterisk.liga", "asterisk_asterisk_asterisk.liga", "asterisk_greater.liga", "asterisk_slash.liga", "numbersign_parenleft.liga", "numbersign_braceleft.liga", "numbersign_bracketleft.liga", "numbersign_colon.liga", "numbersign_exclam.liga", "numbersign_question.liga", "numbersign_equal.liga", "slash_asterisk.liga", "slash_greater.liga", "slash_slash.liga", "slash_slash_slash.liga", "underscore_underscore_parenleft.liga", "hyphen_end.seq", "hyphen_middle.seq", "hyphen_start.seq", "colon_equal_middle.seq", "exclam_equal_middle.seq", "numbersign_end.seq", "numbersign_middle.seq", "numbersign_start.seq", "slash_equal_end.seq", "slash_equal_middle.seq", "slash_equal_start.seq", "slash_slash_equal_end.seq", "slash_slash_equal_middle.seq", "slash_slash_equal_start.seq", "underscore_end.seq", "underscore_middle.seq", "underscore_start.seq", "exclam_equal.liga.ss02", "exclam_equal_equal.liga.ss02", "numbersign_end.ss04.seq", "numbersign_middle.ss04.seq", "numbersign_start.ss04.seq", "asterisk.cv10", "period.spacer", "colon.spacer", "semicolon.spacer", "exclam.spacer", "question.spacer", "asterisk.spacer", "numbersign.spacer", "slash.spacer", "backslash.ss03", "hyphentwo", "nonbreakinghyphen", "hyphen.spacer", "underscore.spacer", "parenleft.spacer", "braceleft.spacer", "bracketleft.spacer", "bracketright.spacer", "guillemetleft", "guillemetright", "ampersand_ampersand.liga", "bar_braceright.liga", "bar_bracketright.liga", "bar_bar.liga", "bar_bar_bar.liga", "bar_bar_bar_greater.liga", "bar_bar_greater.liga", "bar_greater.liga", "dollar_greater.liga", "plus_plus.liga", "plus_plus_plus.liga", "plus_greater.liga", "equal_colon_equal.liga", "equal_exclam_equal.liga", "equal_equal.liga", "equal_equal_equal.liga", "greater_equal.liga", "greater_greater.liga", "greater_greater_greater.liga", "less_exclam_hyphen_hyphen.liga", "less_asterisk.liga", "less_asterisk_greater.liga", "less_bar.liga", "less_bar_bar.liga", "less_bar_bar_bar.liga", "less_bar_greater.liga", "less_dollar.liga", "less_dollar_greater.liga", "less_plus.liga", "less_plus_greater.liga", "less_equal.liga", "less_greater.liga", "less_less.liga", "less_less_less.liga", "less_asciitilde.liga", "less_asciitilde_greater.liga", "less_asciitilde_asciitilde.liga", "less_slash.liga", "less_slash_greater.liga", "asciitilde_greater.liga", "asciitilde_asciitilde.liga", "asciitilde_asciitilde_greater.liga", "asciicircum_equal.liga", "percent_percent.liga", "bar_hyphen_end.seq", "bar_hyphen_middle.seq", "bar_hyphen_start.seq", "bar_bar_hyphen_end.seq", "bar_bar_hyphen_middle.seq", "bar_bar_hyphen_start.seq", "bar_bar_equal_end.seq", "bar_bar_equal_middle.seq", "bar_bar_equal_start.seq", "bar_equal_end.seq", "bar_equal_middle.seq", "bar_equal_start.seq", "bar_underscore_middle.seq", "equal_end.seq", "equal_middle.seq", "equal_start.seq", "greater_hyphen_end.seq", "greater_hyphen_middle.seq", "greater_hyphen_start.seq", "greater_equal_end.seq", "greater_equal_middle.seq", "greater_equal_start.seq", "greater_greater_hyphen_end.seq", "greater_greater_hyphen_middle.seq", "greater_greater_hyphen_start.seq", "greater_greater_equal_end.seq", "greater_greater_equal_middle.seq", "greater_greater_equal_start.seq", "less_hyphen_end.seq", "less_hyphen_middle.seq", "less_hyphen_start.seq", "less_equal_end.seq", "less_equal_middle.seq", "less_equal_start.seq", "less_less_hyphen_end.seq", "less_less_hyphen_middle.seq", "less_less_hyphen_start.seq", "less_less_equal_end.seq", "less_less_equal_middle.seq", "less_less_equal_start.seq", "greater_equal.liga.cv08", "less_equal.liga.cv08", "dollar_greater.liga.cv09", "less_dollar.liga.cv09", "less_dollar_greater.liga.cv09", "bar_greater.liga.cv11", "less_bar.liga.cv11", "equal_equal.liga.ss02", "equal_equal_equal.liga.ss02", "powerSymbol", "powerOnOffSymbol", "heavyCircle", "powerOnSymbol", "powerSleepSymbol", "ampersand.spacer", "bar.spacer", "euro", "cent.cv09", "dollar.cv09", "dollar.spacer", "ratio", "greater.center", "less.center", "asciitilde.original", "plus.spacer", "equal.spacer", "greater.spacer", "less.spacer", "asciitilde.spacer", "asciicircum.spacer", "percent.spacer", "upArrow", "upArrowright", "rightArrow", "downArrowright", "downArrow", "downArrowleft", "leftArrow", "upArrowleft", "leftArrowright", "upArrowdown", "upArrowleftcorner", "upArrowrightcorner", "downArrowleftcorner", "downArrowrightcorner", "rightArrowdowncorner", "rightArrowupcorner", "leftArrowdowncorner", "leftArrowupcorner", "downArrowcounterclockhalf", "downArrowclockhalf", "upArrowleftcounterclock", "upArrowrightclock", "rightArrowleftArrow", "leftArrowrightArrow", "dneighthfullBlock", "dnquarterfullBlock", "dnthreeeighthsfullBlock", "dnhalffullBlock", "dnfiveeighthsfullBlock", "dnthreequartersfullBlock", "dnseveneighthsfullBlock", "fullfullBlock", "uphalffullBlock", "upeighthfullBlock", "lefteighthfullBlock", "leftquarterfullBlock", "leftthreeeighthsfullBlock", "lefthalffullBlock", "leftfiveeighthsfullBlock", "leftthreequartersfullBlock", "leftseveneighthsfullBlock", "righthalffullBlock", "righteighthfullBlock", "lightshademedium", "mediumshademedium", "darkshademedium", "blackCircle", "whiteCircle", "largeCircle", "leftHalfBlackWhiteCircle", "rightHalfBlackWhiteCircle", "lowerHalfBlackWhiteCircle", "upperHalfBlackWhiteCircle", "leftHalfBlackCircle", "rightHalfBlackCircle", "upperRightBlackCircle", "upperLeftArc", "upperRightArc", "lowerRightArc", "lowerLeftArc", "tonos", "tonos.case", "dieresistonos", "uniE0A0", "uniE0A1", "uniE0A2", "uniE0B0", "uniE0B1", "uniE0B2", "uniE0B3", "dotlessjdotbelow", "idotlessdotbelow", "idotlessogonek", "st.ordn", "upArrowleftcounterclock.alt01", "upArrowrightclock.alt01"]
3 changes: 0 additions & 3 deletions scripts/builder/__init__.py

This file was deleted.

107 changes: 0 additions & 107 deletions scripts/find.py

This file was deleted.

5 changes: 2 additions & 3 deletions scripts/lilex.py → scripts/font.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
from argparse import BooleanOptionalAction

from arrrgs import arg, command, global_args, run
from builder import DEFAULT_FORMATS, GlyphsFont
from generator import generate_spacers, render_ligatures
from glyphsLib import GSFeature, GSFont
from utils import print_warn, read_classes, read_features, read_files
from liblilex import DEFAULT_FORMATS, GlyphsFont, generate_spacers, render_ligatures
from utils import read_classes, read_features, read_files

FONT_FILE = "sources/Lilex.glyphs"
CLASSES_DIR = "sources/classes"
Expand Down
4 changes: 4 additions & 0 deletions scripts/liblilex/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Lilex font library"""
from .build import DEFAULT_FORMATS, SUPPORTED_FORMATS
from .generator import generate_spacers, render_ligatures
from .glyphs_font import GlyphsFont
3 changes: 3 additions & 0 deletions scripts/liblilex/build/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""Lilex font builder module"""
from .const import DEFAULT_FORMATS, SUPPORTED_FORMATS
from .make import make
13 changes: 13 additions & 0 deletions scripts/liblilex/build/const.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Lilex builder constants"""

SUPPORTED_FORMATS = [
"ttf",
"otf",
"variable"
]

DEFAULT_FORMATS = [
"ttf",
"variable"
]

File renamed without changes.
3 changes: 3 additions & 0 deletions scripts/liblilex/features/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""OpenType features utils"""
from .name import feature_prefix, name_from_code
from .tpl import NAME_TPL
File renamed without changes.
13 changes: 0 additions & 13 deletions scripts/builder/const.py → scripts/liblilex/features/tpl.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
"""Lilex builder constants"""

SUPPORTED_FORMATS = [
"ttf",
"otf",
"variable"
]

DEFAULT_FORMATS = [
"ttf",
"variable"
]

NAME_TPL = {
"ss": (
"featureNames {\n"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions scripts/builder/font.py → scripts/liblilex/glyphs_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
build_masters,
)

from .const import NAME_TPL, SUPPORTED_FORMATS
from .make import make
from .name import feature_prefix, name_from_code
from .build import SUPPORTED_FORMATS, make
from .features import NAME_TPL, feature_prefix, name_from_code

LIGATURE_SUFFIX = ".liga"
GlyphFilter = Callable[[GSGlyph], bool]

LIGATURE_SUFFIX = ".liga"

class GlyphsFont:
"""Glyphs font builder"""
"""Glyphs font file controller"""
_font: GSFont = None
_path: str
_name: str
Expand Down
72 changes: 72 additions & 0 deletions scripts/porting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env python3
"""A utility for developing pairings to fonts.
I want Italic to have all the same features as a regular font,
this script will allow to control progress
"""
import json
from os import makedirs

from arrrgs import arg, command, global_args, run
from glyphsLib import GSFont

REGULAR_FONT_PATH = "sources/Lilex.glyphs"
ITALIC_FONT_PATH = "sources/Lilex-Italic.glyphs"


global_args(
arg("--snapshot-dir", "-s", default="__snapshots__", help="Snapshot directory"),
)

@command(
arg("--markdown", "-m", action="store_true", help="Markdown output"),
)
def progress(args):
"""Finds missing ligatures"""
missing_glyphs = find_missing_glyphs()
snapshot_path = f"{args.snapshot_dir}/missing_glyphs.json"

with open(snapshot_path, mode="r", encoding="utf-8") as file:
stored_glyphs = json.load(file)

diff = len(stored_glyphs) - len(missing_glyphs)
progress_value = (diff / len(stored_glyphs)) * 100
if not args.markdown:
print(f"Glyphs coverage: {progress_value:.2f}%")
return

print("### Glyphs porting progress")
print(f"![](https://geps.dev/progress/{progress_value:.0f})")
print()

print("<details>")
print("<summary>Glyphs status</summary>")
print("<ul>")
for glyph in stored_glyphs:
if glyph in missing_glyphs:
print(f"<li>{glyph}</li>")
else:
print(f"<li><s>{glyph}</s></li>")
print("</ul>")
print("</details>")

@command()
def snapshot(args):
"""Dumps missing glyphs"""
glyphs = find_missing_glyphs()
makedirs(args.snapshot_dir, exist_ok=True)
with open(f"{args.snapshot_dir}/missing_glyphs.json", mode="w", encoding="utf-8") as file:
json.dump(glyphs, file)
print(f"Missing glyphs saved to {args.snapshot_dir}/missing_glyphs.json")

def find_missing_glyphs() -> list[str]:
"""Finds missing glyphs"""
target_font = GSFont(REGULAR_FONT_PATH)
source_font = GSFont(ITALIC_FONT_PATH)
missing_glyphs = []
for glyph in target_font.glyphs:
if glyph.export and glyph.name not in source_font.glyphs:
missing_glyphs.append(glyph.name)
return missing_glyphs

if __name__ == "__main__":
run()

0 comments on commit 690ebb4

Please sign in to comment.