glyphsLib


NameglyphsLib JSON
Version 6.7.1 PyPI version JSON
download
home_pagehttps://github.com/googlefonts/glyphsLib
SummaryA bridge from Glyphs source files (.glyphs) to UFOs
upload_time2024-04-29 06:51:33
maintainerNone
docs_urlNone
authorJames Godfrey-Kittle
requires_python>=3.8
licenseApache Software License 2.0
keywords
VCS
bugtrack_url
requirements appdirs attrs fonttools fs openstep-plist six ufolib2 unicodedata2
Travis-CI No Travis.
coveralls test coverage
            |CI Build Status| |PyPI Version| |Codecov| |Gitter Chat|

glyphsLib
=========

This Python library provides a bridge from Glyphs source files (.glyphs) to
UFOs and Designspace files via `defcon <https://github.com/typesupply/defcon/>`__ and `designspaceLib <https://github.com/fonttools/fonttools>`__.

The main methods for conversion are found in ``__init__.py``.
Intermediate data can be accessed without actually writing UFOs, if
needed.

Write and return UFOs
^^^^^^^^^^^^^^^^^^^^^

The following code will write UFOs and a Designspace file to disk.

.. code:: python

    import glyphsLib

    master_dir = "master_ufos"
    ufos, designspace_path = glyphsLib.build_masters("MyFont.glyphs", master_dir)

If you want to interpolate instances, please use fontmake instead. It uses this library under the hood when dealing with Glyphs files.

Load UFO objects without writing
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python

    import glyphsLib

    ufos = glyphsLib.load_to_ufos("MyFont.glyphs")

Read and write Glyphs data as Python objects
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python

    from glyphsLib import GSFont

    font = GSFont(glyphs_file)
    font.save(glyphs_file)

The ``glyphsLib.classes`` module aims to provide an interface similar to
Glyphs.app's `Python Scripting API <https://docu.glyphsapp.com>`__.

Note that currently not all the classes and methods may be fully
implemented. We try to keep up to date, but if you find something that
is missing or does not work as expected, please open a issue.

.. TODO Briefly state how much of the Glyphs.app API is currently covered,
   and what is not supported yet.

Go back and forth between UFOs and Glyphs
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1.  You can use the ``ufo2glyphs`` and ``glyphs2ufo`` command line scripts to
    round-trip your source files. By default, the scripts try to preserve as
    much metadata as possible.

    .. code::

        # Generate master UFOs and Designspace file
        glyphs2ufo Example.glyphs

        # Go back
        ufo2glyphs Example.designspace

        # You can also combine single UFOs into a Glyphs source file.
        ufo2glyphs Example-Regular.ufo Example-Bold.ufo

2.  Without a designspace file, using for example the
    `Inria fonts by Black[Foundry] <https://github.com/BlackFoundry/InriaFonts/tree/master/masters/INRIA-SANS>`__:

    .. code:: python

        import glob
        from defcon import Font
        from glyphsLib import to_glyphs

        ufos = [Font(path) for path in glob.glob("*Italic.ufo")]
        # Sort the UFOs because glyphsLib will create masters in the same order
        ufos = sorted(ufos, key=lambda ufo: ufo.info.openTypeOS2WeightClass)
        font = to_glyphs(ufos)
        font.save("InriaSansItalic.glyphs")

    `Here is the resulting glyphs file <https://gist.githubusercontent.com/belluzj/cc3d43bf9b1cf22fde7fd4d2b97fdac4/raw/3222a2bfcf6554aa56a21b80f8fba82f1c5d7444/InriaSansItalic.glyphs>`__

3.  With a designspace, using
    `Spectral from Production Type <https://github.com/productiontype/Spectral/tree/master/sources>`__:

    .. code:: python

        import glob
        from fontTools.designspaceLib import DesignSpaceDocument
        from glyphsLib import to_glyphs

        doc = DesignSpaceDocument()
        doc.read("spectral-build-roman.designspace")
        font = to_glyphs(doc)
        font.save("SpectralRoman.glyphs")

    `Here is the resulting glyphs file <https://gist.githubusercontent.com/belluzj/cc3d43bf9b1cf22fde7fd4d2b97fdac4/raw/3222a2bfcf6554aa56a21b80f8fba82f1c5d7444/SpectralRoman.glyphs>`__

4.  In both programmatic cases, if you intend to go back to UFOs after modifying
    the file with Glyphs, you should use the ``minimize_ufo_diffs`` parameter to
    minimize the amount of diffs that will show up in git after the back and
    forth. To do so, the glyphsLib will add some bookkeeping values in various
    ``userData`` fields. For example, it will try to remember which GSClass came
    from groups.plist or from the feature file.

The same option exists for people who want to do Glyphs->UFOs->Glyphs:
``minimize_glyphs_diffs``, which will add some bookkeeping data in UFO ``lib``.
For example, it will keep the same UUIDs for Glyphs layers, and so will need
to store those layer UUIDs in the UFOs.

.. code:: python

    import glob
    import os
    from fontTools.designspaceLib import DesignSpaceDocument
    from glyphsLib import to_glyphs, to_designspace, GSFont

    doc = DesignSpaceDocument()
    doc.read("spectral-build-roman.designspace")
    font = to_glyphs(doc, minimize_ufo_diffs=True)
    doc2 = to_designspace(font, propagate_anchors=False)
    # UFOs are in memory only, attached to the doc via `sources`
    # Writing doc2 over the original doc should generate very few git diffs (ideally none)
    doc2.write(doc.path)
    for source in doc2.sources:
        path = os.path.join(os.path.dirname(doc.path), source.filename)
        # You will want to use ufoNormalizer after
        source.font.save(path)

    font = GSFont("SpectralRoman.glyphs")
    doc = to_designspace(font, minimize_glyphs_diffs=True, propagate_anchors=False)
    font2 = to_glyphs(doc)
    # Writing font2 over font should generate very few git diffs (ideally none):
    font2.save(font.filepath)

In practice there are always a few diffs on things that don't really make a
difference, like optional things being added/removed or whitespace changes or
things getting reordered...

Make a release
^^^^^^^^^^^^^^

Use ``git tag -a`` to make a new annotated tag, or ``git tag -s`` for a GPG-signed
annotated tag, if you prefer.

Name the new tag with with a leading ā€˜vā€™ followed by three ``MAJOR.MINOR.PATCH``
digits, like in semantic versioning. Look at the existing tags for examples.

In the tag message write some short release notes describing the changes since the
previous tag.

Finally, push the tag to the remote repository (e.g. assuming your upstream is
called ``origin``):

.. code::

    $ git push origin v0.4.3

This will trigger the CI to build the distribution packages and upload them to
the Python Package Index automatically, if all the tests pass successfully.


.. |CI Build Status| image:: https://github.com/googlefonts/glyphsLib/workflows/Test%20+%20Deploy/badge.svg
   :target: https://github.com/googlefonts/glyphsLib/actions
.. |PyPI Version| image:: https://img.shields.io/pypi/v/glyphsLib.svg
   :target: https://pypi.org/project/glyphsLib/
.. |Codecov| image:: https://codecov.io/gh/googlefonts/glyphsLib/branch/main/graph/badge.svg
   :target: https://codecov.io/gh/googlefonts/glyphsLib
.. |Gitter Chat| image:: https://badges.gitter.im/fonttools-dev/glyphsLib.svg
   :alt: Join the chat at https://gitter.im/fonttools-dev/glyphsLib
   :target: https://gitter.im/fonttools-dev/glyphsLib?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/googlefonts/glyphsLib",
    "name": "glyphsLib",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "James Godfrey-Kittle",
    "author_email": "jamesgk@google.com",
    "download_url": "https://files.pythonhosted.org/packages/d8/cd/3a242a90939cca779d4370e3c6028a262c440ccc92e6f6104e129556e51d/glyphslib-6.7.1.tar.gz",
    "platform": null,
    "description": "|CI Build Status| |PyPI Version| |Codecov| |Gitter Chat|\n\nglyphsLib\n=========\n\nThis Python library provides a bridge from Glyphs source files (.glyphs) to\nUFOs and Designspace files via `defcon <https://github.com/typesupply/defcon/>`__ and `designspaceLib <https://github.com/fonttools/fonttools>`__.\n\nThe main methods for conversion are found in ``__init__.py``.\nIntermediate data can be accessed without actually writing UFOs, if\nneeded.\n\nWrite and return UFOs\n^^^^^^^^^^^^^^^^^^^^^\n\nThe following code will write UFOs and a Designspace file to disk.\n\n.. code:: python\n\n    import glyphsLib\n\n    master_dir = \"master_ufos\"\n    ufos, designspace_path = glyphsLib.build_masters(\"MyFont.glyphs\", master_dir)\n\nIf you want to interpolate instances, please use fontmake instead. It uses this library under the hood when dealing with Glyphs files.\n\nLoad UFO objects without writing\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. code:: python\n\n    import glyphsLib\n\n    ufos = glyphsLib.load_to_ufos(\"MyFont.glyphs\")\n\nRead and write Glyphs data as Python objects\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. code:: python\n\n    from glyphsLib import GSFont\n\n    font = GSFont(glyphs_file)\n    font.save(glyphs_file)\n\nThe ``glyphsLib.classes`` module aims to provide an interface similar to\nGlyphs.app's `Python Scripting API <https://docu.glyphsapp.com>`__.\n\nNote that currently not all the classes and methods may be fully\nimplemented. We try to keep up to date, but if you find something that\nis missing or does not work as expected, please open a issue.\n\n.. TODO Briefly state how much of the Glyphs.app API is currently covered,\n   and what is not supported yet.\n\nGo back and forth between UFOs and Glyphs\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n1.  You can use the ``ufo2glyphs`` and ``glyphs2ufo`` command line scripts to\n    round-trip your source files. By default, the scripts try to preserve as\n    much metadata as possible.\n\n    .. code::\n\n        # Generate master UFOs and Designspace file\n        glyphs2ufo Example.glyphs\n\n        # Go back\n        ufo2glyphs Example.designspace\n\n        # You can also combine single UFOs into a Glyphs source file.\n        ufo2glyphs Example-Regular.ufo Example-Bold.ufo\n\n2.  Without a designspace file, using for example the\n    `Inria fonts by Black[Foundry] <https://github.com/BlackFoundry/InriaFonts/tree/master/masters/INRIA-SANS>`__:\n\n    .. code:: python\n\n        import glob\n        from defcon import Font\n        from glyphsLib import to_glyphs\n\n        ufos = [Font(path) for path in glob.glob(\"*Italic.ufo\")]\n        # Sort the UFOs because glyphsLib will create masters in the same order\n        ufos = sorted(ufos, key=lambda ufo: ufo.info.openTypeOS2WeightClass)\n        font = to_glyphs(ufos)\n        font.save(\"InriaSansItalic.glyphs\")\n\n    `Here is the resulting glyphs file <https://gist.githubusercontent.com/belluzj/cc3d43bf9b1cf22fde7fd4d2b97fdac4/raw/3222a2bfcf6554aa56a21b80f8fba82f1c5d7444/InriaSansItalic.glyphs>`__\n\n3.  With a designspace, using\n    `Spectral from Production Type <https://github.com/productiontype/Spectral/tree/master/sources>`__:\n\n    .. code:: python\n\n        import glob\n        from fontTools.designspaceLib import DesignSpaceDocument\n        from glyphsLib import to_glyphs\n\n        doc = DesignSpaceDocument()\n        doc.read(\"spectral-build-roman.designspace\")\n        font = to_glyphs(doc)\n        font.save(\"SpectralRoman.glyphs\")\n\n    `Here is the resulting glyphs file <https://gist.githubusercontent.com/belluzj/cc3d43bf9b1cf22fde7fd4d2b97fdac4/raw/3222a2bfcf6554aa56a21b80f8fba82f1c5d7444/SpectralRoman.glyphs>`__\n\n4.  In both programmatic cases, if you intend to go back to UFOs after modifying\n    the file with Glyphs, you should use the ``minimize_ufo_diffs`` parameter to\n    minimize the amount of diffs that will show up in git after the back and\n    forth. To do so, the glyphsLib will add some bookkeeping values in various\n    ``userData`` fields. For example, it will try to remember which GSClass came\n    from groups.plist or from the feature file.\n\nThe same option exists for people who want to do Glyphs->UFOs->Glyphs:\n``minimize_glyphs_diffs``, which will add some bookkeeping data in UFO ``lib``.\nFor example, it will keep the same UUIDs for Glyphs layers, and so will need\nto store those layer UUIDs in the UFOs.\n\n.. code:: python\n\n    import glob\n    import os\n    from fontTools.designspaceLib import DesignSpaceDocument\n    from glyphsLib import to_glyphs, to_designspace, GSFont\n\n    doc = DesignSpaceDocument()\n    doc.read(\"spectral-build-roman.designspace\")\n    font = to_glyphs(doc, minimize_ufo_diffs=True)\n    doc2 = to_designspace(font, propagate_anchors=False)\n    # UFOs are in memory only, attached to the doc via `sources`\n    # Writing doc2 over the original doc should generate very few git diffs (ideally none)\n    doc2.write(doc.path)\n    for source in doc2.sources:\n        path = os.path.join(os.path.dirname(doc.path), source.filename)\n        # You will want to use ufoNormalizer after\n        source.font.save(path)\n\n    font = GSFont(\"SpectralRoman.glyphs\")\n    doc = to_designspace(font, minimize_glyphs_diffs=True, propagate_anchors=False)\n    font2 = to_glyphs(doc)\n    # Writing font2 over font should generate very few git diffs (ideally none):\n    font2.save(font.filepath)\n\nIn practice there are always a few diffs on things that don't really make a\ndifference, like optional things being added/removed or whitespace changes or\nthings getting reordered...\n\nMake a release\n^^^^^^^^^^^^^^\n\nUse ``git tag -a`` to make a new annotated tag, or ``git tag -s`` for a GPG-signed\nannotated tag, if you prefer.\n\nName the new tag with with a leading \u2018v\u2019 followed by three ``MAJOR.MINOR.PATCH``\ndigits, like in semantic versioning. Look at the existing tags for examples.\n\nIn the tag message write some short release notes describing the changes since the\nprevious tag.\n\nFinally, push the tag to the remote repository (e.g. assuming your upstream is\ncalled ``origin``):\n\n.. code::\n\n    $ git push origin v0.4.3\n\nThis will trigger the CI to build the distribution packages and upload them to\nthe Python Package Index automatically, if all the tests pass successfully.\n\n\n.. |CI Build Status| image:: https://github.com/googlefonts/glyphsLib/workflows/Test%20+%20Deploy/badge.svg\n   :target: https://github.com/googlefonts/glyphsLib/actions\n.. |PyPI Version| image:: https://img.shields.io/pypi/v/glyphsLib.svg\n   :target: https://pypi.org/project/glyphsLib/\n.. |Codecov| image:: https://codecov.io/gh/googlefonts/glyphsLib/branch/main/graph/badge.svg\n   :target: https://codecov.io/gh/googlefonts/glyphsLib\n.. |Gitter Chat| image:: https://badges.gitter.im/fonttools-dev/glyphsLib.svg\n   :alt: Join the chat at https://gitter.im/fonttools-dev/glyphsLib\n   :target: https://gitter.im/fonttools-dev/glyphsLib?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge\n",
    "bugtrack_url": null,
    "license": "Apache Software License 2.0",
    "summary": "A bridge from Glyphs source files (.glyphs) to UFOs",
    "version": "6.7.1",
    "project_urls": {
        "Homepage": "https://github.com/googlefonts/glyphsLib"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3d0c414adbb45ff86875d2c6295c3ab99c7d47ad889c9bdf50cf93287c20091f",
                "md5": "128a28a4c805c5bf25ed20e5de5c2da2",
                "sha256": "ec612285c7ea623dff7554c8afe370fd80eaea0d5d7e0d8203154db28b0920fd"
            },
            "downloads": -1,
            "filename": "glyphsLib-6.7.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "128a28a4c805c5bf25ed20e5de5c2da2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 890380,
            "upload_time": "2024-04-29T06:51:29",
            "upload_time_iso_8601": "2024-04-29T06:51:29.727471Z",
            "url": "https://files.pythonhosted.org/packages/3d/0c/414adbb45ff86875d2c6295c3ab99c7d47ad889c9bdf50cf93287c20091f/glyphsLib-6.7.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d8cd3a242a90939cca779d4370e3c6028a262c440ccc92e6f6104e129556e51d",
                "md5": "2311220c7732cacffbd1f1c608a8a9a3",
                "sha256": "bc7f3edd11096e445c5d3dc9583a7ef423051bb5ab65126e927fdc26e41c4ed4"
            },
            "downloads": -1,
            "filename": "glyphslib-6.7.1.tar.gz",
            "has_sig": false,
            "md5_digest": "2311220c7732cacffbd1f1c608a8a9a3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 25909860,
            "upload_time": "2024-04-29T06:51:33",
            "upload_time_iso_8601": "2024-04-29T06:51:33.027466Z",
            "url": "https://files.pythonhosted.org/packages/d8/cd/3a242a90939cca779d4370e3c6028a262c440ccc92e6f6104e129556e51d/glyphslib-6.7.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-29 06:51:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "googlefonts",
    "github_project": "glyphsLib",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [
        {
            "name": "appdirs",
            "specs": [
                [
                    "==",
                    "1.4.4"
                ]
            ]
        },
        {
            "name": "attrs",
            "specs": [
                [
                    "==",
                    "23.2.0"
                ]
            ]
        },
        {
            "name": "fonttools",
            "specs": [
                [
                    "==",
                    "4.47.2"
                ]
            ]
        },
        {
            "name": "fs",
            "specs": [
                [
                    "==",
                    "2.4.16"
                ]
            ]
        },
        {
            "name": "openstep-plist",
            "specs": [
                [
                    "==",
                    "0.3.1"
                ]
            ]
        },
        {
            "name": "six",
            "specs": [
                [
                    "==",
                    "1.16.0"
                ]
            ]
        },
        {
            "name": "ufolib2",
            "specs": [
                [
                    "==",
                    "0.16.0"
                ]
            ]
        },
        {
            "name": "unicodedata2",
            "specs": [
                [
                    "==",
                    "15.1.0"
                ]
            ]
        }
    ],
    "tox": true,
    "lcname": "glyphslib"
}
        
Elapsed time: 0.23181s