mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-11 18:43:21 +01:00
text/v2: refactoring
This commit is contained in:
parent
c985e9bdc6
commit
999c64cb78
@ -89,6 +89,16 @@ func toFontResource(source io.Reader) (font.Resource, error) {
|
|||||||
return bytes.NewReader(bs), nil
|
return bytes.NewReader(bs), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newGoTextFaceSource(face *font.Face) *GoTextFaceSource {
|
||||||
|
s := &GoTextFaceSource{
|
||||||
|
f: face,
|
||||||
|
}
|
||||||
|
s.addr = s
|
||||||
|
s.metadata = metadataFromFace(face)
|
||||||
|
s.outputCache = newCache[goTextOutputCacheKey, goTextOutputCacheValue](512)
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
// NewGoTextFaceSource parses an OpenType or TrueType font and returns a GoTextFaceSource object.
|
// NewGoTextFaceSource parses an OpenType or TrueType font and returns a GoTextFaceSource object.
|
||||||
func NewGoTextFaceSource(source io.Reader) (*GoTextFaceSource, error) {
|
func NewGoTextFaceSource(source io.Reader) (*GoTextFaceSource, error) {
|
||||||
src, err := toFontResource(source)
|
src, err := toFontResource(source)
|
||||||
@ -106,13 +116,7 @@ func NewGoTextFaceSource(source io.Reader) (*GoTextFaceSource, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
s := &GoTextFaceSource{
|
s := newGoTextFaceSource(&font.Face{Font: f})
|
||||||
f: font.NewFace(f),
|
|
||||||
}
|
|
||||||
s.addr = s
|
|
||||||
s.metadata = metadataFromLoader(l)
|
|
||||||
s.outputCache = newCache[goTextOutputCacheKey, goTextOutputCacheValue](512)
|
|
||||||
|
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,11 +138,7 @@ func NewGoTextFaceSourcesFromCollection(source io.Reader) ([]*GoTextFaceSource,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
s := &GoTextFaceSource{
|
s := newGoTextFaceSource(&font.Face{Font: f})
|
||||||
f: &font.Face{Font: f},
|
|
||||||
}
|
|
||||||
s.addr = s
|
|
||||||
s.metadata = metadataFromLoader(l)
|
|
||||||
sources[i] = s
|
sources[i] = s
|
||||||
}
|
}
|
||||||
return sources, nil
|
return sources, nil
|
||||||
|
@ -16,7 +16,6 @@ package text
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-text/typesetting/font"
|
"github.com/go-text/typesetting/font"
|
||||||
"github.com/go-text/typesetting/font/opentype"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Metadata represents a font face's metadata.
|
// Metadata represents a font face's metadata.
|
||||||
@ -27,8 +26,8 @@ type Metadata struct {
|
|||||||
Stretch Stretch
|
Stretch Stretch
|
||||||
}
|
}
|
||||||
|
|
||||||
func metadataFromLoader(l *opentype.Loader) Metadata {
|
func metadataFromFace(f *font.Face) Metadata {
|
||||||
d, _ := font.Describe(l, nil)
|
d := f.Describe()
|
||||||
return Metadata{
|
return Metadata{
|
||||||
Family: d.Family,
|
Family: d.Family,
|
||||||
Style: Style(d.Aspect.Style),
|
Style: Style(d.Aspect.Style),
|
||||||
|
Loading…
Reference in New Issue
Block a user