googlefonts / ufo2ft

A bridge from UFOs to FontTools objects (and therefore, OTFs and TTFs).
MIT License
148 stars 42 forks source link

fails to build mononoki fonts #339

Open fabiangreffrath opened 4 years ago

fabiangreffrath commented 4 years ago

Hi there,

it is currently impossible to build the mononoki fonts [1] from their sources, because of an error in the ufo2ft step:

$ fontmake -i -o otf -g src/mononoki.glyphs
INFO:fontmake.font_project:Building master UFOs and designspace from Glyphs source
INFO:glyphsLib.classes:Parsing "src/mononoki.glyphs" file into <GSFont>
INFO:fontmake.font_project:Interpolating master UFOs from designspace
INFO:mutatorMath:       Generating instance mononoki-Regular.ufo
INFO:mutatorMath:../instance_ufo/mononoki-Regular.ufo:
Errors calculating 122 glyphs: 
        A.hex
        B.hex
        C.hex
        Che-cy
        D.hex
        Delta
        E.hex
        Ef-cy
        Ereversed-cy
        Eth
        F.hex
        Hardsign-cy
        Ia-cy
        Iu-cy
        K
        Lslash
        Omega
        Oslash
        Psi
        Q
        Softsign-cy
        U
        W
        Yeru-cy
        a
        a.hex
        acute
        ampersand
        ampersand_ampersand
        asterisk
        at
        b
        b.hex
        be-cy
        beta
        c.hex
        che-cy
        chi
        d
        d.hex
        dagger
        daggerdbl
        dollar
        dotlessi
        dotlessj
        e
        e.hex
        ef-cy
        epsilon
        equal_equal
        equal_greater
        ereversed-cy
        eta
        eth
        exclam_equal
        f
        f.hex
        five.hex
        g
        gamma
        germandbls
        greater_equal
        greaterequal
        h
        hardsign-cy
        hyphen_greater
        i
        ia-cy
        increment
        integral
        iota
        iu-cy
        j
        k
        l
        lacute
        lcaron
        ldot
        literSign
        lslash
        m
        multiply
        n
        omega
        onefraction
        onetenth
        ordfeminine
        oslash
        p
        paragraph
        partialdiff
        phi
        pi
        plus
        psi
        q
        question
        quotedbl
        quotereversed
        r
        s
        sigma
        six
        softsign-cy
        sterling
        summation
        t
        tau
        theta
        trademark
        u
        uniE0A2
        v
        ve-cy
        w
        x
        xi
        y
        yeru-cy
        ze-cy
        zero
        zeta
INFO:mutatorMath:       Generating instance mononoki-Bold.ufo
INFO:mutatorMath:../instance_ufo/mononoki-Bold.ufo:
Errors calculating 122 glyphs: 
        A.hex
        B.hex
        C.hex
        Che-cy
        D.hex
        Delta
        E.hex
        Ef-cy
        Ereversed-cy
        Eth
        F.hex
        Hardsign-cy
        Ia-cy
        Iu-cy
        K
        Lslash
        Omega
        Oslash
        Psi
        Q
        Softsign-cy
        U
        W
        Yeru-cy
        a
        a.hex
        acute
        ampersand
        ampersand_ampersand
        asterisk
        at
        b
        b.hex
        be-cy
        beta
        c.hex
        che-cy
        chi
        d
        d.hex
        dagger
        daggerdbl
        dollar
        dotlessi
        dotlessj
        e
        e.hex
        ef-cy
        epsilon
        equal_equal
        equal_greater
        ereversed-cy
        eta
        eth
        exclam_equal
        f
        f.hex
        five.hex
        g
        gamma
        germandbls
        greater_equal
        greaterequal
        h
        hardsign-cy
        hyphen_greater
        i
        ia-cy
        increment
        integral
        iota
        iu-cy
        j
        k
        l
        lacute
        lcaron
        ldot
        literSign
        lslash
        m
        multiply
        n
        omega
        onefraction
        onetenth
        ordfeminine
        oslash
        p
        paragraph
        partialdiff
        phi
        pi
        plus
        psi
        q
        question
        quotedbl
        quotereversed
        r
        s
        sigma
        six
        softsign-cy
        sterling
        summation
        t
        tau
        theta
        trademark
        u
        uniE0A2
        v
        ve-cy
        w
        x
        xi
        y
        yeru-cy
        ze-cy
        zero
        zeta
INFO:mutatorMath:       Generating instance mononoki-Italic.ufo
INFO:mutatorMath:../instance_ufo/mononoki-Italic.ufo:
Errors calculating 122 glyphs: 
        A.hex
        B.hex
        C.hex
        Che-cy
        D.hex
        Delta
        E.hex
        Ef-cy
        Ereversed-cy
        Eth
        F.hex
        Hardsign-cy
        Ia-cy
        Iu-cy
        K
        Lslash
        Omega
        Oslash
        Psi
        Q
        Softsign-cy
        U
        W
        Yeru-cy
        a
        a.hex
        acute
        ampersand
        ampersand_ampersand
        asterisk
        at
        b
        b.hex
        be-cy
        beta
        c.hex
        che-cy
        chi
        d
        d.hex
        dagger
        daggerdbl
        dollar
        dotlessi
        dotlessj
        e
        e.hex
        ef-cy
        epsilon
        equal_equal
        equal_greater
        ereversed-cy
        eta
        eth
        exclam_equal
        f
        f.hex
        five.hex
        g
        gamma
        germandbls
        greater_equal
        greaterequal
        h
        hardsign-cy
        hyphen_greater
        i
        ia-cy
        increment
        integral
        iota
        iu-cy
        j
        k
        l
        lacute
        lcaron
        ldot
        literSign
        lslash
        m
        multiply
        n
        omega
        onefraction
        onetenth
        ordfeminine
        oslash
        p
        paragraph
        partialdiff
        phi
        pi
        plus
        psi
        q
        question
        quotedbl
        quotereversed
        r
        s
        sigma
        six
        softsign-cy
        sterling
        summation
        t
        tau
        theta
        trademark
        u
        uniE0A2
        v
        ve-cy
        w
        x
        xi
        y
        yeru-cy
        ze-cy
        zero
        zeta
INFO:mutatorMath:       Generating instance mononoki-BoldItalic.ufo
INFO:mutatorMath:../instance_ufo/mononoki-BoldItalic.ufo:
Errors calculating 123 glyphs: 
        A.hex
        B.hex
        C.hex
        Che-cy
        D.hex
        Delta
        E.hex
        Ef-cy
        Ereversed-cy
        Eth
        F.hex
        Hardsign-cy
        Ia-cy
        Iu-cy
        K
        Lslash
        Omega
        Oslash
        Psi
        Q
        Softsign-cy
        U
        W
        Yeru-cy
        a
        a.hex
        acute
        ampersand
        ampersand_ampersand
        asterisk
        at
        b
        b.hex
        be-cy
        beta
        c.hex
        che-cy
        chi
        d
        d.hex
        dagger
        daggerdbl
        dollar
        dotlessi
        dotlessj
        e
        e.hex
        ef-cy
        epsilon
        equal_equal
        equal_greater
        ereversed-cy
        eta
        eth
        exclam_equal
        f
        f.hex
        five.hex
        four.dnom
        g
        gamma
        germandbls
        greater_equal
        greaterequal
        h
        hardsign-cy
        hyphen_greater
        i
        ia-cy
        increment
        integral
        iota
        iu-cy
        j
        k
        l
        lacute
        lcaron
        ldot
        literSign
        lslash
        m
        multiply
        n
        omega
        onefraction
        onetenth
        ordfeminine
        oslash
        p
        paragraph
        partialdiff
        phi
        pi
        plus
        psi
        q
        question
        quotedbl
        quotereversed
        r
        s
        sigma
        six
        softsign-cy
        sterling
        summation
        t
        tau
        theta
        trademark
        u
        uniE0A2
        v
        ve-cy
        w
        x
        xi
        y
        yeru-cy
        ze-cy
        zero
        zeta
INFO:fontmake.font_project:Applying instance data from designspace
INFO:fontmake.font_project:Building OTF for mononoki-Regular
INFO:ufo2ft:Pre-processing glyphs
INFO:ufo2ft.filters:Running DecomposeComponentsFilter on mononoki-Regular
INFO:ufo2ft.filters:Running RemoveOverlapsFilter on mononoki-Regular
INFO:ufo2ft:Building OpenType tables
ERROR:ufo2ft.featureCompiler:Compilation failed! Inspect temporary file: '/tmp/tmpwt82550h'
Traceback (most recent call last):
  File "/usr/bin/fontmake", line 11, in <module>
    load_entry_point('fontmake==1.8.0', 'console_scripts', 'fontmake')()
  File "/usr/lib/python3/dist-packages/fontmake/__main__.py", line 267, in main
    project.run_from_glyphs(glyphs_path, **args)
  File "/usr/lib/python3/dist-packages/fontmake/font_project.py", line 578, in run_from_glyphs
    self.run_from_designspace(designspace_path, **kwargs)
  File "/usr/lib/python3/dist-packages/fontmake/font_project.py", line 663, in run_from_designspace
    **kwargs)
  File "/usr/lib/python3/dist-packages/fontmake/font_project.py", line 699, in run_from_ufos
    self.build_otfs(ufos, **kwargs)
  File "/usr/lib/python3/dist-packages/fontmake/font_project.py", line 242, in build_otfs
    self.save_otfs(ufos, **kwargs)
  File "/usr/lib/python3/dist-packages/fontTools/misc/loggingTools.py", line 375, in wrapper
    return func(*args, **kwds)
  File "/usr/lib/python3/dist-packages/fontmake/font_project.py", line 425, in save_otfs
    for font, ufo in zip(fonts, ufos):
  File "/usr/lib/python3/dist-packages/fontmake/font_project.py", line 290, in _iter_compile
    yield compile_func(ufo, **options)
  File "/usr/lib/python3/dist-packages/ufo2ft/__init__.py", line 116, in compileOTF
    featureCompilerClass=featureCompilerClass,
  File "/usr/lib/python3/dist-packages/ufo2ft/__init__.py", line 408, in compileFeatures
    return featureCompiler.compile()
  File "/usr/lib/python3/dist-packages/ufo2ft/featureCompiler.py", line 131, in compile
    self.buildTables()
  File "/usr/lib/python3/dist-packages/ufo2ft/featureCompiler.py", line 252, in buildTables
    self.ttFont, self.features, filename=path
  File "/usr/lib/python3/dist-packages/fontTools/feaLib/builder.py", line 31, in addOpenTypeFeaturesFromString
    addOpenTypeFeatures(font, featurefile, tables=tables)
  File "/usr/lib/python3/dist-packages/fontTools/feaLib/builder.py", line 22, in addOpenTypeFeatures
    builder.build(tables=tables)
  File "/usr/lib/python3/dist-packages/fontTools/feaLib/builder.py", line 118, in build
    self.build_feature_aalt_()
  File "/usr/lib/python3/dist-packages/fontTools/feaLib/builder.py", line 202, in build_feature_aalt_
    location)
fontTools.feaLib.error.FeatureLibError: <features>:8:5: Feature locl has not been defined

This is with the following Debian packages:

ii fontmake 1.8.0-1 all Compile fonts from UFO or Glyphs to OTF/TTF ii python3-ufo2ft 2.6.0-1 all Bridge from UFOs to fonttools objects ii python3-fonttools 3.35.1-1 all Converts OpenType and TrueType fonts to and from XML (Python 3 Library)

[1] https://github.com/madmalik/mononoki/tree/master

anthrotype commented 4 years ago

The error says that the.features contain an "aalt" feature block that references a "locl" feature but the latter is not defined among the features. Check if that's the case and if so remove the reference to locl inside aalt block. The interpolation issues in mutatormath indicates that many of the glyphs are not interpolation compatible. Either you make them compatible, or you do not use the "-i" option and only build the masters, without generating instances.

fabiangreffrath commented 4 years ago

Thanks for your reply! Please note that I don't have any control over the font, I merely realized it is currently impossible to build it from its glyphs source using fontmake. Is there anything that could be done to mitigate this issue on the fontmake/ufo2ft side?

anthrotype commented 4 years ago

The undefined locl in the aalt feature block must be fixed in the sources in order to compile the OpenType features. If the font only has discrete masters with outlines that are not designed to build interpolated instances or variable font, then you can still compile them but without passing the --interpolate option.

fabiangreffrath commented 4 years ago

Indeed, it seems the following change is necessary to generate the fonts without -i:

--- a/src/mononoki.glyphs
+++ b/src/mononoki.glyphs
@@ -37,7 +37,7 @@ name = Languagesystems;
 features = (
 {
 automatic = 1;
-code = "feature locl;\012feature frac;\012feature ordn;\012";
+code = "";
 name = aalt;
 }
 );

Now if we could get generating the interpolated instances to work, that would be perfect...

Thank you very much already!

fabiangreffrath commented 4 years ago

Either you make them compatible

@anthrotype Could you please provide a hint what is required to make glyphs "interpolation compatible"? What does one have to do to achieve this?

madig commented 4 years ago

The short version is that you have to make outlines, anchors and components (and their order) match across all masters. All outlines must have the same amount of points and the same type of points, only their position may be different. There is no open-source app which makes this easy I think, so you have to manually inspect the glyphs that fontmake complains about.

anthrotype commented 4 years ago

but maybe the font he is trying to build with -i was not designed to be interpolatable to begin with, and only has a bunch of unrelated "masters" with "instances" sitting at the same location as their respective masters, thus not meant to be interplated in between them.

If this is the case, then 1) either you do not pass -i and you're happy with the result, or 2) you wait for the new fontmake instantiator (https://github.com/googlefonts/fontmake/pull/555) which will not flag such non-interpolatable instances as errors (as long as they really are identical to their masters, except for some extra metadata).

fabiangreffrath commented 4 years ago

Thank you very much for your replies! I'll probably stick with solution (1) then, i.e. build only masters without instances.

fabiangreffrath commented 4 years ago

Does it make a difference if I pass the -M option and install the font files from instance_ttf or if I don't pass that option and install the font files from master_ttf?

anthrotype commented 4 years ago

no, they should be the same

fabiangreffrath commented 4 years ago

Sorry to bug you again, but there is still something odd with the resulting TTF fonts when building from the glyphs source. Take a look at the GTK+ font chooser: There are two Bold variants and one of them is identical to the Regular variant:

Bildschirmfoto vom 2019-08-07 09-04-32

Also, how do it make sure the font is identified as monospaced?

madig commented 4 years ago

What's the output of fc-list?

Re monospace, try this: https://github.com/madmalik/mononoki/issues/23

fabiangreffrath commented 4 years ago

What's the output of fc-list?

$ fc-list | grep mononoki
/usr/share/fonts/truetype/mononoki/mononoki-Italic.ttf: mononoki:style=Italic
/usr/share/fonts/truetype/mononoki/mononoki-Regular.ttf: mononoki:style=Regular
/usr/share/fonts/truetype/mononoki/mononoki-Bold.ttf: mononoki:style=Bold
/usr/share/fonts/truetype/mononoki/mononoki-BoldItalic.ttf: mononoki,mononoki Bold:style=Bold Italic,Italic

Re monospace, try this: madmalik/mononoki#23

Thanks! It seems the first part of the solution is already been taken care of:

$ grep -r IsFixedPitch -- master_ufo/*.ufo/*
master_ufo/mononoki-BoldItalic.ufo/fontinfo.plist:    <key>postscriptIsFixedPitch</key>
master_ufo/mononoki-Bold.ufo/fontinfo.plist:    <key>postscriptIsFixedPitch</key>
master_ufo/mononoki-Italic.ufo/fontinfo.plist:    <key>postscriptIsFixedPitch</key>
master_ufo/mononoki-Regular.ufo/fontinfo.plist:    <key>postscriptIsFixedPitch</key>

But the width for the individual glyphs vary quite a lot:

$ grep '^width = [[:digit:]]\+' -- src/mononoki.glyphs | sort | uniq
width = 1150;
width = 250;
width = 493;
width = 560;
width = 563;
width = 565;
width = 567;
width = 575;
width = 577;
width = 579;
width = 580;
width = 585;
width = 587;
width = 588;
width = 590;
width = 600;
width = 75;
fabiangreffrath commented 4 years ago

This is the diff between the output of sc-scan between the fonts built from the UFO sources (which do not show this strange behavior, and the ones built from the Glyphs source:

--- /home/fabian/mononoki-ufo.txt   2019-08-07 09:16:30.514025412 +0200
+++ /home/fabian/mononoki-glyphs.txt    2019-08-07 09:17:53.186157154 +0200
@@ -1,13 +1,13 @@
 master_ttf/mononoki-BoldItalic.ttf
-Pattern has 24 elts (size 32)
-   family: "mononoki"(s)
-   familylang: "en"(s)
-   style: "BoldItalic"(s)
-   stylelang: "en"(s)
-   fullname: "mononoki BoldItalic"(s)
+Pattern has 23 elts (size 32)
+   family: "mononoki"(s) "mononoki Bold"(s)
+   familylang: "en"(s) "en"(s)
+   style: "Bold Italic"(s) "Italic"(s)
+   stylelang: "en"(s) "en"(s)
+   fullname: "mononoki Bold Italic"(s)
    fullnamelang: "en"(s)
    slant: 100(i)(s)
-   weight: 200(f)(s)
+   weight: 80(f)(s)
    width: 100(f)(s)
    foundry: "NONE"(s)
    file: "master_ttf/mononoki-BoldItalic.ttf"(s)
@@ -32,7 +32,6 @@
 (s)
    lang: aa|av|ay|bg|bi|br|bs|ca|ce|ch|co|cs|cy|da|de|en|eo|es|et|eu|fi|fj|fo|fr|fur|fy|gd|gl|gv|ho|hr|hu|ia|id|ie|io|is|it|kum|lb|lez|lt|mg|nb|nds|nl|nn|no|nr|nso|ny|oc|om|os|pl|pt|rm|ru|sel|sk|sl|sma|smj|so|sq|ss|st|sv|sw|tk|tl|tn|ts|uz|vo|vot|wa|wen|xh|yap|zu|an|csb|fil|hsb|ht|jv|kj|ku-tr|kwm|li|ms|ng|pap-an|pap-aw|rn|rw|sc|sg|sn|su|za(s)
    fontversion: 65602(i)(s)
-   capability: "otlayout:DFLT"(s)
    fontformat: "TrueType"(s)
    decorative: False(s)
    postscriptname: "mononoki-BoldItalic"(s)
@@ -42,7 +41,7 @@

 master_ttf/mononoki-Bold.ttf
-Pattern has 24 elts (size 32)
+Pattern has 23 elts (size 32)
    family: "mononoki"(s)
    familylang: "en"(s)
    style: "Bold"(s)
@@ -50,7 +49,7 @@
    fullname: "mononoki Bold"(s)
    fullnamelang: "en"(s)
    slant: 0(i)(s)
-   weight: 200(f)(s)
+   weight: 80(f)(s)
    width: 100(f)(s)
    foundry: "NONE"(s)
    file: "master_ttf/mononoki-Bold.ttf"(s)
@@ -75,7 +74,6 @@
 (s)
    lang: aa|av|ay|bg|bi|br|bs|ca|ce|ch|co|cs|cy|da|de|en|eo|es|et|eu|fi|fj|fo|fr|fur|fy|gd|gl|gv|ho|hr|hu|ia|id|ie|io|is|it|kum|lb|lez|lt|mg|nb|nds|nl|nn|no|nr|nso|ny|oc|om|os|pl|pt|rm|ru|sel|sk|sl|sma|smj|so|sq|ss|st|sv|sw|tk|tl|tn|ts|uz|vo|vot|wa|wen|xh|yap|zu|an|csb|fil|hsb|ht|jv|kj|ku-tr|kwm|li|ms|ng|pap-an|pap-aw|rn|rw|sc|sg|sn|su|za(s)
    fontversion: 65602(i)(s)
-   capability: "otlayout:DFLT"(s)
    fontformat: "TrueType"(s)
    decorative: False(s)
    postscriptname: "mononoki-Bold"(s)
@@ -85,7 +83,7 @@

 master_ttf/mononoki-Italic.ttf
-Pattern has 24 elts (size 32)
+Pattern has 23 elts (size 32)
    family: "mononoki"(s)
    familylang: "en"(s)
    style: "Italic"(s)
@@ -118,7 +116,6 @@
 (s)
    lang: aa|av|ay|bg|bi|br|bs|ca|ce|ch|co|cs|cy|da|de|en|eo|es|et|eu|fi|fj|fo|fr|fur|fy|gd|gl|gv|ho|hr|hu|ia|id|ie|io|is|it|kum|lb|lez|lt|mg|nb|nds|nl|nn|no|nr|nso|ny|oc|om|os|pl|pt|rm|ru|sel|sk|sl|sma|smj|so|sq|ss|st|sv|sw|tk|tl|tn|ts|uz|vo|vot|wa|wen|xh|yap|zu|an|csb|fil|hsb|ht|jv|kj|ku-tr|kwm|li|ms|ng|pap-an|pap-aw|rn|rw|sc|sg|sn|su|za(s)
    fontversion: 65602(i)(s)
-   capability: "otlayout:DFLT"(s)
    fontformat: "TrueType"(s)
    decorative: False(s)
    postscriptname: "mononoki-Italic"(s)
@@ -128,7 +125,7 @@

 master_ttf/mononoki-Regular.ttf
-Pattern has 24 elts (size 32)
+Pattern has 23 elts (size 32)
    family: "mononoki"(s)
    familylang: "en"(s)
    style: "Regular"(s)
@@ -161,7 +158,6 @@
 (s)
    lang: aa|av|ay|bg|bi|br|bs|ca|ce|ch|co|cs|cy|da|de|en|eo|es|et|eu|fi|fj|fo|fr|fur|fy|gd|gl|gv|ho|hr|hu|ia|id|ie|io|is|it|kum|lb|lez|lt|mg|nb|nds|nl|nn|no|nr|nso|ny|oc|om|os|pl|pt|rm|ru|sel|sk|sl|sma|smj|so|sq|ss|st|sv|sw|tk|tl|tn|ts|uz|vo|vot|wa|wen|xh|yap|zu|an|csb|fil|hsb|ht|jv|kj|ku-tr|kwm|li|ms|ng|pap-an|pap-aw|rn|rw|sc|sg|sn|su|za(s)
    fontversion: 65602(i)(s)
-   capability: "otlayout:DFLT"(s)
    fontformat: "TrueType"(s)
    decorative: False(s)
    postscriptname: "mononoki-Regular"(s)
anthrotype commented 4 years ago

@fabiangreffrath try rebuinding using the latest fontmake 2.0b1 (use --pre when you upgrade with pip since it's a pre-release). You should be able now to pass -i option (provided there are no truly interpolated instances, but only instances at the same locations as the masters). It may be that the instances defined in the .glyphs file contain extra metadata that is not applied when only building the masters (I haven't looked at the mononoki sources).

madig commented 4 years ago

The feature code is broken though. It seems incomplete. Glyphs seems to export it fine though. The special hex glyphs are not going to work.

fabiangreffrath commented 4 years ago

@anthrotype and @madig Thank you very much! I am now building the fonts from their UFO sources and the resulting TTF files do not show the strange behavior I reported above. Also, forcefully setting all glyph widths to 575 (or 1150, respectively) was enough to recognize the fonts as monospaced.

madig commented 4 years ago

Congratulations :) You still might want to run your changes by the original designer (and mention the broken features, but he/she probably already knows), mass-changing widths is a sledgehammer method :)

fabiangreffrath commented 4 years ago

I have reported the issues upstream, thanks!