628a97cd712e306c4748ed0ece977e7785e22421 — Elias Naur 14 days ago 5c3dcc6
ui/measure: document and export Face

Signed-off-by: Elias Naur <mail@eliasnaur.com>
1 files changed, 16 insertions(+), 8 deletions(-)

M ui/measure/measure.go
M ui/measure/measure.go => ui/measure/measure.go +16 -8
@@ 1,5 1,8 @@ // SPDX-License-Identifier: Unlicense OR MIT
  
+ /*
+ Package measure implements text layout and shaping.
+ */
  package measure
  
  import (


@@ 9,16 12,17 @@   	"gioui.org/ui"
  	"gioui.org/ui/f32"
- 	"gioui.org/ui/text"
  	"gioui.org/ui/paint"
+ 	"gioui.org/ui/text"
  	"golang.org/x/image/font"
  	"golang.org/x/image/font/sfnt"
  	"golang.org/x/image/math/fixed"
  )
  
+ // Faces is a cache of text layouts and paths.
  type Faces struct {
  	config      ui.Config
- 	faceCache   map[faceKey]*textFace
+ 	faceCache   map[faceKey]*Face
  	layoutCache map[layoutKey]cachedLayout
  	pathCache   map[pathKey]cachedPath
  }


@@ 51,12 55,15 @@ size ui.Value
  }
  
- type textFace struct {
+ // Face is a cached implementation of text.Face.
+ type Face struct {
  	faces *Faces
  	size  ui.Value
  	font  *opentype
  }
  
+ // Reset the cache, discarding any measures or paths that
+ // haven't been used since the last call to Reset.
  func (f *Faces) Reset(c ui.Config) {
  	f.config = c
  	f.init()


@@ 78,13 85,14 @@ }
  }
  
- func (f *Faces) For(fnt *sfnt.Font, size ui.Value) text.Face {
+ // For returns a Face for the given font and size.
+ func (f *Faces) For(fnt *sfnt.Font, size ui.Value) *Face {
  	f.init()
  	fk := faceKey{fnt, size}
  	if f, exist := f.faceCache[fk]; exist {
  		return f
  	}
- 	face := &textFace{
+ 	face := &Face{
  		faces: f,
  		size:  size,
  		font:  &opentype{Font: fnt, Hinting: font.HintingFull},


@@ 97,12 105,12 @@ if f.faceCache != nil {
  		return
  	}
- 	f.faceCache = make(map[faceKey]*textFace)
+ 	f.faceCache = make(map[faceKey]*Face)
  	f.pathCache = make(map[pathKey]cachedPath)
  	f.layoutCache = make(map[layoutKey]cachedLayout)
  }
  
- func (f *textFace) Layout(str string, opts text.LayoutOptions) *text.Layout {
+ func (f *Face) Layout(str string, opts text.LayoutOptions) *text.Layout {
  	ppem := fixed.Int26_6(f.faces.config.Px(f.size) * 64)
  	lk := layoutKey{
  		f:    f.font.Font,


@@ 120,7 128,7 @@ return l
  }
  
- func (f *textFace) Path(str text.String) ui.MacroOp {
+ func (f *Face) Path(str text.String) ui.MacroOp {
  	ppem := fixed.Int26_6(f.faces.config.Px(f.size) * 64)
  	pk := pathKey{
  		f:    f.font.Font,