From 40ded7c2f021397044a35c90e6d5dba8ab385ad6 Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Wed, 4 Jan 2023 20:30:21 +0100 Subject: [PATCH] gotta-patch-em-all: Create all fonts with unified release timestamp [why] All the fonts will have different timestamps, and within each font the creation and modification date might also differ. That is quite confusing and makes automated testing very complicated. [how] Use one date-time for ALL fonts and for creation and modification date in the font file. But do not change the date-time if we already set that somewhere before :-} Also remove the 'special' properitary fontforge timestamp tables FFTM from the patched fonts. This is only possible since FontForge 20th Anniversary Edition. Signed-off-by: Fini Jastrow --- bin/scripts/gotta-patch-em-all-font-patcher!.sh | 14 ++++++++++++-- font-patcher | 11 +++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/bin/scripts/gotta-patch-em-all-font-patcher!.sh b/bin/scripts/gotta-patch-em-all-font-patcher!.sh index 06f393fe2..fd1e442b4 100755 --- a/bin/scripts/gotta-patch-em-all-font-patcher!.sh +++ b/bin/scripts/gotta-patch-em-all-font-patcher!.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # Nerd Fonts Version: 2.3.0-RC -# Script Version: 1.1.1 +# Script Version: 1.2.0 # used for debugging # set -x @@ -60,7 +60,6 @@ while getopts ":h-:" option; do info_only=$2 echo "${LINE_PREFIX} 'Info Only' option given, only generating font info (not patching)" ;; - ;; *) echo >&2 "Option '${OPTARG}' unknown" exit 1;; @@ -100,6 +99,17 @@ done < <(find "$source_fonts_dir" -iregex ${like_pattern} -type f -print0) # print total number of source fonts found echo "$LINE_PREFIX Total source fonts found: ${#source_fonts[*]}" +# Use one date-time for ALL fonts and for creation and modification date in the font file +if [ -z "${SOURCE_DATE_EPOCH}" ] +then + export SOURCE_DATE_EPOCH=$(date +%s) +fi +release_timestamp=$(date -R --date=@${SOURCE_DATE_EPOCH} 2>/dev/null) || { + echo >&2 "$LINE_PREFIX Invalid release timestamp SOURCE_DATE_EPOCH: ${SOURCE_DATE_EPOCH}" + exit 2 +} +echo "$LINE_PREFIX Release timestamp is ${release_timestamp}" + function patch_font { local f=$1; shift local i=$1; shift diff --git a/font-patcher b/font-patcher index e2251d31e..8a12e3e1e 100755 --- a/font-patcher +++ b/font-patcher @@ -315,6 +315,11 @@ class font_patcher: def generate(self, sourceFonts): sourceFont = sourceFonts[0] + # the `PfEd-comments` flag is required for Fontforge to save '.comment' and '.fontlog'. + if int(fontforge.version()) >= 20201107: + gen_flags = (str('opentype'), str('PfEd-comments'), str('no-FFTM-table')) + else: + gen_flags = (str('opentype'), str('PfEd-comments')) if len(sourceFonts) > 1: layer = None # use first non-background layer @@ -325,8 +330,7 @@ class font_patcher: outfile = os.path.normpath(os.path.join( sanitize_filename(self.args.outputdir, True), sanitize_filename(sourceFont.familyname) + ".ttc")) - # the `PfEd-comments` flag is required for Fontforge to save '.comment' and '.fontlog'. - sourceFonts[0].generateTtc(outfile, sourceFonts[1:], flags=(str('opentype'), str('PfEd-comments')), layer=layer) + sourceFonts[0].generateTtc(outfile, sourceFonts[1:], flags=gen_flags, layer=layer) message = "\nGenerated: {} fonts in '{}'".format(len(sourceFonts), outfile) else: fontname = sourceFont.fullname @@ -335,12 +339,11 @@ class font_patcher: outfile = os.path.normpath(os.path.join( sanitize_filename(self.args.outputdir, True), sanitize_filename(fontname) + self.args.extension)) - # the `PfEd-comments` flag is required for Fontforge to save '.comment' and '.fontlog'. bitmaps = str() if len(self.sourceFont.bitmapSizes): print("Preserving bitmaps {}".format(self.sourceFont.bitmapSizes)) bitmaps = str('otf') # otf/ttf, both is bf_ttf - sourceFont.generate(outfile, bitmap_type=bitmaps, flags=(str('opentype'), str('PfEd-comments'))) + sourceFont.generate(outfile, bitmap_type=bitmaps, flags=gen_flags) message = "\nGenerated: {} in '{}'".format(self.sourceFont.fullname, outfile) # Adjust flags that can not be changed via fontforge