text/v2: remove the common UnsafeInternal and add ones to GoTextFaceSource and StdFace

Updates #2454
This commit is contained in:
Hajime Hoshi 2023-11-25 22:55:53 +09:00
parent 989d749475
commit f34f93a117
4 changed files with 11 additions and 12 deletions

View File

@ -202,11 +202,6 @@ func (g *GoTextFace) Metrics() Metrics {
return m return m
} }
// UnsafeInternal implements Face.
func (g *GoTextFace) UnsafeInternal() any {
return g.Source.f
}
func (g *GoTextFace) ensureVariationsString() string { func (g *GoTextFace) ensureVariationsString() string {
if g.variationsString != "" { if g.variationsString != "" {
return g.variationsString return g.variationsString

View File

@ -157,6 +157,13 @@ func (g *GoTextFaceSource) Metadata() Metadata {
return g.metadata return g.metadata
} }
// UnsafeInternal returns its font.Face.
//
// This is unsafe since this might make internal cache states out of sync.
func (g *GoTextFaceSource) UnsafeInternal() font.Face {
return g.f
}
func (g *GoTextFaceSource) shape(text string, face *GoTextFace) (shaping.Output, []glyph) { func (g *GoTextFaceSource) shape(text string, face *GoTextFace) (shaping.Output, []glyph) {
g.copyCheck() g.copyCheck()

View File

@ -74,8 +74,10 @@ func (s *StdFace) Metrics() Metrics {
} }
} }
// UnsafeInternal implements Face. // UnsafeInternal returns its internal font.Face.
func (s *StdFace) UnsafeInternal() any { //
// This is unsafe since this might make internal cache states out of sync.
func (s *StdFace) UnsafeInternal() font.Face {
s.copyCheck() s.copyCheck()
return s.f.f return s.f.f
} }

View File

@ -32,11 +32,6 @@ type Face interface {
// Metrics returns the metrics for this Face. // Metrics returns the metrics for this Face.
Metrics() Metrics Metrics() Metrics
// UnsafeInternal returns the internal object for this face.
// The returned value is either a semi-standard font.Face or go-text's font.Face.
// This is unsafe since this might make internal cache states out of sync.
UnsafeInternal() any
advance(text string) float64 advance(text string) float64
appendGlyphsForLine(glyphs []Glyph, line string, indexOffset int, originX, originY float64) []Glyph appendGlyphsForLine(glyphs []Glyph, line string, indexOffset int, originX, originY float64) []Glyph