mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
text: consume io.Reader in shaper
io.Reader is actually a more efficient interface than io.RuneReader, as we can pull bytes out and check for cache hits without doing redundant rune<->string conversions. This isn't implemented yet, however. Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
package text
|
package text
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -182,6 +183,12 @@ func (l *Shaper) Layout(params Parameters, minWidth, maxWidth int, lc system.Loc
|
|||||||
l.layoutText(params, minWidth, maxWidth, lc, txt, "")
|
l.layoutText(params, minWidth, maxWidth, lc, txt, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Layout text from an io.Reader according to a set of options. Results can be retrieved by
|
||||||
|
// iteratively calling NextGlyph.
|
||||||
|
func (l *Shaper) LayoutReader(params Parameters, minWidth, maxWidth int, lc system.Locale, txt io.Reader) {
|
||||||
|
l.layoutText(params, minWidth, maxWidth, lc, bufio.NewReader(txt), "")
|
||||||
|
}
|
||||||
|
|
||||||
// LayoutString is Layout for strings.
|
// LayoutString is Layout for strings.
|
||||||
func (l *Shaper) LayoutString(params Parameters, minWidth, maxWidth int, lc system.Locale, str string) {
|
func (l *Shaper) LayoutString(params Parameters, minWidth, maxWidth int, lc system.Locale, str string) {
|
||||||
l.layoutText(params, minWidth, maxWidth, lc, nil, str)
|
l.layoutText(params, minWidth, maxWidth, lc, nil, str)
|
||||||
|
|||||||
+1
-1
@@ -113,7 +113,7 @@ func TestShapingNewlineHandling(t *testing.T) {
|
|||||||
}
|
}
|
||||||
checkGlyphs()
|
checkGlyphs()
|
||||||
|
|
||||||
cache.Layout(Parameters{
|
cache.LayoutReader(Parameters{
|
||||||
Alignment: Middle,
|
Alignment: Middle,
|
||||||
PxPerEm: fixed.I(10),
|
PxPerEm: fixed.I(10),
|
||||||
}, 200, 200, english, strings.NewReader(tc.textInput))
|
}, 200, 200, english, strings.NewReader(tc.textInput))
|
||||||
|
|||||||
Reference in New Issue
Block a user