umanwizard / libeot

Library for parsing Embedded OpenType files (Microsoft embedded font "standard"), and converting them to other formats
Other
14 stars 6 forks source link

Corrupt 'loca' table after convert #11

Open pablopla opened 2 months ago

pablopla commented 2 months ago

I'm trying to convert the attached eot file from a pptx presentation with libeot latest commit. The ttf font doesn't open in Debain 12 and 'fonttols ttx font1.ttf' gives me a warning: WARNING: corrupt 'loca' table, or wrong numGlyphs in 'maxp': -1 1151

font1.zip

Is there something wrong with the original font or the conversion? Is it possible to fix the loca table in the ttf font?

umanwizard commented 2 months ago

Confirmed, this is because the font file doesn't have a glyf table. Instead it has a CFF table: see https://learn.microsoft.com/en-us/typography/opentype/spec/cff .

We only rebuild the loca table if the glyf table is present. To fix this bug I probably need to also build it in the case of a CFF table (probably also CFF2).

umanwizard commented 2 months ago

I think we actually shouldn't emit loca at all in this case.

Can you try with the latest commit in master?

pablopla commented 2 months ago

Thank you for the patch. With the latest commit I'm not getting an error but I'm not able to use the font. Double clicking on the font under Debain 12 gives me an error This font could not be displayed and I can't use it in LibreOffice when I place it under the ~/.fonts dir.

libeot/eot2ttf font1.fntdata font1.ttf
has table: CFF 
has table: DSIH
has table: GDEF
has table: GPOS
has table: GSUB
has table: OS/2
has table: cmap
has table: head
has table: hhea
has table: hmtx
has table: maxp
has table: name
has table: post

When I'm trying to install eot2ttf with make install and running it from /usr/local/bin/eot2ttf I'm getting an error: EOT out of spec: no blank loca table found! Shouldn't it work the same as running it from the local libeot/eot2ttf dir?

umanwizard commented 2 months ago

I am able to open the resulting font in fontforge. It will take me a bit longer to investigate why it doesn't work in gnome-font-viewer or libreoffice.

I'll leave this issue open in the meantime.

The issue with make install is a separate problem. I suspect the eot2ttf it is installing is pointing to your system version of libeot rather than the libeot built from this repo. System libeot is many years old and many bugs have been fixed since then. Maybe you can override via LD_LIBRARY_PATH.

pablopla commented 2 months ago

ots-sanitize is able to fix the font. It gives a wrong sfntVersion for glyph data warning. diff of the ttx files shows small changes in sfntVersion, checkSumAdjustment and DSIH.

sudo apt-get install opentype-sanitizer
ots-sanitize font1.ttf font1-santized.ttf
WARNING: wrong sfntVersion for glyph data
File sanitized successfully!
sudo apt-get install fonttools
ttx font1.ttf
ttx font1-santized.ttf
diff font1.ttx font1-santized.ttx
2c2
< <ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="4.38">
---
> <ttFont sfntVersion="OTTO" ttLibVersion="4.38">
1163c1163
<     <checkSumAdjustment value="0x0"/>
---
>     <checkSumAdjustment value="0x5372b4d3"/>
20424,20429d20423
< 
<   <DSIH raw="True">
<     <hexdata>
<       00000001 00000000  
<     </hexdata>
<   </DSIH>
pablopla commented 2 months ago

The eot is otf. this PR fixes the magic number https://github.com/umanwizard/libeot/pull/2 and output a working font. Any chance you could include the fix?

umanwizard commented 2 months ago

Hi @pablopla , can you try with the pr-2 branch: https://github.com/umanwizard/libeot/tree/pr-2

Also, are you able to share the .eot ?

pablopla commented 2 months ago

It works. Thank you. The font is attached to the first message in this issue.

Can you please tag a new release? It might help distros to update their libeot version.