From 7a54465eb3e9da9ba7a8206a51db92ce703446b8 Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Wed, 17 Feb 2021 09:05:29 +0100 Subject: [PATCH 1/3] hotfix: font table format: fontGlyph is now exported --- d2common/d2fileformats/d2font/font.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/d2common/d2fileformats/d2font/font.go b/d2common/d2fileformats/d2font/font.go index fd952b46..38ce32ea 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,17 @@ type fontGlyph struct { height int } -func (fg *fontGlyph) setHeight(h int) { +func (fg *FontGlyph) setHeight(h int) { fg.height = 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 } // FrameIndex returns glyph's frame -func (fg *fontGlyph) FrameIndex() int { +func (fg *FontGlyph) FrameIndex() int { return fg.frame } @@ -50,7 +51,7 @@ type Font struct { unknownHeaderBytes []byte sheet d2interface.Animation table []byte - Glyphs map[rune]*fontGlyph + Glyphs map[rune]*FontGlyph color color.Color } @@ -167,7 +168,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 +176,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) From 66ac5ff6578e4dcc57d025600270db162e34bf44 Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Wed, 17 Feb 2021 10:28:36 +0100 Subject: [PATCH 2/3] font table format: methods to set size and frame index --- d2common/d2fileformats/d2font/font.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/d2common/d2fileformats/d2font/font.go b/d2common/d2fileformats/d2font/font.go index 38ce32ea..015b4178 100644 --- a/d2common/d2fileformats/d2font/font.go +++ b/d2common/d2fileformats/d2font/font.go @@ -32,8 +32,8 @@ type FontGlyph struct { height int } -func (fg *FontGlyph) setHeight(h int) { - fg.height = h +func (fg *FontGlyph) SetSize(w, h int) { + fg.width, fg.height = w, h } // Size returns glyph's size @@ -41,6 +41,10 @@ func (fg *FontGlyph) Size() (w, h int) { return fg.width, fg.height } +func (fg *FontGlyph) SetFrameIndex(idx int) { + fg.frame = idx +} + // FrameIndex returns glyph's frame func (fg *FontGlyph) FrameIndex() int { return fg.frame @@ -94,7 +98,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) } } From 6fdbaa07bd35f47a15b561d3a15713e39a7b2315 Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Wed, 17 Feb 2021 10:37:04 +0100 Subject: [PATCH 3/3] font table format: lintfix --- d2common/d2fileformats/d2font/font.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/d2common/d2fileformats/d2font/font.go b/d2common/d2fileformats/d2font/font.go index 015b4178..0edcd2de 100644 --- a/d2common/d2fileformats/d2font/font.go +++ b/d2common/d2fileformats/d2font/font.go @@ -32,6 +32,7 @@ type FontGlyph struct { height int } +// SetSize sets glyph's size to w, h func (fg *FontGlyph) SetSize(w, h int) { fg.width, fg.height = w, h } @@ -41,6 +42,7 @@ 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 }