mirror of
https://github.com/unidoc/unipdf.git
synced 2025-05-02 22:17:06 +08:00
Allow TrueType font files to not have PostScript entries in their "name" table.
This commit is contained in:
parent
24d522bdb2
commit
b0f5329425
@ -316,9 +316,14 @@ func (font pdfCIDFontType2) SetEncoder(encoder textencoding.TextEncoder) {
|
|||||||
|
|
||||||
// GetGlyphCharMetrics returns the character metrics for the specified glyph. A bool flag is
|
// GetGlyphCharMetrics returns the character metrics for the specified glyph. A bool flag is
|
||||||
// returned to indicate whether or not the entry was found in the glyph to charcode mapping.
|
// returned to indicate whether or not the entry was found in the glyph to charcode mapping.
|
||||||
|
// XXX:TODO(peterwilliams97): Cache enc creation and cache glyph:metrics in a map.
|
||||||
func (font pdfCIDFontType2) GetGlyphCharMetrics(glyph string) (fonts.CharMetrics, bool) {
|
func (font pdfCIDFontType2) GetGlyphCharMetrics(glyph string) (fonts.CharMetrics, bool) {
|
||||||
metrics := fonts.CharMetrics{}
|
metrics := fonts.CharMetrics{}
|
||||||
|
|
||||||
|
if font.ttfParser == nil {
|
||||||
|
return metrics, false
|
||||||
|
}
|
||||||
|
|
||||||
enc := textencoding.NewTrueTypeFontEncoder(font.ttfParser.Chars)
|
enc := textencoding.NewTrueTypeFontEncoder(font.ttfParser.Chars)
|
||||||
|
|
||||||
// Convert the glyph to character code.
|
// Convert the glyph to character code.
|
||||||
|
@ -317,6 +317,16 @@ var charcodeBytesToUnicodeTest = []fontFragmentTest{
|
|||||||
75, 76, 77},
|
75, 76, 77},
|
||||||
" *ﺏﻁﻝﺍﺔﻴﻠﻜ،ﺕﺭﺘﻌﻤﺎﺠﻲﻨﻘﺩﻬ/ﻙﻭﻕﺃﻡﻋﻓﺴ٢٠٣ﻯﻥﺒﺸﺌﺱﻷ,ﺯﺤﺄﻀـﺓﺫ.)٤(٩ل٥٧٨ﻸﻰ%١ﺇ٦ﺡﻫﻱﻅﻐﺼﻑﺨﺀﻊLM",
|
" *ﺏﻁﻝﺍﺔﻴﻠﻜ،ﺕﺭﺘﻌﻤﺎﺠﻲﻨﻘﺩﻬ/ﻙﻭﻕﺃﻡﻋﻓﺴ٢٠٣ﻯﻥﺒﺸﺌﺱﻷ,ﺯﺤﺄﻀـﺓﺫ.)٤(٩ل٥٧٨ﻸﻰ%١ﺇ٦ﺡﻫﻱﻅﻐﺼﻑﺨﺀﻊLM",
|
||||||
},
|
},
|
||||||
|
fontFragmentTest{"Tesseract",
|
||||||
|
"./testdata/font/tesseract.txt", 3,
|
||||||
|
[]byte{0, 65, 0, 97,
|
||||||
|
1, 2, 1, 65, 1, 97,
|
||||||
|
12, 2, 12, 65, 12, 97,
|
||||||
|
20, 65, 20, 97, 20, 255,
|
||||||
|
42, 2, 42, 65, 42, 97,
|
||||||
|
65, 66, 67, 255},
|
||||||
|
"AaĂŁšంుౡᑁᑡᓿ⨂⩁⩡䅂䏿",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
type fontFragmentTest struct {
|
type fontFragmentTest struct {
|
||||||
|
@ -566,6 +566,7 @@ func (t *ttfParser) parseCmapFormat12() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ParseName parses the "name" table.
|
||||||
func (t *ttfParser) ParseName() error {
|
func (t *ttfParser) ParseName() error {
|
||||||
if err := t.Seek("name"); err != nil {
|
if err := t.Seek("name"); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -596,7 +597,7 @@ func (t *ttfParser) ParseName() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if t.rec.PostScriptName == "" {
|
if t.rec.PostScriptName == "" {
|
||||||
return fmt.Errorf("the name PostScript was not found")
|
common.Log.Debug("ParseName: The name PostScript was not found.")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
BIN
pdf/model/testdata/font/tesseract.txt
vendored
Executable file
BIN
pdf/model/testdata/font/tesseract.txt
vendored
Executable file
Binary file not shown.
@ -24,8 +24,8 @@ type TrueTypeFontEncoder struct {
|
|||||||
cmap CMap
|
cmap CMap
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTrueTypeFontEncoder creates a new text encoder for TTF fonts with a pre-loaded
|
// NewTrueTypeFontEncoder creates a new text encoder for TTF fonts with a runeToGlyphIndexMap that
|
||||||
// runeToGlyphIndexMap, that has been pre-loaded from the font file.
|
// has been preloaded from the font file.
|
||||||
// The new instance is preloaded with a CMapIdentityH (Identity-H) CMap which maps 2-byte charcodes
|
// The new instance is preloaded with a CMapIdentityH (Identity-H) CMap which maps 2-byte charcodes
|
||||||
// to CIDs (glyph index).
|
// to CIDs (glyph index).
|
||||||
func NewTrueTypeFontEncoder(runeToGlyphIndexMap map[uint16]uint16) TrueTypeFontEncoder {
|
func NewTrueTypeFontEncoder(runeToGlyphIndexMap map[uint16]uint16) TrueTypeFontEncoder {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user