mirror of
https://github.com/ryanoasis/nerd-fonts.git
synced 2024-09-19 09:51:48 +02:00
font-patcher: Correct overlap
[why] The overlap formula seems to be off sometimes. Although the shift is correct (and thus the number of 'pixels' that overlap), but the non overlapping part of the glyph is often not as wide as expected, off by up to some percent. [how] The formula is too simple. It just calculates an additional scale factor on top of the already existing factor. To get it 'pixel perfect' we need to calculate first how much the glyph fills the cell - because we want the overlap to be in 'cell percent' and not 'glyph percent'. That might be sometimes the same (if the cell is filled completely), but usually it is not completely full, and that means the overlap will be smaller than intended. [note] To get the current glyph bounding box we pull some lines up in the code that get the 'dim' variable. Also use float constants to calculate with float variables. Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
This commit is contained in:
parent
95f29260b0
commit
b3c079d6d3
1 changed files with 8 additions and 7 deletions
15
font-patcher
15
font-patcher
|
@ -1116,17 +1116,18 @@ class font_patcher:
|
|||
|
||||
overlap = sym_attr['params'].get('overlap')
|
||||
|
||||
if scale_ratio_x != 1 or scale_ratio_y != 1:
|
||||
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 + overlap
|
||||
scale_ratio_y *= 1 + 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):
|
||||
if glyph_scale_data is not None and glyph_scale_data[1] is not None:
|
||||
dim = glyph_scale_data[1]
|
||||
else:
|
||||
dim = sym_dim
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue