type1

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: MIT, MIT Imports: 16 Imported by: 2

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 added in v0.0.8

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 added in v0.0.6

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) Cmap added in v0.0.2

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

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 added in v0.0.5

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 occured.

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) LineMetric

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

func (Font) LoadBitmaps added in v0.0.2

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) NominalGlyph

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

func (Font) NormalizeVariations

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

func (*Font) PoscriptName

func (f *Font) PoscriptName() string

func (*Font) PostscriptInfo

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

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

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