9fans.net/go@v0.0.5/draw/memdraw/string.go (about) 1 // #include <u.h> 2 // #include <libc.h> 3 // #include <draw.h> 4 // #include <memdraw.h> 5 6 package memdraw 7 8 import ( 9 "unicode/utf8" 10 11 "9fans.net/go/draw" 12 ) 13 14 func memimagestring(b *Image, p draw.Point, color *Image, cp draw.Point, f *subfont, s []byte) draw.Point { 15 var width int 16 for ; len(s) > 0; func() { p.X += width; cp.X += width }() { 17 c := rune(s[0]) 18 width = 0 19 if c < utf8.RuneSelf { 20 s = s[1:] 21 } else { 22 var w int 23 c, w = utf8.DecodeRune(s) 24 s = s[w:] 25 } 26 if int(c) >= f.n { 27 continue 28 } 29 i := &f.info[c] 30 width = int(i.Width) 31 Draw(b, draw.Rect(p.X+int(i.Left), p.Y+int(i.Top), p.X+int(i.Left)+(f.info[c+1].X-i.X), p.Y+int(i.Bottom)), color, cp, f.bits, draw.Pt(i.X, int(i.Top)), draw.SoverD) 32 } 33 return p 34 } 35 36 func memsubfontwidth(f *subfont, s []byte) draw.Point { 37 p := draw.Pt(0, int(f.height)) 38 var width int 39 for ; len(s) > 0; p.X += width { 40 c := rune(s[0]) 41 width = 0 42 if c < utf8.RuneSelf { 43 s = s[1:] 44 } else { 45 var w int 46 c, w = utf8.DecodeRune(s) 47 s = s[w:] 48 } 49 if int(c) >= f.n { 50 continue 51 } 52 i := &f.info[c] 53 width = int(i.Width) 54 } 55 return p 56 }