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

Problem with OpenType bitmap font (Ambrosia.otb) #684

Open
lemzwerg opened this issue Oct 1, 2016 · 13 comments
Open

Problem with OpenType bitmap font (Ambrosia.otb) #684

lemzwerg opened this issue Oct 1, 2016 · 13 comments
Labels

Comments

@lemzwerg
Copy link

lemzwerg commented Oct 1, 2016

This zipped SFNT bitmap-only font, created a long time ago by George Williams with FontForge, can't be correctly disassembled with current git (1eba7b3).
I get (with paths shortened for readability)

Dumping "Ambrosia.otb" to "Ambrosia.ttx"...
Dumping 'GlyphOrder' table...
Dumping 'head' table...
Dumping 'hhea' table...
Dumping 'maxp' table...
Dumping 'OS/2' table...
Dumping 'hmtx' table...
Dumping 'cmap' table...
WARNING: corrupt 'loca' table, or wrong numGlyphs in 'maxp': 0 250
Dumping 'loca' table...
ERROR: An exception occurred during the decompilation of the 'glyf' table
Traceback (most recent call last):
  File ".../fontTools/ttLib/__init__.py", line 418, in __getitem__
    table.decompile(data, self)
  File ".../fontTools/ttLib/tables/_g_l_y_f.py", line 62, in decompile
    if len(data) - next >= 4:
UnboundLocalError: local variable 'next' referenced before assignment
Dumping 'glyf' table...
Dumping 'name' table...
Dumping 'post' table...
Dumping 'EBDT' table...
Dumping 'EBLC' table...
Dumping 'EBSC' table...
Dumping 'GDEF' table...
Dumping 'GPOS' table...
Dumping 'GSUB' table...

The glyf table is empty, and ttx doesn't like this while assembling.

Parsing 'GlyphOrder' table...
Parsing 'head' table...
Parsing 'hhea' table...
Parsing 'maxp' table...
Parsing 'OS/2' table...
Parsing 'hmtx' table...
Parsing 'cmap' table...
Parsing 'loca' table...
Parsing 'glyf' table...
Parsing 'name' table...
Parsing 'post' table...
Parsing 'EBDT' table...
Parsing 'EBLC' table...
Parsing 'EBSC' table...
Parsing 'GDEF' table...
Parsing 'GPOS' table...
Parsing 'GSUB' table...
ERROR: Unhandled exception has occurred
Traceback (most recent call last):
  File ".../fontTools/ttx.py", line 381, in main
    process(jobs, options)
  File ".../fontTools/ttx.py", line 355, in process
    action(input, output, options)
  File ".../fontTools/misc/loggingTools.py", line 372, in wrapper
    return func(*args, **kwds)
  File ".../fontTools/ttx.py", line 276, in ttCompile
    ttf.save(output)
  File ".../fontTools/ttLib/__init__.py", line 216, in save
    self._writeTable(tag, writer, done)
  File ".../fontTools/ttLib/__init__.py", line 649, in _writeTable
    self._writeTable(masterTable, writer, done)
  File ".../fontTools/ttLib/__init__.py", line 652, in _writeTable
    tabledata = self.getTableData(tag)
  File ".../fontTools/ttLib/__init__.py", line 663, in getTableData
    return self.tables[tag].compile(self)
  File ".../fontTools/ttLib/tables/_m_a_x_p.py", line 45, in compile
    self.recalc(ttFont)
  File ".../fontTools/ttLib/tables/_m_a_x_p.py", line 64, in recalc
    self.numGlyphs = len(glyfTable)
TypeError: object of type 'DefaultTable' has no len()

I don't know whether such a font without any data in the glyf table is supported except by FreeType, however, ttx should either support it or cleanly reject it.

@anthrotype
Copy link
Member

UnboundLocalError is not good.
Does the spec say anything about such an empy glyf table?

@lemzwerg
Copy link
Author

lemzwerg commented Oct 2, 2016

Here's a document w.r.t. bitmap-only SFNTs.

https://fontforge.github.io/bitmaponlysfnt.html

The X11 proposal is probably dead – it was suggested by Juliusz Chroboczek, cf.

https://www.irif.fr/~jch//software/xfree86-bitmap-fonts.html

but obviously never adapted.

IIRC, other people have added a single .notdef glyph to glyf to make MS accept the bitmap only font.

@anthrotype anthrotype added the bug label Oct 2, 2016
@anthrotype
Copy link
Member

Thanks for the links.

Basically, if we exclude the *.otb X11 proposal which you say is dead, we are left with the Apple bitmap-only fonts, which have no glyf/loca tables (but havebdat, bloc, bhed tables, which fonttools does not support yet); and the Microsoft's bitmap-only fonts for which the glyf/loca tables are non-empty, and an extra EBSC table is needed (#685).

So, if I'm correct, we want fonttools to assert that glyf is not empty when it's there, right?

@lemzwerg
Copy link
Author

lemzwerg commented Oct 2, 2016

Note that EBSC is an optional table.

I suggest that ttx can read OTB files but not write. And yes, for writing bitmap-only SFNT fonts I suggest that you add a glyf table with a single .notdef glyph in case the font doesn't contain it.

@anthrotype
Copy link
Member

anthrotype commented Oct 2, 2016

you mean, we should allow to decompile empty glyf tables (such as in OTB files), but then when we compile them back we should automatically add a .notdef glyph? I think the user should fix the latter.

@lemzwerg
Copy link
Author

lemzwerg commented Oct 2, 2016

Exactly. Perhaps it would help if ttx emits a message that OTBs are dead.

@behdad
Copy link
Member

behdad commented Nov 1, 2016

you mean, we should allow to decompile empty glyf tables (such as in OTB files), but then when we compile them back we should automatically add a .notdef glyph? I think the user should fix the latter.

Right now fonttools is not in the business of enforcing anything on this level. I think it should stay that way.

@lemzwerg
Copy link
Author

lemzwerg commented Nov 1, 2016

OK, then this font should rejected with a proper error message.

@joukewitteveen
Copy link

The X11 proposal is probably dead

I'd say it is not! With the recent release of Pango 1.44, it is practically the only way to distribute bitmap fonts on linux.

but obviously never adopted.

At least Harfbuzz, FreeType, and FontForge support it. Probably other projects do too.

It is true that it took quite some time to go from BDF to PCF to OTB, but we do seem to be getting there.

@khaledhosny
Copy link
Collaborator

I think the empty glyf/loca tables are complicating thins needlessly. They are not needed, HarfBuzz (and I think FreeType) will handle the fonts without these tables just fine and no other systems support these fonts any way. FontForge should either no added the empty table or have an option not to do so.

justvanrossum added a commit to justvanrossum/fonttools that referenced this issue Aug 3, 2019
justvanrossum added a commit that referenced this issue Aug 3, 2019
* Rename last to pos, and next to nextPos
* make sure nextPos is initialized, to avoid UnboundLocalError on an empty glyf table, partially addressing #684
@justvanrossum
Copy link
Collaborator

justvanrossum commented Aug 3, 2019

Fixing the UnboundLocalError reveals that there's a lot of code in fonttools that assumes len(ttf['glyf']) == len(ttf.getGlyphOrder()), especially when compiling.

I have a rough patch that allows that assumption to be broken, but I tend to agree with @khaledhosny that the loca/glyf tables should simply not be there.

To allow this font to be dumped requires a small change to glyfTable.toXML(). I will make a PR for that.

justvanrossum added a commit to justvanrossum/fonttools that referenced this issue Aug 3, 2019
… from the glyph order) when writing to XML. Partially addresses fonttools#684.
@behdad
Copy link
Member

behdad commented Aug 4, 2019

Basically, just EBLC/EBDT and head, hhea, hmtx should be enough. "Empty" glyf/loca is wrong to me.

If each size of a font goes into its own OT face, it's easy. Multiple of those can be combined in the same TTC file. This should work just fine with fontconfig / Pango.

If multiple bitmap sizes are to go into the same OT face, that becomes more problematic as the hmtx table can represent extents of one only. It's not an issue for monospace fonts, but probably will be for others.

@lemzwerg
Copy link
Author

lemzwerg commented Aug 4, 2019 via email

justvanrossum added a commit that referenced this issue Aug 15, 2019
)

[ttLib] Allow the glyf table to be incomplete (to not contain everything from the glyph order) when writing to XML. This partially addresses #684 in that it will allow the font Ambrosia.otb to be dumped with ttx (but not recompiled). Log a warning when a glyph is not present.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants