text: remove String, Layout and add Glyph

In preparation for using Shaper with an io.Reader, rework the API to not refer
to strings. In particular, introduce Glyph for holding the rune in addition to
the advance. For fast traversing of the underlying text, add Len to Line with
the UTF8 length.

Layout is a useless wrapper around []Line; remove it while we're
here.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-01-13 19:54:11 +01:00
parent e25b1639b9
commit 16d2a3ac0a
6 changed files with 95 additions and 116 deletions
+3 -3
View File
@@ -20,7 +20,7 @@ type pathCache struct {
type layoutElem struct {
next, prev *layoutElem
key layoutKey
layout *Layout
layout []Line
}
type path struct {
@@ -42,7 +42,7 @@ type pathKey struct {
const maxSize = 1000
func (l *layoutCache) Get(k layoutKey) (*Layout, bool) {
func (l *layoutCache) Get(k layoutKey) ([]Line, bool) {
if lt, ok := l.m[k]; ok {
l.remove(lt)
l.insert(lt)
@@ -51,7 +51,7 @@ func (l *layoutCache) Get(k layoutKey) (*Layout, bool) {
return nil, false
}
func (l *layoutCache) Put(k layoutKey, lt *Layout) {
func (l *layoutCache) Put(k layoutKey, lt []Line) {
if l.m == nil {
l.m = make(map[layoutKey]*layoutElem)
l.head = new(layoutElem)