Esempio n. 1
0
func TestFillString() {
	draw2d.SetFontFolder("../resource/font/")
	i, gc := initGc(100, 100)
	draw2d.RoundRect(gc, 5, 5, 95, 95, 10, 10)
	gc.FillStroke()
	gc.SetFontSize(18)
	gc.MoveTo(10, 52)
	gc.SetFontData(draw2d.FontData{"luxi", draw2d.FontFamilyMono, draw2d.FontStyleBold | draw2d.FontStyleItalic})
	width := gc.FillString("cou")
	gc.RMoveTo(width+1, 0)
	gc.FillString("cou")
	saveToPngFile("TestFillString", i)
}
func main() {
	var file *os.File
	var outFile *os.File
	var img image.Image
	var err error

	if file, err = os.Open("pkg.png"); err != nil {
		println("Error", err)
		return
	}
	defer file.Close()

	if img, err = png.Decode(file); err != nil {
		println("Error", err)
		return
	}

	// 描画の前にフォントのディレクトリを設定しておく。
	// フォント名はルールに従って
	draw2d.SetFontFolder("font/")
	//	draw2d.SetFontFolder("/System/Library/Fonts/")
	i := image.NewRGBA(img.Bounds())
	gc := draw2d.NewGraphicContext(i)

	// 画像のコピーをしようと思ったら、DrawImage()を呼び出して、元の画像を描画させる?
	gc.DrawImage(img)

	// 任意の線を描画
	gc.MoveTo(60.0, 10.0)
	gc.LineTo(60.0, 20.0)
	gc.MoveTo(65.0, 10.0)
	gc.LineTo(65.0, 20.0)
	gc.MoveTo(58.0, 13.0)
	gc.LineTo(68.0, 13.0)
	gc.MoveTo(58.0, 16.0)
	gc.LineTo(68.0, 16.0)
	gc.Stroke()
	gc.StrokeStringAt("golang", 70, 10)
	//    gc.FillStringAt("golang", 70, 10)

	if outFile, err = os.Create("out_write_pkg.png"); err != nil {
		println("Error", err)
		return
	}
	defer outFile.Close()

	if err = png.Encode(outFile, i); err != nil {
		println("Error", err)
		return
	}
}
Esempio n. 3
0
func TestFillString() {
	draw2d.SetFontFolder("../resource/font/")
	i, gc := initGc(100, 100)
	draw2d.RoundRect(gc, 5, 5, 95, 95, 10, 10)
	gc.FillStroke()
	gc.SetFillColor(image.Black)
	gc.SetFontSize(18)
	gc.Translate(6, 52)
	gc.SetFontData(draw2d.FontData{"luxi", draw2d.FontFamilyMono, draw2d.FontStyleBold | draw2d.FontStyleItalic})
	width := gc.FillString("cou")
	gc.Translate(width+1, 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(3.0)
	gc.Stroke()
	gc.SetStrokeColor(image.Black)
	gc.SetLineWidth(1.0)
	gc.StrokeString("cou")
	saveToPngFile("TestFillString", i)
}