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:
Christophe Meessen
2021-12-16 17:15:01 +01:00
committed by Elias Naur
parent 3db11cbaad
commit a34e239c04
8 changed files with 25 additions and 28 deletions
+4 -4
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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