font/sfnt: check the versions of proprietary fonts.

Change-Id: If8d104f5d0e60b6270e7f6a0762432dfe66cfe48
Reviewed-on: https://go-review.googlesource.com/37174
Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
Nigel Tao 2017-02-18 10:56:28 +11:00
parent ed91dc314e
commit b952c941a6

View File

@ -135,13 +135,29 @@ func testProprietary(t *testing.T, proprietor, filename string, minNumGlyphs, fi
t.Fatalf("Parse: %v", err) t.Fatalf("Parse: %v", err)
} }
ppem := fixed.Int26_6(f.UnitsPerEm()) << 6 ppem := fixed.Int26_6(f.UnitsPerEm()) << 6
qualifiedFilename := proprietor + "/" + filename
var buf Buffer
// Some of the tests below, such as which glyph index a particular rune
// maps to, can depend on the specific version of the proprietary font. If
// tested against a different version of that font, the test might (but not
// necessarily will) fail, even though the Go code is good. If so, log a
// message, but don't automatically fail (i.e. dont' call t.Fatalf).
gotVersion, err := f.Name(&buf, NameIDVersion)
if err != nil {
t.Fatalf("Name: %v", err)
}
wantVersion := proprietaryVersions[qualifiedFilename]
if gotVersion != wantVersion {
t.Logf("font version provided differs from the one the tests were written against:"+
"\ngot %q\nwant %q", gotVersion, wantVersion)
}
numGlyphs := f.NumGlyphs() numGlyphs := f.NumGlyphs()
if numGlyphs < minNumGlyphs { if numGlyphs < minNumGlyphs {
t.Fatalf("NumGlyphs: got %d, want at least %d", numGlyphs, minNumGlyphs) t.Fatalf("NumGlyphs: got %d, want at least %d", numGlyphs, minNumGlyphs)
} }
var buf Buffer
iMax := numGlyphs iMax := numGlyphs
if firstUnsupportedGlyph >= 0 { if firstUnsupportedGlyph >= 0 {
iMax = firstUnsupportedGlyph iMax = firstUnsupportedGlyph
@ -156,7 +172,7 @@ func testProprietary(t *testing.T, proprietor, filename string, minNumGlyphs, fi
} }
} }
for r, want := range proprietaryGlyphIndexTestCases[proprietor+"/"+filename] { for r, want := range proprietaryGlyphIndexTestCases[qualifiedFilename] {
got, err := f.GlyphIndex(&buf, r) got, err := f.GlyphIndex(&buf, r)
if err != nil { if err != nil {
t.Errorf("GlyphIndex(%q): %v", r, err) t.Errorf("GlyphIndex(%q): %v", r, err)
@ -169,6 +185,26 @@ func testProprietary(t *testing.T, proprietor, filename string, minNumGlyphs, fi
} }
} }
// proprietaryVersions holds the expected version string of each proprietary
// font tested. If third parties such as Adobe or Microsoft update their fonts,
// and the tests subsequently fail, these versions should be updated too.
//
// Updates are expected to be infrequent. For example, as of 2017, the fonts
// installed by the Debian ttf-mscorefonts-installer package have last modified
// times no later than 2001.
var proprietaryVersions = map[string]string{
"adobe/SourceCodePro-Regular.otf": "Version 2.030;PS 1.0;hotconv 16.6.51;makeotf.lib2.5.65220",
"adobe/SourceCodePro-Regular.ttf": "Version 2.030;PS 1.000;hotconv 16.6.51;makeotf.lib2.5.65220",
"adobe/SourceHanSansSC-Regular.otf": "Version 1.004;PS 1.004;hotconv 1.0.82;makeotf.lib2.5.63406",
"adobe/SourceSansPro-Regular.otf": "Version 2.020;PS 2.0;hotconv 1.0.86;makeotf.lib2.5.63406",
"adobe/SourceSansPro-Regular.ttf": "Version 2.020;PS 2.000;hotconv 1.0.86;makeotf.lib2.5.63406",
"microsoft/Arial.ttf": "Version 2.82",
"microsoft/Comic_Sans_MS.ttf": "Version 2.10",
"microsoft/Times_New_Roman.ttf": "Version 2.82",
"microsoft/Webdings.ttf": "Version 1.03",
}
// proprietaryGlyphIndexTestCases hold a sample of each font's rune to glyph // proprietaryGlyphIndexTestCases hold a sample of each font's rune to glyph
// index cmap. The numerical values can be verified by running the ttx tool. // index cmap. The numerical values can be verified by running the ttx tool.
var proprietaryGlyphIndexTestCases = map[string]map[rune]GlyphIndex{ var proprietaryGlyphIndexTestCases = map[string]map[rune]GlyphIndex{