mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-29 13:48:54 +08:00
Remove NewX for each standard font in std. Go through a single exported function instead.
This commit is contained in:
parent
a03198000b
commit
9d714ad639
@ -95,7 +95,11 @@ func (font *PdfFont) ToUnicode() string {
|
||||
|
||||
// DefaultFont returns the default font, which is currently the built in Helvetica.
|
||||
func DefaultFont() *PdfFont {
|
||||
std := stdFontToSimpleFont(fonts.NewFontHelvetica())
|
||||
helvetica, ok := fonts.NewStdFontByName(HelveticaName)
|
||||
if !ok {
|
||||
panic("Helvetica should always be available")
|
||||
}
|
||||
std := stdFontToSimpleFont(helvetica)
|
||||
return &PdfFont{context: &std}
|
||||
}
|
||||
|
||||
|
@ -15,10 +15,10 @@ func init() {
|
||||
// The aliases seen for the standard 14 font names.
|
||||
// Most of these are from table 5.5.1 in
|
||||
// https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/adobe_supplement_iso32000.pdf
|
||||
RegisterStdFont(CourierName, NewFontCourier, "CourierCourierNew", "CourierNew")
|
||||
RegisterStdFont(CourierBoldName, NewFontCourierBold, "CourierNew,Bold")
|
||||
RegisterStdFont(CourierObliqueName, NewFontCourierOblique, "CourierNew,Italic")
|
||||
RegisterStdFont(CourierBoldObliqueName, NewFontCourierBoldOblique, "CourierNew,BoldItalic")
|
||||
RegisterStdFont(CourierName, newFontCourier, "CourierCourierNew", "CourierNew")
|
||||
RegisterStdFont(CourierBoldName, newFontCourierBold, "CourierNew,Bold")
|
||||
RegisterStdFont(CourierObliqueName, newFontCourierOblique, "CourierNew,Italic")
|
||||
RegisterStdFont(CourierBoldObliqueName, newFontCourierBoldOblique, "CourierNew,BoldItalic")
|
||||
}
|
||||
|
||||
const (
|
||||
@ -32,8 +32,8 @@ const (
|
||||
CourierBoldObliqueName = StdFontName("Courier-BoldOblique")
|
||||
)
|
||||
|
||||
// NewFontCourier returns a new instance of the font with a default encoder set (WinAnsiEncoding).
|
||||
func NewFontCourier() StdFont {
|
||||
// newFontCourier returns a new instance of the font with a default encoder set (WinAnsiEncoding).
|
||||
func newFontCourier() StdFont {
|
||||
courierOnce.Do(initCourier)
|
||||
desc := Descriptor{
|
||||
Name: CourierName,
|
||||
@ -52,8 +52,8 @@ func NewFontCourier() StdFont {
|
||||
return NewStdFont(desc, courierCharMetrics)
|
||||
}
|
||||
|
||||
// NewFontCourierBold returns a new instance of the font with a default encoder set (WinAnsiEncoding).
|
||||
func NewFontCourierBold() StdFont {
|
||||
// newFontCourierBold returns a new instance of the font with a default encoder set (WinAnsiEncoding).
|
||||
func newFontCourierBold() StdFont {
|
||||
courierOnce.Do(initCourier)
|
||||
desc := Descriptor{
|
||||
Name: CourierBoldName,
|
||||
@ -73,7 +73,7 @@ func NewFontCourierBold() StdFont {
|
||||
}
|
||||
|
||||
// NewFontCourierOblique returns a new instance of the font with a default encoder set (WinAnsiEncoding).
|
||||
func NewFontCourierOblique() StdFont {
|
||||
func newFontCourierOblique() StdFont {
|
||||
courierOnce.Do(initCourier)
|
||||
desc := Descriptor{
|
||||
Name: CourierObliqueName,
|
||||
@ -94,7 +94,7 @@ func NewFontCourierOblique() StdFont {
|
||||
|
||||
// NewFontCourierBoldOblique returns a new instance of the font with a default encoder set
|
||||
// (WinAnsiEncoding).
|
||||
func NewFontCourierBoldOblique() StdFont {
|
||||
func newFontCourierBoldOblique() StdFont {
|
||||
courierOnce.Do(initCourier)
|
||||
desc := Descriptor{
|
||||
Name: CourierBoldObliqueName,
|
||||
|
@ -15,10 +15,10 @@ func init() {
|
||||
// The aliases seen for the standard 14 font names.
|
||||
// Most of these are from table 5.5.1 in
|
||||
// https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/adobe_supplement_iso32000.pdf
|
||||
RegisterStdFont(HelveticaName, NewFontHelvetica, "Arial")
|
||||
RegisterStdFont(HelveticaBoldName, NewFontHelveticaBold, "Arial,Bold")
|
||||
RegisterStdFont(HelveticaObliqueName, NewFontHelveticaOblique, "Arial,Italic")
|
||||
RegisterStdFont(HelveticaBoldObliqueName, NewFontHelveticaBoldOblique, "Arial,BoldItalic")
|
||||
RegisterStdFont(HelveticaName, newFontHelvetica, "Arial")
|
||||
RegisterStdFont(HelveticaBoldName, newFontHelveticaBold, "Arial,Bold")
|
||||
RegisterStdFont(HelveticaObliqueName, newFontHelveticaOblique, "Arial,Italic")
|
||||
RegisterStdFont(HelveticaBoldObliqueName, newFontHelveticaBoldOblique, "Arial,BoldItalic")
|
||||
}
|
||||
|
||||
const (
|
||||
@ -32,8 +32,8 @@ const (
|
||||
HelveticaBoldObliqueName = StdFontName("Helvetica-BoldOblique")
|
||||
)
|
||||
|
||||
// NewFontHelvetica returns a new instance of the font with a default encoder set (WinAnsiEncoding).
|
||||
func NewFontHelvetica() StdFont {
|
||||
// newFontHelvetica returns a new instance of the font with a default encoder set (WinAnsiEncoding).
|
||||
func newFontHelvetica() StdFont {
|
||||
helveticaOnce.Do(initHelvetica)
|
||||
desc := Descriptor{
|
||||
Name: HelveticaName,
|
||||
@ -52,9 +52,9 @@ func NewFontHelvetica() StdFont {
|
||||
return NewStdFont(desc, helveticaCharMetrics)
|
||||
}
|
||||
|
||||
// NewFontHelveticaBold returns a new instance of the font with a default encoder set
|
||||
// newFontHelveticaBold returns a new instance of the font with a default encoder set
|
||||
// (WinAnsiEncoding).
|
||||
func NewFontHelveticaBold() StdFont {
|
||||
func newFontHelveticaBold() StdFont {
|
||||
helveticaOnce.Do(initHelvetica)
|
||||
desc := Descriptor{
|
||||
Name: HelveticaBoldName,
|
||||
@ -73,8 +73,8 @@ func NewFontHelveticaBold() StdFont {
|
||||
return NewStdFont(desc, helveticaBoldCharMetrics)
|
||||
}
|
||||
|
||||
// NewFontHelveticaOblique returns a new instance of the font with a default encoder set (WinAnsiEncoding).
|
||||
func NewFontHelveticaOblique() StdFont {
|
||||
// newFontHelveticaOblique returns a new instance of the font with a default encoder set (WinAnsiEncoding).
|
||||
func newFontHelveticaOblique() StdFont {
|
||||
helveticaOnce.Do(initHelvetica)
|
||||
desc := Descriptor{
|
||||
Name: HelveticaObliqueName,
|
||||
@ -93,8 +93,8 @@ func NewFontHelveticaOblique() StdFont {
|
||||
return NewStdFont(desc, helveticaObliqueCharMetrics)
|
||||
}
|
||||
|
||||
// NewFontHelveticaBoldOblique returns a new instance of the font with a default encoder set (WinAnsiEncoding).
|
||||
func NewFontHelveticaBoldOblique() StdFont {
|
||||
// newFontHelveticaBoldOblique returns a new instance of the font with a default encoder set (WinAnsiEncoding).
|
||||
func newFontHelveticaBoldOblique() StdFont {
|
||||
helveticaOnce.Do(initHelvetica)
|
||||
desc := Descriptor{
|
||||
Name: HelveticaBoldObliqueName,
|
||||
|
@ -17,8 +17,8 @@ func init() {
|
||||
// The aliases seen for the standard 14 font names.
|
||||
// Most of these are from table 5.5.1 in
|
||||
// https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/adobe_supplement_iso32000.pdf
|
||||
RegisterStdFont(SymbolName, NewFontSymbol, "Symbol,Italic", "Symbol,Bold", "Symbol,BoldItalic")
|
||||
RegisterStdFont(ZapfDingbatsName, NewFontZapfDingbats)
|
||||
RegisterStdFont(SymbolName, newFontSymbol, "Symbol,Italic", "Symbol,Bold", "Symbol,BoldItalic")
|
||||
RegisterStdFont(ZapfDingbatsName, newFontZapfDingbats)
|
||||
}
|
||||
|
||||
const (
|
||||
@ -28,8 +28,8 @@ const (
|
||||
ZapfDingbatsName = StdFontName("ZapfDingbats")
|
||||
)
|
||||
|
||||
// NewFontSymbol returns a new instance of the font with a default encoder set (SymbolEncoder).
|
||||
func NewFontSymbol() StdFont {
|
||||
// newFontSymbol returns a new instance of the font with a default encoder set (SymbolEncoder).
|
||||
func newFontSymbol() StdFont {
|
||||
enc := textencoding.NewSymbolEncoder()
|
||||
desc := Descriptor{
|
||||
Name: SymbolName,
|
||||
@ -48,8 +48,8 @@ func NewFontSymbol() StdFont {
|
||||
return NewStdFontWithEncoding(desc, symbolCharMetrics, enc)
|
||||
}
|
||||
|
||||
// NewFontZapfDingbats returns a new instance of the font with a default encoder set (ZapfDingbatsEncoder).
|
||||
func NewFontZapfDingbats() StdFont {
|
||||
// newFontZapfDingbats returns a new instance of the font with a default encoder set (ZapfDingbatsEncoder).
|
||||
func newFontZapfDingbats() StdFont {
|
||||
enc := textencoding.NewZapfDingbatsEncoder()
|
||||
desc := Descriptor{
|
||||
Name: ZapfDingbatsName,
|
||||
|
@ -15,10 +15,10 @@ func init() {
|
||||
// The aliases seen for the standard 14 font names.
|
||||
// Most of these are from table 5.5.1 in
|
||||
// https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/adobe_supplement_iso32000.pdf
|
||||
RegisterStdFont(TimesRomanName, NewFontTimesRoman, "TimesNewRoman", "Times")
|
||||
RegisterStdFont(TimesBoldName, NewFontTimesBold, "TimesNewRoman,Bold", "Times,Bold")
|
||||
RegisterStdFont(TimesItalicName, NewFontTimesItalic, "TimesNewRoman,Italic", "Times,Italic")
|
||||
RegisterStdFont(TimesBoldItalicName, NewFontTimesBoldItalic, "TimesNewRoman,BoldItalic", "Times,BoldItalic")
|
||||
RegisterStdFont(TimesRomanName, newFontTimesRoman, "TimesNewRoman", "Times")
|
||||
RegisterStdFont(TimesBoldName, newFontTimesBold, "TimesNewRoman,Bold", "Times,Bold")
|
||||
RegisterStdFont(TimesItalicName, newFontTimesItalic, "TimesNewRoman,Italic", "Times,Italic")
|
||||
RegisterStdFont(TimesBoldItalicName, newFontTimesBoldItalic, "TimesNewRoman,BoldItalic", "Times,BoldItalic")
|
||||
}
|
||||
|
||||
const (
|
||||
@ -34,8 +34,8 @@ const (
|
||||
TimesBoldItalicName = StdFontName("Times-BoldItalic")
|
||||
)
|
||||
|
||||
// NewFontTimesRoman returns a new instance of the font with a default encoder set (WinAnsiEncoding).
|
||||
func NewFontTimesRoman() StdFont {
|
||||
// newFontTimesRoman returns a new instance of the font with a default encoder set (WinAnsiEncoding).
|
||||
func newFontTimesRoman() StdFont {
|
||||
timesOnce.Do(initTimes)
|
||||
desc := Descriptor{
|
||||
Name: TimesRomanName,
|
||||
@ -54,8 +54,8 @@ func NewFontTimesRoman() StdFont {
|
||||
return NewStdFont(desc, timesRomanCharMetrics)
|
||||
}
|
||||
|
||||
// NewFontTimesBold returns a new instance of the font with a default encoder set (WinAnsiEncoding).
|
||||
func NewFontTimesBold() StdFont {
|
||||
// newFontTimesBold returns a new instance of the font with a default encoder set (WinAnsiEncoding).
|
||||
func newFontTimesBold() StdFont {
|
||||
timesOnce.Do(initTimes)
|
||||
desc := Descriptor{
|
||||
Name: TimesBoldName,
|
||||
@ -74,8 +74,8 @@ func NewFontTimesBold() StdFont {
|
||||
return NewStdFont(desc, timesBoldCharMetrics)
|
||||
}
|
||||
|
||||
// NewFontTimesItalic returns a new instance of the font with a default encoder set (WinAnsiEncoding).
|
||||
func NewFontTimesItalic() StdFont {
|
||||
// newFontTimesItalic returns a new instance of the font with a default encoder set (WinAnsiEncoding).
|
||||
func newFontTimesItalic() StdFont {
|
||||
timesOnce.Do(initTimes)
|
||||
desc := Descriptor{
|
||||
Name: TimesItalicName,
|
||||
@ -94,8 +94,8 @@ func NewFontTimesItalic() StdFont {
|
||||
return NewStdFont(desc, timesItalicCharMetrics)
|
||||
}
|
||||
|
||||
// NewFontTimesBoldItalic returns a new instance of the font with a default encoder set (WinAnsiEncoding).
|
||||
func NewFontTimesBoldItalic() StdFont {
|
||||
// newFontTimesBoldItalic returns a new instance of the font with a default encoder set (WinAnsiEncoding).
|
||||
func newFontTimesBoldItalic() StdFont {
|
||||
timesOnce.Do(initTimes)
|
||||
desc := Descriptor{
|
||||
Name: TimesBoldItalicName,
|
||||
|
@ -22,8 +22,6 @@ 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/internal/fonts"
|
||||
)
|
||||
|
||||
type crossReference struct {
|
||||
@ -505,7 +503,7 @@ func procPage(p *PdfPage) {
|
||||
}
|
||||
|
||||
// Add font as needed.
|
||||
f := fonts.NewFontHelvetica()
|
||||
f := DefaultFont()
|
||||
p.Resources.SetFontByName("UF1", f.ToPdfObject())
|
||||
|
||||
var ops []string
|
||||
|
Loading…
x
Reference in New Issue
Block a user