From 19f95527b8955d9975ec85c8c16a5cfc3e153a3c Mon Sep 17 00:00:00 2001 From: Denys Smirnov Date: Sun, 9 Dec 2018 18:56:18 +0200 Subject: [PATCH] creator: remove SetEncoder from top --- pdf/creator/creator.go | 9 --------- pdf/creator/paragraph.go | 11 +++-------- pdf/model/font.go | 14 -------------- 3 files changed, 3 insertions(+), 31 deletions(-) diff --git a/pdf/creator/creator.go b/pdf/creator/creator.go index 4f9071cb..27409944 100644 --- a/pdf/creator/creator.go +++ b/pdf/creator/creator.go @@ -13,7 +13,6 @@ import ( "strconv" "github.com/unidoc/unidoc/common" - "github.com/unidoc/unidoc/pdf/internal/textencoding" "github.com/unidoc/unidoc/pdf/model" ) @@ -57,9 +56,6 @@ type Creator struct { // Default fonts used by all components instantiated through the creator. defaultFontRegular *model.PdfFont defaultFontBold *model.PdfFont - - // Default encoder used by all components instantiated through the creator. - defaultTextEncoder textencoding.TextEncoder } // SetForms adds an Acroform to a PDF file. Sets the specified form for writing. @@ -112,9 +108,6 @@ func New() *Creator { c.pageMargins.top = m c.pageMargins.bottom = m - // Initialize default text encoder. - c.defaultTextEncoder = textencoding.NewWinAnsiTextEncoder() - // Initialize default fonts. var err error @@ -122,13 +115,11 @@ func New() *Creator { if err != nil { c.defaultFontRegular = model.DefaultFont() } - c.defaultFontRegular.SetEncoder(c.defaultTextEncoder) c.defaultFontBold, err = model.NewStandard14Font(model.HelveticaBold) if err != nil { c.defaultFontRegular = model.DefaultFont() } - c.defaultFontBold.SetEncoder(c.defaultTextEncoder) // Initialize creator table of contents. c.toc = c.NewTOC("Table of Contents") diff --git a/pdf/creator/paragraph.go b/pdf/creator/paragraph.go index 937c02a5..d7b960ce 100644 --- a/pdf/creator/paragraph.go +++ b/pdf/creator/paragraph.go @@ -74,14 +74,14 @@ func newParagraph(text string, style TextStyle) *Paragraph { p := &Paragraph{} p.text = text - font, encoder, err := model.NewStandard14FontWithEncoding("Helvetica", model.GetAlphabet(text)) + // TODO(dennwc): looks like it's tried to verify if the font has some runes missing + // but do we really care? the user knows better what font to use, and he can change it with SetFont + font, err := model.NewStandard14Font("Helvetica") if err != nil { common.Log.Debug("ERROR: NewStandard14FontWithEncoding failed err=%v. Falling back.", err) p.textFont = model.DefaultFont() } p.textFont = font - // TODO(dennwc): can it use the default font encoder? - p.SetEncoder(encoder) p.fontSize = 10 p.lineHeight = 1.0 @@ -116,11 +116,6 @@ func (p *Paragraph) SetTextAlignment(align TextAlignment) { p.alignment = align } -// SetEncoder sets the text encoding. -func (p *Paragraph) SetEncoder(encoder textencoding.TextEncoder) { - p.textFont.SetEncoder(encoder) -} - // SetLineHeight sets the line height (1.0 default). func (p *Paragraph) SetLineHeight(lineheight float64) { p.lineHeight = lineheight diff --git a/pdf/model/font.go b/pdf/model/font.go index fe732c5c..64319f86 100644 --- a/pdf/model/font.go +++ b/pdf/model/font.go @@ -380,20 +380,6 @@ func (font PdfFont) Encoder() textencoding.TextEncoder { return t.Encoder() } -// SetEncoder sets the encoding for the underlying font. -func (font PdfFont) SetEncoder(encoder textencoding.TextEncoder) { - t := font.actualFont() - if t == nil { - common.Log.Debug("ERROR: SetEncoder. Not implemented for font type=%#T", font.context) - return - } - if t, ok := t.(interface { - SetEncoder(encoder textencoding.TextEncoder) - }); ok { - t.SetEncoder(encoder) - } -} - // GetGlyphCharMetrics returns the specified char metrics for a specified glyph name. func (font PdfFont) GetGlyphCharMetrics(glyph textencoding.GlyphName) (fonts.CharMetrics, bool) { t := font.actualFont()