From cd395456287d672431f2c9ba389885abdea61ba9 Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Fri, 6 Jan 2023 23:33:57 +0100 Subject: [PATCH] font-patcher: Add mixture of ScaleGlyph and ScaleGroups [why] ScaleGlyph always did scaling only (no translation) based on one reference glyph. ScaleGroups does scaling and translation but can not work with one reference glyph but constructs always a combined bounding box. Missing is a way to scale AND translate, but with only one reference glyph. [how] Invent GlyphsToScale+ keyword, that supports just that. Signed-off-by: Fini Jastrow --- font-patcher | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/font-patcher b/font-patcher index 11ef3fad3..34d97feb4 100755 --- a/font-patcher +++ b/font-patcher @@ -6,7 +6,7 @@ from __future__ import absolute_import, print_function, unicode_literals # Change the script version when you edit this script: -script_version = "3.4.1" +script_version = "3.4.2" version = "2.3.0-RC" projectName = "Nerd Fonts" @@ -776,6 +776,7 @@ class font_patcher: # Here one specific glyph is used as 'scale blueprint'. Other glyphs are # scaled by the same factor as this glyph. This is useful if you have one # 'biggest' glyph and all others should stay relatively in size. + # Shifting in addition to scaling can be selected too (see below). # - ScaleGroups: # Here you specify a group of glyphs that should be handled together # with the same scaling and shifting. The basis for it is a 'combined @@ -785,12 +786,14 @@ class font_patcher: # The ScaleGlyph method: You set 'ScaleGlyph' to the unicode of the reference glyph. # Note that there can be only one per patch-set. # Additionally you set 'GlyphsToScale' that contains all the glyphs that shall be - # handled like the reference glyph. + # handled (scaled) like the reference glyph. # It is a List of: ((glyph code) or (tuple of two glyph codes that form a closed range)) # 'GlyphsToScale': [ # 0x0100, 0x0300, 0x0400, # The single glyphs 0x0100, 0x0300, and 0x0400 # (0x0200, 0x0210), # All glyphs 0x0200 to 0x0210 including both 0x0200 and 0x0210 # ]} + # If you want to not only scale but also shift as the refenerce glyph you give the + # data as 'GlyphsToScale+'. Note that only one set is used and the plus version is preferred. # # For the ScaleGroup method you define any number groups of glyphs and each group is # handled separately. The combined bounding box of all glyphs in the group is determined @@ -1324,7 +1327,13 @@ class font_patcher: if 'ScaleGlyph' in scaleRules: # Rewrite to equivalent ScaleGroup group_list = [] - for i in scaleRules['GlyphsToScale']: + if 'GlyphsToScale+' in scaleRules: + key = 'GlyphsToScale+' + plus = True + else: + key = 'GlyphsToScale' + plus = False + for i in scaleRules[key]: if isinstance(i, tuple): group_list.append(range(i[0], i[1] + 1)) else: @@ -1333,7 +1342,10 @@ class font_patcher: scale = self.get_scale_factors(sym_dim, 'pa')[0] scaleRules['ScaleGroups'].append(group_list) scaleRules['scales'].append(scale) - scaleRules['bbdims'].append(None) # The 'old' style keeps just the scale, not the positioning + if plus: + scaleRules['bbdims'].append(sym_dim) + else: + scaleRules['bbdims'].append(None) # The 'old' style keeps just the scale, not the positioning def get_glyph_scale(self, symbol_unicode, scaleRules, symbolFont, dest_unicode): """ Determines whether or not to use scaled glyphs for glyph in passed symbol_unicode """