Merge pull request #1065 from gucio321/hotfix2

Hotfix: methods for editing FontGlyph (font glyph is now exported)
This commit is contained in:
gravestench 2021-02-17 02:35:02 -08:00 committed by GitHub
commit e9c9786af1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 9 deletions

View File

@ -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)