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)
}
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)
}
@@ -130,7 +130,7 @@ func layoutText(buf *sfnt.Buffer, ppem fixed.Int26_6, str string, f *opentype, o
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 builder clip.Path
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]
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) {
+5 -5
View File
@@ -3,7 +3,7 @@
package text
import (
"gioui.org/op/clip"
"gioui.org/op"
"golang.org/x/image/math/fixed"
)
@@ -26,7 +26,7 @@ type layoutElem struct {
type path struct {
next, prev *path
key pathKey
val clip.Op
val op.CallOp
}
type layoutKey struct {
@@ -81,16 +81,16 @@ func (l *layoutCache) insert(lt *layoutElem) {
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 {
c.remove(v)
c.insert(v)
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 {
c.m = make(map[pathKey]*path)
c.head = new(path)
+2 -2
View File
@@ -6,7 +6,7 @@ import (
"strconv"
"testing"
"gioui.org/op/clip"
"gioui.org/op"
)
func TestLayoutLRU(t *testing.T) {
@@ -24,7 +24,7 @@ func TestLayoutLRU(t *testing.T) {
func TestPathLRU(t *testing.T) {
c := new(pathCache)
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 {
_, ok := c.Get(pathKey{str: strconv.Itoa(i)})
+4 -4
View File
@@ -5,7 +5,7 @@ package text
import (
"unicode/utf8"
"gioui.org/op/clip"
"gioui.org/op"
"gioui.org/unit"
"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)
}
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)
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
}
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 {
return clip.Op{}
return op.CallOp{}
}
pk := pathKey{
ppem: ppem,
+2 -2
View File
@@ -3,7 +3,7 @@
package text
import (
"gioui.org/op/clip"
"gioui.org/op"
"gioui.org/unit"
"golang.org/x/image/font"
"golang.org/x/image/math/fixed"
@@ -60,7 +60,7 @@ type Font struct {
// Face implements text layout and shaping for a particular font.
type Face interface {
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
}
+1 -2
View File
@@ -15,7 +15,6 @@ import (
"gioui.org/io/pointer"
"gioui.org/layout"
"gioui.org/op"
"gioui.org/op/clip"
"gioui.org/op/paint"
"gioui.org/text"
"gioui.org/unit"
@@ -81,7 +80,7 @@ type SubmitEvent struct {
type line struct {
offset f32.Point
clip clip.Op
clip op.CallOp
}
const (