hotfix: font format:

- removed magic numbers
- corrected unknown1 bytes count in d2fontglyph.Create
This commit is contained in:
M. Sz 2021-02-19 08:48:20 +01:00
parent 30fb02bc10
commit 7574293624
2 changed files with 5 additions and 3 deletions

View File

@ -6,7 +6,7 @@ func Create(frame, width, height int) *FontGlyph {
// nolint:gomnd // thes bytes are constant
// comes from https://d2mods.info/forum/viewtopic.php?t=42044
result := &FontGlyph{
unknown1: []byte{0, 0},
unknown1: []byte{0},
unknown2: []byte{1, 0, 0},
unknown3: []byte{0, 0, 0, 0, 0},
frame: frame,

View File

@ -16,6 +16,8 @@ const (
)
const (
numHeaderBytes = 12
bytesPerGlyph = 14
signatureBytesCount = 5
unknownHeaderBytesCount = 7
unknown1BytesCount = 1
@ -147,13 +149,13 @@ func (f *Font) RenderText(text string, target d2interface.Surface) error {
func (f *Font) initGlyphs(sr *d2datautils.StreamReader) error {
glyphs := make(map[rune]*d2fontglyph.FontGlyph)
for i := 12; i < len(f.table); i += 14 {
for i := numHeaderBytes; i < len(f.table); i += bytesPerGlyph {
code, err := sr.ReadUInt16()
if err != nil {
return err
}
// two bytes of 0
// byte of 0
sr.SkipBytes(unknown1BytesCount)
width, err := sr.ReadByte()