From 55ae12acc992ce6034ae993e4212fd6f8057b1c6 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Thu, 2 Feb 2017 19:04:00 +1100 Subject: [PATCH] font/sfnt: use ../testdata/cmapTest.ttf. The index numbers can be verified by running ttx over the ttf file: Change-Id: I8c3b3f09ca25c14d92725d121481287cf57d0d01 Reviewed-on: https://go-review.googlesource.com/36080 Reviewed-by: David Crawshaw --- font/sfnt/cmap.go | 3 + font/sfnt/sfnt_test.go | 65 +++++++-- font/testdata/cmapTest.sfd | 265 +++++++++++++++++++++++++++++++++++++ font/testdata/cmapTest.ttf | Bin 0 -> 2528 bytes 4 files changed, 319 insertions(+), 14 deletions(-) create mode 100644 font/testdata/cmapTest.sfd create mode 100644 font/testdata/cmapTest.ttf diff --git a/font/sfnt/cmap.go b/font/sfnt/cmap.go index 19b0a9d..be302d2 100644 --- a/font/sfnt/cmap.go +++ b/font/sfnt/cmap.go @@ -19,6 +19,9 @@ const ( psidUnicode2BMPOnly = 3 psidUnicode2FullRepertoire = 4 + // Note that FontForge may generate a bogus Platform Specific ID (value 10) + // for the Unicode Platform ID (value 0). See + // https://github.com/fontforge/fontforge/issues/2728 psidMacintoshRoman = 0 diff --git a/font/sfnt/sfnt_test.go b/font/sfnt/sfnt_test.go index 4b72221..f1c6ac1 100644 --- a/font/sfnt/sfnt_test.go +++ b/font/sfnt/sfnt_test.go @@ -89,7 +89,7 @@ func testTrueType(t *testing.T, f *Font) { } func TestGlyphIndex(t *testing.T) { - data, err := ioutil.ReadFile(filepath.FromSlash("../testdata/CFFTest.otf")) + data, err := ioutil.ReadFile(filepath.FromSlash("../testdata/cmapTest.ttf")) if err != nil { t.Fatal(err) } @@ -120,27 +120,64 @@ func testGlyphIndex(t *testing.T, data []byte, cmapFormat int) { r rune want GlyphIndex }{ - {'0', 1}, - {'1', 2}, - {'Q', 3}, - // TODO: add the U+00E0 non-ASCII Latin-1 Supplement rune to - // CFFTest.otf and change 0 to something non-zero. - {'\u00e0', 0}, - {'\u4e2d', 4}, - // TODO: add a rune >= U+00010000 to CFFTest.otf? - - // Glyphs that aren't present in CFFTest.otf. + // Glyphs that aren't present in cmapTest.ttf. {'?', 0}, {'\ufffd', 0}, {'\U0001f4a9', 0}, + + // For a .TTF file, FontForge maps: + // - ".notdef" to glyph index 0. + // - ".null" to glyph index 1. + // - "nonmarkingreturn" to glyph index 2. + + {'/', 0}, + {'0', 3}, + {'1', 4}, + {'2', 5}, + {'3', 0}, + + {'@', 0}, + {'A', 6}, + {'B', 7}, + {'C', 0}, + + {'`', 0}, + {'a', 8}, + {'b', 0}, + + // Of the remaining runes, only U+00FF LATIN SMALL LETTER Y WITH + // DIAERESIS is in both the Mac Roman encoding and the cmapTest.ttf + // font file. + {'\u00fe', 0}, + {'\u00ff', 9}, + {'\u0100', 10}, + {'\u0101', 11}, + {'\u0102', 0}, + + {'\u4e2c', 0}, + {'\u4e2d', 12}, + {'\u4e2e', 0}, + + /* + TODO: support runes above U+FFFF, i.e. cmap format 12. + + {'\U0001f0a0', 0}, + {'\U0001f0a1', 13}, + {'\U0001f0a2', 0}, + + {'\U0001f0b0', 0}, + {'\U0001f0b1', 14}, + {'\U0001f0b2', 15}, + {'\U0001f0b3', 0}, + */ } var b Buffer for _, tc := range testCases { want := tc.want - // cmap format 0, with the Macintosh Roman encoding, can't represent - // U+4E2D. - if cmapFormat == 0 && tc.r == '\u4e2d' { + // cmap format 0, with the Macintosh Roman encoding, can only represent + // a limited set of non-ASCII runes, e.g. U+00FF. + if cmapFormat == 0 && tc.r > '\u007f' && tc.r != '\u00ff' { want = 0 } diff --git a/font/testdata/cmapTest.sfd b/font/testdata/cmapTest.sfd new file mode 100644 index 0000000..34c7cd6 --- /dev/null +++ b/font/testdata/cmapTest.sfd @@ -0,0 +1,265 @@ +SplineFontDB: 3.0 +FontName: cmapTest +FullName: cmapTest +FamilyName: cmapTest +Weight: Regular +Copyright: Copyright 2016 The Go Authors. All rights reserved.\nUse of this font is governed by a BSD-style license that can be found at https://golang.org/LICENSE. +Version: 001.000 +ItalicAngle: -11.25 +UnderlinePosition: -204 +UnderlineWidth: 102 +Ascent: 1638 +Descent: 410 +LayerCount: 2 +Layer: 0 1 "Back" 1 +Layer: 1 1 "Fore" 0 +XUID: [1021 367 888937226 7862908] +FSType: 8 +OS2Version: 0 +OS2_WeightWidthSlopeOnly: 0 +OS2_UseTypoMetrics: 1 +CreationTime: 1484386143 +ModificationTime: 1486021330 +PfmFamily: 17 +TTFWeight: 400 +TTFWidth: 5 +LineGap: 184 +VLineGap: 0 +OS2TypoAscent: 0 +OS2TypoAOffset: 1 +OS2TypoDescent: 0 +OS2TypoDOffset: 1 +OS2TypoLinegap: 184 +OS2WinAscent: 0 +OS2WinAOffset: 1 +OS2WinDescent: 0 +OS2WinDOffset: 1 +HheadAscent: 0 +HheadAOffset: 1 +HheadDescent: 0 +HheadDOffset: 1 +OS2Vendor: 'PfEd' +MarkAttachClasses: 1 +DEI: 91125 +LangName: 1033 +Encoding: UnicodeFull +UnicodeInterp: none +NameList: Adobe Glyph List +DisplaySize: -24 +AntiAlias: 1 +FitToEm: 1 +WinInfo: 126976 32 23 +BeginPrivate: 0 +EndPrivate +TeXData: 1 0 0 346030 173015 115343 0 -1048576 115343 783286 444596 497025 792723 393216 433062 380633 303038 157286 324010 404750 52429 2506097 1059062 262144 +BeginChars: 1114112 13 + +StartChar: zero +Encoding: 48 48 0 +Width: 800 +VWidth: 0 +Flags: W +LayerCount: 2 +Fore +SplineSet +0 0 m 29,0,-1 + 400 800 l 25,1,-1 + 800 0 l 25,2,-1 + 0 0 l 29,0,-1 +EndSplineSet +Validated: 1 +EndChar + +StartChar: one +Encoding: 49 49 1 +Width: 800 +VWidth: 0 +Flags: W +LayerCount: 2 +Fore +SplineSet +0 0 m 29,0,-1 + 400 800 l 25,1,-1 + 800 0 l 25,2,-1 + 0 0 l 29,0,-1 +EndSplineSet +Validated: 1 +EndChar + +StartChar: two +Encoding: 50 50 2 +Width: 800 +VWidth: 0 +Flags: W +LayerCount: 2 +Fore +SplineSet +0 0 m 29,0,-1 + 400 800 l 25,1,-1 + 800 0 l 25,2,-1 + 0 0 l 29,0,-1 +EndSplineSet +Validated: 1 +EndChar + +StartChar: A +Encoding: 65 65 3 +Width: 800 +VWidth: 0 +Flags: W +LayerCount: 2 +Fore +SplineSet +0 0 m 29,0,-1 + 400 800 l 25,1,-1 + 800 0 l 25,2,-1 + 0 0 l 29,0,-1 +EndSplineSet +Validated: 1 +EndChar + +StartChar: uni4E2D +Encoding: 20013 20013 4 +Width: 800 +VWidth: 0 +Flags: W +LayerCount: 2 +Fore +SplineSet +0 0 m 29,0,-1 + 400 800 l 25,1,-1 + 800 0 l 25,2,-1 + 0 0 l 29,0,-1 +EndSplineSet +Validated: 1 +EndChar + +StartChar: u1F0A1 +Encoding: 127137 127137 5 +Width: 800 +VWidth: 0 +Flags: W +LayerCount: 2 +Fore +SplineSet +0 0 m 29,0,-1 + 400 800 l 25,1,-1 + 800 0 l 25,2,-1 + 0 0 l 29,0,-1 +EndSplineSet +Validated: 1 +EndChar + +StartChar: ydieresis +Encoding: 255 255 6 +Width: 800 +VWidth: 0 +Flags: W +LayerCount: 2 +Fore +SplineSet +0 0 m 29,0,-1 + 400 800 l 25,1,-1 + 800 0 l 25,2,-1 + 0 0 l 29,0,-1 +EndSplineSet +Validated: 1 +EndChar + +StartChar: Amacron +Encoding: 256 256 7 +Width: 800 +VWidth: 0 +Flags: W +LayerCount: 2 +Fore +SplineSet +0 0 m 29,0,-1 + 400 800 l 25,1,-1 + 800 0 l 25,2,-1 + 0 0 l 29,0,-1 +EndSplineSet +Validated: 1 +EndChar + +StartChar: amacron +Encoding: 257 257 8 +Width: 800 +VWidth: 0 +Flags: W +LayerCount: 2 +Fore +SplineSet +0 0 m 29,0,-1 + 400 800 l 25,1,-1 + 800 0 l 25,2,-1 + 0 0 l 29,0,-1 +EndSplineSet +Validated: 1 +EndChar + +StartChar: B +Encoding: 66 66 9 +Width: 800 +VWidth: 0 +Flags: W +LayerCount: 2 +Fore +SplineSet +0 0 m 29,0,-1 + 400 800 l 25,1,-1 + 800 0 l 25,2,-1 + 0 0 l 29,0,-1 +EndSplineSet +Validated: 1 +EndChar + +StartChar: a +Encoding: 97 97 10 +Width: 800 +VWidth: 0 +Flags: W +LayerCount: 2 +Fore +SplineSet +0 0 m 29,0,-1 + 400 800 l 25,1,-1 + 800 0 l 25,2,-1 + 0 0 l 29,0,-1 +EndSplineSet +Validated: 1 +EndChar + +StartChar: u1F0B1 +Encoding: 127153 127153 11 +Width: 800 +VWidth: 0 +Flags: W +LayerCount: 2 +Fore +SplineSet +0 0 m 29,0,-1 + 400 800 l 25,1,-1 + 800 0 l 25,2,-1 + 0 0 l 29,0,-1 +EndSplineSet +Validated: 1 +EndChar + +StartChar: u1F0B2 +Encoding: 127154 127154 12 +Width: 800 +VWidth: 0 +Flags: W +LayerCount: 2 +Fore +SplineSet +0 0 m 29,0,-1 + 400 800 l 25,1,-1 + 800 0 l 25,2,-1 + 0 0 l 29,0,-1 +EndSplineSet +Validated: 1 +EndChar +EndChars +EndSplineFont diff --git a/font/testdata/cmapTest.ttf b/font/testdata/cmapTest.ttf new file mode 100644 index 0000000000000000000000000000000000000000..ebe6be200c38f0944875d06dfb97da6737d2fe68 GIT binary patch literal 2528 zcmeHJO>7%g5T3U`c9J$}0+bU9FI9>-H1^u9QW1qxC$`f{C7|X<;sV*&>s?FsuJNv; z=2kBJTp&_~R79l+goJ7dGluHJ(~m(4bXYgX{lJ8f3o%Zbs)W0fj%^oFBItj4MTqi`tVb8>8$fzbc{%N z(3eVeyV3vBXYWD31-f2Zi6rICAtL=t*bUbX8|^kCQ|~3{J#KBa(*H{9BiPyhs^{3{ zeH+gog6%iZxCfwjN`D!)QRt&yJv!IBM0w~O@6lRNvW)@#GUi`{eyDDrYtTGB2Ky=K z(zokQ|1$@dh|G`S(`p1^G`arBYgqpX>;ds!K`%bx?mTy3@(w?$Kb!je; zMm?a;z#Je%Te@Tb?=n5W((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