diff --git a/d2common/d2fileformats/d2font/font.go b/d2common/d2fileformats/d2font/font.go index fd952b46..0edcd2de 100644 --- a/d2common/d2fileformats/d2font/font.go +++ b/d2common/d2fileformats/d2font/font.go @@ -22,7 +22,8 @@ const ( unknown3BytesCount = 4 ) -type fontGlyph struct { +// FontGlyph represents a single font glyph +type FontGlyph struct { unknown1 []byte unknown2 []byte unknown3 []byte @@ -31,17 +32,23 @@ type fontGlyph struct { height int } -func (fg *fontGlyph) setHeight(h int) { - fg.height = h +// SetSize sets glyph's size to w, h +func (fg *FontGlyph) SetSize(w, h int) { + fg.width, fg.height = w, h } // Size returns glyph's size -func (fg *fontGlyph) Size() (w, h int) { +func (fg *FontGlyph) Size() (w, h int) { return fg.width, fg.height } +// SetFrameIndex sets frame index to idx +func (fg *FontGlyph) SetFrameIndex(idx int) { + fg.frame = idx +} + // FrameIndex returns glyph's frame -func (fg *fontGlyph) FrameIndex() int { +func (fg *FontGlyph) FrameIndex() int { return fg.frame } @@ -50,7 +57,7 @@ type Font struct { unknownHeaderBytes []byte sheet d2interface.Animation table []byte - Glyphs map[rune]*fontGlyph + Glyphs map[rune]*FontGlyph color color.Color } @@ -93,7 +100,7 @@ func (f *Font) SetBackground(sheet d2interface.Animation) { _, h := f.sheet.GetFrameBounds() for i := range f.Glyphs { - f.Glyphs[i].setHeight(h) + f.Glyphs[i].SetSize(f.Glyphs[i].width, h) } } @@ -167,7 +174,7 @@ func (f *Font) RenderText(text string, target d2interface.Surface) error { } func (f *Font) initGlyphs(sr *d2datautils.StreamReader) error { - glyphs := make(map[rune]*fontGlyph) + glyphs := make(map[rune]*FontGlyph) for i := 12; i < len(f.table); i += 14 { code, err := sr.ReadUInt16() @@ -175,7 +182,7 @@ func (f *Font) initGlyphs(sr *d2datautils.StreamReader) error { return err } - var glyph fontGlyph + var glyph FontGlyph // two bytes of 0 glyph.unknown1, err = sr.ReadBytes(unknown1BytesCount)