diff --git a/font/opentype/opentype.go b/font/opentype/opentype.go index 27afea4b..568faee8 100644 --- a/font/opentype/opentype.go +++ b/font/opentype/opentype.go @@ -19,10 +19,10 @@ import ( "golang.org/x/image/math/fixed" ) -// Font implements text.Face. +// Font implements text.Face. It's methods are safe to use +// concurrently. type Font struct { font *sfnt.Font - buf sfnt.Buffer } // Collection is a collection of one or more fonts. @@ -90,16 +90,19 @@ func (f *Font) Layout(ppem fixed.Int26_6, maxWidth int, txt io.Reader) ([]text.L if err != nil { return nil, err } - return layoutText(&f.buf, ppem, maxWidth, &opentype{Font: f.font, Hinting: font.HintingFull}, glyphs) + var buf sfnt.Buffer + return layoutText(&buf, ppem, maxWidth, &opentype{Font: f.font, Hinting: font.HintingFull}, glyphs) } func (f *Font) Shape(ppem fixed.Int26_6, str []text.Glyph) op.CallOp { - return textPath(&f.buf, ppem, &opentype{Font: f.font, Hinting: font.HintingFull}, str) + var buf sfnt.Buffer + return textPath(&buf, ppem, &opentype{Font: f.font, Hinting: font.HintingFull}, str) } func (f *Font) Metrics(ppem fixed.Int26_6) font.Metrics { o := &opentype{Font: f.font, Hinting: font.HintingFull} - return o.Metrics(&f.buf, ppem) + var buf sfnt.Buffer + return o.Metrics(&buf, ppem) } func layoutText(sbuf *sfnt.Buffer, ppem fixed.Int26_6, maxWidth int, f *opentype, glyphs []text.Glyph) ([]text.Line, error) { diff --git a/text/text.go b/text/text.go index 3ec7d1f2..3601e367 100644 --- a/text/text.go +++ b/text/text.go @@ -45,7 +45,8 @@ type Font struct { Weight Weight } -// Face implements text layout and shaping for a particular font. +// Face implements text layout and shaping for a particular font. All +// methods must be safe for concurrent use. type Face interface { Layout(ppem fixed.Int26_6, maxWidth int, txt io.Reader) ([]Line, error) Shape(ppem fixed.Int26_6, str []Glyph) op.CallOp