text: convert clip.Ops to op.CallOp

MacroOp is about to lose the ability to run a different operation list
than the one it was recorded on. Text shape caches rely on that property,
and must use the new CallOp operation added for purpose.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-12-11 22:58:08 +01:00
parent 06217c5320
commit 0768fbe590
6 changed files with 18 additions and 18 deletions
+4 -3
View File
@@ -42,7 +42,7 @@ func (f *Font) Layout(ppem fixed.Int26_6, str string, opts text.LayoutOptions) *
return layoutText(&f.buf, ppem, str, &opentype{Font: f.font, Hinting: font.HintingFull}, opts) return layoutText(&f.buf, ppem, str, &opentype{Font: f.font, Hinting: font.HintingFull}, opts)
} }
func (f *Font) Shape(ppem fixed.Int26_6, str text.String) clip.Op { func (f *Font) Shape(ppem fixed.Int26_6, str text.String) op.CallOp {
return textPath(&f.buf, ppem, &opentype{Font: f.font, Hinting: font.HintingFull}, str) return textPath(&f.buf, ppem, &opentype{Font: f.font, Hinting: font.HintingFull}, str)
} }
@@ -130,7 +130,7 @@ func layoutText(buf *sfnt.Buffer, ppem fixed.Int26_6, str string, f *opentype, o
return &text.Layout{Lines: lines} return &text.Layout{Lines: lines}
} }
func textPath(buf *sfnt.Buffer, ppem fixed.Int26_6, f *opentype, str text.String) clip.Op { func textPath(buf *sfnt.Buffer, ppem fixed.Int26_6, f *opentype, str text.String) op.CallOp {
var lastPos f32.Point var lastPos f32.Point
var builder clip.Path var builder clip.Path
ops := new(op.Ops) ops := new(op.Ops)
@@ -188,7 +188,8 @@ func textPath(buf *sfnt.Buffer, ppem fixed.Int26_6, f *opentype, str text.String
x += str.Advances[advIdx] x += str.Advances[advIdx]
advIdx++ advIdx++
} }
return builder.End() builder.End().Add(ops)
return op.CallOp{Ops: ops}
} }
func (f *opentype) GlyphAdvance(buf *sfnt.Buffer, ppem fixed.Int26_6, r rune) (advance fixed.Int26_6, ok bool) { func (f *opentype) GlyphAdvance(buf *sfnt.Buffer, ppem fixed.Int26_6, r rune) (advance fixed.Int26_6, ok bool) {
+5 -5
View File
@@ -3,7 +3,7 @@
package text package text
import ( import (
"gioui.org/op/clip" "gioui.org/op"
"golang.org/x/image/math/fixed" "golang.org/x/image/math/fixed"
) )
@@ -26,7 +26,7 @@ type layoutElem struct {
type path struct { type path struct {
next, prev *path next, prev *path
key pathKey key pathKey
val clip.Op val op.CallOp
} }
type layoutKey struct { type layoutKey struct {
@@ -81,16 +81,16 @@ func (l *layoutCache) insert(lt *layoutElem) {
lt.next.prev = lt lt.next.prev = lt
} }
func (c *pathCache) Get(k pathKey) (clip.Op, bool) { func (c *pathCache) Get(k pathKey) (op.CallOp, bool) {
if v, ok := c.m[k]; ok { if v, ok := c.m[k]; ok {
c.remove(v) c.remove(v)
c.insert(v) c.insert(v)
return v.val, true return v.val, true
} }
return clip.Op{}, false return op.CallOp{}, false
} }
func (c *pathCache) Put(k pathKey, v clip.Op) { func (c *pathCache) Put(k pathKey, v op.CallOp) {
if c.m == nil { if c.m == nil {
c.m = make(map[pathKey]*path) c.m = make(map[pathKey]*path)
c.head = new(path) c.head = new(path)
+2 -2
View File
@@ -6,7 +6,7 @@ import (
"strconv" "strconv"
"testing" "testing"
"gioui.org/op/clip" "gioui.org/op"
) )
func TestLayoutLRU(t *testing.T) { func TestLayoutLRU(t *testing.T) {
@@ -24,7 +24,7 @@ func TestLayoutLRU(t *testing.T) {
func TestPathLRU(t *testing.T) { func TestPathLRU(t *testing.T) {
c := new(pathCache) c := new(pathCache)
put := func(i int) { put := func(i int) {
c.Put(pathKey{str: strconv.Itoa(i)}, clip.Op{}) c.Put(pathKey{str: strconv.Itoa(i)}, op.CallOp{})
} }
get := func(i int) bool { get := func(i int) bool {
_, ok := c.Get(pathKey{str: strconv.Itoa(i)}) _, ok := c.Get(pathKey{str: strconv.Itoa(i)})
+4 -4
View File
@@ -5,7 +5,7 @@ package text
import ( import (
"unicode/utf8" "unicode/utf8"
"gioui.org/op/clip" "gioui.org/op"
"gioui.org/unit" "gioui.org/unit"
"golang.org/x/image/math/fixed" "golang.org/x/image/math/fixed"
) )
@@ -46,7 +46,7 @@ func (s *Shaper) Layout(c unit.Converter, font Font, str string, opts LayoutOpti
return tf.layout(fixed.I(c.Px(font.Size)), str, opts) return tf.layout(fixed.I(c.Px(font.Size)), str, opts)
} }
func (s *Shaper) Shape(c unit.Converter, font Font, str String) clip.Op { func (s *Shaper) Shape(c unit.Converter, font Font, str String) op.CallOp {
tf := s.faceForFont(font) tf := s.faceForFont(font)
return tf.shape(fixed.I(c.Px(font.Size)), str) return tf.shape(fixed.I(c.Px(font.Size)), str)
} }
@@ -99,9 +99,9 @@ func (t *face) layout(ppem fixed.Int26_6, str string, opts LayoutOptions) *Layou
return l return l
} }
func (t *face) shape(ppem fixed.Int26_6, str String) clip.Op { func (t *face) shape(ppem fixed.Int26_6, str String) op.CallOp {
if t == nil { if t == nil {
return clip.Op{} return op.CallOp{}
} }
pk := pathKey{ pk := pathKey{
ppem: ppem, ppem: ppem,
+2 -2
View File
@@ -3,7 +3,7 @@
package text package text
import ( import (
"gioui.org/op/clip" "gioui.org/op"
"gioui.org/unit" "gioui.org/unit"
"golang.org/x/image/font" "golang.org/x/image/font"
"golang.org/x/image/math/fixed" "golang.org/x/image/math/fixed"
@@ -60,7 +60,7 @@ type Font struct {
// Face implements text layout and shaping for a particular font. // Face implements text layout and shaping for a particular font.
type Face interface { type Face interface {
Layout(ppem fixed.Int26_6, str string, opts LayoutOptions) *Layout Layout(ppem fixed.Int26_6, str string, opts LayoutOptions) *Layout
Shape(ppem fixed.Int26_6, str String) clip.Op Shape(ppem fixed.Int26_6, str String) op.CallOp
Metrics(ppem fixed.Int26_6) font.Metrics Metrics(ppem fixed.Int26_6) font.Metrics
} }
+1 -2
View File
@@ -15,7 +15,6 @@ import (
"gioui.org/io/pointer" "gioui.org/io/pointer"
"gioui.org/layout" "gioui.org/layout"
"gioui.org/op" "gioui.org/op"
"gioui.org/op/clip"
"gioui.org/op/paint" "gioui.org/op/paint"
"gioui.org/text" "gioui.org/text"
"gioui.org/unit" "gioui.org/unit"
@@ -81,7 +80,7 @@ type SubmitEvent struct {
type line struct { type line struct {
offset f32.Point offset f32.Point
clip clip.Op clip op.CallOp
} }
const ( const (