From 54d3d47daf9190275bbdaf8703b84969a4593451 Mon Sep 17 00:00:00 2001 From: Corey Hulen Date: Fri, 24 Mar 2017 23:31:34 -0700 Subject: PLT-6076 Adding viper libs for config file changes (#5871) * Adding viper libs for config file changes * Removing the old fsnotify lib * updating some missing libs --- .../x/image/font/sfnt/proprietary_test.go | 394 +++++++++++++++++++-- 1 file changed, 368 insertions(+), 26 deletions(-) (limited to 'vendor/golang.org/x/image/font/sfnt/proprietary_test.go') diff --git a/vendor/golang.org/x/image/font/sfnt/proprietary_test.go b/vendor/golang.org/x/image/font/sfnt/proprietary_test.go index b105ee593..ccf013d1d 100644 --- a/vendor/golang.org/x/image/font/sfnt/proprietary_test.go +++ b/vendor/golang.org/x/image/font/sfnt/proprietary_test.go @@ -19,14 +19,14 @@ End User License Agreement (EULA) and a CAB format decoder. These tests assume that such fonts have already been installed. You may need to specify the directories for these fonts: -go test golang.org/x/image/font/sfnt -args -proprietary -adobeDir=/foo/bar/aFonts -microsoftDir=/foo/bar/mFonts +go test golang.org/x/image/font/sfnt -args -proprietary -adobeDir=$HOME/fonts/adobe -appleDir=$HOME/fonts/apple -microsoftDir=$HOME/fonts/microsoft To only run those tests for the Microsoft fonts: -go test golang.org/x/image/font/sfnt -test.run=ProprietaryMicrosoft -args -proprietary +go test golang.org/x/image/font/sfnt -test.run=ProprietaryMicrosoft -args -proprietary etc */ -// TODO: add Apple system fonts? Google fonts (Droid? Noto?)? Emoji fonts? +// TODO: add Google fonts (Droid? Noto?)? Emoji fonts? // TODO: enable Apple/Microsoft tests by default on Darwin/Windows? @@ -35,6 +35,8 @@ import ( "flag" "io/ioutil" "path/filepath" + "strconv" + "strings" "testing" "golang.org/x/image/font" @@ -60,6 +62,16 @@ var ( "directory name for the Adobe proprietary fonts", ) + appleDir = flag.String( + "appleDir", + // This needs to be set explicitly. These fonts come with macOS, which + // is widely available but not freely available. + // + // On a Mac, set this to "/System/Library/Fonts/". + "", + "directory name for the Apple proprietary fonts", + ) + microsoftDir = flag.String( "microsoftDir", "/usr/share/fonts/truetype/msttcorefonts", @@ -68,11 +80,11 @@ var ( ) func TestProprietaryAdobeSourceCodeProOTF(t *testing.T) { - testProprietary(t, "adobe", "SourceCodePro-Regular.otf", 1500, 2) + testProprietary(t, "adobe", "SourceCodePro-Regular.otf", 1500, 34) } func TestProprietaryAdobeSourceCodeProTTF(t *testing.T) { - testProprietary(t, "adobe", "SourceCodePro-Regular.ttf", 1500, 36) + testProprietary(t, "adobe", "SourceCodePro-Regular.ttf", 1500, -1) } func TestProprietaryAdobeSourceHanSansSC(t *testing.T) { @@ -80,23 +92,47 @@ func TestProprietaryAdobeSourceHanSansSC(t *testing.T) { } func TestProprietaryAdobeSourceSansProOTF(t *testing.T) { - testProprietary(t, "adobe", "SourceSansPro-Regular.otf", 1800, 2) + testProprietary(t, "adobe", "SourceSansPro-Regular.otf", 1800, 34) } func TestProprietaryAdobeSourceSansProTTF(t *testing.T) { - testProprietary(t, "adobe", "SourceSansPro-Regular.ttf", 1800, 54) + testProprietary(t, "adobe", "SourceSansPro-Regular.ttf", 1800, -1) +} + +func TestProprietaryAppleAppleSymbols(t *testing.T) { + testProprietary(t, "apple", "Apple Symbols.ttf", 4600, -1) +} + +func TestProprietaryAppleGeezaPro0(t *testing.T) { + testProprietary(t, "apple", "GeezaPro.ttc?0", 1700, -1) +} + +func TestProprietaryAppleGeezaPro1(t *testing.T) { + testProprietary(t, "apple", "GeezaPro.ttc?1", 1700, -1) +} + +func TestProprietaryAppleHiragino0(t *testing.T) { + testProprietary(t, "apple", "ヒラギノ角ゴシック W0.ttc?0", 9000, 6) +} + +func TestProprietaryAppleHiragino1(t *testing.T) { + testProprietary(t, "apple", "ヒラギノ角ゴシック W0.ttc?1", 9000, 6) } func TestProprietaryMicrosoftArial(t *testing.T) { - testProprietary(t, "microsoft", "Arial.ttf", 1200, 98) + testProprietary(t, "microsoft", "Arial.ttf", 1200, -1) +} + +func TestProprietaryMicrosoftArialAsACollection(t *testing.T) { + testProprietary(t, "microsoft", "Arial.ttf?0", 1200, -1) } func TestProprietaryMicrosoftComicSansMS(t *testing.T) { - testProprietary(t, "microsoft", "Comic_Sans_MS.ttf", 550, 98) + testProprietary(t, "microsoft", "Comic_Sans_MS.ttf", 550, -1) } func TestProprietaryMicrosoftTimesNewRoman(t *testing.T) { - testProprietary(t, "microsoft", "Times_New_Roman.ttf", 1200, 98) + testProprietary(t, "microsoft", "Times_New_Roman.ttf", 1200, -1) } func TestProprietaryMicrosoftWebdings(t *testing.T) { @@ -117,27 +153,55 @@ func testProprietary(t *testing.T, proprietor, filename string, minNumGlyphs, fi t.Skip("skipping proprietary font test") } - file, err := []byte(nil), error(nil) - switch proprietor { - case "adobe": - file, err = ioutil.ReadFile(filepath.Join(*adobeDir, filename)) + basename, fontIndex, err := filename, -1, error(nil) + if i := strings.IndexByte(filename, '?'); i >= 0 { + fontIndex, err = strconv.Atoi(filename[i+1:]) if err != nil { - t.Fatalf("%v\nPerhaps you need to set the -adobeDir=%v flag?", err, *adobeDir) + t.Fatalf("could not parse collection font index from filename %q", filename) } + basename = filename[:i] + } + + dir := "" + switch proprietor { + case "adobe": + dir = *adobeDir + case "apple": + dir = *appleDir case "microsoft": - file, err = ioutil.ReadFile(filepath.Join(*microsoftDir, filename)) - if err != nil { - t.Fatalf("%v\nPerhaps you need to set the -microsoftDir=%v flag?", err, *microsoftDir) - } + dir = *microsoftDir default: panic("unreachable") } - f, err := Parse(file) + file, err := ioutil.ReadFile(filepath.Join(dir, basename)) if err != nil { - t.Fatalf("Parse: %v", err) + t.Fatalf("%v\nPerhaps you need to set the -%sDir flag?", err, proprietor) } - ppem := fixed.Int26_6(f.UnitsPerEm()) qualifiedFilename := proprietor + "/" + filename + + f := (*Font)(nil) + if fontIndex >= 0 { + c, err := ParseCollection(file) + if err != nil { + t.Fatalf("ParseCollection: %v", err) + } + if want, ok := proprietaryNumFonts[qualifiedFilename]; ok { + if got := c.NumFonts(); got != want { + t.Fatalf("NumFonts: got %d, want %d", got, want) + } + } + f, err = c.Font(fontIndex) + if err != nil { + t.Fatalf("Font: %v", err) + } + } else { + f, err = Parse(file) + if err != nil { + t.Fatalf("Parse: %v", err) + } + } + + ppem := fixed.Int26_6(f.UnitsPerEm()) var buf Buffer // Some of the tests below, such as which glyph index a particular rune @@ -147,7 +211,7 @@ func testProprietary(t *testing.T, proprietor, filename string, minNumGlyphs, fi // 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) + t.Fatalf("Name(Version): %v", err) } wantVersion := proprietaryVersions[qualifiedFilename] if gotVersion != wantVersion { @@ -155,6 +219,15 @@ func testProprietary(t *testing.T, proprietor, filename string, minNumGlyphs, fi "\ngot %q\nwant %q", gotVersion, wantVersion) } + gotFull, err := f.Name(&buf, NameIDFull) + if err != nil { + t.Fatalf("Name(Full): %v", err) + } + wantFull := proprietaryFullNames[qualifiedFilename] + if gotFull != wantFull { + t.Fatalf("Name(Full):\ngot %q\nwant %q", gotFull, wantFull) + } + numGlyphs := f.NumGlyphs() if numGlyphs < minNumGlyphs { t.Fatalf("NumGlyphs: got %d, want at least %d", numGlyphs, minNumGlyphs) @@ -231,6 +304,15 @@ kernLoop: } } +// proprietaryNumFonts holds the expected number of fonts in each collection, +// or 1 for a single font. It is not necessarily an exhaustive list of all +// proprietary fonts tested. +var proprietaryNumFonts = map[string]int{ + "apple/ヒラギノ角ゴシック W0.ttc?0": 2, + "apple/ヒラギノ角ゴシック W0.ttc?1": 2, + "microsoft/Arial.ttf?0": 1, +} + // 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. @@ -245,12 +327,41 @@ var proprietaryVersions = map[string]string{ "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", + "apple/Apple Symbols.ttf": "12.0d3e10", + "apple/GeezaPro.ttc?0": "12.0d1e3", + "apple/GeezaPro.ttc?1": "12.0d1e3", + "apple/ヒラギノ角ゴシック W0.ttc?0": "11.0d7e1", + "apple/ヒラギノ角ゴシック W0.ttc?1": "11.0d7e1", + "microsoft/Arial.ttf": "Version 2.82", + "microsoft/Arial.ttf?0": "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", } +// proprietaryFullNames holds the expected full name of each proprietary font +// tested. +var proprietaryFullNames = map[string]string{ + "adobe/SourceCodePro-Regular.otf": "Source Code Pro", + "adobe/SourceCodePro-Regular.ttf": "Source Code Pro", + "adobe/SourceHanSansSC-Regular.otf": "Source Han Sans SC Regular", + "adobe/SourceSansPro-Regular.otf": "Source Sans Pro", + "adobe/SourceSansPro-Regular.ttf": "Source Sans Pro", + + "apple/Apple Symbols.ttf": "Apple Symbols", + "apple/GeezaPro.ttc?0": "Geeza Pro Regular", + "apple/GeezaPro.ttc?1": "Geeza Pro Bold", + "apple/ヒラギノ角ゴシック W0.ttc?0": "Hiragino Sans W0", + "apple/ヒラギノ角ゴシック W0.ttc?1": ".Hiragino Kaku Gothic Interface W0", + + "microsoft/Arial.ttf": "Arial", + "microsoft/Arial.ttf?0": "Arial", + "microsoft/Comic_Sans_MS.ttf": "Comic Sans MS", + "microsoft/Times_New_Roman.ttf": "Times New Roman", + "microsoft/Webdings.ttf": "Webdings", +} + // proprietaryGlyphIndexTestCases hold a sample of each font's rune to glyph // index cmap. The numerical values can be verified by running the ttx tool. var proprietaryGlyphIndexTestCases = map[string]map[rune]GlyphIndex{ @@ -338,7 +449,6 @@ var proprietaryGlyphIndexTestCases = map[string]map[rune]GlyphIndex{ var proprietaryGlyphTestCases = map[string]map[rune][]Segment{ "adobe/SourceSansPro-Regular.otf": { ',': { - // - contour #0 // 67 -170 rmoveto moveTo(67, -170), // 81 34 50 67 86 vvcurveto @@ -350,9 +460,10 @@ var proprietaryGlyphTestCases = map[string]map[rune][]Segment{ cubeTo(130, -1, 134, -1, 137, 0), // 1 -53 -34 -44 -57 -25 rrcurveto cubeTo(138, -53, 104, -97, 47, -122), + // endchar }, + 'Q': { - // - contour #0 // 332 57 rmoveto moveTo(332, 57), // -117 -77 106 168 163 77 101 117 117 77 -101 -163 -168 -77 -106 -117 hvcurveto @@ -360,7 +471,6 @@ var proprietaryGlyphTestCases = map[string]map[rune][]Segment{ cubeTo(138, 494, 215, 595, 332, 595), cubeTo(449, 595, 526, 494, 526, 331), cubeTo(526, 163, 449, 57, 332, 57), - // - contour #1 // 201 -222 rmoveto moveTo(533, -165), // 39 35 7 8 20 hvcurveto @@ -379,6 +489,123 @@ var proprietaryGlyphTestCases = map[string]map[rune][]Segment{ cubeTo(52, 138, 148, 11, 291, -9), // -90 38 83 -66 121 hhcurveto cubeTo(329, -99, 412, -165, 533, -165), + // endchar + }, + + 'ī': { // U+012B LATIN SMALL LETTER I WITH MACRON + // 92 callgsubr # 92 + bias = 199. + // : # Arg stack is []. + // : -312 21 85 callgsubr # 85 + bias = 192. + // : : # Arg stack is [-312 21]. + // : : -21 486 -20 return + // : : # Arg stack is [-312 21 -21 486 -20]. + // : return + // : # Arg stack is [-312 21 -21 486 -20]. + // 135 57 112 callgsubr # 112 + bias = 219 + // : # Arg stack is [-312 21 -21 486 -20 135 57]. + // : hstem + // : 82 82 vstem + // : 134 callsubr # 134 + bias = 241 + // : : # Arg stack is []. + // : : 82 hmoveto + moveTo(82, 0), + // : : 82 127 callsubr # 127 + bias = 234 + // : : : # Arg stack is [82]. + // : : : 486 -82 hlineto + lineTo(164, 0), + lineTo(164, 486), + lineTo(82, 486), + // : : : return + // : : : # Arg stack is []. + // : : return + // : : # Arg stack is []. + // : return + // : # Arg stack is []. + // -92 115 -60 callgsubr # -60 + bias = 47 + // : # Arg stack is [-92 115]. + // : rmoveto + moveTo(-10, 601), + // : 266 57 -266 hlineto + lineTo(256, 601), + lineTo(256, 658), + lineTo(-10, 658), + // : endchar + }, + + 'ĭ': { // U+012D LATIN SMALL LETTER I WITH BREVE + // 92 callgsubr # 92 + bias = 199. + // : # Arg stack is []. + // : -312 21 85 callgsubr # 85 + bias = 192. + // : : # Arg stack is [-312 21]. + // : : -21 486 -20 return + // : : # Arg stack is [-312 21 -21 486 -20]. + // : return + // : # Arg stack is [-312 21 -21 486 -20]. + // 105 55 96 -20 hstem + // -32 51 63 82 65 51 vstem + // 134 callsubr # 134 + bias = 241 + // : # Arg stack is []. + // : 82 hmoveto + moveTo(82, 0), + // : 82 127 callsubr # 127 + bias = 234 + // : : # Arg stack is [82]. + // : : 486 -82 hlineto + lineTo(164, 0), + lineTo(164, 486), + lineTo(82, 486), + // : : return + // : : # Arg stack is []. + // : return + // : # Arg stack is []. + // 42 85 143 callsubr # 143 + bias = 250 + // : # Arg stack is [42 85]. + // : rmoveto + moveTo(124, 571), + // : -84 callsubr # -84 + bias = 23 + // : : # Arg stack is []. + // : : 107 44 77 74 5 hvcurveto + cubeTo(231, 571, 275, 648, 280, 722), + // : : -51 8 rlineto + lineTo(229, 730), + // : : -51 -8 -32 -53 -65 hhcurveto + cubeTo(221, 679, 189, 626, 124, 626), + // : : -65 -32 53 51 -8 hvcurveto + cubeTo(59, 626, 27, 679, 19, 730), + // : : -51 -22 callsubr # -22 + bias = 85 + // : : : # Arg stack is [-51]. + // : : : -8 rlineto + lineTo(-32, 722), + // : : : -74 5 44 -77 107 hhcurveto + cubeTo(-27, 648, 17, 571, 124, 571), + // : : : return + // : : : # Arg stack is []. + // : : return + // : : # Arg stack is []. + // : return + // : # Arg stack is []. + // endchar + }, + + 'Λ': { // U+039B GREEK CAPITAL LETTER LAMDA + // 0 vmoveto + moveTo(0, 0), + // 85 hlineto + lineTo(85, 0), + // 105 355 23 77 16 63 24 77 rlinecurve + lineTo(190, 355), + cubeTo(213, 432, 229, 495, 253, 572), + // 4 hlineto + lineTo(257, 572), + // 25 -77 16 -63 23 -77 106 -355 rcurveline + cubeTo(282, 495, 298, 432, 321, 355), + lineTo(427, 0), + // 88 hlineto + lineTo(515, 0), + // -210 656 rlineto + lineTo(305, 656), + // -96 hlineto + lineTo(209, 656), + // endchar }, }, @@ -396,6 +623,7 @@ var proprietaryGlyphTestCases = map[string]map[rune][]Segment{ quadTo(281, -91, 284, 0), lineTo(182, 0), }, + 'i': { // - contour #0 moveTo(136, 1259), @@ -410,6 +638,7 @@ var proprietaryGlyphTestCases = map[string]map[rune][]Segment{ lineTo(316, 0), lineTo(136, 0), }, + 'o': { // - contour #0 moveTo(68, 531), @@ -433,6 +662,119 @@ var proprietaryGlyphTestCases = map[string]map[rune][]Segment{ quadTo(431, 937, 342, 836), quadTo(253, 735, 253, 531), }, + + 'í': { // U+00ED LATIN SMALL LETTER I WITH ACUTE + // - contour #0 + translate(0, 0, moveTo(198, 0)), + translate(0, 0, lineTo(198, 1062)), + translate(0, 0, lineTo(378, 1062)), + translate(0, 0, lineTo(378, 0)), + translate(0, 0, lineTo(198, 0)), + // - contour #1 + translate(-33, 0, moveTo(222, 1194)), + translate(-33, 0, lineTo(355, 1474)), + translate(-33, 0, lineTo(591, 1474)), + translate(-33, 0, lineTo(371, 1194)), + translate(-33, 0, lineTo(222, 1194)), + }, + + 'Ī': { // U+012A LATIN CAPITAL LETTER I WITH MACRON + // - contour #0 + translate(0, 0, moveTo(191, 0)), + translate(0, 0, lineTo(191, 1466)), + translate(0, 0, lineTo(385, 1466)), + translate(0, 0, lineTo(385, 0)), + translate(0, 0, lineTo(191, 0)), + // - contour #1 + translate(-57, 336, moveTo(29, 1227)), + translate(-57, 336, lineTo(29, 1375)), + translate(-57, 336, lineTo(653, 1375)), + translate(-57, 336, lineTo(653, 1227)), + translate(-57, 336, lineTo(29, 1227)), + }, + + // Ǻ is a compound glyph whose elements are also compound glyphs. + 'Ǻ': { // U+01FA LATIN CAPITAL LETTER A WITH RING ABOVE AND ACUTE + // - contour #0 + translate(0, 0, moveTo(-3, 0)), + translate(0, 0, lineTo(560, 1466)), + translate(0, 0, lineTo(769, 1466)), + translate(0, 0, lineTo(1369, 0)), + translate(0, 0, lineTo(1148, 0)), + translate(0, 0, lineTo(977, 444)), + translate(0, 0, lineTo(364, 444)), + translate(0, 0, lineTo(203, 0)), + translate(0, 0, lineTo(-3, 0)), + // - contour #1 + translate(0, 0, moveTo(420, 602)), + translate(0, 0, lineTo(917, 602)), + translate(0, 0, lineTo(764, 1008)), + translate(0, 0, quadTo(694, 1193, 660, 1312)), + translate(0, 0, quadTo(632, 1171, 581, 1032)), + translate(0, 0, lineTo(420, 602)), + // - contour #2 + translate(319, 263, moveTo(162, 1338)), + translate(319, 263, quadTo(162, 1411, 215, 1464)), + translate(319, 263, quadTo(269, 1517, 342, 1517)), + translate(319, 263, quadTo(416, 1517, 469, 1463)), + translate(319, 263, quadTo(522, 1410, 522, 1334)), + translate(319, 263, quadTo(522, 1257, 469, 1204)), + translate(319, 263, quadTo(416, 1151, 343, 1151)), + translate(319, 263, quadTo(268, 1151, 215, 1204)), + translate(319, 263, quadTo(162, 1258, 162, 1338)), + // - contour #3 + translate(319, 263, moveTo(238, 1337)), + translate(319, 263, quadTo(238, 1290, 269, 1258)), + translate(319, 263, quadTo(301, 1226, 344, 1226)), + translate(319, 263, quadTo(387, 1226, 418, 1258)), + translate(319, 263, quadTo(450, 1290, 450, 1335)), + translate(319, 263, quadTo(450, 1380, 419, 1412)), + translate(319, 263, quadTo(388, 1444, 344, 1444)), + translate(319, 263, quadTo(301, 1444, 269, 1412)), + translate(319, 263, quadTo(238, 1381, 238, 1337)), + // - contour #4 + translate(339, 650, moveTo(222, 1194)), + translate(339, 650, lineTo(355, 1474)), + translate(339, 650, lineTo(591, 1474)), + translate(339, 650, lineTo(371, 1194)), + translate(339, 650, lineTo(222, 1194)), + }, + + '﴾': { // U+FD3E ORNATE LEFT PARENTHESIS. + // - contour #0 + moveTo(560, -384), + lineTo(516, -429), + quadTo(412, -304, 361, -226), + quadTo(258, -68, 201, 106), + quadTo(127, 334, 127, 595), + quadTo(127, 845, 201, 1069), + quadTo(259, 1246, 361, 1404), + quadTo(414, 1487, 514, 1608), + lineTo(560, 1566), + quadTo(452, 1328, 396, 1094), + quadTo(336, 845, 336, 603), + quadTo(336, 359, 370, 165), + quadTo(398, 8, 454, -142), + quadTo(482, -217, 560, -384), + }, + + '﴿': { // U+FD3F ORNATE RIGHT PARENTHESIS + // - contour #0 + transform(-1<<14, 0, 0, +1<<14, 653, 0, moveTo(560, -384)), + transform(-1<<14, 0, 0, +1<<14, 653, 0, lineTo(516, -429)), + transform(-1<<14, 0, 0, +1<<14, 653, 0, quadTo(412, -304, 361, -226)), + transform(-1<<14, 0, 0, +1<<14, 653, 0, quadTo(258, -68, 201, 106)), + transform(-1<<14, 0, 0, +1<<14, 653, 0, quadTo(127, 334, 127, 595)), + transform(-1<<14, 0, 0, +1<<14, 653, 0, quadTo(127, 845, 201, 1069)), + transform(-1<<14, 0, 0, +1<<14, 653, 0, quadTo(259, 1246, 361, 1404)), + transform(-1<<14, 0, 0, +1<<14, 653, 0, quadTo(414, 1487, 514, 1608)), + transform(-1<<14, 0, 0, +1<<14, 653, 0, lineTo(560, 1566)), + transform(-1<<14, 0, 0, +1<<14, 653, 0, quadTo(452, 1328, 396, 1094)), + transform(-1<<14, 0, 0, +1<<14, 653, 0, quadTo(336, 845, 336, 603)), + transform(-1<<14, 0, 0, +1<<14, 653, 0, quadTo(336, 359, 370, 165)), + transform(-1<<14, 0, 0, +1<<14, 653, 0, quadTo(398, 8, 454, -142)), + transform(-1<<14, 0, 0, +1<<14, 653, 0, quadTo(482, -217, 560, -384)), + }, }, } -- cgit v1.2.3-1-g7c22