Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions bin/travis-build.sh

This file was deleted.

11 changes: 6 additions & 5 deletions sfmono-square.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# typed: strict
# frozen_string_literal: true

# Formula to install the font: SF Mono Square
class SfmonoSquare < Formula
desc "Square-sized SF Mono + Japanese fonts + nerd-fonts"
homepage "https://github.com/delphinus/homebrew-sfmono-square"
url "https://github.com/delphinus/homebrew-sfmono-square/archive/v3.3.1.tar.gz"
sha256 "38cb48dd8dbc21e54b7c6a4f29f7676bdf8131731a8870248a1d1fa024b91006"
url "https://github.com/delphinus/homebrew-sfmono-square/archive/refs/tags/v3.3.1.tar.gz"
version "3.3.1"
sha256 "38cb48dd8dbc21e54b7c6a4f29f7676bdf8131731a8870248a1d1fa024b91006"
head "https://github.com/delphinus/homebrew-sfmono-square.git"

depends_on "fontforge" => :build
depends_on "fonttools" => :build
depends_on "[email protected]" => :build
depends_on "pod2man" => :build
depends_on "[email protected]" => :build

resource "migu1mfonts" do
output = `#{Utils::Curl.curl_executable} --version`
Expand All @@ -36,7 +37,7 @@ def install
(share / "fonts/src").install Dir["*.ttf"]

dir = "script/convert_codepoints"
system "#{Formula['pod2man'].opt_bin}/pod2man", "#{dir}/convert_codepoints", "#{dir}/convert_codepoints.1"
system "#{Formula["pod2man"].opt_bin}/pod2man", "#{dir}/convert_codepoints", "#{dir}/convert_codepoints.1"
bin.install "#{dir}/convert_codepoints"
man1.install "#{dir}/convert_codepoints.1"
end
Expand Down Expand Up @@ -64,7 +65,7 @@ def _compile

system python, "-c", <<~PYTHON
import sys
sys.path.append('#{buildpath / 'src'}')
sys.path.append('#{buildpath / "src"}')
sys.path.append('#{fontforge_lib}')
sys.path.append('#{fonttools_lib}')
import build
Expand Down
14 changes: 9 additions & 5 deletions src/build.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# -*- coding:utf-8 -*-
import sys
from __future__ import annotations

import sys
from collections.abc import Callable, Sequence
from concurrent.futures import ProcessPoolExecutor, as_completed
from typing import Any

import font_patcher
import fonttools
import migu1m
import sfmono
import sfmono_square
import fonttools


MIGU1M = [["migu-1m-regular.ttf"], ["migu-1m-bold.ttf"]]
Expand All @@ -32,7 +36,7 @@
OUT_DIR = "build"


def build(version):
def build(version: str) -> int:
print("---- modifying migu-1m ----")
if concurrent_execute(migu1m.modify, MIGU1M):
return 1
Expand All @@ -57,7 +61,7 @@ def build(version):
return 0


def concurrent_execute(func, args):
def concurrent_execute(func: Callable[..., Any], args: Sequence[Sequence[Any]]) -> int:
executor = ProcessPoolExecutor()
futures = [executor.submit(func, *a) for a in args]
return 1 if any([r.result() for r in as_completed(futures)]) else 0
return 1 if any(r.result() for r in as_completed(futures)) else 0
24 changes: 17 additions & 7 deletions src/font_patcher.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
# -*- coding=utf8 -*-
from __future__ import annotations

import errno
import os
from typing import TypedDict

import fontforge
import psMat


class PatchInfo(TypedDict):
name: str
filename: str
sym_start: int
sym_end: int
src_start: int | None
exact: bool

# Define the character ranges
# Symbol font ranges

PATCH_SET = [
PATCH_SET: list[PatchInfo] = [
{
"name": "Seti-UI + Custom",
"filename": "original-source.otf",
Expand Down Expand Up @@ -206,7 +217,7 @@
]


def patch(in_file, out_dir):
def patch(in_file: str, out_dir: str) -> int:
font = fontforge.open(in_file)
_patch(font)
try:
Expand All @@ -220,11 +231,11 @@ def patch(in_file, out_dir):
return 0


def _patch(font):
def _patch(font: fontforge.font) -> None:
# Prevent opening and closing the fontforge font. Makes things faster when
# patching multiple ranges using the same symbol font.
previous_symbol_filename = ""
symfont = None
symfont: fontforge.font | None = None

for info in PATCH_SET:
if previous_symbol_filename != info["filename"]:
Expand All @@ -243,7 +254,7 @@ def _patch(font):
symfont.close()


def _transform_sym(symfont, info):
def _transform_sym(symfont: fontforge.font, info: PatchInfo) -> None:
x_ratio = 1.0
y_ratio = 1.0
x_diff = 0
Expand Down Expand Up @@ -303,7 +314,7 @@ def _transform_sym(symfont, info):
symfont.transform(transform)


def _copy_glyphs(font, symfont, info):
def _copy_glyphs(font: fontforge.font, symfont: fontforge.font, info: PatchInfo) -> None:
selected = symfont.selection.select(
("ranges", "unicode"), info["sym_start"], info["sym_end"]
)
Expand All @@ -320,4 +331,3 @@ def _copy_glyphs(font, symfont, info):
font.selection.select(src_encoding)
font.paste()
font[src_encoding].glyphname = glyph.glyphname
return
8 changes: 6 additions & 2 deletions src/fonttools.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# -*- coding:utf-8 -*-
from fontTools.ttLib import TTFont
from __future__ import annotations

from os import rename
from tempfile import mkstemp

from fontTools.ttLib import TTFont

X_AVG_CHAR_WIDTH = 1024
FS_SELECTION = {
"Regular": 0b00000001_01000000,
Expand All @@ -18,7 +21,7 @@
}


def update(fontname, style):
def update(fontname: str, style: str) -> int:
font = TTFont(fontname)
font["post"].isFixedPitch = 1
font["CFF "].cff[0].isFixedPitch = 1
Expand All @@ -29,3 +32,4 @@ def update(fontname, style):
font.save(new_fontname)
font.close()
rename(new_fontname, fontname)
return 0
14 changes: 8 additions & 6 deletions src/migu1m.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding:utf-8 -*-
from __future__ import annotations

from os import getenv
from os.path import splitext

Expand All @@ -20,7 +22,7 @@
X_TO_CENTER = EM * (1 - SCALE) / 2


def modify(in_file):
def modify(in_file: str) -> int:
font = fontforge.open(in_file)
_set_new_em(font)
_set_proportion(font)
Expand All @@ -31,7 +33,7 @@ def modify(in_file):
return 0


def oblique(in_file):
def oblique(in_file: str) -> int:
font = fontforge.open(in_file)
_make_oblique(font)
name, ext = splitext(in_file)
Expand All @@ -43,7 +45,7 @@ def oblique(in_file):
return 0


def _set_new_em(font):
def _set_new_em(font: fontforge.font) -> None:
"""
This sets new ascent & descent and scale glyphs. This sets new ascent &
descent before it sets em. When in inverse, it does not change ascent &
Expand All @@ -56,7 +58,7 @@ def _set_new_em(font):
font.em = EM


def _set_proportion(font):
def _set_proportion(font: fontforge.font) -> None:
scale = psMat.scale(SCALE)
font.selection.all()
for glyph in list(font.selection.byGlyphs):
Expand All @@ -68,7 +70,7 @@ def _set_proportion(font):
glyph.width = round(EM / 2) if is_hankaku_kana else EM


def _zenkaku_space(font):
def _zenkaku_space(font: fontforge.font) -> None:
font.selection.none()
font.selection.select(0x2610) # ☐ BALLOT BOX
font.copy()
Expand All @@ -81,7 +83,7 @@ def _zenkaku_space(font):
font.intersect()


def _make_oblique(font):
def _make_oblique(font: fontforge.font) -> None:
mat = psMat.skew(OBLIQUE_SKEW)
font.selection.all()
font.transform(mat)
Expand Down
40 changes: 22 additions & 18 deletions src/sfmono.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# -*- coding:utf-8 -*-
from pathlib import Path
from os.path import splitext
from __future__ import annotations

from json import load
from os.path import splitext
from pathlib import Path
from typing import Any

import fontforge
from psMat import compose, scale, translate
Expand Down Expand Up @@ -40,7 +43,7 @@
]


def modify(in_file):
def modify(in_file: str) -> int:
name, ext = splitext(in_file)
style = name.replace(FILE_PREFIX, "")
regular_font = ""
Expand All @@ -60,33 +63,34 @@ def modify(in_file):
font.familyname = f"{PS_FAMILY} {FAMILY_SUFFIX}"
font.fullname = f"{PS_FAMILY} {FAMILY_SUFFIX} {style}"
font.fontname = f"{PS_FAMILY}-{FAMILY_SUFFIX}-{style}"
sfnt_names = list(font.sfnt_names)
for i in range(len(sfnt_names)):
name = list(sfnt_names[i])
key = name[1]
sfnt_names_list = list(font.sfnt_names)
for i in range(len(sfnt_names_list)):
name_tuple = sfnt_names_list[i]
name_list = list(name_tuple)
key = name_list[1]
if key == "Family":
name[2] = f"{FAMILY} {FAMILY_SUFFIX}"
name_list[2] = f"{FAMILY} {FAMILY_SUFFIX}"
elif key == "SubFamily":
name[2] = style
name_list[2] = style
elif key == "UniqueID" or key == "Fullname":
name[2] = f"{FAMILY} {FAMILY_SUFFIX} {style}"
sfnt_names[i] = tuple(name)
font.sfnt_names = tuple(sfnt_names)
name_list[2] = f"{FAMILY} {FAMILY_SUFFIX} {style}"
sfnt_names_list[i] = tuple(name_list)
font.sfnt_names = tuple(sfnt_names_list)
out_file = f"{PS_FAMILY}-{FAMILY_SUFFIX}-{style}{ext}"
print(f"Generate {out_file}")
font.generate(out_file, flags=("opentype",))
return 0


def _expand_shades(font, code):
def _expand_shades(font: fontforge.font, code: int) -> None:
shades = fontforge.open(SHADES_FILE)
shades.selection.select(code)
shades.copy()
font.selection.select(code)
font.paste()


def _add_white_triangle(font):
def _add_white_triangle(font: fontforge.font) -> None:
wt = fontforge.open(GEOMETRIC_SHAPES_FILE)
for code in GROMETRIC_SHAPES_GLYPHS:
wt.selection.select(code)
Expand All @@ -95,7 +99,7 @@ def _add_white_triangle(font):
font.paste()


def _add_bar_to_shade_bottom(font):
def _add_bar_to_shade_bottom(font: fontforge.font) -> None:
font.selection.select(LOWER_BLOCK)
font.copy()
font.selection.select(PRIVATE)
Expand Down Expand Up @@ -131,7 +135,7 @@ def _add_bar_to_shade_bottom(font):
]


def _add_braille(font):
def _add_braille(font: fontforge.font) -> None:
font.selection.select(BLACK_CIRCLE)
font.copy()
font.selection.select(PRIVATE)
Expand All @@ -144,7 +148,7 @@ def _add_braille(font):
glyph.transform(compose(move_to_origin, make_small))

with BRAILLE_JSON.open() as f:
braille = load(f)
braille: list[dict[str, Any]] = load(f)

for b in braille:
for p in b["points"]:
Expand All @@ -164,7 +168,7 @@ def _add_braille(font):
font.cut()


def _set_proportion(font):
def _set_proportion(font: fontforge.font) -> None:
mat = scale(SCALE_DOWN)
font.selection.all()
scaled = set()
Expand Down
Loading
Loading