package
0.0.0-20231230061527-f3557b44e492
Repository: https://github.com/omniskop/canvas.git
Documentation: pkg.go.dev

# README

Font API reference

This library contains font parsers for WOFF, WOFF2, and EOT. It takes a byte-slice as input and converts it to SFNT formats (either TTF or OTF). As font formats for the web, WOFF, WOFF2, and EOT are really just containers for SFNT fonts (such as TTF and OTF) that have better compression.

The WOFF and WOFF2 converters have been testing using the validation tests from the W3C. Font collections (such as TTC and OTC) are not yet supported, but will be in the near future. Compression in EOT files are also not yet supported.

Usage

Import using:

import "github.com/tdewolff/canvas/font"

Then we can parse any byte-slice that is in the WOFF/WOFF2/EOT file format and extract its TTF/OTF content.

font, err := ioutil.ReadFile("DejaVuSerif.woff")
if err != nil {
    panic(err)
}

sfnt, err := font.ToSFNT(font)
if err != nil {
    panic(err)
}

or using an io.Reader

font, err := os.Open("DejaVuSerif.woff")
if err != nil {
    panic(err)
}

font, err = font.NewSFNTReader(font)
if err != nil {
    panic(err)
}

WOFF

woff, err := ioutil.ReadFile("DejaVuSerif.woff")
if err != nil {
    panic(err)
}

sfnt, err := font.ParseWOFF(woff)
if err != nil {
    panic(err)
}

ext := font.Extension(sfnt)
if err = ioutil.WriteFile("DejaVuSerif"+ext, sfnt, 0644); err != nil {
    panic(err)
}

Tested using https://github.com/w3c/woff/tree/master/woff1/tests.

WOFF2

woff2, err := ioutil.ReadFile("DejaVuSerif.woff2")
if err != nil {
    panic(err)
}

sfnt, err := font.ParseWOFF2(woff2)
if err != nil {
    panic(err)
}

ext := font.Extension(sfnt)
if err = ioutil.WriteFile("DejaVuSerif"+ext, sfnt, 0644); err != nil {
    panic(err)
}

Tested using https://github.com/w3c/woff2-tests.

EOT

eof, err := ioutil.ReadFile("DejaVuSerif.eot")
if err != nil {
    panic(err)
}

sfnt, err = font.ParseEOT(eot)
if err != nil {
    panic(err)
}

ext := font.Extension(sfnt)
if err = ioutil.WriteFile("DejaVuSerif"+ext, sfnt, 0644); err != nil {
    panic(err)
}

License

Released under the MIT license.

# Functions

No description provided by the author
No description provided by the author
Extension returns the file extension for a given font.
No description provided by the author
FromGoFreetype parses a structure from truetype.Font to a valid SFNT byte slice.
FromGoSFNT parses a structure from sfnt.Font to a valid SFNT byte slice.
No description provided by the author
MediaType returns the media type (MIME) for a given font.
NewBinaryReader returns a big endian binary file format reader.
NewBinaryWriter returns a big endian binary file format writer.
NewBitmapReader returns a binary bitmap reader.
NewSFNTReader takes an io.Reader and transforms it into an SFNT reader.
ParseEmbeddedSFNT is like ParseSFNT but for embedded font files in PDFs.
ParseEOT parses the EOT font format and returns its contained SFNT font format (TTF or OTF).
ParseFont parses a byte slice and of a TTF, OTF, WOFF, WOFF2, or EOT font format.
ParseSFNT parses an OpenType file format (TTF, OTF, TTC).
No description provided by the author
No description provided by the author
ParseWOFF parses the WOFF font format and returns its contained SFNT font format (TTF or OTF).
ParseWOFF2 parses the WOFF2 font format and returns its contained SFNT font format (TTF or OTF).
ToSFNT takes a byte slice and transforms it into an SFNT byte slice.
Uint16ToFlags converts a uint16 in 16 booleans from least to most significant.
Uint8ToFlags converts a uint8 in 8 booleans from least to most significant.

# Constants

see Style.
see Style.
permanently reserved and not used in font.
No description provided by the author
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see EncodingID.
see Style.
see Style.
see Style.
see Style.
MaxCmapSegments is the maximum number of cmap segments that will be accepted.
see Style.
see NameID.
see NameID.
see NameID.
see NameID.
see NameID.
see NameID.
see NameID.
see NameID.
see NameID.
see NameID.
see NameID.
see NameID.
see NameID.
see NameID.
see NameID.
see NameID.
see NameID.
see NameID.
see NameID.
see NameID.
see NameID.
see NameID.
see NameID.
see NameID.
see NameID.
see Hinting.
see PlatformID.
see PlatformID.
see PlatformID.
see PlatformID.
see Style.
see Style.
see Style.
No description provided by the author
No description provided by the author
No description provided by the author
see Style.
see Hinting.
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

ErrExceedsMemory is returned if the font is malformed.
ErrInvalidFontData is returned if the font is malformed.
MaxMemory is the maximum memory that can be allocated by a font.

# Structs

BinaryReader is a binary big endian file format reader.
BinaryWriter is a big endian binary file format writer.
BitmapReader is a binary bitmap reader.
No description provided by the author
SFNT is a parsed OpenType font.
No description provided by the author
No description provided by the author

# Interfaces

Pather is an interface to append a glyph's path to canvas.Path.

# Type aliases

EncodingID is the encoding identifier for the name table.
No description provided by the author
Hinting specifies the type of hinting to use (none supported yes).
No description provided by the author
NameID is the name identifier for the name table.
PlatformID is the platform identifier for the name table.
No description provided by the author
Style defines the font style to be used for the font.
No description provided by the author