當前位置: 首頁>>代碼示例>>Golang>>正文


Golang freetype.Pt函數代碼示例

本文整理匯總了Golang中code/google/com/p/freetype-go/freetype.Pt函數的典型用法代碼示例。如果您正苦於以下問題:Golang Pt函數的具體用法?Golang Pt怎麽用?Golang Pt使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Pt函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: main

func main() {
	flag.Parse()

	font, err := loadFont()
	if err != nil {
		log.Println(err)
		return
	}

	fontHeight := int(createContext(font).PointToFix32(*size) >> 8)
	// two points to output the text and its shadow
	ptA := freetype.Pt(*indent+1, *indent+1+fontHeight)
	ptB := freetype.Pt(*indent, *indent+fontHeight)

	proxy := goproxy.NewProxyHttpServer()
	proxy.OnResponse().Do(goproxy_image.HandleImage(func(img image.Image, ctx *goproxy.ProxyCtx) image.Image {
		outImage := image.NewRGBA(img.Bounds())
		draw.Copy(outImage, image.ZP, img, img.Bounds(), nil)
		text := fmt.Sprintf("%dx%d", img.Bounds().Dx(), img.Bounds().Dy())
		fontContext := createContext(font)
		fontContext.SetClip(img.Bounds())
		fontContext.SetDst(outImage)

		drawString(image.White, fontContext, ptA, text)
		drawString(image.Black, fontContext, ptB, text)

		return outImage
	}))
	proxy.Verbose = *verbose
	log.Fatal(http.ListenAndServe(":"+*port, proxy))
}
開發者ID:vchervanev,項目名稱:img-debug-proxy,代碼行數:31,代碼來源:img_debug_proxy.go

示例2: makeImage

func makeImage(req *http.Request, caption, font string, pt, size, border, scale int, f func(x, y int) uint32) *image.RGBA {
	d := (size + 2*border) * scale
	csize := 0
	if caption != "" {
		if pt == 0 {
			pt = 11
		}
		csize = pt * 2
	}
	c := image.NewRGBA(image.Rect(0, 0, d, d+csize))

	// white
	u := &image.Uniform{C: color.White}
	draw.Draw(c, c.Bounds(), u, image.ZP, draw.Src)

	for y := 0; y < size; y++ {
		for x := 0; x < size; x++ {
			r := image.Rect((x+border)*scale, (y+border)*scale, (x+border+1)*scale, (y+border+1)*scale)
			rgba := f(x, y)
			u.C = color.RGBA{byte(rgba >> 24), byte(rgba >> 16), byte(rgba >> 8), byte(rgba)}
			draw.Draw(c, r, u, image.ZP, draw.Src)
		}
	}

	if csize != 0 {
		if font == "" {
			font = "data/luxisr.ttf"
		}
		ctxt := fs.NewContext(req)
		dat, _, err := ctxt.Read(font)
		if err != nil {
			panic(err)
		}
		tfont, err := freetype.ParseFont(dat)
		if err != nil {
			panic(err)
		}
		ft := freetype.NewContext()
		ft.SetDst(c)
		ft.SetDPI(100)
		ft.SetFont(tfont)
		ft.SetFontSize(float64(pt))
		ft.SetSrc(image.NewUniform(color.Black))
		ft.SetClip(image.Rect(0, 0, 0, 0))
		wid, err := ft.DrawString(caption, freetype.Pt(0, 0))
		if err != nil {
			panic(err)
		}
		p := freetype.Pt(d, d+3*pt/2)
		p.X -= wid.X
		p.X /= 2
		ft.SetClip(c.Bounds())
		ft.DrawString(caption, p)
	}

	return c
}
開發者ID:amrhassan,項目名稱:rsc,代碼行數:57,代碼來源:pic.go

示例3: nosuchtile

func nosuchtile(v ...interface{}) []byte {
	im := image.NewRGBA(image.Rect(0, 0, tilesize, tilesize))
	col := color.RGBA{255, 0, 0, 255}
	for i := 0; i < tilesize; i++ {
		im.Set(i, 0, col)
		im.Set(i, tilesize-1, col)
		im.Set(0, i, col)
		im.Set(tilesize-1, i, col)
	}
	ctx := freetype.NewContext()
	ctx.SetDPI(72)
	ctx.SetFont(nstfont)
	ctx.SetFontSize(16)
	ctx.SetClip(im.Bounds())
	ctx.SetDst(im)
	ctx.SetSrc(image.Black)
	for i, n := range v {
		_, err := ctx.DrawString(fmt.Sprint(n), freetype.Pt(30, 30+i*20))
		if err != nil {
			fmt.Println(err)
		}
	}
	var buf bytes.Buffer
	err := png.Encode(&buf, im)
	if err != nil {
		fmt.Println(err)
	}
	return buf.Bytes()
}
開發者ID:tajtiattila,項目名稱:go-mbtiles,代碼行數:29,代碼來源:tile.go

示例4: DrawInfoBox

func (a *Annotator) DrawInfoBox() error {

	tStart, tEnd := a.table.TimeStart, a.table.TimeEnd
	// tDuration := humanize.RelTime(*tStart, *tEnd, "", "")
	tPixel := (tEnd.Unix() - tStart.Unix()) / int64(a.table.Integrations)

	fStart, fEnd := a.table.HzLow, a.table.HzHigh
	fBandwidth := fEnd - fStart
	fPixel := fBandwidth / float64(a.table.Bins)

	perPixel := fmt.Sprintf("%s x %d seconds", a.humanHz(fPixel), tPixel)

	// positioning
	imgSize := a.table.Image().Bounds().Size()
	top, left := imgSize.Y-75, 3

	strings := []string{
		"Scan start: " + tStart.String(),
		"Scan end: " + tEnd.String(),
		// "Scan duration: " + tDuration,
		fmt.Sprintf("Band: %s to %s", a.humanHz(fStart), a.humanHz(fEnd)),
		fmt.Sprintf("Bandwidth: %s", a.humanHz(fBandwidth)),
		"1 pixel = " + perPixel,
	}

	// drawing
	pt := freetype.Pt(left, top)
	for _, s := range strings {
		_, _ = a.context.DrawString(s, pt)
		pt.Y += a.context.PointToFix32(size * spacing)
	}

	return nil
}
開發者ID:shmick,項目名稱:rtl-gopow,代碼行數:34,代碼來源:annotater.go

示例5: DrawText

// Color in HEX format: FAFAFA
func (g *Gummy) DrawText(text, textColor string, fontSize, xPosition, yPosition int) error {

	// Get black or white depending on the background
	if textColor == "" {
		c := (*g.Color).(color.RGBA)
		if blackWithBackground(float64(c.R), float64(c.G), float64(c.B)) {
			textColor = "000000"
		} else {
			textColor = "FFFFFF"
		}
	}

	fc := freetype.NewContext()
	fc.SetDst(g.Img)
	fc.SetFont(g.Font)
	fc.SetClip(g.Img.Bounds())

	// Color parsing
	cr, _ := strconv.ParseUint(string(textColor[:2]), 16, 64)
	cg, _ := strconv.ParseUint(string(textColor[2:4]), 16, 64)
	cb, _ := strconv.ParseUint(string(textColor[4:]), 16, 64)
	c := image.NewUniform(color.RGBA{R: uint8(cr), G: uint8(cg), B: uint8(cb), A: 255})

	fc.SetSrc(c)
	fc.SetFontSize(float64(fontSize))

	_, err := fc.DrawString(text, freetype.Pt(xPosition, yPosition))

	return err
}
開發者ID:slok,項目名稱:gummyimage,代碼行數:31,代碼來源:imageutils.go

示例6: FillString

func (gc *ImageGraphicContext) FillString(text string) (cursor float64) {
	gc.freetype.SetSrc(image.NewUniform(gc.Current.StrokeColor))
	// Draw the text.
	x, y := gc.Current.Path.LastPoint()
	gc.Current.Tr.Transform(&x, &y)
	x0, fontSize := 0.0, gc.Current.FontSize
	gc.Current.Tr.VectorTransform(&x0, &fontSize)
	font := GetFont(gc.Current.FontData)
	if font == nil {
		font = GetFont(defaultFontData)
	}
	if font == nil {
		return 0
	}
	gc.freetype.SetFont(font)
	gc.freetype.SetFontSize(fontSize)
	pt := freetype.Pt(int(x), int(y))
	p, err := gc.freetype.DrawString(text, pt)
	if err != nil {
		log.Println(err)
	}
	x1, _ := gc.Current.Path.LastPoint()
	x2, y2 := float64(p.X)/256, float64(p.Y)/256
	gc.Current.Tr.InverseTransform(&x2, &y2)
	width := x2 - x1
	return width
}
開發者ID:zqc115322536,項目名稱:draw2d.newdraw2d,代碼行數:27,代碼來源:image.go

示例7: drawStringImage

// 畫一個帶有text的圖片
func (this *Signer) drawStringImage(text string) (image.Image, error) {
	fg, bg := image.Black, image.Transparent
	rgba := image.NewRGBA(image.Rect(0, 0, this.signPoint.X, this.signPoint.Y))
	draw.Draw(rgba, rgba.Bounds(), bg, image.ZP, draw.Src)

	c := freetype.NewContext()
	c.SetDPI(this.Dpi)
	c.SetFont(this.font)
	c.SetFontSize(this.FontSize)
	c.SetClip(rgba.Bounds())
	c.SetDst(rgba)
	c.SetSrc(fg)

	// Draw the text.
	pt := freetype.Pt(10, 10+int(c.PointToFix32(12)>>8))
	for _, s := range strings.Split(text, "\r\n") {
		_, err := c.DrawString(s, pt)
		if err != nil {
			glog.Errorf("c.DrawString(%s) error(%v)", s, err)
			return nil, err
		}
		pt.Y += c.PointToFix32(12 * 1.5)
	}

	// fff, _ := os.Create("aaa.png")
	// defer fff.Close()
	// png.Encode(fff, rgba)

	return rgba, nil
}
開發者ID:jShi-git,項目名稱:go-demos,代碼行數:31,代碼來源:signer.go

示例8: GenerateCaptcha

/*
生成驗證碼
bg:背景色
fg:前景色
length:字符長度
width:寬度
height:高度
size:字體大小
fontPath:字體文件路徑
*/
func GenerateCaptcha(bg, fg *image.Uniform, length int, width int, height int, size float64, fontPath string) *Captcha {
	fontBytes, err := ioutil.ReadFile(fontPath)
	if err != nil {
		panic(err)
	}
	font, err := truetype.Parse(fontBytes)

	if err != nil {
		panic(err)
	}
	cap := &Captcha{}
	cap.Text = randString(length)
	cap.Image = image.NewRGBA(image.Rect(0, 0, width, height))
	draw.Draw(cap.Image, cap.Image.Bounds(), bg, image.ZP, draw.Src)
	c := freetype.NewContext()
	c.SetFont(font)
	c.SetFontSize(size)
	c.SetClip(cap.Image.Bounds())
	c.SetDst(cap.Image)
	c.SetSrc(fg)
	pt := freetype.Pt(0, int(c.PointToFix32(size)>>8))
	for _, s := range cap.Text {
		_, err = c.DrawString(string(s), pt)
		if err != nil {
			panic(err)
			return nil
		}
		pt.X += c.PointToFix32(size * 0.5)
	}
	return cap
}
開發者ID:jango2015,項目名稱:entropy,代碼行數:41,代碼來源:captcha.go

示例9: drawStringImage

// 畫一個帶有text的圖片
func drawStringImage(text string, fontFile string) image.Image {
	fontBytes, err := ioutil.ReadFile(fontFile)
	if err != nil {
		log.Fatalln(err)
	}

	font, err := freetype.ParseFont(fontBytes)
	if err != nil {
		log.Fatalln(err)
	}

	fg, bg := image.Black, image.White
	rgba := image.NewRGBA(image.Rect(0, 0, 640, 480))
	draw.Draw(rgba, rgba.Bounds(), bg, image.ZP, draw.Src)

	c := freetype.NewContext()
	c.SetDPI(72)
	c.SetFont(font)
	c.SetFontSize(12)
	c.SetClip(rgba.Bounds())
	c.SetDst(rgba)
	c.SetSrc(fg)

	// Draw the text.
	pt := freetype.Pt(10, 10+int(c.PointToFix32(12)>>8))
	for _, s := range strings.Split(text, "\r\n") {
		_, err = c.DrawString(s, pt)
		pt.Y += c.PointToFix32(12 * 1.5)
	}

	return rgba
}
開發者ID:jianfengye,項目名稱:GO_Works,代碼行數:33,代碼來源:main.go

示例10: textBox

// textBox renders t into a tight fitting image
func (ig *ImageGraphics) textBox(t string, size int) image.Image {
	// Initialize the context.
	fg := image.NewUniform(color.Alpha{0xff})
	bg := image.NewUniform(color.Alpha{0x00})
	canvas := image.NewAlpha(image.Rect(0, 0, 400, 2*size))
	draw.Draw(canvas, canvas.Bounds(), bg, image.ZP, draw.Src)

	c := freetype.NewContext()
	c.SetDPI(dpi)
	c.SetFont(ig.font)
	c.SetFontSize(float64(size))
	c.SetClip(canvas.Bounds())
	c.SetDst(canvas)
	c.SetSrc(fg)

	// Draw the text.
	h := c.FUnitToPixelRU(ig.font.UnitsPerEm())
	pt := freetype.Pt(0, h)
	extent, err := c.DrawString(t, pt)
	if err != nil {
		log.Println(err)
		return nil
	}
	// log.Printf("text %q, extent: %v", t, extent)
	return canvas.SubImage(image.Rect(0, 0, int(extent.X/256), h*5/4))
}
開發者ID:ajstarks,項目名稱:chart,代碼行數:27,代碼來源:image.go

示例11: textBox

// textBox renders t into a tight fitting image
func (ig *ImageGraphics) textBox(t string, font chart.Font) image.Image {
	// Initialize the context.
	fg := image.NewUniform(color.Alpha{0xff})
	bg := image.NewUniform(color.Alpha{0x00})
	width := ig.TextLen(t, font)
	size := ig.relFontsizeToPixel(font.Size)
	canvas := image.NewAlpha(image.Rect(0, 0, width, int(1.5*size+0.5)))
	draw.Draw(canvas, canvas.Bounds(), bg, image.ZP, draw.Src)

	c := freetype.NewContext()
	c.SetDPI(dpi)
	c.SetFont(ig.font)
	c.SetFontSize(size)
	c.SetClip(canvas.Bounds())
	c.SetDst(canvas)
	c.SetSrc(fg)

	// Draw the text.
	h := c.FUnitToPixelRU(ig.font.UnitsPerEm())
	pt := freetype.Pt(0, h)
	extent, err := c.DrawString(t, pt)
	if err != nil {
		log.Println(err)
		return nil
	}
	// log.Printf("text %q, extent: %v", t, extent)
	return canvas.SubImage(image.Rect(0, 0, int((extent.X+127)/256), h*5/4))
}
開發者ID:JessonChan,項目名稱:go-chart,代碼行數:29,代碼來源:image.go

示例12: TextToImage

func (q *Quote) TextToImage() *image.RGBA {
	spacing := 1.5
	var fontsize float64 = 8

	// read font
	fontBytes, err := ioutil.ReadFile(os.Getenv("FONT_FILE"))
	checkErr(err)
	font, err := freetype.ParseFont(fontBytes)
	checkErr(err)

	// Initialize the context.
	fg, bg := image.White, image.Transparent

	// 755px by 378px is the size Vox uses
	rgba := image.NewRGBA(image.Rect(0, 0, 755, 378))
	draw.Draw(rgba, rgba.Bounds(), bg, image.ZP, draw.Src)
	c := freetype.NewContext()
	c.SetDPI(300)
	c.SetFont(font)
	c.SetFontSize(fontsize)
	c.SetClip(rgba.Bounds())
	c.SetDst(rgba)
	c.SetSrc(fg)

	// Draw the text
	pt := freetype.Pt(50, 50+int(c.PointToFix32(fontsize)>>8))
	lines := strings.Split(q.Text, "\n")
	for _, s := range lines {
		_, err = c.DrawString(s, pt)
		checkErr(err)
		pt.Y += c.PointToFix32(fontsize * spacing)
	}

	return rgba
}
開發者ID:kleitz,項目名稱:quotable,代碼行數:35,代碼來源:quote.go

示例13: generateAtlas

func generateAtlas(font *truetype.Font, scale int32, dpi float64, width, height float32) ([]Vector4, *image.RGBA, []float32) {
	var low rune = 32
	var high rune = 127
	glyphCount := int32(high - low + 1)
	offsets := make([]float32, glyphCount)

	bounds := font.Bounds(scale)
	gw := float32(bounds.XMax - bounds.XMin)
	gh := float32(bounds.YMax - bounds.YMin)
	imageWidth := glh.Pow2(uint32(gw * float32(glyphCount)))
	imageHeight := glh.Pow2(uint32(gh))
	imageBounds := image.Rect(0, 0, int(imageWidth), int(imageHeight))
	sx := float32(2) / width
	sy := float32(2) / height
	w := gw * sx
	h := gh * sy
	img := image.NewRGBA(imageBounds)
	c := freetype.NewContext()
	c.SetDst(img)
	c.SetClip(img.Bounds())
	c.SetSrc(image.White)
	c.SetDPI(dpi)
	c.SetFontSize(float64(scale))
	c.SetFont(font)

	var gi int32
	var gx, gy float32
	verts := make([]Vector4, 0)
	texWidth := float32(img.Bounds().Dx())
	texHeight := float32(img.Bounds().Dy())

	for ch := low; ch <= high; ch++ {
		index := font.Index(ch)
		metric := font.HMetric(scale, index)

		//the offset is used when drawing a string of glyphs - we will advance a glyph's quad by the width of all previous glyphs in the string
		offsets[gi] = float32(metric.AdvanceWidth) * sx

		//draw the glyph into the atlas at the correct location
		pt := freetype.Pt(int(gx), int(gy)+int(c.PointToFix32(float64(scale))>>8))
		c.DrawString(string(ch), pt)

		tx1 := gx / texWidth
		ty1 := gy / texHeight
		tx2 := (gx + gw) / texWidth
		ty2 := (gy + gh) / texHeight

		//the x,y coordinates are the same for each quad; only the texture coordinates (stored in z,w) change.
		//an optimization would be to only store texture coords, but I haven't figured that out yet
		verts = append(verts, Vector4{-1, 1, tx1, ty1},
			Vector4{-1 + (w), 1, tx2, ty1},
			Vector4{-1, 1 - (h), tx1, ty2},
			Vector4{-1 + (w), 1 - (h), tx2, ty2})

		gx += gw
		gi++
	}
	return verts, img, offsets
}
開發者ID:jimarnold,項目名稱:gltext,代碼行數:59,代碼來源:font.go

示例14: renderString

func renderString(s string, c *freetype.Context) (*image.RGBA, int) {
	estWidth := 8 * len(s)
	dst := image.NewRGBA(image.Rect(0, 0, estWidth, h))

	c.SetDst(dst)
	c.SetClip(dst.Bounds())

	c.SetSrc(&image.Uniform{C: shadow})
	pt := freetype.Pt(0, 13)
	c.DrawString(s, pt)

	c.SetSrc(image.White)

	pt = freetype.Pt(0, 12)
	pt, _ = c.DrawString(s, pt)

	return dst, getTextOffset(pt)
}
開發者ID:jorik041,項目名稱:buckler,代碼行數:18,代碼來源:png.go

示例15: drawBorderedText

func drawBorderedText(c *freetype.Context, text string, x, y int) {
	// God-awful hack to add a 2px black border around the text.
	c.SetSrc(image.Black)
	c.DrawString(text, freetype.Pt(x-2, y-2))
	c.DrawString(text, freetype.Pt(x, y-2))
	c.DrawString(text, freetype.Pt(x+2, y-2))
	c.DrawString(text, freetype.Pt(x-2, y))
	c.DrawString(text, freetype.Pt(x+2, y))
	c.DrawString(text, freetype.Pt(x-2, y+2))
	c.DrawString(text, freetype.Pt(x, y+2))
	c.DrawString(text, freetype.Pt(x+2, y+2))

	c.SetSrc(image.White)
	c.DrawString(text, freetype.Pt(x, y))
}
開發者ID:joelgwebber,項目名稱:memething,代碼行數:15,代碼來源:memething.go


注:本文中的code/google/com/p/freetype-go/freetype.Pt函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。