mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 10:25:37 +00:00
font/opentype,text,widget: use clip.Op for text shapes, not a macro
This change avoids a macro wrapping every text shape, and prepares text shaping for scoped clip operations. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+5
-6
@@ -3,9 +3,8 @@
|
||||
package text
|
||||
|
||||
import (
|
||||
"gioui.org/op/clip"
|
||||
"golang.org/x/image/math/fixed"
|
||||
|
||||
"gioui.org/op"
|
||||
)
|
||||
|
||||
type layoutCache struct {
|
||||
@@ -27,7 +26,7 @@ type layoutElem struct {
|
||||
type path struct {
|
||||
next, prev *path
|
||||
key pathKey
|
||||
val op.CallOp
|
||||
val clip.Op
|
||||
}
|
||||
|
||||
type layoutKey struct {
|
||||
@@ -82,16 +81,16 @@ func (l *layoutCache) insert(lt *layoutElem) {
|
||||
lt.next.prev = lt
|
||||
}
|
||||
|
||||
func (c *pathCache) Get(k pathKey) (op.CallOp, bool) {
|
||||
func (c *pathCache) Get(k pathKey) (clip.Op, bool) {
|
||||
if v, ok := c.m[k]; ok {
|
||||
c.remove(v)
|
||||
c.insert(v)
|
||||
return v.val, true
|
||||
}
|
||||
return op.CallOp{}, false
|
||||
return clip.Op{}, false
|
||||
}
|
||||
|
||||
func (c *pathCache) Put(k pathKey, v op.CallOp) {
|
||||
func (c *pathCache) Put(k pathKey, v clip.Op) {
|
||||
if c.m == nil {
|
||||
c.m = make(map[pathKey]*path)
|
||||
c.head = new(path)
|
||||
|
||||
+2
-2
@@ -6,7 +6,7 @@ import (
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"gioui.org/op"
|
||||
"gioui.org/op/clip"
|
||||
)
|
||||
|
||||
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)}, op.CallOp{})
|
||||
c.Put(pathKey{str: strconv.Itoa(i)}, clip.Op{})
|
||||
}
|
||||
get := func(i int) bool {
|
||||
_, ok := c.Get(pathKey{str: strconv.Itoa(i)})
|
||||
|
||||
+5
-5
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"golang.org/x/image/math/fixed"
|
||||
|
||||
"gioui.org/op"
|
||||
"gioui.org/op/clip"
|
||||
)
|
||||
|
||||
// Shaper implements layout and shaping of text.
|
||||
@@ -18,7 +18,7 @@ type Shaper interface {
|
||||
// LayoutString is Layout for strings.
|
||||
LayoutString(font Font, size fixed.Int26_6, maxWidth int, str string) []Line
|
||||
// Shape a line of text and return a clipping operation for its outline.
|
||||
Shape(font Font, size fixed.Int26_6, layout Layout) op.CallOp
|
||||
Shape(font Font, size fixed.Int26_6, layout Layout) clip.Op
|
||||
}
|
||||
|
||||
// A FontFace is a Font and a matching Face.
|
||||
@@ -121,7 +121,7 @@ func (c *Cache) LayoutString(font Font, size fixed.Int26_6, maxWidth int, str st
|
||||
|
||||
// Shape is a caching implementation of the Shaper interface. Shape assumes that the layout
|
||||
// argument is unchanged from a call to Layout or LayoutString.
|
||||
func (c *Cache) Shape(font Font, size fixed.Int26_6, layout Layout) op.CallOp {
|
||||
func (c *Cache) Shape(font Font, size fixed.Int26_6, layout Layout) clip.Op {
|
||||
cache := c.lookup(font)
|
||||
return cache.shape(size, layout)
|
||||
}
|
||||
@@ -143,9 +143,9 @@ func (f *faceCache) layout(ppem fixed.Int26_6, maxWidth int, str string) []Line
|
||||
return l
|
||||
}
|
||||
|
||||
func (f *faceCache) shape(ppem fixed.Int26_6, layout Layout) op.CallOp {
|
||||
func (f *faceCache) shape(ppem fixed.Int26_6, layout Layout) clip.Op {
|
||||
if f == nil {
|
||||
return op.CallOp{}
|
||||
return clip.Op{}
|
||||
}
|
||||
pk := pathKey{
|
||||
ppem: ppem,
|
||||
|
||||
+2
-3
@@ -5,9 +5,8 @@ package text
|
||||
import (
|
||||
"io"
|
||||
|
||||
"gioui.org/op/clip"
|
||||
"golang.org/x/image/math/fixed"
|
||||
|
||||
"gioui.org/op"
|
||||
)
|
||||
|
||||
// A Line contains the measurements of a line of text.
|
||||
@@ -49,7 +48,7 @@ type Font struct {
|
||||
// methods must be safe for concurrent use.
|
||||
type Face interface {
|
||||
Layout(ppem fixed.Int26_6, maxWidth int, txt io.Reader) ([]Line, error)
|
||||
Shape(ppem fixed.Int26_6, str Layout) op.CallOp
|
||||
Shape(ppem fixed.Int26_6, str Layout) clip.Op
|
||||
}
|
||||
|
||||
// Typeface identifies a particular typeface design. The empty
|
||||
|
||||
Reference in New Issue
Block a user