Added more font description strings for pdf_fonts.go test program

This commit is contained in:
Peter Williams 2018-06-29 14:21:59 +10:00
parent 539a3be976
commit 187c3e37dd
3 changed files with 22 additions and 4 deletions

View File

@ -41,7 +41,19 @@ func (font PdfFont) BaseFont() string {
// Subtype returns the font's "Subtype" field. // Subtype returns the font's "Subtype" field.
func (font PdfFont) Subtype() string { func (font PdfFont) Subtype() string {
return font.fontSkeleton.subtype subtype := font.fontSkeleton.subtype
if t, ok := font.context.(*pdfFontType0); ok {
subtype = fmt.Sprintf("%s:%s", subtype, t.DescendantFont.Subtype())
}
return subtype
}
// ToUnicode returns the name of the font's "ToUnicode" field if there is one, or "" if there isn't.
func (font PdfFont) ToUnicode() string {
if font.ucMap == nil {
return ""
}
return font.ucMap.Name()
} }
// NewPdfFontFromPdfObject loads a PdfFont from the dictionary `fontObj`. If there is a problem an // NewPdfFontFromPdfObject loads a PdfFont from the dictionary `fontObj`. If there is a problem an

View File

@ -161,7 +161,8 @@ func newPdfFontType0FromPdfObject(obj PdfObject, skeleton *fontSkeleton) (*pdfFo
} }
encoderName, err := GetName(TraceToDirectObject(d.Get("Encoding"))) encoderName, err := GetName(TraceToDirectObject(d.Get("Encoding")))
if err == nil && encoderName == "Identity-H" { // XXX: FIXME This is not valid if encoder is not Identity-H !@#$
if err == nil /*&& encoderName == "Identity-H"*/ {
font.encoder = textencoding.NewIdentityTextEncoder(encoderName) font.encoder = textencoding.NewIdentityTextEncoder(encoderName)
} }
return font, nil return font, nil

View File

@ -15,6 +15,7 @@ package textencoding
import ( import (
"errors" "errors"
"fmt"
"sort" "sort"
"github.com/unidoc/unidoc/common" "github.com/unidoc/unidoc/common"
@ -52,11 +53,14 @@ func NewSimpleTextEncoder(baseName string, differences map[byte]string) (SimpleE
} }
} }
} }
return makeEncoder(baseName, codeToRune), nil return makeEncoder(baseName, differences, codeToRune), nil
} }
// String returns a string that describes `se`. // String returns a string that describes `se`.
func (se SimpleEncoder) String() string { func (se SimpleEncoder) String() string {
if len(se.differences) > 0 {
return fmt.Sprintf("%s + differences", se.baseName)
}
return se.baseName return se.baseName
} }
@ -124,7 +128,7 @@ func (se SimpleEncoder) ToPdfObject() PdfObject {
} }
// makeEncoder returns a SimpleEncoder based on `codeToRune`. // makeEncoder returns a SimpleEncoder based on `codeToRune`.
func makeEncoder(baseName string, codeToRune map[uint16]rune) SimpleEncoder { func makeEncoder(baseName string, differences map[byte]string, codeToRune map[uint16]rune) SimpleEncoder {
codeToGlyph := map[uint16]string{} codeToGlyph := map[uint16]string{}
glyphToCode := map[string]uint16{} glyphToCode := map[string]uint16{}
for code, r := range codeToRune { for code, r := range codeToRune {
@ -134,6 +138,7 @@ func makeEncoder(baseName string, codeToRune map[uint16]rune) SimpleEncoder {
} }
return SimpleEncoder{ return SimpleEncoder{
baseName: baseName, baseName: baseName,
differences: differences,
codeToGlyph: codeToGlyph, codeToGlyph: codeToGlyph,
glyphToCode: glyphToCode, glyphToCode: glyphToCode,
} }