mirror of
https://github.com/ryanoasis/nerd-fonts.git
synced 2024-09-12 09:41:47 +02:00
font-patcher: Unwrap complicated looking code
[why] We have two variables that hold the same data (sym_dim and dim), which is confusing ('why do we have it?'). There is also the big 'if' on 'do we want to scale', which contains too much. In the unlikely event that we have a glyph that needs to be scaled by 1.0 AND have an overlap the code produces the wrong results. [how] Shuffle lines but no functional change (except that now we obey 'overlap' always (not that it has been a problem)). Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
This commit is contained in:
parent
c303a1ee18
commit
1637ef7ff2
1 changed files with 12 additions and 15 deletions
27
font-patcher
27
font-patcher
|
@ -1107,6 +1107,8 @@ class font_patcher:
|
|||
# Prepare symbol glyph dimensions
|
||||
sym_dim = get_glyph_dimensions(self.sourceFont[currentSourceFontGlyph])
|
||||
if glyph_scale_data is not None:
|
||||
if glyph_scale_data[1] is not None:
|
||||
sym_dim = glyph_scale_data[1] # Use combined bounding box
|
||||
# This is roughly alike get_scale_factors(glyph_scale_data[1], 'pa')
|
||||
# Except we do not have glyph_scale_data[1] always...
|
||||
(scale_ratio_x, scale_ratio_y) = (glyph_scale_data[0], glyph_scale_data[0])
|
||||
|
@ -1114,23 +1116,18 @@ class font_patcher:
|
|||
(scale_ratio_x, scale_ratio_y) = self.get_scale_factors(sym_dim, sym_attr['stretch'])
|
||||
|
||||
overlap = sym_attr['params'].get('overlap')
|
||||
if overlap:
|
||||
scale_ratio_x *= 1.0 + (self.font_dim['width'] / (sym_dim['width'] * scale_ratio_x)) * overlap
|
||||
scale_ratio_y *= 1.0 + (self.font_dim['width'] / (sym_dim['width'] * scale_ratio_y)) * overlap
|
||||
|
||||
# Size in x to size in y ratio limit (to prevent over-wide glyphs)
|
||||
xy_ratio_max = sym_attr['params'].get('xy-ratio')
|
||||
if (xy_ratio_max):
|
||||
xy_ratio = sym_dim['width'] * scale_ratio_x / (sym_dim['height'] * scale_ratio_y)
|
||||
if xy_ratio > xy_ratio_max:
|
||||
scale_ratio_x = scale_ratio_x * xy_ratio_max / xy_ratio
|
||||
|
||||
if scale_ratio_x != 1.0 or scale_ratio_y != 1.0:
|
||||
if glyph_scale_data is not None and glyph_scale_data[1] is not None:
|
||||
dim = glyph_scale_data[1]
|
||||
else:
|
||||
dim = sym_dim
|
||||
if overlap:
|
||||
scale_ratio_x *= 1.0 + (self.font_dim['width'] / (dim['width'] * scale_ratio_x)) * overlap
|
||||
scale_ratio_y *= 1.0 + (self.font_dim['width'] / (dim['width'] * scale_ratio_y)) * overlap
|
||||
|
||||
# Size in x to size in y ratio limit (to prevent over-wide glyphs)
|
||||
xy_ratio_max = sym_attr['params'].get('xy-ratio')
|
||||
if (xy_ratio_max):
|
||||
xy_ratio = dim['width'] * scale_ratio_x / (dim['height'] * scale_ratio_y)
|
||||
if xy_ratio > xy_ratio_max:
|
||||
scale_ratio_x = scale_ratio_x * xy_ratio_max / xy_ratio
|
||||
|
||||
self.sourceFont[currentSourceFontGlyph].transform(psMat.scale(scale_ratio_x, scale_ratio_y))
|
||||
|
||||
# We pasted and scaled now we want to align/move
|
||||
|
|
Loading…
Reference in a new issue