mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-29 13:48:54 +08:00
Support Encoding dictionaries with type not explicitly set (#455)
This commit is contained in:
parent
07ba42176d
commit
fa9ac473a0
@ -325,10 +325,9 @@ func (font *pdfFontSimple) getFontEncoding() (baseName string, differences map[t
|
|||||||
case *core.PdfObjectName:
|
case *core.PdfObjectName:
|
||||||
return string(*encoding), nil, nil
|
return string(*encoding), nil, nil
|
||||||
case *core.PdfObjectDictionary:
|
case *core.PdfObjectDictionary:
|
||||||
if typ, ok := core.GetNameVal(encoding.Get("Type")); ok && typ == "Encoding" {
|
baseenc, ok := core.GetName(encoding.Get("BaseEncoding"))
|
||||||
if base, ok := core.GetNameVal(encoding.Get("BaseEncoding")); ok {
|
if ok {
|
||||||
baseName = base
|
baseName = baseenc.String()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if diffObj := encoding.Get("Differences"); diffObj != nil {
|
if diffObj := encoding.Get("Differences"); diffObj != nil {
|
||||||
diffList, ok := core.GetArray(diffObj)
|
diffList, ok := core.GetArray(diffObj)
|
||||||
|
@ -11,6 +11,8 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/unidoc/unidoc/common"
|
"github.com/unidoc/unidoc/common"
|
||||||
"github.com/unidoc/unidoc/pdf/core"
|
"github.com/unidoc/unidoc/pdf/core"
|
||||||
"github.com/unidoc/unidoc/pdf/model"
|
"github.com/unidoc/unidoc/pdf/model"
|
||||||
@ -821,7 +823,36 @@ endobj
|
|||||||
t.Fatalf("Mismatch for char code %d (%X), font has: %q and expected is: %q (StandardEncoding)", code, code, fontrune, rune)
|
t.Fatalf("Mismatch for char code %d (%X), font has: %q and expected is: %q (StandardEncoding)", code, code, fontrune, rune)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLoadSimpleFontWithDifferences(t *testing.T) {
|
||||||
|
testcases := []struct {
|
||||||
|
Path string
|
||||||
|
FontObjNumber int64
|
||||||
|
BaseEncodingName string
|
||||||
|
}{
|
||||||
|
{"./testdata/font/diff1.obj", 53, "WinAnsiEncoding"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tcase := range testcases {
|
||||||
|
data, err := ioutil.ReadFile(tcase.Path)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
objects, err := testutils.ParseIndirectObjects(string(data))
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
font, err := model.NewPdfFontFromPdfObject(objects[tcase.FontObjNumber])
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, font)
|
||||||
|
|
||||||
|
encoder := font.Encoder()
|
||||||
|
require.NotNil(t, encoder)
|
||||||
|
|
||||||
|
stdEncoder, ok := encoder.(textencoding.SimpleEncoder)
|
||||||
|
require.True(t, ok)
|
||||||
|
|
||||||
|
require.Equal(t, tcase.BaseEncodingName, stdEncoder.BaseName())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// newStandandTextEncoder returns a simpleEncoder that implements StandardEncoding.
|
// newStandandTextEncoder returns a simpleEncoder that implements StandardEncoding.
|
||||||
|
BIN
pdf/model/testdata/font/diff1.obj
vendored
Normal file
BIN
pdf/model/testdata/font/diff1.obj
vendored
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user