font-patcher: Copy selection instead of continuously regenerating

[why]
This is a TODO item. Well, two in fact.

The symbolFont's selection is used for two things
- the main loop to iterate over all glyphs to insert
- to select the one glyph that is actually copied over

Because the main loop uses iterators on the selection.
The iterator is not 'stable' but invalidates if the selection
is changed.
The current code therefor restores the old selection before the loop
jumps to the head again.

This design is not very robust.

[how]
We need the selection to copy the symbol glyph.

But we can rewrite the loop that it does not need the selection at every
iteration, but that the selection is copied into a list, and we loop
over that list - which is independent on a later selection state.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
This commit is contained in:
Fini Jastrow 2021-12-22 14:29:34 +01:00
parent db026dd5c9
commit a19800195a

View file

@ -669,15 +669,14 @@ class font_patcher:
symbolFont.selection.select((str("ranges"), str("unicode")), symbolFontStart, symbolFontEnd)
self.sourceFont.selection.select((str("ranges"), str("unicode")), sourceFontStart, sourceFontEnd)
# Get number of selected non-empty glyphs @TODO FIXME
for index, sym_glyph in enumerate(symbolFont.selection.byGlyphs):
glyphSetLength += 1
# end for
# Get number of selected non-empty glyphs
symbolFontSelection = list(symbolFont.selection.byGlyphs)
glyphSetLength = len(symbolFontSelection)
if self.args.quiet is False:
sys.stdout.write("Adding " + str(max(1, glyphSetLength)) + " Glyphs from " + setName + " Set \n")
for index, sym_glyph in enumerate(symbolFont.selection.byGlyphs):
for index, sym_glyph in enumerate(symbolFontSelection):
index = max(1, index)
try:
@ -822,12 +821,6 @@ class font_patcher:
# does not overlap the bearings (edges)
self.remove_glyph_neg_bearings(self.sourceFont[currentSourceFontGlyph])
# reset selection so iteration works properly @TODO fix? rookie misunderstanding?
# This is likely needed because the selection was changed when the glyph was copy/pasted
if symbolFontStart == 0:
symbolFont.selection.all()
else:
symbolFont.selection.select((str("ranges"), str("unicode")), symbolFontStart, symbolFontEnd)
# end for
if self.args.quiet is False or self.args.progressbars: