type1

package
v0.0.0-...-b7ff752 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2023 License: MIT, MIT Imports: 15 Imported by: 0

Documentation

Overview

Package type1 implements a parser for Adobe Type1 fonts, defined by .afm files (https://www.adobe.com/content/dam/acom/en/devnet/font/pdfs/5004.AFM_Spec.pdf) and .pdf files (https://www.adobe.com/content/dam/acom/en/devnet/font/pdfs/T1_SPEC.pdf)

Index

Constants

View Source
const (
	CHARSTRING_KEY = 4330
)
View Source
const Notdef = ".notdef"

Variables

This section is empty.

Functions

func Load

func Load(file fonts.Resource) (fonts.Faces, error)

Load implements fonts.FontLoader. When the error is `nil`, one (and only one) font is returned.

func ScanFont

func ScanFont(file fonts.Resource) ([]fonts.FontDescriptor, error)

ScanFont lazily parse `file` to extract the information about the font. If no error occurs, the returned slice has always length 1.

Types

type AFMFont

type AFMFont struct {
	// Represents the section CharMetrics in the AFM file.
	// The key is the name of the char.
	// Even not encoded chars are present
	CharMetrics        map[string]CharMetric
	CharCodeToCharName [256]string // encoded chars

	KernPairs map[string][]KernPair
	// the character set of the font.
	CharacterSet string

	fonts.PSInfo

	Ascender  Fl
	CapHeight Fl
	Descender Fl
	Llx       Fl // the llx of the FontBox
	Lly       Fl // the lly of the FontBox
	Urx       Fl // the urx of the FontBox
	Ury       Fl // the ury of the FontBox

	XHeight int

	StdHw int
	StdVw int
	// contains filtered or unexported fields
}

AFMFont represents a type1 font as found in a .afm file.

func ParseAFMFile

func ParseAFMFile(source io.Reader) (AFMFont, error)

ParseAFMFile read a .afm file and return the associated font.

func (AFMFont) CharSet

func (f AFMFont) CharSet() string

CharSet returns a string listing the character names defined in the font subset. The names in this string shall be in PDF syntax—that is, each name preceded by a slash (/). The names may appear in any order. The name .notdef shall be omitted; it shall exist in the font subset.

type CharMetric

type CharMetric struct {
	CharBBox [4]int

	Width int
	// contains filtered or unexported fields
}

type Encoding

type Encoding struct {
	Custom   simpleencodings.Encoding
	Standard bool
}

Encoding is either the standard encoding, or defined by the font

type Fl

type Fl = float32

type Font

type Font struct {
	Encoding *simpleencodings.Encoding

	FontID   string
	FontBBox []Fl

	FontMatrix []Fl

	fonts.PSInfo

	StrokeWidth Fl

	PaintType int
	FontType  int
	UniqueID  int
	// contains filtered or unexported fields
}

Font exposes the content of a .pfb file. The main field, regarding PDF processing, is the Encoding entry, which defines the "builtin encoding" of the font.

func Parse

func Parse(pfb fonts.Resource) (*Font, error)

Parse parses an Adobe Type 1 (.pfb) font file. See `ParseAFMFile` to read the associated Adobe font metric file.

func (*Font) AscenderPDF

func (f *Font) AscenderPDF() int

AscenderPDF returns the /Ascent value for the PDF file

func (*Font) BoundingBoxPDF

func (f *Font) BoundingBoxPDF() string

BoundingBoxPDF returns the /FontBBox value for the PDF file

func (*Font) CMapPDF

func (f *Font) CMapPDF() string

CMapPDF returns a CMap string to be used in a PDF file

func (*Font) CapHeightPDF

func (f *Font) CapHeightPDF() int

CapHeightPDF returns the /CapHeight value for the PDF file

func (*Font) Cmap

func (f *Font) Cmap() (fonts.Cmap, fonts.CmapEncoding)

func (*Font) DescenderPDF

func (f *Font) DescenderPDF() int

DescenderPDF returns the /Descent value for the PDF file

func (*Font) FlagsPDF

func (f *Font) FlagsPDF() int

FlagsPDF returns the /Flags value for the PDF file

func (*Font) FontHExtents

func (f *Font) FontHExtents() (fonts.FontExtents, bool)

func (*Font) FontVExtents

func (f *Font) FontVExtents() (fonts.FontExtents, bool)

FontVExtents returns zero values.

func (*Font) GlyphData

func (f *Font) GlyphData(gid fonts.GID, _, _ uint16) fonts.GlyphData

GlyphData returns the outlines of the given glyph. The returned value is either a fonts.GlyphOutline or nil if an error occurred.

func (*Font) GlyphExtents

func (f *Font) GlyphExtents(glyph fonts.GID, _, _ uint16) (fonts.GlyphExtents, bool)

func (Font) GlyphHOrigin

func (Font) GlyphHOrigin(fonts.GID) (x, y int32, found bool)

GlyphHOrigin always return 0,0,true

func (*Font) GlyphName

func (f *Font) GlyphName(gid fonts.GID) string

func (Font) GlyphVOrigin

func (Font) GlyphVOrigin(fonts.GID) (x, y int32, found bool)

GlyphVOrigin always return 0,0,false

func (*Font) HorizontalAdvance

func (f *Font) HorizontalAdvance(gid fonts.GID) float32

HorizontalAdvance returns the advance of the glyph with index `index` The return value is expressed in font units. 0 is returned for invalid index values and for invalid charstring glyph data.

func (*Font) ItalicAnglePDF

func (f *Font) ItalicAnglePDF() int

ItalicAnglePDF returns the /ItalicAngle value for the PDF file

func (*Font) LineMetric

func (f *Font) LineMetric(metric fonts.LineMetric) (float32, bool)

func (Font) LoadBitmaps

func (Font) LoadBitmaps() []fonts.BitmapSize

func (*Font) LoadMetrics

func (f *Font) LoadMetrics() fonts.FaceMetrics

LoadMetrics returns the font itself.

func (*Font) LoadSummary

func (f *Font) LoadSummary() (fonts.FontSummary, error)

func (*Font) NamePDF

func (f *Font) NamePDF() string

NamePDF returns the PDF name of the font.

func (*Font) NominalGlyph

func (f *Font) NominalGlyph(ch rune) (fonts.GID, bool)

func (Font) NormalizeVariations

func (Font) NormalizeVariations(coords []float32) []float32

func (*Font) PostscriptInfo

func (f *Font) PostscriptInfo() (fonts.PSInfo, bool)

func (*Font) PostscriptName

func (f *Font) PostscriptName() string

func (*Font) StemVPDF

func (f *Font) StemVPDF() int

StemVPDF returns the /StemV value for the PDF file

func (*Font) Subset

func (f *Font) Subset(codepoints []fonts.GID) error

Subset removes all data from the font except the one needed for the given code points.

func (*Font) Upem

func (f *Font) Upem() uint16

Upem reads the FontMatrix to extract the scaling factor (the maximum between x and y coordinates)

func (*Font) VerticalAdvance

func (f *Font) VerticalAdvance(gid fonts.GID) float32

func (*Font) WidthsPDF

func (f *Font) WidthsPDF() string

WidthsPDF returns a width entry suitable for embedding in a PDF file.

func (*Font) WriteSubset

func (f *Font) WriteSubset(w io.Writer) error

WriteSubset writes a valid font to w that is suitable for including in PDF

func (*Font) XHeightPDF

func (f *Font) XHeightPDF() int

XHeightPDF returns the /XHeight value for the PDF file

type KernPair

type KernPair struct {
	SndChar string // glyph name
	// KerningDistance is expressed in glyph units.
	// It is most often negative,
	// that is, a negative value indicates that chars
	// should be closer.
	KerningDistance int
}

KernPair represents a kerning pair, from an implicit first first glyph.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL