opentype

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Overview

Package opentype implements OpenType fonts embedded into PDF files.

Use of this package should be avoided when creating new documents: If the given font contains CFF glyphs, then it is more efficient to embed the font via cff.NewSimple or cff.NewComposite instead. If the given font contains TrueType glyphs, truetype.NewSimple or truetype.NewComposite should be used instead of the function from this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New added in v0.4.0

func New(info *sfnt.Font) (font.Embedder, error)

New makes a PDF font from an OpenType/TrueType font. The font can be embedded as a simple font or as a composite font.

If the font has CFF outlines, it is often more efficient to embed the CFF glyph data without the OpenType wrapper. Consider using seehuhn.de/go/pdf/font/cff.New instead of this function. If the font has TrueType outlines, it is often more efficient to embed the font as a TrueType font instead of an OpenType font. Consider using seehuhn.de/go/pdf/font/truetype.New instead of this function.

Types

type EmbedInfoCFFComposite

type EmbedInfoCFFComposite struct {
	// Font is the font to embed (already subsetted, if needed).
	Font *sfnt.Font

	// SubsetTag should be a unique tag for the font subset,
	// or the empty string if this is the full font.
	SubsetTag string

	CMap *cmap.Info

	IsAllCap   bool
	IsSmallCap bool

	// ToUnicode (optional) is a map from character codes to unicode strings.
	ToUnicode *cmap.ToUnicode
}

EmbedInfoCFFComposite is the information needed to embed a composite OpenType/CFF font.

func ExtractCFFComposite

func ExtractCFFComposite(r pdf.Getter, dicts *font.Dicts) (*EmbedInfoCFFComposite, error)

ExtractCFFComposite extracts information about a composite OpenType/CFF font from a PDF file. This is the inverse of EmbedInfoCFFComposite.Embed.

func (*EmbedInfoCFFComposite) Embed

func (info *EmbedInfoCFFComposite) Embed(w pdf.Putter, fontDictRef pdf.Reference) error

Embed adds a composite OpenType/CFF font to a PDF file. This is the reverse of ExtractCFFComposite

type EmbedInfoCFFSimple

type EmbedInfoCFFSimple struct {
	// Font is the font to embed (already subsetted, if needed).
	Font *sfnt.Font

	// SubsetTag should be a unique tag for the font subset,
	// or the empty string if this is the full font.
	SubsetTag string

	// Encoding is the encoding vector used by the client (a slice of length 256).
	// This may be different from the font's built-in encoding.
	Encoding []glyph.ID

	IsAllCap   bool
	IsSmallCap bool

	// ToUnicode (optional) is a map from character codes to unicode strings.
	ToUnicode *cmap.ToUnicode
}

EmbedInfoCFFSimple is the information needed to embed a simple OpenType/CFF font.

func ExtractCFFSimple

func ExtractCFFSimple(r pdf.Getter, dicts *font.Dicts) (*EmbedInfoCFFSimple, error)

ExtractCFFSimple extracts information about a simple OpenType/CFF font. This is the inverse of EmbedInfoCFFSimple.Embed.

func (*EmbedInfoCFFSimple) Embed

func (info *EmbedInfoCFFSimple) Embed(w pdf.Putter, fontDictRef pdf.Reference) error

Embed adds the font to a PDF file. This is the reverse of ExtractCFFSimple

type EmbedInfoGlyfComposite

type EmbedInfoGlyfComposite struct {
	// Font is the font to embed (already subsetted, if needed).
	Font *sfnt.Font

	// SubsetTag should be a unique tag for the font subset,
	// or the empty string if this is the full font.
	SubsetTag string

	CMap *cmap.Info

	CIDToGID []glyph.ID

	ForceBold bool

	IsAllCap   bool
	IsSmallCap bool

	// ToUnicode (optional) is a map from character codes to unicode strings.
	ToUnicode *cmap.ToUnicode
}

EmbedInfoGlyfComposite is the information needed to embed a composite OpenType/glyf font.

func ExtractGlyfComposite

func ExtractGlyfComposite(r pdf.Getter, dicts *font.Dicts) (*EmbedInfoGlyfComposite, error)

ExtractGlyfComposite extracts information for a composite OpenType/glyf font.

func (*EmbedInfoGlyfComposite) Embed

func (info *EmbedInfoGlyfComposite) Embed(w pdf.Putter, fontDictRef pdf.Reference) error

Embed adds the font to the PDF file.

type EmbedInfoGlyfSimple

type EmbedInfoGlyfSimple struct {
	// Font is the font to embed (already subsetted, if needed).
	Font *sfnt.Font

	// SubsetTag should be a unique tag for the font subset,
	// or the empty string if this is the full font.
	SubsetTag string

	// Encoding is the encoding vector used by the client (a slice of length 256).
	// Together with the font's built-in encoding, this is used to determine
	// the `Encoding` entry of the PDF font dictionary.
	Encoding []glyph.ID

	ForceBold bool

	IsAllCap   bool
	IsSmallCap bool

	// ToUnicode (optional) is a map from character codes to unicode strings.
	ToUnicode *cmap.ToUnicode
}

EmbedInfoGlyfSimple is the information needed to embed a simple OpenType/glyf font.

func ExtractGlyfSimple

func ExtractGlyfSimple(r pdf.Getter, dicts *font.Dicts) (*EmbedInfoGlyfSimple, error)

ExtractGlyfSimple extracts information about a simple OpenType font.

func (*EmbedInfoGlyfSimple) Embed

func (info *EmbedInfoGlyfSimple) Embed(w pdf.Putter, fontDictRef pdf.Reference) error

Embed adds the font to a PDF file.

Jump to

Keyboard shortcuts

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