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 TextOfGlyphName(name string) (string, 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) HasWidth(code int) 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.
func TextOfGlyphName ¶ added in v0.3.0
TextOfGlyphName turns a glyph name into the text it stands for, which is not always one character: a name may say it is a ligature of several.
Three of the rules here are the ones the Adobe Glyph List lays down for reading a name nobody has listed, and each was costing real text. A name may carry a variant after a full stop — "a.sc" is a small-capital A and is still an A, 7 272 of them in the corpus. A name may be several component names with underscores between them — "f_i" is the fi ligature, and without this "Definition" comes back "Denition", which is not a missing character so much as a misspelt word. And a name may simply be one nobody thought to list.
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) HasWidth ¶ added in v0.2.0
HasWidth reports whether the document said how wide this code is, rather than the width being the fallback Font.Width gives for one it did not.
It matters for a font the document does not carry. One of the fourteen standard faces is written with no widths at all — every reader is expected to know Times and Helvetica and Courier by heart — so a reader drawing a stand-in has to take the advances from the stand-in too. Half an em for every letter reads as a typewriter, which is not what the page says.
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.