freetype icon indicating copy to clipboard operation
freetype copied to clipboard

OpenSans font compatability

Open GoogleCodeExporter opened this issue 9 years ago • 16 comments

It seems that the truetype package cannot load the OpenSans font.

The font is compatible with other TTF viewers/editors.. so I wonder why I 
receive this error (from freetype.ParseFont() function):

freetype: invalid TrueType format: bad kern table length

Download font at www.opensans.com, I used the OpenSans-Regular.ttf font, but it 
seems all the OpenSans fonts do not parse properly.

Best regards,
Stephen

Original issue reported on code.google.com by [email protected] on 26 May 2013 at 4:47

GoogleCodeExporter avatar Aug 11 '15 04:08 GoogleCodeExporter

Just ran into the same issue. Any plans to fix this in the near future?

boriwo avatar Sep 21 '15 04:09 boriwo

For me it opens Open-sans-regular but fails on many others (on a mac OSX 10.11, go 1.5.1 )

alimoeeny avatar Nov 09 '15 17:11 alimoeeny

I'm having the same problem.

jeffwilliams avatar Jan 30 '16 02:01 jeffwilliams

Here's a great explanation on what's wrong with Open Sans kerning table; its parsing indeed fails on this check:

        if 6*f.nKern != length-14 {
                return FormatError("bad kern table length")
        }

artyom avatar Feb 06 '16 13:02 artyom

Same problem for me. Are there any plans to fix this?

narqo avatar Feb 22 '16 01:02 narqo

Any update? It seems to fail with Open Sans regular as well now.

fstanis avatar Apr 09 '17 22:04 fstanis

A quick fix is to apply the following patch:

--- a/truetype/truetype.go
+++ b/truetype/truetype.go
@@ -345,7 +345,7 @@ func (f *Font) parseKern() error {
                return UnsupportedError(fmt.Sprintf("kern coverage: 0x%04x", coverage))
        }
        f.nKern, offset = int(u16(f.kern, offset)), offset+2
-       if 6*f.nKern != length-14 {
+	if uint16(6*f.nKern) != uint16(length-14) {
                return FormatError("bad kern table length")
        }
        return nil

This allows at least Calibri to be loaded successfully. I have no idea about other consequences, though.

rillig avatar May 25 '17 06:05 rillig

For some reason this problem is still not fixed in the main repo. This prevents lots of fonts from being used with this library.

The original freetype repo, would load such fonts. IMHO a bit incorrectly, but better than nothing.

Here is my version of a slightly more robust check:

	// For large kerning tables, the extracted length value may be incorrect.
	// For such fonts, often only the lower 16 bits of the actual length are
	// stored. Here we validate the lower 16 bits, and also make sure that
	// the extracted number of kerning pairs does not exceed the total length
	// of the kerning table.
	if uint16(6*f.nKern) != uint16(length-14) || 6*f.nKern > len(f.kern)-18 {
		return FormatError("bad kern table length")
	}

adnsv avatar May 30 '19 16:05 adnsv

Hello! There is any updates on this? :thinking:

guilhermehubner avatar Aug 06 '19 17:08 guilhermehubner

This is still an issue, btw

SamusAranX avatar May 09 '20 02:05 SamusAranX

Also hitting this with the the https://fonts.google.com/specimen/Anton downloaded ttf file.

montanaflynn avatar Jul 02 '20 05:07 montanaflynn

Still an issue in 2021

zwang avatar May 04 '21 21:05 zwang

+1

Vahanerevan avatar Jul 16 '21 18:07 Vahanerevan

Still an issue in 2022

dastanaron avatar Feb 10 '22 11:02 dastanaron

Still have issue with Clear Sans

rothcold avatar Feb 11 '22 17:02 rothcold

This appears to still be an issue as of 2024; we just got a report about this over on the Ikemen GO repository (see https://github.com/ikemen-engine/Ikemen-GO/issues/1715); it affects this font.

Is there any reason why the changes made in unidoc's fork or adnsv's fix above haven't been incorporated into the main branch?

SuperFromND avatar Apr 01 '24 12:04 SuperFromND