dosfont

package module
v0.0.0-...-baf68bd Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

README

go-dosfont

Implementation of the PSF/MZ font file format. With this library you can use the old dos bitmap fonts in go.

Example

fonts, err := OpenFonts("fonts/NEW1252.FON")

// use font face fonts[i].Face
// of type golang.org/x/image/font/basicfont.Face

Rendering

fonts/NEW1252.FON.png

TODO

  • Implementation of the PE format

Resources

Other resources for implementing the font lib.

Implementations / Documentation

Test fonts

The fonts used for testing are sourced from https://www.uwe-sieber.de/dosfon.html. Thanks for your free font Uwe Sieber.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFontHeaderTooShort = errors.New("Error psf header too short")

ErrFontHeaderTooShort error in case the header is to short

View Source
var ErrHeaderToShort = errors.New("Error MZ header too short")

ErrHeaderToShort error in case the mz header is too short

View Source
var ErrInvalidOffset = errors.New("Error MZ file contains invalid offset")

ErrInvalidOffset the resource table contains invalid offsets

View Source
var ErrNoMZFile = errors.New("Error no MZ file")

ErrNoMZFile the passed reader doesn't contain the correct header

Functions

This section is empty.

Types

type Font

type Font struct {
	Version         uint16 `struc:"uint16,little"`
	Size            uint32 `struc:"uint32,little"`
	Copyright       string `struc:"[60]byte"`
	Type            uint16 `struc:"uint16,little"`
	Points          uint16 `struc:"uint16,little"`
	VertRes         uint16 `struc:"uint16,little"`
	HorizRes        uint16 `struc:"uint16,little"`
	Ascent          uint16 `struc:"uint16,little"`
	InternalLeading uint16 `struc:"uint16,little"`
	ExternalLeading uint16 `struc:"uint16,little"`
	Italic          bool
	Underline       bool
	StrikeOut       bool
	Weight          uint16 `struc:"uint16,little"`
	CharSet         uint8
	PixWidth        uint16 `struc:"uint16,little"`
	PixHeight       uint16 `struc:"uint16,little"`
	PitchAndFamily  uint8
	AvgWidth        uint16 `struc:"uint16,little"`
	MaxWidth        uint16 `struc:"uint16,little"`
	FirstChar       uint8
	LastChar        uint8
	DefaultChar     uint8
	BreakChar       uint8
	WidthBytes      uint16 `struc:"uint16,little"`
	Device          uint16 `struc:"uint16,little"`
	FaceData        uint16 `struc:"uint16,little"`
	BitsPointer     uint16 `struc:"uint16,little"`
	BitsOffset      uint16 `struc:"uint16,little"`
	Reserved        uint8
	Name            string `struc:"skip"`
	basicfont.Face  `struc:"skip"`
}

Font contains all the PC Screen Font (PSF) meta data and font face.

func OpenFonts

func OpenFonts(path string) ([]Font, error)

OpenFonts opens the file under given location and returns contained fonts

func ReadFonts

func ReadFonts(r io.ReadSeeker) ([]Font, error)

ReadFonts reads font faces from a read seeker

type MZ

type MZ struct {
	Signature          uint16 `struc:"uint16,little"`
	BytesInLastBlock   uint16 `struc:"uint16,little"`
	BlocksInFile       uint16 `struc:"uint16,little"`
	NumRelocs          uint16 `struc:"uint16,little"`
	HeaderParagraphs   uint16 `struc:"uint16,little"`
	MinExtraParagraphs uint16 `struc:"uint16,little"`
	MaxExtraParagraphs uint16 `struc:"uint16,little"`
	Ss                 uint16 `struc:"uint16,little"`
	Sp                 uint16 `struc:"uint16,little"`
	Checksum           uint16 `struc:"uint16,little"`
	IP                 uint16 `struc:"uint16,little"`
	Cs                 uint16 `struc:"uint16,little"`
	RelocTableOffset   uint16 `struc:"uint16,little"`
	OverlayNumber      uint16 `struc:"uint16,little"`
	Unknown            []byte `struc:"[32]pad"`
	COFFHeaderOffset   uint32 `struc:"uint32,little"` // at 0x3c
	// contains filtered or unexported fields
}

MZ dos resource container

func ReadMZ

func ReadMZ(r io.ReadSeeker) (*MZ, error)

ReadMZ reads the MZ file from the passed reader

func (*MZ) Resources

func (mz *MZ) Resources(filterType uint16) []Resource

Resources filters for resources of passed type, that are contained inside the MZ file

type Resource

type Resource struct {
	Start uint16
	Size  uint16
	Type  uint16
}

Resource resource table entry

Jump to

Keyboard shortcuts

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