mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
text,widget,opentype: change text.Face.Shape to return a clip.PathSpec
With this change, the Shape function returns a clip.PathSpec instead of a clip.Outline op. It is then possible to create a clip.Outline or clip.Stroke op to fill the text path or draw its stroke. Signed-off-by: Christophe Meessen <meessen@cppm.in2p3.fr>
This commit is contained in:
committed by
Elias Naur
parent
3db11cbaad
commit
a34e239c04
+4
-4
@@ -26,7 +26,7 @@ type layoutElem struct {
|
||||
type path struct {
|
||||
next, prev *path
|
||||
key pathKey
|
||||
val clip.Op
|
||||
val clip.PathSpec
|
||||
}
|
||||
|
||||
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) (clip.PathSpec, bool) {
|
||||
if v, ok := c.m[k]; ok {
|
||||
c.remove(v)
|
||||
c.insert(v)
|
||||
return v.val, true
|
||||
}
|
||||
return clip.Op{}, false
|
||||
return clip.PathSpec{}, false
|
||||
}
|
||||
|
||||
func (c *pathCache) Put(k pathKey, v clip.Op) {
|
||||
func (c *pathCache) Put(k pathKey, v clip.PathSpec) {
|
||||
if c.m == nil {
|
||||
c.m = make(map[pathKey]*path)
|
||||
c.head = new(path)
|
||||
|
||||
+1
-1
@@ -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)}, clip.PathSpec{})
|
||||
}
|
||||
get := func(i int) bool {
|
||||
_, ok := c.Get(pathKey{str: strconv.Itoa(i)})
|
||||
|
||||
+4
-4
@@ -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) clip.Op
|
||||
Shape(font Font, size fixed.Int26_6, layout Layout) clip.PathSpec
|
||||
}
|
||||
|
||||
// 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) clip.Op {
|
||||
func (c *Cache) Shape(font Font, size fixed.Int26_6, layout Layout) clip.PathSpec {
|
||||
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) clip.Op {
|
||||
func (f *faceCache) shape(ppem fixed.Int26_6, layout Layout) clip.PathSpec {
|
||||
if f == nil {
|
||||
return clip.Op{}
|
||||
return clip.PathSpec{}
|
||||
}
|
||||
pk := pathKey{
|
||||
ppem: ppem,
|
||||
|
||||
+1
-1
@@ -48,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) clip.Op
|
||||
Shape(ppem fixed.Int26_6, str Layout) clip.PathSpec
|
||||
}
|
||||
|
||||
// Typeface identifies a particular typeface design. The empty
|
||||
|
||||
Reference in New Issue
Block a user