Closed BlackFoundry closed 3 years ago
It shouldn't be "prettified": .glif should be formatted exactly as how ufoLib/glifLib saves it, otherwise we can never make changes from the git side without potentally adding format changes. The best way to do that is to build the XML with glifLib.
@justvanrossum what do you mean? xml data is the same independently by how it is formatted, I think in this case the prettify is just for readable reasons, @BlackFoundry isn't it?
If I edit a glyph with fonttools based code, and commit it to the repo, I don't want to be distracted by formatting differences. glifLib provides the canonical formatting, why not use it?
Yes that's the point @fabiocaccamo
The changeover to the MySQL frontend should not have caused any formatting changes whatsoever. (The case renaming of the .rcjk folders was very unfortunate also.)
@justvanrossum thank you for the explanation, understood.
Actually on server side we don't use glifLib
at all, we manage (just read) xml using ElementTree
.
Using glifLib
is it possible just format an xml to obtain the desired result?
Unfortunately it doesn't have this functionality builtin, and this is the shortest I could come up with (only lightly tested):
from fontTools.pens.recordingPen import RecordingPointPen
from fontTools.ufoLib.glifLib import readGlyphFromString, writeGlyphToString
class GlyphObject:
pass
def reformatGLIF(original):
glyph = GlyphObject()
recorder = RecordingPointPen()
readGlyphFromString(original, glyph, pointPen=recorder)
return writeGlyphToString(glyph.name, glyph, drawPointsFunc=recorder.replay)
p = 'path/to/glyph.glif'
with open(p) as f:
original = f.read()
new = reformatGLIF(original)
print(new)
@justvanrossum I'm sorry for the inconvenience, keeping data formatted identically was not in the requirements, so I thought the only important thing was that the data was not changed. Btw, now that I know it I can fix it easily. Thank you very much for the snippet.
I would have thought a requirement "data was not changed" would mean "in the repo" and therefore implies to include formatting... But I'm glad this is being fixed.
This seems to be done as well. (Again, please reference #N
issue numbers in commits and/or PRs.)
@justvanrossum yes this has been implemented.
Unfortunately the issue has been opened on the wrong repo, so it was not possible for me to reference the issue in the commit.
To avoid this problem in future the next issues related to backend/api should be opened on the django-robo-cjk repository.
@justvanrossum I also compared performance of glifLib
vs native xml
on 30000 iterations and there is not difference.
Excellent. (But even if there is a difference, given the granularity of the system, I would not expect glifLib to be a bottleneck wrt. responsiveness.)
the XML files should be formated nicely with proper lines and indents