d2font: fixed lint errors
This commit is contained in:
parent
662d4489c4
commit
e2ec1c6613
|
@ -0,0 +1,3 @@
|
||||||
|
// Package d2font contains logic for loading and processing
|
||||||
|
// d2 fonts
|
||||||
|
package d2font
|
|
@ -14,6 +14,14 @@ const (
|
||||||
knownSignature = "Woo!\x01"
|
knownSignature = "Woo!\x01"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
signatureBytesCount = 5
|
||||||
|
unknownHeaderBytesCount = 7
|
||||||
|
unknown1BytesCount = 1
|
||||||
|
unknown2BytesCount = 4
|
||||||
|
unknown3BytesCount = 4
|
||||||
|
)
|
||||||
|
|
||||||
type fontGlyph struct {
|
type fontGlyph struct {
|
||||||
unknown1 []byte
|
unknown1 []byte
|
||||||
unknown2 []byte
|
unknown2 []byte
|
||||||
|
@ -36,7 +44,7 @@ type Font struct {
|
||||||
func Load(data []byte, sheet d2interface.Animation) (*Font, error) {
|
func Load(data []byte, sheet d2interface.Animation) (*Font, error) {
|
||||||
sr := d2datautils.CreateStreamReader(data)
|
sr := d2datautils.CreateStreamReader(data)
|
||||||
|
|
||||||
signature, err := sr.ReadBytes(5)
|
signature, err := sr.ReadBytes(signatureBytesCount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -51,12 +59,15 @@ func Load(data []byte, sheet d2interface.Animation) (*Font, error) {
|
||||||
color: color.White,
|
color: color.White,
|
||||||
}
|
}
|
||||||
|
|
||||||
font.unknownHeaderBytes, err = sr.ReadBytes(7)
|
font.unknownHeaderBytes, err = sr.ReadBytes(unknownHeaderBytesCount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
font.initGlyphs(sr)
|
err = font.initGlyphs(sr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return font, nil
|
return font, nil
|
||||||
}
|
}
|
||||||
|
@ -68,7 +79,6 @@ func (f *Font) SetColor(c color.Color) {
|
||||||
|
|
||||||
// GetTextMetrics returns the dimensions of the Font element in pixels
|
// GetTextMetrics returns the dimensions of the Font element in pixels
|
||||||
func (f *Font) GetTextMetrics(text string) (width, height int) {
|
func (f *Font) GetTextMetrics(text string) (width, height int) {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
lineWidth int
|
lineWidth int
|
||||||
lineHeight int
|
lineHeight int
|
||||||
|
@ -144,7 +154,7 @@ func (f *Font) initGlyphs(sr *d2datautils.StreamReader) error {
|
||||||
|
|
||||||
var glyph fontGlyph
|
var glyph fontGlyph
|
||||||
|
|
||||||
glyph.unknown1, err = sr.ReadBytes(1)
|
glyph.unknown1, err = sr.ReadBytes(unknown1BytesCount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -158,7 +168,7 @@ func (f *Font) initGlyphs(sr *d2datautils.StreamReader) error {
|
||||||
|
|
||||||
glyph.height = maxCharHeight
|
glyph.height = maxCharHeight
|
||||||
|
|
||||||
glyph.unknown2, err = sr.ReadBytes(4)
|
glyph.unknown2, err = sr.ReadBytes(unknown2BytesCount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -170,7 +180,7 @@ func (f *Font) initGlyphs(sr *d2datautils.StreamReader) error {
|
||||||
|
|
||||||
glyph.frame = int(frame)
|
glyph.frame = int(frame)
|
||||||
|
|
||||||
glyph.unknown3, err = sr.ReadBytes(4)
|
glyph.unknown3, err = sr.ReadBytes(unknown3BytesCount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -183,6 +193,7 @@ func (f *Font) initGlyphs(sr *d2datautils.StreamReader) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Marshal encodes font back into byte slice
|
||||||
func (f *Font) Marshal() []byte {
|
func (f *Font) Marshal() []byte {
|
||||||
sw := d2datautils.CreateStreamWriter()
|
sw := d2datautils.CreateStreamWriter()
|
||||||
|
|
||||||
|
|
|
@ -226,6 +226,8 @@ func (am *AssetManager) LoadFont(tablePath, spritePath, palettePath string) (*d2
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
am.Debugf(fmtLoadFont, tablePath, spritePath, palettePath)
|
||||||
|
|
||||||
font, err := d2font.Load(tableData, sheet)
|
font, err := d2font.Load(tableData, sheet)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error while loading font table %s: %v", tablePath, err)
|
return nil, fmt.Errorf("error while loading font table %s: %v", tablePath, err)
|
||||||
|
|
Loading…
Reference in New Issue