diff options
author | gbr | 2023-01-25 06:47:28 -0300 |
---|---|---|
committer | gbr | 2023-01-25 06:47:28 -0300 |
commit | 48a8a911a62be0edd2fb8b8835fbbffb2469104e (patch) | |
tree | c5386968748dd88904d0250dbbb11b84f9a08ad2 | |
parent | 4bddb2b7522bcc7184962a740b30d893be3cd576 (diff) | |
download | aur-48a8a911a62be0edd2fb8b8835fbbffb2469104e.tar.gz |
otf-nerd-fonts-monacob-mono v2.3.3
-rw-r--r-- | .SRCINFO | 12 | ||||
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | PKGBUILD | 39 | ||||
-rwxr-xr-x | fix_font_name.py | 37 | ||||
-rwxr-xr-x | monacob-font-patcher.py | 142 |
5 files changed, 170 insertions, 62 deletions
@@ -1,6 +1,6 @@ pkgbase = otf-nerd-fonts-monacob-mono pkgdesc = MonacoB fonts patched with nerd-fonts - pkgver = 2.3.2 + pkgver = 2.3.3 pkgrel = 1 url = https://github.com/vjpr/monaco-bold arch = any @@ -8,14 +8,14 @@ pkgbase = otf-nerd-fonts-monacob-mono makedepends = fontforge makedepends = subversion source = COPYRIGHT - source = fix_font_name.py + source = monacob-font-patcher.py source = monaco-bold::git+https://github.com/vjpr/monaco-bold.git#commit=b77db4b6fc2e9df074f8db59cead862d7068e3d7 - source = nerd-fonts-glyphs::svn+https://github.com/ryanoasis/nerd-fonts/tags/v2.3.2/src/glyphs - source = https://github.com/ryanoasis/nerd-fonts/raw/v2.3.2/font-patcher + source = nerd-fonts-glyphs::svn+https://github.com/ryanoasis/nerd-fonts/tags/v2.3.3/src/glyphs + source = font-patcher-2.3.3.py::https://github.com/ryanoasis/nerd-fonts/raw/v2.3.3/font-patcher sha256sums = 4a9d48f5368ca3b5699f61c505412a8d734a57c5da00ac0ac5ea70881f615ef3 - sha256sums = 45322eec525058c1bc55f2a999fad74eac9e9869caf7174bb292e92474d5aa73 + sha256sums = 153b3fcf2d418582d5293a50d8bf3e17f9f500db5633b7927a1921d4527b158d sha256sums = SKIP sha256sums = SKIP - sha256sums = 3b733a8030c9c85fa369714eaeaddef766ed788717eb38334903c30f1523bd27 + sha256sums = b8fba54cd34cd506a4f48b8780763c13f32b326a6cd37b74bcf33e5841b84cf8 pkgname = otf-nerd-fonts-monacob-mono diff --git a/.gitignore b/.gitignore index 1a9adbfca83a..7fe548944b85 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ monaco-bold/ nerd-fonts-glyphs/ pkg/ src/ -font-patcher +font-patcher-* *.tar *.tar.xz *.tar.zst @@ -1,7 +1,7 @@ # Maintainer: gbr <gbr@protonmail.com> # Contributor: Karmenzind pkgname=otf-nerd-fonts-monacob-mono -pkgver=2.3.2 +pkgver=2.3.3 pkgrel=1 pkgdesc='MonacoB fonts patched with nerd-fonts' arch=('any') @@ -10,33 +10,36 @@ license=('custom:Apple') depends=() makedepends=('fontforge' 'subversion') source=('COPYRIGHT' - 'fix_font_name.py' + 'monacob-font-patcher.py' 'monaco-bold::git+https://github.com/vjpr/monaco-bold.git#commit=b77db4b6fc2e9df074f8db59cead862d7068e3d7' - "nerd-fonts-glyphs::svn+https://github.com/ryanoasis/nerd-fonts/tags/v$pkgver/src/glyphs" - "https://github.com/ryanoasis/nerd-fonts/raw/v$pkgver/font-patcher") + "nerd-fonts-glyphs::svn+https://github.com/ryanoasis/nerd-fonts/tags/v${pkgver}/src/glyphs" + "font-patcher-${pkgver}.py::https://github.com/ryanoasis/nerd-fonts/raw/v${pkgver}/font-patcher") sha256sums=('4a9d48f5368ca3b5699f61c505412a8d734a57c5da00ac0ac5ea70881f615ef3' - '45322eec525058c1bc55f2a999fad74eac9e9869caf7174bb292e92474d5aa73' + '153b3fcf2d418582d5293a50d8bf3e17f9f500db5633b7927a1921d4527b158d' 'SKIP' 'SKIP' - '3b733a8030c9c85fa369714eaeaddef766ed788717eb38334903c30f1523bd27') + 'b8fba54cd34cd506a4f48b8780763c13f32b326a6cd37b74bcf33e5841b84cf8') prepare() { - find "$srcdir/monaco-bold/" -type f -name '*.otf' \ - -exec ./fix_font_name.py {} \; - mkdir -p "$srcdir/src/" - ln -sf "$srcdir/nerd-fonts-glyphs/" "$srcdir/src/glyphs" + mkdir -p "${srcdir}/monaco-patched" + find "${srcdir}/monaco-bold" -type f -name '*.otf' | + xargs python3 "${srcdir}/monacob-font-patcher.py" \ + --output-dir "${srcdir}/monaco-patched" 2> /dev/null + + mkdir -p "${srcdir}/src" + ln -sf "${srcdir}/nerd-fonts-glyphs" "${srcdir}/src/glyphs" } build() { - mkdir -p "$srcdir/patched/" - find "$srcdir/monaco-bold/" -type f -name '*.otf' \ - -exec fontforge -script "$srcdir/font-patcher" {} \ - --mono --careful --complete --progressbars --outputdir "$srcdir/patched/" \; + mkdir -p "${srcdir}/nerd-patched" + find "${srcdir}/monaco-patched" -type f -name '*.otf' \ + -exec fontforge -script "${srcdir}/font-patcher-${pkgver}.py" {} \ + --mono --careful --complete --progressbars --outputdir "${srcdir}/nerd-patched" \; } package() { - install -d "$pkgdir/usr/share/licenses/$pkgname" - install -d "$pkgdir/usr/share/fonts/monacob/" - install -Dm644 "$srcdir/patched/"*.otf "$pkgdir/usr/share/fonts/monacob/" - install -Dm644 "$srcdir/COPYRIGHT" "$pkgdir/usr/share/licenses/$pkgname/" + install -d "${pkgdir}/usr/share/licenses/${pkgname}" + install -d "${pkgdir}/usr/share/fonts/monacob" + install -Dm644 "${srcdir}/nerd-patched/"*.otf "${pkgdir}/usr/share/fonts/monacob" + install -Dm644 "${srcdir}/COPYRIGHT" "${pkgdir}/usr/share/licenses/${pkgname}" } diff --git a/fix_font_name.py b/fix_font_name.py deleted file mode 100755 index f27b984ccaf7..000000000000 --- a/fix_font_name.py +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env python -# coding=utf8 -# Fixes the 'fontname' property of the MonacoB2 font family -# so that Nerd Fonts patcher can generate all fonts correctly - -import os, sys, re, fontforge - -script_name = os.path.basename(__file__) - -try: - font_path = sys.argv[1] - pretty_path = "{}/{}".format(os.path.basename(os.path.dirname(font_path)), os.path.basename(font_path)) - - print(">>> {}: [{}] Opening font file...".format(script_name, pretty_path)) - - font = fontforge.open(font_path) -except: - sys.exit(">>> {}: Error: Unable to open font file!".format(script_name)) - -# This font in specific has the weight and the fullname properties set incorrectly -if font.fontname == "MonacoBItalic": - new_name = "MonacoB-Italic" - font.weight = "Italic" -else: - new_name = "{}-{}".format(font.fullname.split(" ")[0], font.weight) - -print(">>> {}: [{}] Renaming font: '{}' -> '{}'".format(script_name, pretty_path, font.fontname, new_name)) -print(">>> {}: [{}] Fixing font properties...".format(script_name, pretty_path)) - -font.fontname = new_name -font.fullname = new_name - -print(">>> {}: [{}] Overwriting font...".format(script_name, pretty_path)) - -font.generate(font_path) - -print(">>> {}: [{}] Done!".format(script_name, pretty_path)) diff --git a/monacob-font-patcher.py b/monacob-font-patcher.py new file mode 100755 index 000000000000..16ec0184f57f --- /dev/null +++ b/monacob-font-patcher.py @@ -0,0 +1,142 @@ +#!/usr/bin/env python3 + +# Fixes a bunch of inconsistencies and wrong properties in MonacoB fonts. + +import os +import shutil +import sys + +import fontforge + +print("=== MonacoB font patcher ===") + +def usage(): + sys.exit(f"Usage: {sys.argv[0]} [--output-dir <dir>] <font file, ...>") + +argc = len(sys.argv) + +if argc < 2: + usage() + +output_dir = None + +if sys.argv[1] == "--output-dir": + if argc < 3: + usage() + output_dir = sys.argv[2] + + if not os.path.isdir(output_dir): + sys.exit(f"Error: Output directory '{output_dir}' does not exist.") + + output_dir = os.path.realpath(output_dir) + fonts_list = sys.argv[3:] +else: + fonts_list = sys.argv[1:] + +total = len(fonts_list) + +if total == 0: + usage() + +for i, font_file in enumerate(fonts_list): + print(f"\n=== Patching font #{i + 1} of #{total} ===") + + try: + file_full_path = os.path.realpath(font_file) + except OSError: + print(f" -> ERROR: Failed to resolve the real path of '{font_file}'.") + sys.exit(1) + + file_name = os.path.basename(file_full_path) + + print(f"==> Opening font file: '{file_name}'...") + + try: + font = fontforge.open(file_full_path) + except: + print(" -> ERROR: Failed to open font.") + sys.exit(1) + + font_changed = False + + # Uncomment for debugging. + # print(f" -> font.fontname: {font.fontname}") # 'Fontname' + # print(f" -> font.familyname: {font.familyname}") # 'Family Name' + # print(f" -> font.fullname: {font.fullname}") # 'Name For Humans' + # print(f" -> font.weight: {font.weight}") # 'Weight' + # print(f" -> font.italicangle: {font.italicangle}") # 'Italic Angle' + # print(f" -> font.sfnt_names: {font.sfnt_names}") # 'TTF Names' + + proper_fontname = font.fullname.replace(" ", "-") + + if font.fontname != proper_fontname: + print(f" -> Fixing font's `fontname`: '{font.fontname}' -> '{proper_fontname}'") + font.fontname = proper_fontname + font_changed = True + + # Try to extract font family and style from font.fontname. + if "-" in font.fontname: + font_family, font_style = font.fontname.split("-", 1) + else: + font_family = font.fontname + font_style = "Regular" + + removed_count = 0 + + # Iterate over the 'TTF Names' table. + for lang, strid, string in font.sfnt_names: + # Remove any row that's not 'English (US)'. + if lang != "English (US)" or strid.startswith("Preferred"): + removed_count += 1 + font.appendSFNTName(lang, strid, None) + font_changed = True + continue + + # Remove any row that's not either 'Copyright', 'UniqueID' or 'Version'. + # Ideally, we should be updating 'Family', 'SubFamily' and 'PostScriptName', + # but for whatever reason, appendSFNTName() does not work when we add values. + # Fortunately, removing these properties seem to also work in our case, so let's just do that. + if strid != "Copyright" and strid != "UniqueID" and strid != "Version": + removed_count += 1 + font.appendSFNTName(lang, strid, None) + continue + + print(f" -> Removed a total of {removed_count} rows from SFNT name table.") + + if font_style == "Italic" and font.italicangle >= 0: + print(f" -> Fixing font's `italicangle`: '{font.italicangle}' -> '-12.0'") + font.italicangle = -12.0 + font_changed = True + + if font.familyname != font_family: + print(f" -> Fixing font's `familyname`: '{font.familyname}' -> '{font_family}'") + font.familyname = font_family + font_changed = True + + file_name_without_ext, file_ext = os.path.splitext(file_name) + + if output_dir: + new_file_full_path = output_dir + os.sep + proper_fontname + file_ext + else: + new_file_full_path = file_full_path + + if font_changed: + print(" -> Re-generating font...") + + if output_dir: + print(f" -> Writing font file '{os.path.basename(new_file_full_path)}' to output directory '{output_dir}'...") + else: + print(" -> Overwriting font file...") + try: + font.generate(new_file_full_path) + font.close() + except: + print(" -> ERROR: Failed to re-generate font.") + sys.exit(1) + elif output_dir and not os.path.isfile(new_file_full_path): + print(f" -> Writing font file '{os.path.basename(new_file_full_path)}' to output directory '{output_dir}'...") + shutil.copy2(file_full_path, new_file_full_path) + else: + print(" -> Font does not need to be re-generated/overwritten...") + + print(" -> Done!") |