github.com/andybalholm/giopdf@v0.0.0-20220317170119-aad9a095ad48/text.go (about) 1 package giopdf 2 3 import ( 4 "gioui.org/f32" 5 ) 6 7 // BeginText starts a text object, setting the text matrix and text line matrix 8 // to the identity matrix. 9 func (c *Canvas) BeginText() { 10 c.SetTextMatrix(1, 0, 0, 1, 0, 0) 11 } 12 13 // EndText ends a text object. 14 func (c *Canvas) EndText() { 15 16 } 17 18 // ShowText displays a string of text. 19 func (c *Canvas) ShowText(s string) { 20 glyphs := c.font.ToGlyphs(s) 21 vSize := c.fontSize 22 hSize := c.fontSize * c.hScale / 100 23 sizeMatrix := f32.NewAffine2D(hSize, 0, 0, 0, vSize, 0) 24 for _, g := range glyphs { 25 glyphSpace := c.textMatrix.Mul(sizeMatrix) 26 c.Path = append(c.Path, transformPath(g.Outlines, glyphSpace)...) 27 // TODO: clipping 28 switch c.textRenderingMode { 29 case 0, 4: 30 c.Fill() 31 case 1, 5: 32 c.Stroke() 33 case 2, 6: 34 c.FillAndStroke() 35 case 3, 7: 36 // Invisible 37 } 38 c.textMatrix = c.textMatrix.Offset(f32.Pt(g.Width*hSize, 0)) 39 } 40 } 41 42 // Kern moves the next text character to the left the specified amount. 43 // The distance is in units of 1/1000 of an em. 44 func (c *Canvas) Kern(amount float32) { 45 distance := c.fontSize * c.hScale / 100 * amount / 1000 46 c.textMatrix = c.textMatrix.Offset(f32.Pt(-distance, 0)) 47 }