diff --git a/pdf/annotator/form_field.go b/pdf/annotator/form_field.go index 7461d7a9..ef34ada3 100644 --- a/pdf/annotator/form_field.go +++ b/pdf/annotator/form_field.go @@ -12,7 +12,6 @@ import ( "github.com/unidoc/unidoc/pdf/contentstream" "github.com/unidoc/unidoc/pdf/core" "github.com/unidoc/unidoc/pdf/model" - "github.com/unidoc/unidoc/pdf/model/fonts" ) // TextFieldOptions defines optional parameter for a text field in a form. @@ -77,7 +76,10 @@ func NewCheckboxField(page *model.PdfPage, name string, rect []float64, opt Chec return nil, errors.New("invalid range") } - zapfdb := fonts.NewFontZapfDingbats() + zapfdb, err := model.NewStandard14Font(model.ZapfDingbatsName) + if err != nil { + return nil, err + } field := model.NewPdfField() buttonfield := &model.PdfFieldButton{} diff --git a/pdf/creator/creator.go b/pdf/creator/creator.go index a0a0e872..356170c9 100644 --- a/pdf/creator/creator.go +++ b/pdf/creator/creator.go @@ -14,7 +14,6 @@ import ( "github.com/unidoc/unidoc/common" "github.com/unidoc/unidoc/pdf/model" - "github.com/unidoc/unidoc/pdf/model/fonts" ) // Creator is a wrapper around functionality for creating PDF reports and/or adding new @@ -118,12 +117,12 @@ func New() *Creator { // Initialize default fonts. var err error - c.defaultFontRegular, err = model.NewStandard14Font(fonts.HelveticaName) + c.defaultFontRegular, err = model.NewStandard14Font(model.HelveticaName) if err != nil { c.defaultFontRegular = model.DefaultFont() } - c.defaultFontBold, err = model.NewStandard14Font(fonts.HelveticaBoldName) + c.defaultFontBold, err = model.NewStandard14Font(model.HelveticaBoldName) if err != nil { c.defaultFontRegular = model.DefaultFont() } diff --git a/pdf/creator/creator_test.go b/pdf/creator/creator_test.go index f363e092..8e22acff 100644 --- a/pdf/creator/creator_test.go +++ b/pdf/creator/creator_test.go @@ -30,11 +30,11 @@ import ( "github.com/boombuler/barcode" "github.com/boombuler/barcode/qr" + "github.com/unidoc/unidoc/common" "github.com/unidoc/unidoc/pdf/contentstream/draw" "github.com/unidoc/unidoc/pdf/core" "github.com/unidoc/unidoc/pdf/model" - "github.com/unidoc/unidoc/pdf/model/fonts" "github.com/unidoc/unidoc/pdf/model/optimize" ) @@ -550,7 +550,7 @@ func TestParagraphFonts(t *testing.T) { return } - helvetica := model.NewStandard14FontMustCompile(fonts.HelveticaName) + helvetica := model.NewStandard14FontMustCompile(model.HelveticaName) fonts := []*model.PdfFont{roboto, robotoBold, helvetica, roboto, robotoBold, helvetica} for _, font := range fonts { @@ -580,21 +580,21 @@ func TestParagraphFonts(t *testing.T) { func TestParagraphStandardFonts(t *testing.T) { creator := New() - names := []fonts.StdFontName{ - fonts.CourierName, - fonts.CourierBoldName, - fonts.CourierBoldObliqueName, - fonts.CourierObliqueName, - fonts.HelveticaName, - fonts.HelveticaBoldName, - fonts.HelveticaBoldObliqueName, - fonts.HelveticaObliqueName, - fonts.TimesRomanName, - fonts.TimesBoldName, - fonts.TimesBoldItalicName, - fonts.TimesItalicName, - fonts.SymbolName, - fonts.ZapfDingbatsName, + names := []model.StdFontName{ + model.CourierName, + model.CourierBoldName, + model.CourierBoldObliqueName, + model.CourierObliqueName, + model.HelveticaName, + model.HelveticaBoldName, + model.HelveticaBoldObliqueName, + model.HelveticaObliqueName, + model.TimesRomanName, + model.TimesBoldName, + model.TimesBoldItalicName, + model.TimesItalicName, + model.SymbolName, + model.ZapfDingbatsName, } texts := []string{ @@ -785,7 +785,7 @@ func TestSubchaptersSimple(t *testing.T) { c.AddTOC = true lineStyle := c.NewTextStyle() - lineStyle.Font = model.NewStandard14FontMustCompile(fonts.HelveticaBoldName) + lineStyle.Font = model.NewStandard14FontMustCompile(model.HelveticaBoldName) toc := c.TOC() toc.SetLineStyle(lineStyle) @@ -864,7 +864,7 @@ func TestSubchaptersSimple(t *testing.T) { lineStyle := c.NewTextStyle() lineStyle.FontSize = 14 - helveticaBold := model.NewStandard14FontMustCompile(fonts.HelveticaBoldName) + helveticaBold := model.NewStandard14FontMustCompile(model.HelveticaBoldName) lines := toc.Lines() for _, line := range lines { @@ -885,7 +885,7 @@ func TestSubchapters(t *testing.T) { c.AddTOC = true lineStyle := c.NewTextStyle() - lineStyle.Font = model.NewStandard14FontMustCompile(fonts.HelveticaName) + lineStyle.Font = model.NewStandard14FontMustCompile(model.HelveticaName) lineStyle.FontSize = 14 lineStyle.Color = ColorRGBFromArithmetic(0.5, 0.5, 0.5) @@ -974,7 +974,7 @@ func TestSubchapters(t *testing.T) { toc.SetHeading("Table of Contents", style) // Set style of TOC lines just before render. - helveticaBold := model.NewStandard14FontMustCompile(fonts.HelveticaBoldName) + helveticaBold := model.NewStandard14FontMustCompile(model.HelveticaBoldName) lines := toc.Lines() for _, line := range lines { @@ -1242,7 +1242,7 @@ func newContent(c *Creator, text string, alignment TextAlignment, font *model.Pd } func newBillItem(c *Creator, t *Table, no, date, notes, amount, con, retApplied, ret, netBill string) { - timesBold := model.NewStandard14FontMustCompile(fonts.TimesBoldName) + timesBold := model.NewStandard14FontMustCompile(model.TimesBoldName) billNo := t.NewCell() billNo.SetContent(newContent(c, no, TextAlignmentLeft, timesBold, 8, ColorBlack)) @@ -1266,8 +1266,8 @@ func newBillItem(c *Creator, t *Table, no, date, notes, amount, con, retApplied, func TestCreatorHendricksReq1(t *testing.T) { c := New() - timesRoman := model.NewStandard14FontMustCompile(fonts.TimesRomanName) - timesBold := model.NewStandard14FontMustCompile(fonts.TimesBoldName) + timesRoman := model.NewStandard14FontMustCompile(model.TimesRomanName) + timesBold := model.NewStandard14FontMustCompile(model.TimesBoldName) table := c.NewTable(3) // Mx4 table // Default, equal column sizes (4x0.25)... table.SetColumnWidths(0.35, 0.30, 0.35) @@ -1462,7 +1462,7 @@ func TestCreatorHendricksReq1(t *testing.T) { func TestCreatorTableBorderReq1(t *testing.T) { c := New() - timesRoman := model.NewStandard14FontMustCompile(fonts.TimesRomanName) + timesRoman := model.NewStandard14FontMustCompile(model.TimesRomanName) table := c.NewTable(1) // Mx4 table table.SetColumnWidths(1) @@ -1789,7 +1789,7 @@ func TestCreatorTableBorderReq1(t *testing.T) { func TestCellBorder(t *testing.T) { c := New() - timesBold := model.NewStandard14FontMustCompile(fonts.TimesBoldName) + timesBold := model.NewStandard14FontMustCompile(model.TimesBoldName) table := c.NewTable(2) table.SetColumnWidths(0.50, 0.50) @@ -1806,8 +1806,8 @@ func TestCellBorder(t *testing.T) { func TestTableInSubchapter(t *testing.T) { c := New() - fontRegular := model.NewStandard14FontMustCompile(fonts.HelveticaName) - fontBold := model.NewStandard14FontMustCompile(fonts.HelveticaBoldName) + fontRegular := model.NewStandard14FontMustCompile(model.HelveticaName) + fontBold := model.NewStandard14FontMustCompile(model.HelveticaBoldName) ch := c.NewChapter("Document control") ch.SetMargins(0, 0, 40, 0) @@ -2255,7 +2255,7 @@ func createPdf4Optimization(t *testing.T) *Creator { p := c.NewParagraph("Test text1") // Change to times bold font (default is helvetica). - font, err := model.NewStandard14Font(fonts.CourierBoldName) + font, err := model.NewStandard14Font(model.CourierBoldName) if err != nil { t.Errorf("Fail: %v\n", err) t.FailNow() @@ -2326,7 +2326,7 @@ func createPdf4Optimization(t *testing.T) *Creator { c.NewPage() p = c.NewParagraph("Test text2") // Change to times bold font (default is helvetica). - font, err = model.NewStandard14Font(fonts.HelveticaName) + font, err = model.NewStandard14Font(model.HelveticaName) if err != nil { t.Errorf("Fail: %v\n", err) t.FailNow() @@ -2715,7 +2715,7 @@ func TestCompressStreams(t *testing.T) { page := c.pages[0] // Need to add Arial to the page resources to avoid generating invalid PDF (avoid build fail). - times := model.NewStandard14FontMustCompile(fonts.TimesRomanName) + times := model.NewStandard14FontMustCompile(model.TimesRomanName) page.Resources.SetFontByName("Times", times.ToPdfObject()) rawContent := ` BT diff --git a/pdf/creator/division_test.go b/pdf/creator/division_test.go index a5fe4ae2..4292075c 100644 --- a/pdf/creator/division_test.go +++ b/pdf/creator/division_test.go @@ -12,7 +12,6 @@ import ( "time" "github.com/unidoc/unidoc/pdf/model" - "github.com/unidoc/unidoc/pdf/model/fonts" ) var seed = rand.New(rand.NewSource(time.Now().UnixNano())) @@ -27,7 +26,7 @@ func RandString(length int) string { return string(b) } -func newStandard14Font(t testing.TB, base fonts.StdFontName) *model.PdfFont { +func newStandard14Font(t testing.TB, base model.StdFontName) *model.PdfFont { f, err := model.NewStandard14Font(base) if err != nil { t.Fatalf("Error opening font: %v", err) @@ -36,8 +35,8 @@ func newStandard14Font(t testing.TB, base fonts.StdFontName) *model.PdfFont { } func TestDivVertical(t *testing.T) { - fontRegular := newStandard14Font(t, fonts.CourierName) - fontBold := newStandard14Font(t, fonts.CourierBoldName) + fontRegular := newStandard14Font(t, model.CourierName) + fontBold := newStandard14Font(t, model.CourierBoldName) c := New() c.NewPage() @@ -94,8 +93,8 @@ func TestDivVertical(t *testing.T) { } func TestDivInline(t *testing.T) { - fontRegular := newStandard14Font(t, fonts.CourierName) - fontBold := newStandard14Font(t, fonts.CourierBoldName) + fontRegular := newStandard14Font(t, model.CourierName) + fontBold := newStandard14Font(t, model.CourierBoldName) c := New() c.NewPage() @@ -172,8 +171,8 @@ func TestDivInline(t *testing.T) { } func TestDivNumberMatrix(t *testing.T) { - fontRegular := newStandard14Font(t, fonts.CourierName) - fontBold := newStandard14Font(t, fonts.CourierBoldName) + fontRegular := newStandard14Font(t, model.CourierName) + fontBold := newStandard14Font(t, model.CourierBoldName) c := New() c.NewPage() @@ -223,8 +222,8 @@ func TestDivNumberMatrix(t *testing.T) { } func TestDivRandomSequences(t *testing.T) { - fontRegular := newStandard14Font(t, fonts.HelveticaName) - fontBold := newStandard14Font(t, fonts.HelveticaBoldName) + fontRegular := newStandard14Font(t, model.HelveticaName) + fontBold := newStandard14Font(t, model.HelveticaBoldName) c := New() c.NewPage() @@ -299,8 +298,8 @@ func TestDivRandomSequences(t *testing.T) { } func TestTableDivisions(t *testing.T) { - fontRegular := newStandard14Font(t, fonts.HelveticaName) - fontBold := newStandard14Font(t, fonts.HelveticaBoldName) + fontRegular := newStandard14Font(t, model.HelveticaName) + fontBold := newStandard14Font(t, model.HelveticaBoldName) c := New() c.NewPage() diff --git a/pdf/creator/invoice_test.go b/pdf/creator/invoice_test.go index e8331653..11974e23 100644 --- a/pdf/creator/invoice_test.go +++ b/pdf/creator/invoice_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/unidoc/unidoc/pdf/model" - "github.com/unidoc/unidoc/pdf/model/fonts" ) func TestInvoiceSimple(t *testing.T) { @@ -82,7 +81,7 @@ func TestInvoiceSimple(t *testing.T) { } func TestInvoiceAdvanced(t *testing.T) { - fontHelvetica := model.NewStandard14FontMustCompile(fonts.HelveticaName) + fontHelvetica := model.NewStandard14FontMustCompile(model.HelveticaName) c := New() c.NewPage() diff --git a/pdf/creator/list_test.go b/pdf/creator/list_test.go index 75fda5c2..cb761674 100644 --- a/pdf/creator/list_test.go +++ b/pdf/creator/list_test.go @@ -9,7 +9,6 @@ import ( "testing" "github.com/unidoc/unidoc/pdf/model" - "github.com/unidoc/unidoc/pdf/model/fonts" ) func TestListSimple(t *testing.T) { @@ -57,7 +56,7 @@ func TestListSimple(t *testing.T) { } func TestListAdvanced(t *testing.T) { - fontHelveticaBold := model.NewStandard14FontMustCompile(fonts.HelveticaBoldName) + fontHelveticaBold := model.NewStandard14FontMustCompile(model.HelveticaBoldName) red := ColorRGBFrom8bit(255, 0, 0) blue := ColorRGBFrom8bit(0, 0, 255) diff --git a/pdf/creator/styled_paragraph_test.go b/pdf/creator/styled_paragraph_test.go index a6bd8f19..341cb019 100644 --- a/pdf/creator/styled_paragraph_test.go +++ b/pdf/creator/styled_paragraph_test.go @@ -8,12 +8,12 @@ package creator import ( "testing" - "github.com/unidoc/unidoc/pdf/model/fonts" + "github.com/unidoc/unidoc/pdf/model" ) func TestParagraphRegularVsStyled(t *testing.T) { - fontRegular := newStandard14Font(t, fonts.HelveticaName) - fontBold := newStandard14Font(t, fonts.HelveticaBoldName) + fontRegular := newStandard14Font(t, model.HelveticaName) + fontBold := newStandard14Font(t, model.HelveticaBoldName) c := New() c.NewPage() @@ -277,9 +277,9 @@ func TestParagraphRegularVsStyled(t *testing.T) { } func TestStyledParagraph(t *testing.T) { - fontRegular := newStandard14Font(t, fonts.CourierName) - fontBold := newStandard14Font(t, fonts.CourierBoldName) - fontHelvetica := newStandard14Font(t, fonts.HelveticaName) + fontRegular := newStandard14Font(t, model.CourierName) + fontBold := newStandard14Font(t, model.CourierBoldName) + fontHelvetica := newStandard14Font(t, model.HelveticaName) c := New() c.NewPage() @@ -438,7 +438,7 @@ Sed imperdiet sodales lacus sed sollicitudin. In porta tortor quis augue tempor, } func TestStyledParagraphRenderingModes(t *testing.T) { - fontRegular := newStandard14Font(t, fonts.HelveticaName) + fontRegular := newStandard14Font(t, model.HelveticaName) c := New() c.NewPage() @@ -510,8 +510,8 @@ func TestStyledParagraphRenderingModes(t *testing.T) { } func TestStyledParagraphCharacterSpacing(t *testing.T) { - fontRegular := newStandard14Font(t, fonts.HelveticaName) - fontBold := newStandard14Font(t, fonts.HelveticaBoldName) + fontRegular := newStandard14Font(t, model.HelveticaName) + fontBold := newStandard14Font(t, model.HelveticaBoldName) c := New() c.NewPage() diff --git a/pdf/creator/table_test.go b/pdf/creator/table_test.go index 6364f6d2..bedf524a 100644 --- a/pdf/creator/table_test.go +++ b/pdf/creator/table_test.go @@ -11,12 +11,11 @@ import ( "testing" "github.com/unidoc/unidoc/pdf/model" - "github.com/unidoc/unidoc/pdf/model/fonts" ) var ( - fontHelvetica = model.NewStandard14FontMustCompile(fonts.HelveticaName) - fontHelveticaBold = model.NewStandard14FontMustCompile(fonts.HelveticaBoldName) + fontHelvetica = model.NewStandard14FontMustCompile(model.HelveticaName) + fontHelveticaBold = model.NewStandard14FontMustCompile(model.HelveticaBoldName) ) func TestTableMultiParagraphWrapped(t *testing.T) { diff --git a/pdf/creator/toc_test.go b/pdf/creator/toc_test.go index 99beb169..a743086c 100644 --- a/pdf/creator/toc_test.go +++ b/pdf/creator/toc_test.go @@ -8,12 +8,11 @@ import ( "testing" "github.com/unidoc/unidoc/pdf/model" - "github.com/unidoc/unidoc/pdf/model/fonts" ) func TestTOCAdvanced(t *testing.T) { - fontHelvetica := model.NewStandard14FontMustCompile(fonts.HelveticaName) - fontHelveticaBold := model.NewStandard14FontMustCompile(fonts.HelveticaBoldName) + fontHelvetica := model.NewStandard14FontMustCompile(model.HelveticaName) + fontHelveticaBold := model.NewStandard14FontMustCompile(model.HelveticaBoldName) c := New() c.NewPage() diff --git a/pdf/extractor/text_test.go b/pdf/extractor/text_test.go index 9f28995f..4459af46 100644 --- a/pdf/extractor/text_test.go +++ b/pdf/extractor/text_test.go @@ -14,10 +14,9 @@ import ( "strings" "testing" - "github.com/unidoc/unidoc/pdf/model/fonts" - "github.com/unidoc/unidoc/common" "github.com/unidoc/unidoc/pdf/model" + "golang.org/x/text/unicode/norm" ) @@ -100,8 +99,8 @@ func TestTextExtractionFragments(t *testing.T) { // Setup mock resources. resources := model.NewPdfPageResources() { - courier := model.NewStandard14FontMustCompile(fonts.CourierName) - helvetica := model.NewStandard14FontMustCompile(fonts.HelveticaName) + courier := model.NewStandard14FontMustCompile(model.CourierName) + helvetica := model.NewStandard14FontMustCompile(model.HelveticaName) resources.SetFontByName("UniDocHelvetica", helvetica.ToPdfObject()) resources.SetFontByName("UniDocCourier", courier.ToPdfObject()) } diff --git a/pdf/model/font.go b/pdf/model/font.go index c6bfd51e..b286d434 100644 --- a/pdf/model/font.go +++ b/pdf/model/font.go @@ -13,14 +13,17 @@ import ( "github.com/unidoc/unidoc/common" "github.com/unidoc/unidoc/pdf/core" + "github.com/unidoc/unidoc/pdf/internal/cmap" "github.com/unidoc/unidoc/pdf/internal/textencoding" - "github.com/unidoc/unidoc/pdf/model/fonts" + "github.com/unidoc/unidoc/pdf/model/internal/fonts" ) // pdfFont is an internal interface for fonts that can be stored in PDF documents. type pdfFont interface { fonts.Font + // ToPdfObject returns a PDF representation of the font and implements interface Model. + ToPdfObject() core.PdfObject // getFontDescriptor returns the font descriptor of the font. getFontDescriptor() *PdfFontDescriptor // baseFields returns fields that are common for PDF fonts. @@ -96,7 +99,7 @@ func DefaultFont() *PdfFont { return &PdfFont{context: &std} } -func newStandard14Font(basefont fonts.StdFontName) (pdfFontSimple, error) { +func newStandard14Font(basefont StdFontName) (pdfFontSimple, error) { fnt, ok := fonts.NewStdFontByName(basefont) if !ok { return pdfFontSimple{}, ErrFontNotSupported @@ -105,9 +108,30 @@ func newStandard14Font(basefont fonts.StdFontName) (pdfFontSimple, error) { return std, nil } +// StdFontName represents name of a standard font. +type StdFontName = fonts.StdFontName + +// Names of the standard 14 fonts. +var ( + CourierName = fonts.CourierName + CourierBoldName = fonts.CourierBoldName + CourierObliqueName = fonts.CourierObliqueName + CourierBoldObliqueName = fonts.CourierBoldObliqueName + HelveticaName = fonts.HelveticaName + HelveticaBoldName = fonts.HelveticaBoldName + HelveticaObliqueName = fonts.HelveticaObliqueName + HelveticaBoldObliqueName = fonts.HelveticaBoldObliqueName + SymbolName = fonts.SymbolName + ZapfDingbatsName = fonts.ZapfDingbatsName + TimesRomanName = fonts.TimesRomanName + TimesBoldName = fonts.TimesBoldName + TimesItalicName = fonts.TimesItalicName + TimesBoldItalicName = fonts.TimesBoldItalicName +) + // NewStandard14Font returns the standard 14 font named `basefont` as a *PdfFont, or an error if it // `basefont` is not one of the standard 14 font names. -func NewStandard14Font(basefont fonts.StdFontName) (*PdfFont, error) { +func NewStandard14Font(basefont StdFontName) (*PdfFont, error) { std, err := newStandard14Font(basefont) if err != nil { return nil, err @@ -118,7 +142,7 @@ func NewStandard14Font(basefont fonts.StdFontName) (*PdfFont, error) { // NewStandard14FontMustCompile returns the standard 14 font named `basefont` as a *PdfFont. // If `basefont` is one of the 14 Standard14Font values defined above then NewStandard14FontMustCompile // is guaranteed to succeed. -func NewStandard14FontMustCompile(basefont fonts.StdFontName) *PdfFont { +func NewStandard14FontMustCompile(basefont StdFontName) *PdfFont { font, err := NewStandard14Font(basefont) if err != nil { panic(fmt.Errorf("invalid Standard14Font %#q", basefont)) @@ -129,7 +153,7 @@ func NewStandard14FontMustCompile(basefont fonts.StdFontName) *PdfFont { // NewStandard14FontWithEncoding returns the standard 14 font named `basefont` as a *PdfFont and // a TextEncoder that encodes all the runes in `alphabet`, or an error if this is not possible. // An error can occur if `basefont` is not one the standard 14 font names. -func NewStandard14FontWithEncoding(basefont fonts.StdFontName, alphabet map[rune]int) (*PdfFont, +func NewStandard14FontWithEncoding(basefont StdFontName, alphabet map[rune]int) (*PdfFont, textencoding.SimpleEncoder, error) { std, err := newStandard14Font(basefont) if err != nil { @@ -493,10 +517,13 @@ func (font *PdfFont) Encoder() textencoding.TextEncoder { return t.Encoder() } +// CharMetrics represents width and height metrics of a glyph. +type CharMetrics = fonts.CharMetrics + // GetRuneMetrics returns the char metrics for a rune. // TODO(peterwilliams97) There is nothing callers can do if no CharMetrics are found so we might as // well give them 0 width. There is no need for the bool return. -func (font *PdfFont) GetRuneMetrics(r rune) (fonts.CharMetrics, bool) { +func (font *PdfFont) GetRuneMetrics(r rune) (CharMetrics, bool) { t := font.actualFont() if t == nil { common.Log.Debug("ERROR: GetGlyphCharMetrics Not implemented for font type=%#T", font.context) @@ -524,7 +551,7 @@ func (font *PdfFont) GetRuneMetrics(r rune) (fonts.CharMetrics, bool) { // TODO(peterwilliams97) There is nothing callers can do if no CharMetrics are found so we might as // well give them 0 width. There is no need for the bool return. // TODO(gunnsth): Reconsider whether needed or if can map via GlyphName. -func (font *PdfFont) GetCharMetrics(code textencoding.CharCode) (fonts.CharMetrics, bool) { +func (font *PdfFont) GetCharMetrics(code textencoding.CharCode) (CharMetrics, bool) { var nometrics fonts.CharMetrics // TODO(peterwilliams97): pdfFontType0.GetCharMetrics() calls pdfCIDFontType2.GetCharMetrics() diff --git a/pdf/model/font_composite.go b/pdf/model/font_composite.go index 8acdce39..deb68a3f 100644 --- a/pdf/model/font_composite.go +++ b/pdf/model/font_composite.go @@ -14,8 +14,9 @@ import ( "github.com/unidoc/unidoc/common" "github.com/unidoc/unidoc/pdf/core" + "github.com/unidoc/unidoc/pdf/internal/textencoding" - "github.com/unidoc/unidoc/pdf/model/fonts" + "github.com/unidoc/unidoc/pdf/model/internal/fonts" ) /* diff --git a/pdf/model/font_composite_test.go b/pdf/model/font_composite_test.go index 6199933b..81866846 100644 --- a/pdf/model/font_composite_test.go +++ b/pdf/model/font_composite_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/unidoc/unidoc/pdf/core" - "github.com/unidoc/unidoc/pdf/model/fonts" + "github.com/unidoc/unidoc/pdf/model/internal/fonts" ) func TestCIDWidthArr(t *testing.T) { diff --git a/pdf/model/font_simple.go b/pdf/model/font_simple.go index 48298418..7aaa2327 100644 --- a/pdf/model/font_simple.go +++ b/pdf/model/font_simple.go @@ -12,8 +12,9 @@ import ( "github.com/unidoc/unidoc/common" "github.com/unidoc/unidoc/pdf/core" + "github.com/unidoc/unidoc/pdf/internal/textencoding" - "github.com/unidoc/unidoc/pdf/model/fonts" + "github.com/unidoc/unidoc/pdf/model/internal/fonts" ) // pdfFontSimple implements pdfFont diff --git a/pdf/model/font_test.go b/pdf/model/font_test.go index 539f1209..df422c99 100644 --- a/pdf/model/font_test.go +++ b/pdf/model/font_test.go @@ -13,10 +13,11 @@ import ( "github.com/unidoc/unidoc/common" "github.com/unidoc/unidoc/pdf/core" + "github.com/unidoc/unidoc/pdf/model" + "github.com/unidoc/unidoc/pdf/internal/testutils" "github.com/unidoc/unidoc/pdf/internal/textencoding" - "github.com/unidoc/unidoc/pdf/model" - "github.com/unidoc/unidoc/pdf/model/fonts" + "github.com/unidoc/unidoc/pdf/model/internal/fonts" ) func init() { diff --git a/pdf/model/fonts/doc.go b/pdf/model/internal/fonts/doc.go similarity index 100% rename from pdf/model/fonts/doc.go rename to pdf/model/internal/fonts/doc.go diff --git a/pdf/model/fonts/font.go b/pdf/model/internal/fonts/font.go similarity index 91% rename from pdf/model/fonts/font.go rename to pdf/model/internal/fonts/font.go index 7e54528b..ebbdbb0f 100644 --- a/pdf/model/fonts/font.go +++ b/pdf/model/internal/fonts/font.go @@ -8,7 +8,6 @@ package fonts import ( "fmt" - "github.com/unidoc/unidoc/pdf/core" "github.com/unidoc/unidoc/pdf/internal/textencoding" ) @@ -17,7 +16,7 @@ import ( type Font interface { Encoder() textencoding.TextEncoder GetRuneMetrics(r rune) (CharMetrics, bool) - ToPdfObject() core.PdfObject + //ToPdfObject() core.PdfObject } // CharMetrics represents width and height metrics of a glyph. diff --git a/pdf/model/fonts/std.go b/pdf/model/internal/fonts/std.go similarity index 100% rename from pdf/model/fonts/std.go rename to pdf/model/internal/fonts/std.go diff --git a/pdf/model/fonts/std_courier.go b/pdf/model/internal/fonts/std_courier.go similarity index 100% rename from pdf/model/fonts/std_courier.go rename to pdf/model/internal/fonts/std_courier.go diff --git a/pdf/model/fonts/std_helvetica.go b/pdf/model/internal/fonts/std_helvetica.go similarity index 100% rename from pdf/model/fonts/std_helvetica.go rename to pdf/model/internal/fonts/std_helvetica.go diff --git a/pdf/model/fonts/std_other.go b/pdf/model/internal/fonts/std_other.go similarity index 100% rename from pdf/model/fonts/std_other.go rename to pdf/model/internal/fonts/std_other.go diff --git a/pdf/model/fonts/std_times.go b/pdf/model/internal/fonts/std_times.go similarity index 100% rename from pdf/model/fonts/std_times.go rename to pdf/model/internal/fonts/std_times.go diff --git a/pdf/model/fonts/testdata/afms/Courier-Bold.afm b/pdf/model/internal/fonts/testdata/afms/Courier-Bold.afm similarity index 100% rename from pdf/model/fonts/testdata/afms/Courier-Bold.afm rename to pdf/model/internal/fonts/testdata/afms/Courier-Bold.afm diff --git a/pdf/model/fonts/testdata/afms/Courier-BoldOblique.afm b/pdf/model/internal/fonts/testdata/afms/Courier-BoldOblique.afm similarity index 100% rename from pdf/model/fonts/testdata/afms/Courier-BoldOblique.afm rename to pdf/model/internal/fonts/testdata/afms/Courier-BoldOblique.afm diff --git a/pdf/model/fonts/testdata/afms/Courier-Oblique.afm b/pdf/model/internal/fonts/testdata/afms/Courier-Oblique.afm similarity index 100% rename from pdf/model/fonts/testdata/afms/Courier-Oblique.afm rename to pdf/model/internal/fonts/testdata/afms/Courier-Oblique.afm diff --git a/pdf/model/fonts/testdata/afms/Courier.afm b/pdf/model/internal/fonts/testdata/afms/Courier.afm similarity index 100% rename from pdf/model/fonts/testdata/afms/Courier.afm rename to pdf/model/internal/fonts/testdata/afms/Courier.afm diff --git a/pdf/model/fonts/testdata/afms/Helvetica-Bold.afm b/pdf/model/internal/fonts/testdata/afms/Helvetica-Bold.afm similarity index 100% rename from pdf/model/fonts/testdata/afms/Helvetica-Bold.afm rename to pdf/model/internal/fonts/testdata/afms/Helvetica-Bold.afm diff --git a/pdf/model/fonts/testdata/afms/Helvetica-BoldOblique.afm b/pdf/model/internal/fonts/testdata/afms/Helvetica-BoldOblique.afm similarity index 100% rename from pdf/model/fonts/testdata/afms/Helvetica-BoldOblique.afm rename to pdf/model/internal/fonts/testdata/afms/Helvetica-BoldOblique.afm diff --git a/pdf/model/fonts/testdata/afms/Helvetica-Oblique.afm b/pdf/model/internal/fonts/testdata/afms/Helvetica-Oblique.afm similarity index 100% rename from pdf/model/fonts/testdata/afms/Helvetica-Oblique.afm rename to pdf/model/internal/fonts/testdata/afms/Helvetica-Oblique.afm diff --git a/pdf/model/fonts/testdata/afms/Helvetica.afm b/pdf/model/internal/fonts/testdata/afms/Helvetica.afm similarity index 100% rename from pdf/model/fonts/testdata/afms/Helvetica.afm rename to pdf/model/internal/fonts/testdata/afms/Helvetica.afm diff --git a/pdf/model/fonts/testdata/afms/MustRead.html b/pdf/model/internal/fonts/testdata/afms/MustRead.html similarity index 100% rename from pdf/model/fonts/testdata/afms/MustRead.html rename to pdf/model/internal/fonts/testdata/afms/MustRead.html diff --git a/pdf/model/fonts/testdata/afms/Symbol.afm b/pdf/model/internal/fonts/testdata/afms/Symbol.afm similarity index 100% rename from pdf/model/fonts/testdata/afms/Symbol.afm rename to pdf/model/internal/fonts/testdata/afms/Symbol.afm diff --git a/pdf/model/fonts/testdata/afms/Times-Bold.afm b/pdf/model/internal/fonts/testdata/afms/Times-Bold.afm similarity index 100% rename from pdf/model/fonts/testdata/afms/Times-Bold.afm rename to pdf/model/internal/fonts/testdata/afms/Times-Bold.afm diff --git a/pdf/model/fonts/testdata/afms/Times-BoldItalic.afm b/pdf/model/internal/fonts/testdata/afms/Times-BoldItalic.afm similarity index 100% rename from pdf/model/fonts/testdata/afms/Times-BoldItalic.afm rename to pdf/model/internal/fonts/testdata/afms/Times-BoldItalic.afm diff --git a/pdf/model/fonts/testdata/afms/Times-Italic.afm b/pdf/model/internal/fonts/testdata/afms/Times-Italic.afm similarity index 100% rename from pdf/model/fonts/testdata/afms/Times-Italic.afm rename to pdf/model/internal/fonts/testdata/afms/Times-Italic.afm diff --git a/pdf/model/fonts/testdata/afms/Times-Roman.afm b/pdf/model/internal/fonts/testdata/afms/Times-Roman.afm similarity index 100% rename from pdf/model/fonts/testdata/afms/Times-Roman.afm rename to pdf/model/internal/fonts/testdata/afms/Times-Roman.afm diff --git a/pdf/model/fonts/testdata/afms/ZapfDingbats.afm b/pdf/model/internal/fonts/testdata/afms/ZapfDingbats.afm similarity index 100% rename from pdf/model/fonts/testdata/afms/ZapfDingbats.afm rename to pdf/model/internal/fonts/testdata/afms/ZapfDingbats.afm diff --git a/pdf/model/fonts/testdata/afms/export_metrics.go b/pdf/model/internal/fonts/testdata/afms/export_metrics.go similarity index 97% rename from pdf/model/fonts/testdata/afms/export_metrics.go rename to pdf/model/internal/fonts/testdata/afms/export_metrics.go index 2abdfcc5..c38222db 100644 --- a/pdf/model/fonts/testdata/afms/export_metrics.go +++ b/pdf/model/internal/fonts/testdata/afms/export_metrics.go @@ -18,7 +18,8 @@ import ( "flag" pdfcommon "github.com/unidoc/unidoc/common" - "github.com/unidoc/unidoc/pdf/model/fonts" + "github.com/unidoc/unidoc/pdf/internal/fonts" + "github.com/unidoc/unidoc/pdf/model" ) func main() { @@ -117,8 +118,8 @@ func runGlyphToCharcodeRetrievalOnFile(afmpath string) error { return nil } -func GetCharmetricsFromAfmFile(filename string) (map[string]fonts.CharMetrics, error) { - glyphMetricsMap := map[string]fonts.CharMetrics{} +func GetCharmetricsFromAfmFile(filename string) (map[string]model.CharMetrics, error) { + glyphMetricsMap := map[string]model.CharMetrics{} f, err := os.Open(filename) if err != nil { @@ -151,7 +152,7 @@ func GetCharmetricsFromAfmFile(filename string) (map[string]fonts.CharMetrics, e } parts = strings.Split(line, ";") - var metrics fonts.CharMetrics + var metrics model.CharMetrics glyphName := "" for _, part := range parts { cmd := strings.TrimSpace(part) @@ -334,7 +335,7 @@ var standard14Names = []string{ } // createFontDescriptor creates a literal DescriptorLiteral that can be copied into -// pdf/model/fonts/const.go. +// pdf/internal/fonts/const.go. func createFontDescriptor(name, filename string) (string, error) { fmt.Println("----------------------------------------------------") fmt.Printf("createFontDescriptor: name=%#q filename=%q\n", name, filename) diff --git a/pdf/model/fonts/ttfparser.go b/pdf/model/internal/fonts/ttfparser.go similarity index 100% rename from pdf/model/fonts/ttfparser.go rename to pdf/model/internal/fonts/ttfparser.go diff --git a/pdf/model/fonts/ttfparser_test.go b/pdf/model/internal/fonts/ttfparser_test.go similarity index 100% rename from pdf/model/fonts/ttfparser_test.go rename to pdf/model/internal/fonts/ttfparser_test.go diff --git a/pdf/model/writer.go b/pdf/model/writer.go index 7e4b653b..df4a54d5 100644 --- a/pdf/model/writer.go +++ b/pdf/model/writer.go @@ -22,7 +22,8 @@ import ( "github.com/unidoc/unidoc/pdf/core" "github.com/unidoc/unidoc/pdf/core/security" "github.com/unidoc/unidoc/pdf/core/security/crypt" - "github.com/unidoc/unidoc/pdf/model/fonts" + + "github.com/unidoc/unidoc/pdf/model/internal/fonts" ) type crossReference struct {