Merge branch 'v3' into patch-1

This commit is contained in:
Gunnsteinn Hall 2019-01-07 16:43:50 +00:00 committed by GitHub
commit 1085bf1a2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 12 deletions

View File

@ -60,13 +60,27 @@ func toFontDifferences(differences map[CharCode]GlyphName) *core.PdfObjectArray
// ApplyDifferences modifies or wraps the base encoding and overlays differences over it.
func ApplyDifferences(base SimpleEncoder, differences map[CharCode]GlyphName) SimpleEncoder {
// TODO(dennwc): check if it's a differencesEncoding, and merge the mapping
if len(differences) == 0 {
return base
}
d := &differencesEncoding{
base: base,
differences: differences,
decode: make(map[byte]rune),
encode: make(map[rune]byte),
}
if d2, ok := base.(*differencesEncoding); ok {
// merge differences
diff := make(map[CharCode]GlyphName)
for code, glyph := range d2.differences {
diff[code] = glyph
}
for code, glyph := range differences {
diff[code] = glyph
}
differences = diff
base = d2.base
}
for code, glyph := range differences {
b := byte(code)
r, ok := GlyphToRune(glyph)
@ -177,6 +191,11 @@ func (enc *differencesEncoding) ToPdfObject() core.PdfObject {
dict := core.MakeDict()
dict.Set("Type", core.MakeName("Encoding"))
dict.Set("BaseEncoding", enc.base.ToPdfObject())
dict.Set("Differences", toFontDifferences(enc.differences))
diff := toFontDifferences(enc.differences)
if diff == nil {
// this should never happen, because the constructor checks if it is empty
panic("differences should not be nil")
}
dict.Set("Differences", diff)
return core.MakeIndirectObject(dict)
}

View File

@ -221,16 +221,7 @@ func (enc *simpleEncoding) CharcodeToRune(code CharCode) (rune, bool) {
}
func (enc *simpleEncoding) ToPdfObject() core.PdfObject {
switch enc.baseName {
case "MacRomanEncoding", "MacExpertEncoding", baseWinAnsi:
return core.MakeName(enc.baseName)
}
// TODO(dennwc): check if this switch is necessary, or an old code was incorrect
dict := core.MakeDict()
dict.Set("Type", core.MakeName("Encoding"))
dict.Set("BaseEncoding", core.MakeName(enc.baseName))
dict.Set("Differences", toFontDifferences(nil))
return core.MakeIndirectObject(dict)
return core.MakeName(enc.baseName)
}
// newSimpleMapping creates a byte-to-rune mapping that can be used to create simple encodings.