os2

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: GPL-3.0 Imports: 7 Imported by: 1

Documentation

Overview

Package os2 reads and writes "OS/2" tables. https://docs.microsoft.com/en-us/typography/opentype/spec/os2

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CodePage added in v0.3.5

type CodePage int

CodePage represents the positions of individual bits which may be set in a [CodeSpaceRange].

const (
	CP1252      CodePage = 0  // CP1252, Latin 1
	CP1250      CodePage = 1  // CP1250, Latin 2: Eastern Europe
	CP1251      CodePage = 2  // CP1251, Cyrillic
	CP1253      CodePage = 3  // CP1253, Greek
	CP1254      CodePage = 4  // CP1254, Turkish
	CP1255      CodePage = 5  // CP1255, Hebrew
	CP1256      CodePage = 6  // CP1256, Arabic
	CP1257      CodePage = 7  // CP1257, Windows Baltic
	CP1258      CodePage = 8  // CP1258, Vietnamese
	CP874       CodePage = 16 // CP874, Thai
	CP932       CodePage = 17 // CP932, JIS/Japan
	CP936       CodePage = 18 // CP936, Chinese: Simplified chars—PRC and Singapore
	CP949       CodePage = 19 // CP949, Korean Wansung
	CP950       CodePage = 20 // CP950, Chinese: Traditional chars—Taiwan and Hong Kong
	CP1361      CodePage = 21 // CP1361, Korean Johab
	CPMacintosh CodePage = 29 // Macintosh Character Set (US Roman)
	CPOEM       CodePage = 30 // OEM Character Set
	CPSymbol    CodePage = 31 // Symbol Character Set
	CP869       CodePage = 48 // CP869, IBM Greek
	CP866       CodePage = 49 // CP866, MS-DOS Russian
	CP865       CodePage = 50 // CP865, MS-DOS Nordic
	CP864       CodePage = 51 // CP864, Arabic
	CP863       CodePage = 52 // CP863, MS-DOS Canadian French
	CP862       CodePage = 53 // CP862, Hebrew
	CP861       CodePage = 54 // CP861, MS-DOS Icelandic
	CP860       CodePage = 55 // CP860, MS-DOS Portuguese
	CP857       CodePage = 56 // CP857, IBM Turkish
	CP855       CodePage = 57 // CP855, IBM Cyrillic; primarily Russian
	CP852       CodePage = 58 // CP852, Latin 2
	CP775       CodePage = 59 // CP775, MS-DOS Baltic
	CP737       CodePage = 60 // CP737, Greek; former 437 G
	CP708       CodePage = 61 // CP708, Arabic; ASMO 708
	CP850       CodePage = 62 // CP850, WE/Latin 1
	CP437       CodePage = 63 // CP437, US
)

List of code pages supported by the "OS/2" table.

type CodePageRange

type CodePageRange uint64

CodePageRange is a bitmask of code pages supported by a font.

func (*CodePageRange) Set

func (cpr *CodePageRange) Set(bit CodePage)

Set sets the given bit in the code page range.

type Info

type Info struct {
	WeightClass Weight
	WidthClass  Width

	IsBold    bool // glyphs are emboldened
	IsItalic  bool // font contains italic or oblique glyphs
	IsRegular bool // glyphs are in the standard weight/style for the font
	IsOblique bool // font contains oblique glyphs

	FirstCharIndex uint16
	LastCharIndex  uint16

	Ascent     funit.Int16
	Descent    funit.Int16 // negative
	WinAscent  funit.Int16
	WinDescent funit.Int16 // positive
	LineGap    funit.Int16
	CapHeight  funit.Int16
	XHeight    funit.Int16

	AvgGlyphWidth funit.Int16 // arithmetic average of the width of all non-zero width glyphs

	SubscriptXSize     funit.Int16
	SubscriptYSize     funit.Int16
	SubscriptXOffset   funit.Int16
	SubscriptYOffset   funit.Int16
	SuperscriptXSize   funit.Int16
	SuperscriptYSize   funit.Int16
	SuperscriptXOffset funit.Int16
	SuperscriptYOffset funit.Int16
	StrikeoutSize      funit.Int16
	StrikeoutPosition  funit.Int16

	FamilyClass int16    // https://docs.microsoft.com/en-us/typography/opentype/spec/ibmfc
	Panose      [10]byte // https://monotype.github.io/panose/
	Vendor      string   // https://docs.microsoft.com/en-us/typography/opentype/spec/os2#achvendid

	UnicodeRange  UnicodeRange
	CodePageRange CodePageRange

	PermUse          Permissions
	PermNoSubsetting bool // the font may not be subsetted prior to embedding
	PermOnlyBitmap   bool // only bitmaps contained in the font may be embedded
}

Info contains information from the "OS/2" table.

func Read

func Read(r io.Reader) (*Info, error)

Read reads the "OS/2" table from r.

func (*Info) Encode

func (info *Info) Encode() []byte

Encode converts the info to a "OS/2" table.

type Permissions

type Permissions int

Permissions describes rights to embed and use a font.

const (
	PermInstall    Permissions = iota // bits 0-3 unset
	PermEdit                          // only bit 3 set
	PermView                          // only bit 2 set
	PermRestricted                    // only bit 1 set
)

The possible permission values. https://learn.microsoft.com/en-us/typography/opentype/spec/os2#fstype

func (Permissions) String

func (perm Permissions) String() string

type UnicodeRange

type UnicodeRange [4]uint32

UnicodeRange is a bitfield which describes which unicode blocks or ranges are "functional" in a font. https://learn.microsoft.com/en-us/typography/opentype/spec/os2#ur

func (*UnicodeRange) Bool

func (ur *UnicodeRange) Bool(bit UnicodeRangeBit, set bool)

Bool sets or clears the given bit in the unicode range.

func (*UnicodeRange) Set

func (ur *UnicodeRange) Set(bit UnicodeRangeBit)

Set sets the given bit in the unicode range.

type UnicodeRangeBit

type UnicodeRangeBit int
const (
	URBasicLatin                UnicodeRangeBit = 0
	URLatin1Sup                 UnicodeRangeBit = 1
	URLatinExtA                 UnicodeRangeBit = 2
	URLatinExtB                 UnicodeRangeBit = 3
	URIPAExtensions             UnicodeRangeBit = 4
	URSpacingModifierLetters    UnicodeRangeBit = 5
	URCombiningDiacriticalMarks UnicodeRangeBit = 6
	URGreek                     UnicodeRangeBit = 7
	URCoptic                    UnicodeRangeBit = 8
	URCyrillic                  UnicodeRangeBit = 9
	URArmenian                  UnicodeRangeBit = 10
	URHebrew                    UnicodeRangeBit = 11
	URVai                       UnicodeRangeBit = 12
	URArabic                    UnicodeRangeBit = 13
	URNko                       UnicodeRangeBit = 14
	URDevanagari                UnicodeRangeBit = 15
	URBengali                   UnicodeRangeBit = 16
	URGurmukhi                  UnicodeRangeBit = 17
	URGujarati                  UnicodeRangeBit = 18
	UROriya                     UnicodeRangeBit = 19
	URTamil                     UnicodeRangeBit = 20
	URTelugu                    UnicodeRangeBit = 21
	URKannada                   UnicodeRangeBit = 22
	URMalayalam                 UnicodeRangeBit = 23
	URThai                      UnicodeRangeBit = 24
	URLao                       UnicodeRangeBit = 25
	URGeorgian                  UnicodeRangeBit = 26
	URBalinese                  UnicodeRangeBit = 27
	URHangulJamo                UnicodeRangeBit = 28
	URLatinExtAdditional        UnicodeRangeBit = 29
	URGreekExt                  UnicodeRangeBit = 30
	URGeneralPunctuation        UnicodeRangeBit = 31
	URSuperscriptsSubscripts    UnicodeRangeBit = 32
	URCurrencySymbols           UnicodeRangeBit = 33
)

type Weight

type Weight uint16

Weight indicates the visual weight (degree of blackness or thickness of strokes) of the characters in the font. Values from 1 to 1000 are valid.

const (
	WeightThin       Weight = 100
	WeightExtraLight Weight = 200
	WeightLight      Weight = 300
	WeightNormal     Weight = 400
	WeightMedium     Weight = 500
	WeightSemiBold   Weight = 600
	WeightBold       Weight = 700
	WeightExtraBold  Weight = 800
	WeightBlack      Weight = 900
)

Pre-defined weight classes.

func WeightFromString

func WeightFromString(s string) Weight

WeightFromString returns the weight class for the given string. This is the converse of Weight.String().

func (Weight) Rounded

func (w Weight) Rounded() Weight

Rounded returns the nearest weight corresponding to one of the named classes.

func (Weight) SimpleString

func (w Weight) SimpleString() string

SimpleString converts the Weight to a string, preferring the nearest textual description over the precise numeric value where needed.

func (Weight) String

func (w Weight) String() string

type Width

type Width uint16

Width indicates the aspect ratio (width to height ratio) as specified by a font designer for the glyphs in a font.

const (
	WidthUltraCondensed Width = 1 // 50% of WidthNormal
	WidthExtraCondensed Width = 2 // 62.5% of WidthNormal
	WidthCondensed      Width = 3 // 75% of WidthNormal
	WidthSemiCondensed  Width = 4 // 87.5% of WidthNormal
	WidthNormal         Width = 5
	WidthSemiExpanded   Width = 6 // 112.5% of WidthNormal
	WidthExpanded       Width = 7 // 125% of WidthNormal
	WidthExtraExpanded  Width = 8 // 150% of WidthNormal
	WidthUltraExpanded  Width = 9 // 200% of WidthNormal
)

Valid width values.

func WidthFromString

func WidthFromString(s string) Width

WidthFromString returns the width class for the given string. This is the converse of Width.String().

func (Width) String

func (w Width) String() string

Jump to

Keyboard shortcuts

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