mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-02-09 01:56:47 -05:00
font table interpreter: moved d stuff responsible for font table into d2fileformats/d2font
This commit is contained in:
parent
5e1dbf56f0
commit
721a67b404
@ -1,7 +1,8 @@
|
||||
package d2asset
|
||||
package d2font
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"image/color"
|
||||
"strings"
|
||||
|
||||
@ -23,6 +24,23 @@ type Font struct {
|
||||
color color.Color
|
||||
}
|
||||
|
||||
// Load loads a new font from byte slice
|
||||
func Load(data []byte, sheet d2interface.Animation) (*Font, error) {
|
||||
if string(data[:5]) != "Woo!\x01" {
|
||||
return nil, fmt.Errorf("invalid font table format")
|
||||
}
|
||||
|
||||
font := &Font{
|
||||
table: data,
|
||||
sheet: sheet,
|
||||
color: color.White,
|
||||
}
|
||||
|
||||
font.initGlyphs()
|
||||
|
||||
return font, nil
|
||||
}
|
||||
|
||||
// SetColor sets the fonts color
|
||||
func (f *Font) SetColor(c color.Color) {
|
||||
f.color = c
|
||||
@ -30,9 +48,6 @@ func (f *Font) SetColor(c color.Color) {
|
||||
|
||||
// GetTextMetrics returns the dimensions of the Font element in pixels
|
||||
func (f *Font) GetTextMetrics(text string) (width, height int) {
|
||||
if f.glyphs == nil {
|
||||
f.initGlyphs()
|
||||
}
|
||||
|
||||
var (
|
||||
lineWidth int
|
@ -2,7 +2,6 @@ package d2asset
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image/color"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
@ -19,6 +18,7 @@ import (
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2records"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2font"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||
@ -209,11 +209,11 @@ func (am *AssetManager) LoadComposite(baseType d2enum.ObjectType, token, palette
|
||||
}
|
||||
|
||||
// LoadFont loads a font the resource files
|
||||
func (am *AssetManager) LoadFont(tablePath, spritePath, palettePath string) (*Font, error) {
|
||||
func (am *AssetManager) LoadFont(tablePath, spritePath, palettePath string) (*d2font.Font, error) {
|
||||
cachePath := fmt.Sprintf("%s;%s;%s", tablePath, spritePath, palettePath)
|
||||
|
||||
if cached, found := am.fonts.Retrieve(cachePath); found {
|
||||
return cached.(*Font), nil
|
||||
return cached.(*d2font.Font), nil
|
||||
}
|
||||
|
||||
sheet, err := am.LoadAnimation(spritePath, palettePath)
|
||||
@ -226,16 +226,9 @@ func (am *AssetManager) LoadFont(tablePath, spritePath, palettePath string) (*Fo
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if string(tableData[:5]) != "Woo!\x01" {
|
||||
return nil, fmt.Errorf("invalid font table format: %s", tablePath)
|
||||
}
|
||||
|
||||
am.Debugf(fmtLoadFont, tablePath, spritePath, palettePath)
|
||||
|
||||
font := &Font{
|
||||
table: tableData,
|
||||
sheet: sheet,
|
||||
color: color.White,
|
||||
font, err := d2font.Load(tableData, sheet)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error while loading font table %s: %v", tablePath, err)
|
||||
}
|
||||
|
||||
err = am.fonts.Insert(cachePath, font, defaultCacheEntryWeight)
|
||||
|
@ -4,8 +4,8 @@ import (
|
||||
"image/color"
|
||||
"time"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2font"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
||||
)
|
||||
|
||||
// Constants defining the main shades of basic colors
|
||||
@ -25,7 +25,7 @@ type Label struct {
|
||||
|
||||
renderer d2interface.Renderer
|
||||
text string
|
||||
font *d2asset.Font
|
||||
font *d2font.Font
|
||||
surface d2interface.Surface
|
||||
color color.RGBA
|
||||
hoverColor color.RGBA
|
||||
@ -35,7 +35,7 @@ type Label struct {
|
||||
blinkTimer time.Time
|
||||
}
|
||||
|
||||
func createLabel(renderer d2interface.Renderer, text string, font *d2asset.Font, col color.RGBA) (*Label, error) {
|
||||
func createLabel(renderer d2interface.Renderer, text string, font *d2font.Font, col color.RGBA) (*Label, error) {
|
||||
label := &Label{
|
||||
font: font,
|
||||
renderer: renderer,
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"image/color"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2font"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
|
||||
@ -532,7 +533,7 @@ func (l *Layout) createButton(renderer d2interface.Renderer, text string,
|
||||
return button, nil
|
||||
}
|
||||
|
||||
func (l *Layout) loadFont(fontStyle FontStyle) (*d2asset.Font, error) {
|
||||
func (l *Layout) loadFont(fontStyle FontStyle) (*d2font.Font, error) {
|
||||
config := getFontStyleConfig(fontStyle)
|
||||
if config == nil {
|
||||
return nil, errors.New("invalid font style")
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2font"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
|
||||
@ -19,7 +19,7 @@ type Label struct {
|
||||
*BaseWidget
|
||||
text string
|
||||
Alignment HorizontalAlign
|
||||
font *d2asset.Font
|
||||
font *d2font.Font
|
||||
Color map[int]color.Color
|
||||
backgroundColor color.Color
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user