Documentation
¶
Overview ¶
Package pdffont is the PDF side of a font: not the outlines, which are the font program's business, but everything the document itself says about how a string of bytes is to be read. Which codes a string holds, how wide each one is, what each is called, and what text each stands for.
It is what a renderer needs before it can ask a font program for a glyph, and all an extractor needs to read a page back as words. Both would otherwise have to say the same things twice.
Index ¶
- Variables
- func NamedEncoding(name reader.Name, fallback [256]string) [256]string
- func ReadToUnicode(data []byte) map[int]string
- func RuneOfGlyphName(name string) (rune, bool)
- func TrimText(s string) string
- type Font
- func (f *Font) CIDToGID(cid int) (int, bool)
- func (f *Font) CharProcs() reader.Dict
- func (f *Font) Chosen(code int) bool
- func (f *Font) Codes(s []byte) []int
- func (f *Font) Descriptor() reader.Dict
- func (f *Font) Dict() reader.Dict
- func (f *Font) FontMatrix() [6]float64
- func (f *Font) GlyphName(code int) (string, bool)
- func (f *Font) Kind() Kind
- func (f *Font) Program() (reader.Name, []byte, bool)
- func (f *Font) SetFallback(fn func(code int) (string, bool))
- func (f *Font) Symbolic() bool
- func (f *Font) Text(code int) (string, bool)
- func (f *Font) Type3Resources() reader.Dict
- func (f *Font) Width(code int) float64
- type Kind
Constants ¶
This section is empty.
Variables ¶
var StandardEncoding = [256]string{}/* 149 elements not displayed */
StandardEncoding is Adobe's own, which most Type 1 fonts assume, and what a simple font is read with when it says nothing else.
var WinAnsiEncoding = [256]string{}/* 218 elements not displayed */
WinAnsiEncoding is the one a file written on Windows assumes, and the one most producers name.
Functions ¶
func NamedEncoding ¶
NamedEncoding is the table a name stands for, or the fallback for a name that is not one of them.
func ReadToUnicode ¶
ReadToUnicode decodes a ToUnicode CMap: a little PostScript program whose only meaningful parts are the bfchar and bfrange blocks saying which characters each code stands for.
func RuneOfGlyphName ¶
RuneOfGlyphName turns a glyph name into the character it stands for, through the table above or through the two conventions the specification defines for naming a character directly. ok is false for a name that says nothing about which character it is, which a subsetted font's own names often do not.
Types ¶
type Font ¶
type Font struct {
// contains filtered or unexported fields
}
A Font is a font as the document describes it.
func Read ¶
Read takes what a font dictionary says. It never fails: a dictionary that says nothing useful gives a font that reads its codes one byte at a time and advances by half an em, which is what a reader has to do with one anyway.
func (*Font) CIDToGID ¶
CIDToGID maps a character identifier to a glyph number for a composite font. ok is false when the font's map does not reach that far.
func (*Font) Chosen ¶
Chosen reports whether the document named this code itself rather than inheriting the name from a base encoding.
func (*Font) Codes ¶
Codes cuts a string into the codes it holds: one byte at a time for a simple font, two for a composite one, which is what every composite encoding seen in the wild uses.
func (*Font) Descriptor ¶
Descriptor is the font descriptor, which is where an embedded program lives.
func (*Font) Dict ¶
Dict is the font dictionary itself, for whatever a caller needs that this does not say.
func (*Font) FontMatrix ¶
FontMatrix is how a Type 3 font's glyph space relates to text space. For every other kind it is a thousandth, which is what the format assumes.
func (*Font) GlyphName ¶
GlyphName is what the document's encoding calls a code. ok is false for a composite font, which names nothing, and for a code the encoding passes over.
func (*Font) Program ¶
Program is the embedded font program: which key it arrived under, and its bytes. ok is false for a font whose program is not embedded, which is every standard face and many others besides.
func (*Font) SetFallback ¶
SetFallback installs a last resort for codes the document says nothing about: what the embedded font program calls them.
A font that says it is symbolic is addressed through its own character map, and what that map says is the only honest answer for a code the document did not name. Reading the program is another package's work, so a caller that can do it hands the answer in here.
func (*Font) Symbolic ¶
Symbolic reports a font that says it is addressed through its own character map rather than through an encoding of names.
func (*Font) Text ¶
Text is what a code stands for as characters: what the font's ToUnicode map says, or failing that what its glyph name says. ok is false when neither does — a subsetted font naming its glyphs g17 and carrying no map cannot be read back, and saying so is better than guessing.
func (*Font) Type3Resources ¶
Type3Resources are what a Type 3 font's glyph drawings draw with.