// FillString draws a filled and stroked string. func FillString(gc draw2d.GraphicContext, x, y, width, height float64) { sx, sy := width/100, height/100 gc.Save() gc.SetStrokeColor(image.Black) gc.SetLineWidth(1) draw2d.RoundRect(gc, x+sx*5, y+sy*5, x+sx*95, y+sy*95, sx*10, sy*10) gc.FillStroke() gc.SetFillColor(image.Black) gc.SetFontSize(height / 6) gc.Translate(x+sx*6, y+sy*52) gc.SetFontData(draw2d.FontData{ Name: "luxi", Family: draw2d.FontFamilyMono, Style: draw2d.FontStyleBold | draw2d.FontStyleItalic}) w := gc.FillString("Hug") gc.Translate(w+sx, 0) left, top, right, bottom := gc.GetStringBounds("cou") gc.SetStrokeColor(color.NRGBA{255, 0x33, 0x33, 0x80}) draw2d.Rect(gc, left, top, right, bottom) gc.SetLineWidth(height / 50) gc.Stroke() gc.SetFillColor(color.NRGBA{0x33, 0x33, 0xff, 0xff}) gc.SetStrokeColor(color.NRGBA{0x33, 0x33, 0xff, 0xff}) gc.SetLineWidth(height / 100) gc.StrokeString("Hug") gc.Restore() }
func (h *spaceFillingImage) drawText(gc draw2d.GraphicContext, px1, py1 float64, t int) { if !h.DrawText { return } text := strconv.Itoa(t) _, top, _, _ := gc.GetStringBounds(text) gc.SetFillColor(h.TextColor) gc.FillStringAt(text, px1+h.TextMargin, py1-top+h.TextMargin) }
func (ts *TextSymbolizer) Draw(gc draw2d.GraphicContext, shape geom.Shape) { if !ts.Applies(shape) { return } if name := shape.Attribute(ts.s.Attr); name != "" { gc.SetFontSize(ts.s.Size) l, t, r, b := gc.GetStringBounds(name) bb := shape.Bbox() dx := math.Abs(bb[2] - bb[0]) dy := math.Abs(bb[3] - bb[1]) ox, oy := dx/2, dy/2 x, y := ts.r.matrix.TransformPoint(bb[0]+ox, bb[1]-oy) gc.SetFillColor(ts.s.Fill) gc.FillStringAt(name, x-(r-l)/2, y-(t-b)/2) } }
// Draw "Hello World" func DrawHello(gc draw2d.GraphicContext, text string) { draw2d.SetFontFolder("static") gc.SetFontData(draw2d.FontData{ Name: "Roboto", }) gc.SetFontSize(14) l, t, r, b := gc.GetStringBounds(text) //log.Println(t, l, r, b) draw2dkit.Rectangle(gc, 0, 0, r-l+30, b-t+30) gc.SetFillColor(image.White) gc.FillStroke() draw2dkit.Rectangle(gc, 10, 10, r-l+20, b-t+20) gc.SetFillColor(image.White) gc.FillStroke() gc.SetFillColor(color.NRGBA{R: 255, G: 0, B: 0, A: 255}) gc.FillStringAt(text, 15-l, 15-t) }