bmf

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2021 License: MPL-2.0 Imports: 10 Imported by: 0

README

AngelCode BMF parsing in Go

Go Report Card

Supports parsing and serializing text, XML and binary formats in version 3.

API

PkgGoDev

bmf.Parse(src io.Reader) (*bmf.Font, error)
Parses AngelCode BMF and automatically chooses the correct format

bmf.ParseText(src io.Reader) (*bmf.Font, error)
Parses AngelCode BMF in text format

bmf.ParseXML(src io.Reader) (*bmf.Font, error)
Parses AngelCode BMF in XML format

bmf.ParseBinary(src io.Reader) (*bmf.Font, error)
Parses AngelCode BMF in binary format

bmf.SerializeBinary(fnt *bmf.Font, dst io.Writer) error
Serializes AngelCode BMF in binary format

bmf.SerializeText(fnt *bmf.Font, dst io.Writer) error
Serializes AngelCode BMF in text format

Issues

If you find any problems please report them. :)

Documentation

Overview

Package bmf implements BMF .fnt file parsing and serialization. It supports only version 3 of the binary format. For more information see http://www.angelcode.com/products/bmfont/doc/file_format.html

Index

Constants

View Source
const SupportedVersion = 3

SupportedVersion of the binary format

Variables

View Source
var CharsetTable = map[int]string{
	186: "Baltic",
	77:  "Mac",
	204: "Russian",
	238: "EastEurope",
	222: "Thai",
	163: "Vietnamese",
	162: "Turkish",
	161: "Greek",
	178: "Arabic",
	177: "Hebrew",
	130: "Johab",
	255: "Oem",
	136: "ChineseBig5",
	134: "GB2312",
	129: "Hangul",
	128: "ShiftJIS",
	2:   "Symbol",
	1:   "Default",
	0:   "Ansi",
}

CharsetTable enumerates known charset values source https://docs.microsoft.com/en-us/previous-versions/windows/desktop/bb322881(v=vs.85)

Functions

func LookupCharset added in v1.0.1

func LookupCharset(charsetEnum int) (name string, found bool)

LookupCharset gets the name of a charset or value as a decimal string when not found

func LookupCharsetValue added in v1.1.0

func LookupCharsetValue(charset string) (value int, found bool)

LookupCharsetValue gets the enum value of a charset or converts a a decimal string to a number

func SerializeBinary added in v1.1.0

func SerializeBinary(fnt *Font, dst io.Writer) error

SerializeBinary serializes a bmf font definition in binary format.

func SerializeText added in v1.1.0

func SerializeText(fnt *Font, dst io.Writer) error

SerializeText serializes a bmf font file in text format

Types

type BinBool

type BinBool bool

BinBool represents a boolean as 0 or 1

func Bool added in v1.1.0

func Bool(i int) BinBool

Bool converts a number to a BinBool where 1 is true

func (BinBool) Byte added in v1.1.0

func (b BinBool) Byte() byte

Byte converts the boolean to a byte where true is 1 and false is 0

func (BinBool) MarshalXMLAttr

func (nb BinBool) MarshalXMLAttr(name xml.Name) (xml.Attr, error)

MarshalXMLAttr converts bool to number

type BinaryParseError

type BinaryParseError struct {
	Offset      int
	Block       BlockType
	BlockLength int
	Err         error
}

BinaryParseError contains info about where and why a parsing error occurred

func (BinaryParseError) Error

func (e BinaryParseError) Error() string

func (BinaryParseError) Unwrap added in v1.1.0

func (e BinaryParseError) Unwrap() error

type BlockType added in v1.1.0

type BlockType byte

BlockType specifies the type of a binary block

func (BlockType) Name added in v1.1.0

func (typ BlockType) Name() string

Name returns the name of the block

type Channel

type Channel int

Channel is a bitfield to specify color channels

const (
	Blue  Channel = 0x1
	Green Channel = 0x2
	Red   Channel = 0x4
	Alpha Channel = 0x8
	All   Channel = 0xf
)

RGBA channel bits

type ChannelData

type ChannelData int

ChannelData specifies the type of data that a color channel holds

const (
	Glyph ChannelData = iota
	Outline
	GlyphAndOutline
	Zero
	One
)

Channel data types

type Char

type Char struct {
	Id       rune    `xml:"id,attr"`
	X        int     `xml:"x,attr"`
	Y        int     `xml:"y,attr"`
	Width    int     `xml:"width,attr"`
	Height   int     `xml:"height,attr"`
	XOffset  int     `xml:"xoffset,attr"`
	YOffset  int     `xml:"yoffset,attr"`
	XAdvance int     `xml:"xadvance,attr"`
	Page     int     `xml:"page,attr"`
	Channel  Channel `xml:"chnl,attr"`
}

Char describes on character in the font. There is one for each included character in the font.

type Common

type Common struct {
	LineHeight   int         `xml:"lineHeight,attr"`
	Base         int         `xml:"base,attr"`
	ScaleW       int         `xml:"scaleW,attr"`
	ScaleH       int         `xml:"scaleH,attr"`
	Pages        int         `xml:"pages,attr"`
	Packed       BinBool     `xml:"packed,attr"`
	AlphaChannel ChannelData `xml:"alphaChnl,attr"`
	RedChannel   ChannelData `xml:"redChnl,attr"`
	GreenChannel ChannelData `xml:"greenChnl,attr"`
	BlueChannel  ChannelData `xml:"blueChnl,attr"`
}

Common holds information common to all characters.

type Font

type Font struct {
	Info     Info      `xml:"info"`
	Common   Common    `xml:"common"`
	Pages    []Page    `xml:"pages>page"`
	Chars    []Char    `xml:"chars>char"`
	Kernings []Kerning `xml:"kernings>kerning"`
}

Font defines an AngelCode Bitmap Font

func Parse

func Parse(src io.Reader) (*Font, error)

Parse parses a bmf font file and detects the format automatically

func ParseBinary

func ParseBinary(src io.Reader) (fnt *Font, err error)

ParseBinary parses a bmf font definition in binary format. For more information see http://www.angelcode.com/products/bmfont/doc/file_format.html#bin

func ParseText

func ParseText(src io.Reader) (fnt *Font, err error)

ParseText parses a bmf font file in text format

func ParseXML

func ParseXML(src io.Reader) (*Font, error)

ParseXML parses a bmf font file in XML format

func (Font) MarshalXML

func (font Font) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML converts a Font struct to XML

type Info

type Info struct {
	Face     string  `xml:"face,attr"`
	Size     int     `xml:"size,attr"`
	Bold     BinBool `xml:"bold,attr"`
	Italic   BinBool `xml:"italic,attr"`
	Charset  string  `xml:"charset,attr"`
	Unicode  BinBool `xml:"unicode,attr"`
	StretchH int     `xml:"stretchH,attr"`
	Smooth   BinBool `xml:"smooth,attr"`
	AA       int     `xml:"aa,attr"`
	Padding  Padding `xml:"padding,attr"`
	Spacing  Spacing `xml:"spacing,attr"`
	Outline  int     `xml:"outline,attr"`
}

Info holds information on how the font was generated

type Kerning

type Kerning struct {
	First  rune `xml:"first,attr"`
	Second rune `xml:"second,attr"`
	Amount int  `xml:"amount,attr"`
}

Kerning specifies the distance between specific character pairs

type Padding

type Padding struct {
	Up    int
	Right int
	Down  int
	Left  int
}

Padding specifies the padding for each character in pixels See https://www.angelcode.com/products/bmfont/doc/export_options.html

func (Padding) MarshalXMLAttr

func (pad Padding) MarshalXMLAttr(name xml.Name) (xml.Attr, error)

MarshalXMLAttr converts to format <up>,<right>,<down>,<left>

func (*Padding) UnmarshalXMLAttr

func (pad *Padding) UnmarshalXMLAttr(attr xml.Attr) error

UnmarshalXMLAttr converts from format <up>,<right>,<down>,<left>

type Page

type Page struct {
	Id   int    `xml:"id,attr"`
	File string `xml:"file,attr"`
}

Page references a bitmap image that contains the glyphs. A font can contain multiple glyph pages.

type Spacing

type Spacing struct {
	Horizontal int
	Vertical   int
}

Spacing specifies the spacing for each character in pixels See https://www.angelcode.com/products/bmfont/doc/export_options.html

func (Spacing) MarshalXMLAttr

func (sp Spacing) MarshalXMLAttr(name xml.Name) (xml.Attr, error)

MarshalXMLAttr converts to format <horizontal>,<vertical>

func (*Spacing) UnmarshalXMLAttr

func (sp *Spacing) UnmarshalXMLAttr(attr xml.Attr) error

UnmarshalXMLAttr converts from format <horizontal>,<vertical>

type TextParseError

type TextParseError struct {
	LineNumber int
	Line       string
	Err        error
}

TextParseError contains info about where and why a parsing error occurred

func (TextParseError) Error

func (e TextParseError) Error() string

func (TextParseError) Unwrap

func (e TextParseError) Unwrap() error

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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