mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-04 17:05:38 +00:00
text: simplify text layout and shaping API
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>
This commit is contained in:
+2
-10
@@ -6,7 +6,6 @@ import (
|
||||
"io"
|
||||
|
||||
"gioui.org/op"
|
||||
"gioui.org/unit"
|
||||
"golang.org/x/image/font"
|
||||
"golang.org/x/image/math/fixed"
|
||||
)
|
||||
@@ -32,23 +31,16 @@ type Glyph struct {
|
||||
Advance fixed.Int26_6
|
||||
}
|
||||
|
||||
// LayoutOptions specify the constraints of a text layout.
|
||||
type LayoutOptions struct {
|
||||
// MaxWidth is the available width of the layout.
|
||||
MaxWidth int
|
||||
}
|
||||
|
||||
// Style is the font style.
|
||||
type Style int
|
||||
|
||||
// Weight is a font weight, in CSS units.
|
||||
type Weight int
|
||||
|
||||
// Font specify a particular typeface, style and size.
|
||||
// Font specify a particular typeface variant, style and weight.
|
||||
type Font struct {
|
||||
Typeface Typeface
|
||||
Variant Variant
|
||||
Size unit.Value
|
||||
Style Style
|
||||
// Weight is the text weight. If zero, Normal is used instead.
|
||||
Weight Weight
|
||||
@@ -56,7 +48,7 @@ type Font struct {
|
||||
|
||||
// Face implements text layout and shaping for a particular font.
|
||||
type Face interface {
|
||||
Layout(ppem fixed.Int26_6, txt io.Reader, opts LayoutOptions) ([]Line, error)
|
||||
Layout(ppem fixed.Int26_6, maxWidth int, txt io.Reader) ([]Line, error)
|
||||
Shape(ppem fixed.Int26_6, str []Glyph) op.CallOp
|
||||
Metrics(ppem fixed.Int26_6) font.Metrics
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user