Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unify loading of glyphs source into GSFont object #327

Open
anthrotype opened this issue Mar 22, 2018 · 6 comments
Open

unify loading of glyphs source into GSFont object #327

anthrotype opened this issue Mar 22, 2018 · 6 comments

Comments

@anthrotype
Copy link
Member

we currently have two alternative ways:

  1. instantiating a new GSFont object and passing a path to a .glyphs file
from glyphsLib import GSFont
font = GSFont("MyFont.glyphs")
  1. using the json-like glyphsLib.load (for a file or path,loads for a string) function
import glyphsLib

with open("MyFont.glyphs") as fp:
    font = glyphsLib.load(fp)

The two methods supposedly produce the same kind of object, however they seem to be calling different methods of glyphsLib.parser.Parser.

this is in GSFont.__init__:
https://github.com/googlei18n/glyphsLib/blob/0a86327a93b3f324f200e35a23f639db4ae58280/Lib/glyphsLib/classes.py#L3010-L3013

this is loads function:
https://github.com/googlei18n/glyphsLib/blob/0a86327a93b3f324f200e35a23f639db4ae58280/Lib/glyphsLib/parser.py#L255-L263

@schriftgestalt
Copy link
Collaborator

I don’t like the loads function ;)

And how it is done in Defcon and ufoLib? No loads functions there as far as I see.

@belluzj
Copy link
Collaborator

belluzj commented Mar 22, 2018

I don't know much about the Python conventions, so I don't know how "pythonic" and "expected" it is to provide the loads function, but personally I find myself using the GSFont constructor all the time :)

@anthrotype
Copy link
Member Author

let's deprecate them, and consistently use only one in our codebase. currently load_to_ufos is using the load function.

@khaledhosny
Copy link
Collaborator

khaledhosny commented Mar 22, 2018 via email

@anthrotype
Copy link
Member Author

GSFont can have a fromstring class method constructor to load from a string

@schriftgestalt
Copy link
Collaborator

Or add a keyword argument to the constructor.

font = GSFont(fromString=string)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants