font/sfnt: use ../testdata/cmapTest.ttf.
The index numbers can be verified by running ttx over the ttf file:
<GlyphOrder>
<!-- The 'id' attribute is only for humans; it is ignored when parsed. -->
<GlyphID id="0" name=".notdef"/>
<GlyphID id="1" name=".null"/>
<GlyphID id="2" name="nonmarkingreturn"/>
<GlyphID id="3" name="zero"/>
<GlyphID id="4" name="one"/>
<GlyphID id="5" name="two"/>
<GlyphID id="6" name="A"/>
<GlyphID id="7" name="B"/>
<GlyphID id="8" name="a"/>
<GlyphID id="9" name="ydieresis"/>
<GlyphID id="10" name="Amacron"/>
<GlyphID id="11" name="amacron"/>
<GlyphID id="12" name="uni4E2D"/>
<GlyphID id="13" name="u1F0A1"/>
<GlyphID id="14" name="u1F0B1"/>
<GlyphID id="15" name="u1F0B2"/>
</GlyphOrder>
Change-Id: I8c3b3f09ca25c14d92725d121481287cf57d0d01
Reviewed-on: https://go-review.googlesource.com/36080
Reviewed-by: David Crawshaw <crawshaw@golang.org>
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 @@
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 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 @@
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 0000000..ebe6be2
--- /dev/null
+++ b/font/testdata/cmapTest.ttf
Binary files differ