forked from joejulian/gio
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
@@ -119,7 +119,7 @@ func (f *Font) Layout(ppem fixed.Int26_6, maxWidth int, txt io.Reader) ([]text.L
|
||||
return layoutText(&buf, ppem, maxWidth, fonts, glyphs)
|
||||
}
|
||||
|
||||
func (f *Font) Shape(ppem fixed.Int26_6, str text.Layout) clip.Op {
|
||||
func (f *Font) Shape(ppem fixed.Int26_6, str text.Layout) clip.PathSpec {
|
||||
var buf sfnt.Buffer
|
||||
return textPath(&buf, ppem, []*opentype{{Font: f.font, Hinting: font.HintingFull}}, str)
|
||||
}
|
||||
@@ -139,7 +139,7 @@ func (c *Collection) Layout(ppem fixed.Int26_6, maxWidth int, txt io.Reader) ([]
|
||||
return layoutText(&buf, ppem, maxWidth, c.fonts, glyphs)
|
||||
}
|
||||
|
||||
func (c *Collection) Shape(ppem fixed.Int26_6, str text.Layout) clip.Op {
|
||||
func (c *Collection) Shape(ppem fixed.Int26_6, str text.Layout) clip.PathSpec {
|
||||
var buf sfnt.Buffer
|
||||
return textPath(&buf, ppem, c.fonts, str)
|
||||
}
|
||||
@@ -261,12 +261,11 @@ func toLayout(glyphs []glyph) text.Layout {
|
||||
return text.Layout{Text: buf.String(), Advances: advs}
|
||||
}
|
||||
|
||||
func textPath(buf *sfnt.Buffer, ppem fixed.Int26_6, fonts []*opentype, str text.Layout) clip.Op {
|
||||
func textPath(buf *sfnt.Buffer, ppem fixed.Int26_6, fonts []*opentype, str text.Layout) clip.PathSpec {
|
||||
var lastPos f32.Point
|
||||
var builder clip.Path
|
||||
ops := new(op.Ops)
|
||||
var x fixed.Int26_6
|
||||
builder.Begin(ops)
|
||||
builder.Begin(new(op.Ops))
|
||||
rune := 0
|
||||
for _, r := range str.Text {
|
||||
if !unicode.IsSpace(r) {
|
||||
@@ -323,9 +322,7 @@ func textPath(buf *sfnt.Buffer, ppem fixed.Int26_6, fonts []*opentype, str text.
|
||||
x += str.Advances[rune]
|
||||
rune++
|
||||
}
|
||||
return clip.Outline{
|
||||
Path: builder.End(),
|
||||
}.Op()
|
||||
return builder.End()
|
||||
}
|
||||
|
||||
func readGlyphs(r io.Reader) ([]glyph, error) {
|
||||
|
||||
Reference in New Issue
Block a user