A slice of FontFace pairs are simpler, and thread safe in case a client
wants to append or modify the font collection.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Before this change, package font implemented a global font registry,
with the usual problems of package global state.
This change deletes the global registry and introduces the text.Collection
type for representing a list of fonts and their faces. Collection exports
Lookup that finds the closest match and its face.
The existing FontRegistry is renamed to Cache to reflect its new limited
functionality: a cache of shapes and measurements on top of a Collection.
Then, material.NewTheme is changed to take a Collection and initialize
a Cache.
Updates gio#19 because multiple windows require a separate (writable) Cache per
window, while (read-only) Collections may be shared.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Converting
macro := op.Record(ops)
...
macro.Stop()
macro.Add()
to
macro := op.Record(ops)
...
call := macro.Stop()
call.Add(ops)
Which is more general (call.Add can take a different ops than the op.Record
that started it), and enforced the order between Stop and the subsequent Add.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
First, replace LayoutOptions with an explicit maximum width parameter. The
single-field option struct doesn't carry its weight, and I don't think we'll
see more global layout options in the future. Rather, I expect options to cover
spans of text or be part of a Font.
Second, replace the unit.Converter with an scaled text size. It's simpler and
allow the Editor and similar widgets to easily detect whether their cached
layouts are stale. Package text no longer depends on package unit, which is
now dealt with at the widget-level only.
Finally, remove the Size field from Font. It was a design mistake: a Font is
assumed to cover all sizes, as evidenced by the FontRegistry disregarding
Size when looking up fonts.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
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>
MacroOp is about to lose the ability to run a different operation list
than the one it was recorded on. Text shape caches rely on that property,
and must use the new CallOp operation added for purpose.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Registering the font as a side effect of importing the gofont package
was too magic. Require an explicit Register call instead. As a side
effect, it is more clear which font is the default (the first one
registered).
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Opentype parsing, layout and shaping will be used by subpackages to package
font. Move the opentype package accordingly.
Remove the Must helper function; programs will no longer use the opentype
package in the normal case.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Package font holds a singleton text.Shaper for general use. Subpackages
call Register to add fonts to the registry.
The intention is that programs can add a typeface by importing a package:
import _ "gioui.org/font/gofont"
Signed-off-by: Elias Naur <mail@eliasnaur.com>