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
|
||||
}
|
||||
|
||||
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.
|
||||
func NewGoTextFaceSource(source io.Reader) (*GoTextFaceSource, error) {
|
||||
src, err := toFontResource(source)
|
||||
@ -106,13 +116,7 @@ func NewGoTextFaceSource(source io.Reader) (*GoTextFaceSource, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s := &GoTextFaceSource{
|
||||
f: font.NewFace(f),
|
||||
}
|
||||
s.addr = s
|
||||
s.metadata = metadataFromLoader(l)
|
||||
s.outputCache = newCache[goTextOutputCacheKey, goTextOutputCacheValue](512)
|
||||
|
||||
s := newGoTextFaceSource(&font.Face{Font: f})
|
||||
return s, nil
|
||||
}
|
||||
|
||||
@ -134,11 +138,7 @@ func NewGoTextFaceSourcesFromCollection(source io.Reader) ([]*GoTextFaceSource,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s := &GoTextFaceSource{
|
||||
f: &font.Face{Font: f},
|
||||
}
|
||||
s.addr = s
|
||||
s.metadata = metadataFromLoader(l)
|
||||
s := newGoTextFaceSource(&font.Face{Font: f})
|
||||
sources[i] = s
|
||||
}
|
||||
return sources, nil
|
||||
|
@ -16,7 +16,6 @@ package text
|
||||
|
||||
import (
|
||||
"github.com/go-text/typesetting/font"
|
||||
"github.com/go-text/typesetting/font/opentype"
|
||||
)
|
||||
|
||||
// Metadata represents a font face's metadata.
|
||||
@ -27,8 +26,8 @@ type Metadata struct {
|
||||
Stretch Stretch
|
||||
}
|
||||
|
||||
func metadataFromLoader(l *opentype.Loader) Metadata {
|
||||
d, _ := font.Describe(l, nil)
|
||||
func metadataFromFace(f *font.Face) Metadata {
|
||||
d := f.Describe()
|
||||
return Metadata{
|
||||
Family: d.Family,
|
||||
Style: Style(d.Aspect.Style),
|
||||
|
Loading…
Reference in New Issue
Block a user