mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-27 13:48:51 +08:00
Fix for loading standard fonts with Encoding difference maps
This commit is contained in:
parent
89d1bce9da
commit
f4deb858ba
@ -223,19 +223,27 @@ func newPdfFontFromPdfObject(fontObj core.PdfObject, allowType0 bool) (*PdfFont,
|
||||
var simplefont *pdfFontSimple
|
||||
if std, ok := standard14Fonts[Standard14Font(base.basefont)]; ok && base.subtype == "Type1" {
|
||||
font.context = &std
|
||||
stdObj := core.TraceToDirectObject(std.ToPdfObject())
|
||||
d, stdBase, err := newFontBaseFieldsFromPdfObject(stdObj)
|
||||
simplefont, err = newSimpleFontFromPdfObject(d, base, true)
|
||||
if err != nil {
|
||||
common.Log.Debug("ERROR: Bad Standard14\n\tfont=%s\n\tstd=%+v", base, std)
|
||||
return nil, err
|
||||
}
|
||||
simplefont, err = newSimpleFontFromPdfObject(d, stdBase, true, std.fontMetrics)
|
||||
if err != nil {
|
||||
common.Log.Debug("ERROR: Bad Standard14\n\tfont=%s\n\tstd=%+v", base, std)
|
||||
return nil, err
|
||||
|
||||
encdict, has := core.GetDict(simplefont.Encoding)
|
||||
if has {
|
||||
// Set the default encoding for the standard 14 font if not specified in Encoding.
|
||||
if encdict.Get("BaseEncoding") == nil {
|
||||
encdict.Set("BaseEncoding", std.encoder.ToPdfObject())
|
||||
}
|
||||
} else {
|
||||
simplefont.encoder = std.encoder
|
||||
}
|
||||
|
||||
simplefont.firstChar = 0
|
||||
simplefont.lastChar = 255
|
||||
simplefont.fontMetrics = std.fontMetrics
|
||||
} else {
|
||||
simplefont, err = newSimpleFontFromPdfObject(d, base, false, nil)
|
||||
simplefont, err = newSimpleFontFromPdfObject(d, base, false)
|
||||
if err != nil {
|
||||
common.Log.Debug("ERROR: While loading simple font: font=%s err=%v", base, err)
|
||||
return nil, err
|
||||
|
@ -131,14 +131,9 @@ func (font pdfFontSimple) GetAverageCharWidth() float64 {
|
||||
// The value of Encoding is subject to limitations that are described in 9.6.6, "Character Encoding".
|
||||
// • The value of BaseFont is derived differently.
|
||||
//
|
||||
func newSimpleFontFromPdfObject(d *core.PdfObjectDictionary, base *fontCommon, std14 bool,
|
||||
fontMetrics map[string]fonts.CharMetrics) (*pdfFontSimple, error) {
|
||||
func newSimpleFontFromPdfObject(d *core.PdfObjectDictionary, base *fontCommon, std14 bool) (*pdfFontSimple, error) {
|
||||
font := pdfFontSimpleFromSkeleton(base)
|
||||
|
||||
if fontMetrics != nil {
|
||||
font.fontMetrics = fontMetrics
|
||||
}
|
||||
|
||||
// FirstChar is not defined in ~/testdata/shamirturing.pdf
|
||||
if !std14 {
|
||||
obj := d.Get("FirstChar")
|
||||
|
Loading…
x
Reference in New Issue
Block a user