mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-02-02 22:57:04 -05:00
d2font: fixed bug, when was unable to create new file doing just &Font{}.Marshal()
This commit is contained in:
parent
ecab467a0f
commit
d72b3e3345
@ -6,12 +6,9 @@ func Create(frame, width, height int) *FontGlyph {
|
|||||||
// nolint:gomnd // thes bytes are constant
|
// nolint:gomnd // thes bytes are constant
|
||||||
// comes from https://d2mods.info/forum/viewtopic.php?t=42044
|
// comes from https://d2mods.info/forum/viewtopic.php?t=42044
|
||||||
result := &FontGlyph{
|
result := &FontGlyph{
|
||||||
unknown1: []byte{0},
|
frame: frame,
|
||||||
unknown2: []byte{1, 0, 0},
|
width: width,
|
||||||
unknown3: []byte{0, 0, 0, 0},
|
height: height,
|
||||||
frame: frame,
|
|
||||||
width: width,
|
|
||||||
height: height,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
@ -19,12 +16,9 @@ func Create(frame, width, height int) *FontGlyph {
|
|||||||
|
|
||||||
// FontGlyph represents a single font glyph
|
// FontGlyph represents a single font glyph
|
||||||
type FontGlyph struct {
|
type FontGlyph struct {
|
||||||
unknown1 []byte
|
frame int
|
||||||
unknown2 []byte
|
width int
|
||||||
unknown3 []byte
|
height int
|
||||||
frame int
|
|
||||||
width int
|
|
||||||
height int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetSize sets glyph's size to w, h
|
// SetSize sets glyph's size to w, h
|
||||||
@ -59,15 +53,15 @@ func (fg *FontGlyph) FrameIndex() int {
|
|||||||
|
|
||||||
// Unknown1 returns unknowns bytes
|
// Unknown1 returns unknowns bytes
|
||||||
func (fg *FontGlyph) Unknown1() []byte {
|
func (fg *FontGlyph) Unknown1() []byte {
|
||||||
return fg.unknown1
|
return []byte{0}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unknown2 returns unknowns bytes
|
// Unknown2 returns unknowns bytes
|
||||||
func (fg *FontGlyph) Unknown2() []byte {
|
func (fg *FontGlyph) Unknown2() []byte {
|
||||||
return fg.unknown2
|
return []byte{1, 0, 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unknown3 returns unknowns bytes
|
// Unknown3 returns unknowns bytes
|
||||||
func (fg *FontGlyph) Unknown3() []byte {
|
func (fg *FontGlyph) Unknown3() []byte {
|
||||||
return fg.unknown3
|
return []byte{0, 0, 0, 0}
|
||||||
}
|
}
|
||||||
|
@ -27,11 +27,10 @@ const (
|
|||||||
|
|
||||||
// Font represents a displayable font
|
// Font represents a displayable font
|
||||||
type Font struct {
|
type Font struct {
|
||||||
unknownHeaderBytes []byte
|
sheet d2interface.Animation
|
||||||
sheet d2interface.Animation
|
table []byte
|
||||||
table []byte
|
Glyphs map[rune]*d2fontglyph.FontGlyph
|
||||||
Glyphs map[rune]*d2fontglyph.FontGlyph
|
color color.Color
|
||||||
color color.Color
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load loads a new font from byte slice
|
// Load loads a new font from byte slice
|
||||||
@ -52,10 +51,7 @@ func Load(data []byte) (*Font, error) {
|
|||||||
color: color.White,
|
color: color.White,
|
||||||
}
|
}
|
||||||
|
|
||||||
font.unknownHeaderBytes, err = sr.ReadBytes(unknownHeaderBytesCount)
|
sr.SkipBytes(unknownHeaderBytesCount)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = font.initGlyphs(sr)
|
err = font.initGlyphs(sr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -149,10 +145,11 @@ func (f *Font) RenderText(text string, target d2interface.Surface) error {
|
|||||||
func (f *Font) initGlyphs(sr *d2datautils.StreamReader) error {
|
func (f *Font) initGlyphs(sr *d2datautils.StreamReader) error {
|
||||||
glyphs := make(map[rune]*d2fontglyph.FontGlyph)
|
glyphs := make(map[rune]*d2fontglyph.FontGlyph)
|
||||||
|
|
||||||
for i := numHeaderBytes; i < len(f.table); i += bytesPerGlyph {
|
// for i := numHeaderBytes; i < len(f.table); i += bytesPerGlyph {
|
||||||
|
for i := numHeaderBytes; true; i += bytesPerGlyph {
|
||||||
code, err := sr.ReadUInt16()
|
code, err := sr.ReadUInt16()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// byte of 0
|
// byte of 0
|
||||||
@ -194,7 +191,13 @@ func (f *Font) Marshal() []byte {
|
|||||||
sw := d2datautils.CreateStreamWriter()
|
sw := d2datautils.CreateStreamWriter()
|
||||||
|
|
||||||
sw.PushBytes([]byte("Woo!\x01")...)
|
sw.PushBytes([]byte("Woo!\x01")...)
|
||||||
sw.PushBytes(f.unknownHeaderBytes...)
|
|
||||||
|
// unknown header bytes - constant
|
||||||
|
sw.PushBytes([]byte{1, 0, 0, 0, 0, 1}...)
|
||||||
|
|
||||||
|
// Expected Height of character cell and Expected Width of character cell
|
||||||
|
// not used in decoder
|
||||||
|
sw.PushBytes([]byte{0, 0}...)
|
||||||
|
|
||||||
for c, i := range f.Glyphs {
|
for c, i := range f.Glyphs {
|
||||||
sw.PushUint16(uint16(c))
|
sw.PushUint16(uint16(c))
|
||||||
|
Loading…
Reference in New Issue
Block a user