Giter Club home page Giter Club logo

sfdlib.py's Introduction

sfd2ufo — An SFD to UFO converter

PyPI version

A simple utility to convert FontForge’s SFD fonts to UFO fonts. The main objective is to create UFO files that are usable in a larger UFO based workflow, and for that existing UFO libraries are used to generate the UFO fonts.

Installation

pip install -U sfdLib # add --user for local install

Or:

git checkout https://github.com/MFEK/sfdLib.py.git
cd ./sfdLib.py/
virtualenv venv
. venv/bin/activate
pip install -e .

License

NB: Out of deference to this project's original author, the MFEK Foundation Inc. has not changed the license. (Normally, MFEK-maintained projects are relicensed as Apache 2.0.)

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

sfdlib.py's People

Contributors

ctrlcctrlv avatar khaledhosny avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sfdlib.py's Issues

Crash: AttributeError: 'fontforge.glyph' object has no attribute 'name'

I'm trying to convert Cantarell-Regular.sfd(ir) to .ufo and encounter this:

$ python2 -m sfd2ufo /tmp/Cantarell-Regular.sfd /tmp/C-R.ufo
SPLFirstVisitorFoundSoughtXY() 221.100000 243.000000 323.000000
SPLFirstVisitorFoundSoughtXY() 221.100000 323.000000 340.000000
SPLFirstVisitorFoundSoughtXY() 7.100000 18.000000 -88.000000
SPLFirstVisitorFoundSoughtXY() 7.100000 -88.000000 -71.000000
Traceback (most recent call last):
  File "/usr/lib64/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/tmp/sfd2ufo/Lib/sfd2ufo/__main__.py", line 16, in <module>
    main()
  File "/tmp/sfd2ufo/Lib/sfd2ufo/__main__.py", line 12, in main
    font = SFDFont(args.sfdfile)
  File "sfd2ufo/__init__.py", line 14, in __init__
    self._buildGlyphs()
  File "sfd2ufo/__init__.py", line 163, in _buildGlyphs
    glyph = layer.newGlyph(sfdGlyph.name)
AttributeError: 'fontforge.glyph' object has no attribute 'name'

Python error related to re.groups()

With Python 3.9.2 on macOS 11.2 I'm trying to convert some sfd files to ufo, but I get this error:

$ sfd2ufo Font.sfd Font.ufo

Traceback (most recent call last):
  File "/Users/eli/Py/python-main/bin/sfd2ufo", line 33, in <module>
    sys.exit(load_entry_point('sfdLib', 'console_scripts', 'sfd2ufo')())
  File "/Users/eli/Py/repos/sfdLib/Lib/sfdLib/__main__.py", line 37, in main
    parser.parse()
  File "/Users/eli/Py/repos/sfdLib/Lib/sfdLib/parser.py", line 1323, in parse
    idx, quadratic, name, _ = m.groups()
AttributeError: 'NoneType' object has no attribute 'groups'

Fails if SFDUTF7 strings include 0x0B

Unclear to me how this ended up in Chomsky:

$ rg 'withershins' ~/Workspace/chomsky/Chomsky.sfd
27071:Comment: "this is the apostrophe copied five times, each time rotated 72deg withershins, then everything scaled to 50%+AAoA
                                                                                                                                 +99QA"
Traceback (most recent call last):
  File "/home/fred/.local/bin/sfd2ufo", line 8, in <module>
    sys.exit(main())
  File "/home/fred/.local/lib/python3.10/site-packages/sfdLib/__main__.py", line 39, in main
    font.save(args.ufofile, overwrite=True, validate=False)
  File "/home/fred/.local/lib/python3.10/site-packages/ufoLib2/objects/font.py", line 574, in save
    self.write(writer, saveAs=saveAs)
  File "/home/fred/.local/lib/python3.10/site-packages/ufoLib2/objects/font.py", line 509, in write
    self.layers.write(writer, saveAs=saveAs)
  File "/home/fred/.local/lib/python3.10/site-packages/ufoLib2/objects/layerSet.py", line 374, in write
    layer.write(glyphSet, saveAs=saveAs)
  File "/home/fred/.local/lib/python3.10/site-packages/ufoLib2/objects/layer.py", line 365, in write
    glyphSet.writeGlyph(
  File "/home/fred/.local/lib/python3.10/site-packages/fontTools/ufoLib/glifLib.py", line 490, in writeGlyph
    data = _writeGlyphToBytes(
  File "/home/fred/.local/lib/python3.10/site-packages/fontTools/ufoLib/glifLib.py", line 724, in _writeGlyphToBytes
    _writeNote(glyphObject, root, validate)
  File "/home/fred/.local/lib/python3.10/site-packages/fontTools/ufoLib/glifLib.py", line 856, in _writeNote
    etree.SubElement(element, "note").text = note
  File "src/lxml/etree.pyx", line 1039, in lxml.etree._Element.text.__set__
  File "src/lxml/apihelpers.pxi", line 747, in lxml.etree._setNodeText
  File "src/lxml/apihelpers.pxi", line 735, in lxml.etree._createTextNode
  File "src/lxml/apihelpers.pxi", line 1540, in lxml.etree._utf8
ValueError: "All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters"

Probably a weird FontForge-ism.

Blocking on #13 and MFEK/sfdutf7.py#1.

Add ufo2sfd

It seems having a UFO editor on Linux good enough for my needs will take quite sometime, so bidirectional UFO/SFD conversion is needed. The SFD files need not to be very canonical since they will be mainly used for editing the glyph outlines and anchor points, they just need to allow for round-trip UFO↔SFD conversion.

Add a font builder

This would take the parsed SFD font an build a binary font out of it, essentially providing a pure Python pipeline for building SFD fonts.

Release on PyPi

I noticed in #9 you don't have plans to bake this into fontmake. Do you have plans to develop it at all? What about releasing to PyPi*?

I'm using this in several places and have a vested interest in keeping the windows from breaking. If you don't plan on running with it I might be interested in at least keeping it afloat.

* Note I already extracted sfdnormalize from its former home burried in Libertinus sources (including history from its even earlier homes) and am keeping it around and published on PyPi.

Offset v metrics

If the v metrics are offsets, rather than halting, could you just not set them?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.