From f34f93a11774e1971a9741a8471f25f39f3a74b3 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 25 Nov 2023 22:55:53 +0900 Subject: [PATCH] text/v2: remove the common UnsafeInternal and add ones to GoTextFaceSource and StdFace Updates #2454 --- text/v2/gotext.go | 5 ----- text/v2/gotextfacesource.go | 7 +++++++ text/v2/std.go | 6 ++++-- text/v2/text.go | 5 ----- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/text/v2/gotext.go b/text/v2/gotext.go index 1eb82dbd7..331996dc1 100644 --- a/text/v2/gotext.go +++ b/text/v2/gotext.go @@ -202,11 +202,6 @@ func (g *GoTextFace) Metrics() Metrics { return m } -// UnsafeInternal implements Face. -func (g *GoTextFace) UnsafeInternal() any { - return g.Source.f -} - func (g *GoTextFace) ensureVariationsString() string { if g.variationsString != "" { return g.variationsString diff --git a/text/v2/gotextfacesource.go b/text/v2/gotextfacesource.go index 8210d3460..59c428c26 100644 --- a/text/v2/gotextfacesource.go +++ b/text/v2/gotextfacesource.go @@ -157,6 +157,13 @@ func (g *GoTextFaceSource) Metadata() 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) { g.copyCheck() diff --git a/text/v2/std.go b/text/v2/std.go index b687255b3..0921a18b6 100644 --- a/text/v2/std.go +++ b/text/v2/std.go @@ -74,8 +74,10 @@ func (s *StdFace) Metrics() Metrics { } } -// UnsafeInternal implements Face. -func (s *StdFace) UnsafeInternal() any { +// UnsafeInternal returns its internal font.Face. +// +// This is unsafe since this might make internal cache states out of sync. +func (s *StdFace) UnsafeInternal() font.Face { s.copyCheck() return s.f.f } diff --git a/text/v2/text.go b/text/v2/text.go index d7aa4c754..d0bee7cbd 100644 --- a/text/v2/text.go +++ b/text/v2/text.go @@ -32,11 +32,6 @@ type Face interface { // Metrics returns the metrics for this Face. 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 appendGlyphsForLine(glyphs []Glyph, line string, indexOffset int, originX, originY float64) []Glyph