mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-27 13:48:51 +08:00
Added more font tests
This commit is contained in:
parent
26e6e114ad
commit
d64785a8ca
BIN
contrib/testdata/font/Weil.txt
vendored
Executable file
BIN
contrib/testdata/font/Weil.txt
vendored
Executable file
Binary file not shown.
BIN
contrib/testdata/font/cover.txt
vendored
Executable file
BIN
contrib/testdata/font/cover.txt
vendored
Executable file
Binary file not shown.
BIN
contrib/testdata/font/lec10.txt
vendored
Executable file
BIN
contrib/testdata/font/lec10.txt
vendored
Executable file
Binary file not shown.
BIN
contrib/testdata/font/noise-contrast.txt
vendored
Executable file
BIN
contrib/testdata/font/noise-contrast.txt
vendored
Executable file
Binary file not shown.
BIN
contrib/testdata/font/preview.txt
vendored
Executable file
BIN
contrib/testdata/font/preview.txt
vendored
Executable file
Binary file not shown.
BIN
contrib/testdata/font/townes.txt
vendored
Executable file
BIN
contrib/testdata/font/townes.txt
vendored
Executable file
Binary file not shown.
BIN
contrib/testdata/font/v14.txt
vendored
Executable file
BIN
contrib/testdata/font/v14.txt
vendored
Executable file
Binary file not shown.
@ -16,6 +16,7 @@ import (
|
||||
"github.com/unidoc/unidoc/pdf/core"
|
||||
"github.com/unidoc/unidoc/pdf/model"
|
||||
"github.com/unidoc/unidoc/pdf/model/fonts"
|
||||
"github.com/unidoc/unidoc/pdf/model/textencoding"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -252,6 +253,50 @@ var charcodeBytesToUnicodeTest = []fontFragmentTest{
|
||||
177, 151, 178, 179, 183, 185, 188, 205, 184, 189},
|
||||
"‘ł’ “Ł” Ø `o´ it's ˝ˆ˜¯˘˙¨˚ˇªº‹ı›—–—†‡•„…˛¸‰",
|
||||
},
|
||||
fontFragmentTest{"base glyphs′",
|
||||
"../../contrib/testdata/font/cover.txt", 11,
|
||||
[]byte{44, 45, 46, 48, 49, 50, 51, 53, 54, 55, 56, 58, 59,
|
||||
65, 66, 67, 68, 69, 70, 71, 72,
|
||||
84, 85,
|
||||
97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 108, 109, 110, 111,
|
||||
114, 115, 116, 117},
|
||||
",-.01235678:;ABCDEFGHTUabcdefghijlmnorstu",
|
||||
},
|
||||
fontFragmentTest{"tex glyphs 48->′",
|
||||
"../../contrib/testdata/font/noise-contrast.txt", 36,
|
||||
[]byte{33, 48, 65, 104, 149, 253},
|
||||
"!′Ah•ý",
|
||||
},
|
||||
fontFragmentTest{"tex2 glyphs ",
|
||||
"../../contrib/testdata/font/Weil.txt", 30,
|
||||
[]byte{55, 0, 1, 2, 20, 24, 33, 50, 102, 103, 104, 105},
|
||||
"↦−·×≤∼→∈{}⟨⟩",
|
||||
},
|
||||
fontFragmentTest{"additional glyphs",
|
||||
"../../contrib/testdata/font/noise-contrast.txt", 34,
|
||||
[]byte{32, 40, 48, 64, 80, 88, 65, 104, 149, 253},
|
||||
"({∑∑h•ý",
|
||||
},
|
||||
fontFragmentTest{".notdef glyphs",
|
||||
"../../contrib/testdata/font/lec10.txt", 6,
|
||||
[]byte{59, 66},
|
||||
string([]rune{textencoding.MissingCodeRune, textencoding.MissingCodeRune}),
|
||||
},
|
||||
fontFragmentTest{"Numbered glyphs pattern 1",
|
||||
"../../contrib/testdata/font/v14.txt", 14,
|
||||
[]byte{24, 25, 26, 27, 29},
|
||||
" ffifflfffi",
|
||||
},
|
||||
fontFragmentTest{"Glyph aliases",
|
||||
"../../contrib/testdata/font/townes.txt", 10,
|
||||
[]byte{2, 3, 4, 5, 6, 7, 1, 8, 9, 5, 1, 10, 9, 5, 48},
|
||||
"Townes van Zan…",
|
||||
},
|
||||
fontFragmentTest{"Glyph `.` extensions. e.g. `integral.disp`",
|
||||
"../../contrib/testdata/font/preview.txt", 156,
|
||||
[]byte{83, 0, 4, 67, 62, 64, 100, 65},
|
||||
"∫=≈≥∈<d>",
|
||||
},
|
||||
fontFragmentTest{"A potpourri of glyph naming conventions",
|
||||
"../../contrib/testdata/font/Ingmar.txt", 144,
|
||||
[]byte{18, 20, 10, 11, 13, 14, 15, 16, 21, 22, 23, 25, 26, 27, 28, 29, 30,
|
||||
|
@ -374,7 +374,7 @@ func (t *ttfParser) parseCmapSubtable10(offset10 int64) error {
|
||||
length = t.ReadULong()
|
||||
language = t.ReadULong()
|
||||
}
|
||||
common.Log.Debug("parseCmapSubtable10: format=%d length=%d language=%d",
|
||||
common.Log.Trace("parseCmapSubtable10: format=%d length=%d language=%d",
|
||||
format, length, language)
|
||||
|
||||
if format != 0 {
|
||||
@ -402,7 +402,7 @@ func (t *ttfParser) ParseCmap() error {
|
||||
if err := t.Seek("cmap"); err != nil {
|
||||
return err
|
||||
}
|
||||
common.Log.Debug("ParseCmap")
|
||||
common.Log.Trace("ParseCmap")
|
||||
t.ReadUShort() // version is ignored.
|
||||
numTables := int(t.ReadUShort())
|
||||
offset10 := int64(0)
|
||||
|
@ -98,6 +98,8 @@ func buildAll() error {
|
||||
return err
|
||||
}
|
||||
|
||||
gs.update("elipsis", map[string]rune{"elipsis": 0x2026}) // …
|
||||
|
||||
printAliases(gs.aliases)
|
||||
printGlyphToRuneList(gs.glyphRune)
|
||||
printRuneToGlyphList(gs.glyphRune)
|
||||
@ -176,14 +178,9 @@ func printGlyphToRuneList(glyphRune map[string]rune) {
|
||||
keys := sorted(glyphRune)
|
||||
|
||||
fmt.Printf("var glyphlistGlyphToRuneMap = map[string]rune{ // %d entries \n", len(keys))
|
||||
runes := map[rune]bool{}
|
||||
for _, glyph := range keys {
|
||||
r := glyphRune[glyph]
|
||||
fmt.Printf("\t\t%q:\t0x%04x, %s\n", glyph, r, showRune(r))
|
||||
if _, ok := runes[r]; ok {
|
||||
panic("duplicate runes")
|
||||
}
|
||||
runes[r] = true
|
||||
}
|
||||
fmt.Printf("}\n")
|
||||
}
|
||||
@ -194,16 +191,9 @@ func printRuneToGlyphList(glyphRune map[string]rune) {
|
||||
keys := sorted(glyphRune)
|
||||
|
||||
fmt.Printf("var glyphlistRuneToGlyphMap = map[rune]string{ // %d entries \n", len(keys))
|
||||
runes := map[rune]bool{}
|
||||
for _, glyph := range keys {
|
||||
r := glyphRune[glyph]
|
||||
fmt.Printf("\t\t0x%04x:\t%q, %s\n", r, glyph, showRune(r))
|
||||
if _, ok := runes[r]; ok {
|
||||
panic("duplicate runes")
|
||||
}
|
||||
if r == 0xfffd {
|
||||
fmt.Fprintf(os.Stderr, "$$ %c->%q\n", r, glyph)
|
||||
}
|
||||
}
|
||||
fmt.Printf("}\n")
|
||||
}
|
||||
@ -250,17 +240,6 @@ func sorted(glyphRune map[string]rune) []string {
|
||||
}
|
||||
return si < sj
|
||||
})
|
||||
if len(keys) != len(glyphRune) {
|
||||
panic("gggk")
|
||||
}
|
||||
|
||||
runes := map[rune]bool{}
|
||||
for _, g := range keys {
|
||||
runes[glyphRune[g]] = true
|
||||
}
|
||||
if len(keys) != len(runes) {
|
||||
panic("h24")
|
||||
}
|
||||
return keys
|
||||
}
|
||||
|
||||
@ -475,10 +454,6 @@ func parseUnknown(filename string) (map[string]rune, error) {
|
||||
fmt.Fprintf(os.Stderr, "parseUnknown: No match line %d: %q\n", i, ln)
|
||||
return nil, errors.New("bad line")
|
||||
}
|
||||
if strings.Contains(ln, "kafmedial") {
|
||||
fmt.Fprintf(os.Stderr, "##@ %q %q\n", ln, g[1:])
|
||||
// panic("rrr")
|
||||
}
|
||||
groups = append(groups, g[1:])
|
||||
}
|
||||
fmt.Printf("// groups=%d\n", len(groups))
|
||||
@ -493,26 +468,13 @@ func parseUnknown(filename string) (map[string]rune, error) {
|
||||
r := rune(n)
|
||||
parts := reSpace.Split(row[1], -1)
|
||||
for _, g := range parts {
|
||||
if g == "" {
|
||||
if g == "" || strings.Contains(g, "000") || strings.Contains(g, "0.0") {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(g, "f_i") {
|
||||
fmt.Fprintf(os.Stderr, "### %q\n", row)
|
||||
// panic("rrr")
|
||||
}
|
||||
if strings.Contains(g, "000") {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(g, " ") {
|
||||
panic("space")
|
||||
}
|
||||
glyph2rune[g] = r
|
||||
}
|
||||
}
|
||||
fmt.Printf("// entries=%d\n", len(glyph2rune))
|
||||
if _, ok := glyph2rune["kafmedial"]; !ok {
|
||||
panic("kafmedial")
|
||||
}
|
||||
return glyph2rune, nil
|
||||
}
|
||||
|
||||
@ -538,6 +500,7 @@ type glyphRune struct {
|
||||
}
|
||||
|
||||
var baseNames = []string{"SymbolEncoding", "WinAnsiEncoding", "ZapfDingbatsEncoding"}
|
||||
|
||||
var basicEncodings = map[string]map[uint16]glyphRune{
|
||||
"SymbolEncoding": map[uint16]glyphRune{ // 189 entries
|
||||
0x20: {"space", '\u0020'}, //
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user