mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-27 13:48:51 +08:00
Move model/fonts to model/internal/fonts - reducing export surface
- Move the folder - Update imports - Add type aliases to access needed types from model (fonts.StdFont, fonts.CharMetrics and the font names)
This commit is contained in:
parent
3eaa55ed14
commit
9665959bcf
@ -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{}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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) {
|
||||
|
@ -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()
|
||||
|
@ -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())
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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"
|
||||
)
|
||||
|
||||
/*
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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() {
|
||||
|
@ -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.
|
@ -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)
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user