Skip to content
New issue

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

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

Already on GitHub? # to your account

Cannot produce variable font from Cantarell glyphs source #217

Open
madig opened this issue Feb 11, 2018 · 11 comments
Open

Cannot produce variable font from Cantarell glyphs source #217

madig opened this issue Feb 11, 2018 · 11 comments

Comments

@madig
Copy link
Collaborator

madig commented Feb 11, 2018

(Not sure if this is a ufo2ft bug or something else.)

  1. wget https://github.com/madig/cantarell-fonts/raw/master/src/Cantarell.glyphs
  2. fontmake -g Cantarell.glyphs -o variable
INFO:fontmake.font_project:Building master UFOs and designspace from Glyphs source
INFO:glyphsLib.parser:Parsing .glyphs file
INFO:glyphsLib:Loading to UFOs
INFO:glyphsLib.util:Writing master_ufo/Cantarell-Light.ufo
INFO:glyphsLib.util:Writing master_ufo/Cantarell-Regular.ufo
INFO:glyphsLib.util:Writing master_ufo/Cantarell-Bold.ufo
INFO:fontmake.font_project:Building interpolation-compatible TTFs
INFO:fontmake.font_project:Converting curves compatibly
INFO:cu2qu.ufo:New spline lengths: 1: 14, 2: 722, 3: 338, 4: 20, 5: 14, 6: 11, 7: 13
INFO:fontmake.font_project:Saving TTF for Cantarell-Light
Traceback (most recent call last):
  File "/home/nikolaus/.local/bin/fontmake", line 11, in <module>
    sys.exit(main())
  File "/home/nikolaus/.local/lib/python3.6/site-packages/fontmake/__main__.py", line 186, in main
    project.run_from_glyphs(glyphs_path, **args)
  File "/home/nikolaus/.local/lib/python3.6/site-packages/fontmake/font_project.py", line 369, in run_from_glyphs
    designspace_path, instance_data=instance_data, **kwargs)
  File "/home/nikolaus/.local/lib/python3.6/site-packages/fontmake/font_project.py", line 437, in run_from_designspace
    interpolate_layout_from=interpolate_layout_from, **kwargs)
  File "/home/nikolaus/.local/lib/python3.6/site-packages/fontmake/font_project.py", line 491, in run_from_ufos
    ufos, reverse_direction, conversion_error, **kwargs)
  File "/home/nikolaus/.local/lib/python3.6/site-packages/fontmake/font_project.py", line 199, in build_interpolatable_ttfs
    self.save_otfs(ufos, ttf=True, interpolatable=True, **kwargs)
  File "/home/nikolaus/.local/lib/python3.6/site-packages/fontTools/misc/loggingTools.py", line 372, in wrapper
    return func(*args, **kwds)
  File "/home/nikolaus/.local/lib/python3.6/site-packages/fontmake/font_project.py", line 284, in save_otfs
    font = compileTTF(ufo, convertCubics=False, **compiler_options)
  File "/home/nikolaus/.local/lib/python3.6/site-packages/ufo2ft/__init__.py", line 116, in compileTTF
    postProcessor = PostProcessor(otf, ufo)
  File "/home/nikolaus/.local/lib/python3.6/site-packages/ufo2ft/postProcessor.py", line 18, in __init__
    otf.save(stream)
  File "/home/nikolaus/.local/lib/python3.6/site-packages/fontTools/ttLib/ttFont.py", line 165, in save
    writer_reordersTables = self._save(tmp)
  File "/home/nikolaus/.local/lib/python3.6/site-packages/fontTools/ttLib/ttFont.py", line 204, in _save
    self._writeTable(tag, writer, done, tableCache)
  File "/home/nikolaus/.local/lib/python3.6/site-packages/fontTools/ttLib/ttFont.py", line 615, in _writeTable
    self._writeTable(masterTable, writer, done, tableCache)
  File "/home/nikolaus/.local/lib/python3.6/site-packages/fontTools/ttLib/ttFont.py", line 615, in _writeTable
    self._writeTable(masterTable, writer, done, tableCache)
  File "/home/nikolaus/.local/lib/python3.6/site-packages/fontTools/ttLib/ttFont.py", line 619, in _writeTable
    tabledata = self.getTableData(tag)
  File "/home/nikolaus/.local/lib/python3.6/site-packages/fontTools/ttLib/ttFont.py", line 637, in getTableData
    return self.tables[tag].compile(self)
  File "/home/nikolaus/.local/lib/python3.6/site-packages/fontTools/ttLib/tables/_g_l_y_f.py", line 84, in compile
    glyphData = glyph.compile(self, recalcBBoxes)
  File "/home/nikolaus/.local/lib/python3.6/site-packages/fontTools/ttLib/tables/_g_l_y_f.py", line 350, in compile
    data = data + self.compileComponents(glyfTable)
  File "/home/nikolaus/.local/lib/python3.6/site-packages/fontTools/ttLib/tables/_g_l_y_f.py", line 573, in compileComponents
    data = data + compo.compile(more, haveInstructions, glyfTable)
  File "/home/nikolaus/.local/lib/python3.6/site-packages/fontTools/ttLib/tables/_g_l_y_f.py", line 1095, in compile
    transform[0][0], transform[1][1])
struct.error: 'h' format requires -32768 <= number <= 32767

Producing non-variable interpolated fonts works.

fontMath==0.4.4
fonttools==3.22.0
glyphsLib==2.2.1
MutatorMath==2.1.0
ufo2ft==1.1.0
ufoLib==2.1.1
@behdad
Copy link
Collaborator

behdad commented Feb 13, 2018

@anthrotype can you debug this?

@belluzj
Copy link
Collaborator

belluzj commented Feb 13, 2018

I had the same problem yesterday with some version of Montserrat on my machine. It looks like it comes from a component that is scale by >= 2.0 which if I understand correctly does not fit in the opentype "2.14" format for floats on two words.

Here is the debug session: https://gist.github.com/belluzj/663b1dfe4431dbb9fdd0e87dc01e0f0d

Here is the transform in the file:
2018-02-12

EDIT: this transform is actually in the latest source as well:
image

In Cantarell it's the same problem:
image

@behdad
Copy link
Collaborator

behdad commented Feb 13, 2018

That doesn't explain why it's failing in glyf table though. Why does it work without variations? Oh, it might be that we flatten composites in the normal output?

@behdad
Copy link
Collaborator

behdad commented Feb 13, 2018

But yeah, transform components are limited to (-2,+2).

@madig
Copy link
Collaborator Author

madig commented Feb 13, 2018

Shouldn't that mean that these transformations shouldn't fail, as they are exactly 2?

Edit: Jany says "It's actually - 2 included to +2 excluded" 😁

@behdad
Copy link
Collaborator

behdad commented Feb 13, 2018

Correct. Correct range is [-2,+2).
I think we should automatically replace +2 with 0b1.11111111111111, which is 1.99993896484375.

@behdad
Copy link
Collaborator

behdad commented Feb 13, 2018

And decompose glyphs using larger values. In the varfont case, we should decompose in all masters.

@anthrotype
Copy link
Member

do you mean, we should special-case the component transfomation values when they are == +2.0 and clamp that to be 0b1.11111111111111?
Where? Inside the fonttools TTGlyphpPen, or in the ufo2ft.outlineCompiler that calls it?
Maybe, in the former. So we can also decompose if the value > +2.0 or < -2.0 and we support the full range [-2,+2] (though we're technically cheating, aren't we?).

@behdad
Copy link
Collaborator

behdad commented Feb 26, 2018

do you mean, we should special-case the component transfomation values when they are == +2.0 and clamp that to be 0b1.11111111111111?

Yes.

Where? Inside the fonttools TTGlyphpPen, or in the ufo2ft.outlineCompiler that calls it?

I'd be fine with TTGlyphPen doing.

Maybe, in the former. So we can also decompose if the value > +2.0 or < -2.0 and we support the full range [-2,+2] (though we're technically cheating, aren't we?).

Whatever. Everything we do has a cheating element to it ;). Just make sure you do that for all masters at the same time, if it's for interpolatable output.

@anthrotype
Copy link
Member

anthrotype commented Sep 18, 2018

this was fixed in upstream fonttools fonttools/fonttools#1200

not yet (see below)

@anthrotype
Copy link
Member

anthrotype commented Sep 18, 2018

fonttools/fonttools#1205 added an option to TTGlyphPen called handleOverflowingTransforms which defaults to True. Ufo2ft now needs to call the pen with handleOverflowingTransforms=False when producing interpolatable output, and handle the decomposition of the overflowing glyph in a compatible way for all the masters.

See @behdad's comment
fonttools/fonttools#1205 (comment)

Make it an option then, default to True is fine, but disable in interpolatable output.

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

No branches or pull requests

4 participants