当前位置: 首页>>代码示例>>Golang>>正文


Golang freetype.Pt函数代码示例

本文整理汇总了Golang中github.com/golang/freetype.Pt函数的典型用法代码示例。如果您正苦于以下问题:Golang Pt函数的具体用法?Golang Pt怎么用?Golang Pt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Pt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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:lucmichalski,项目名称:qr-server,代码行数:57,代码来源:pic.go

示例2: CenterX

// CenterX returns the Point at which string s will be centered within rect r
// along the X coordinate when passed to c.DrawString. The Y coordinate will be 0.
// Clip is set to r before returning.
func CenterX(c *freetype.Context, s string, r image.Rectangle) (fixed.Point26_6, error) {
	w, err := DrawWidth(c, s)
	c.SetClip(r)
	if err != nil {
		return fixed.Point26_6{}, err
	}
	half := Int26_6(0.5)
	xmin := freetype.Pt(r.Min.X, 0)
	return freetype.Pt(r.Dx(), 0).Mul(half).Sub(w.Mul(half)).Add(xmin), nil
}
开发者ID:infogulch,项目名称:fontutil,代码行数:13,代码来源:util.go

示例3: Render

func (f *Font) Render(text string) *Texture {
	width, height, yBearing := f.TextDimensions(text)
	font := f.ttf
	size := f.Size

	// Colors
	fg := image.NewUniform(color.NRGBA{f.FG.R, f.FG.G, f.FG.B, f.FG.A})
	bg := image.NewUniform(color.NRGBA{f.BG.R, f.BG.G, f.BG.B, f.BG.A})

	// Create the font context
	c := freetype.NewContext()

	nrgba := image.NewNRGBA(image.Rect(0, 0, width, height))
	draw.Draw(nrgba, nrgba.Bounds(), bg, image.ZP, draw.Src)

	c.SetDPI(dpi)
	c.SetFont(font)
	c.SetFontSize(size)
	c.SetClip(nrgba.Bounds())
	c.SetDst(nrgba)
	c.SetSrc(fg)

	// Draw the text.
	pt := freetype.Pt(0, int(yBearing))
	_, err := c.DrawString(text, pt)
	if err != nil {
		log.Println(err)
		return nil
	}

	// Create texture
	imObj := &ImageObject{nrgba}
	return NewTexture(imObj)

}
开发者ID:Kunde21,项目名称:engi,代码行数:35,代码来源:font.go

示例4: updateTexture

func (font *Font) updateTexture(texture uint32, text string, width int, height int, size float64, dpi float64, rgba color.Color) (int, int) {
	context := freetype.NewContext()
	context.SetFont(font.ttf)

	img := image.NewRGBA(image.Rect(0, 0, width, height))
	r, g, b, _ := rgba.RGBA()
	draw.Draw(img, img.Bounds(), image.NewUniform(color.RGBA{uint8(r), uint8(g), uint8(b), 0}), image.ZP, draw.Src)

	context.SetDst(img)
	context.SetClip(img.Bounds())
	context.SetSrc(image.NewUniform(rgba))
	context.SetFontSize(size)
	context.SetDPI(dpi)
	pixelBounds, _ := context.DrawString(text, freetype.Pt(0, height/2))

	gl.ActiveTexture(gl.TEXTURE0)
	gl.BindTexture(gl.TEXTURE_2D, texture)

	gl.TexSubImage2D(
		gl.TEXTURE_2D,
		0,
		0,
		0,
		int32(img.Rect.Size().X),
		int32(img.Rect.Size().Y),
		gl.RGBA,
		gl.UNSIGNED_BYTE,
		gl.Ptr(img.Pix))

	return int26_6Ceiling(pixelBounds.X + 0x3f), int26_6Ceiling(pixelBounds.Y + 0x3f)
}
开发者ID:anthonyrego,项目名称:gosmf,代码行数:31,代码来源:font.go

示例5: drawStringImage

func (this *Signer) drawStringImage(text string) (image.Image, error) {
	fontBytes, err := ioutil.ReadFile(this.fontPath)
	if err != nil {
		fmt.Println(err)
	}

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

	rgba := image.NewRGBA(image.Rect(0, 0, 900, 900))

	draw.Draw(rgba, rgba.Bounds(), image.Black, image.ZP, draw.Src)
	c := freetype.NewContext()
	c.SetDPI(this.dpi)
	c.SetFontSize(this.fontSize)
	c.SetClip(rgba.Bounds())
	c.SetDst(rgba)
	c.SetSrc(image.White)
	c.SetFont(font)

	pt := freetype.Pt(100, 100+int(c.PointToFixed(this.fontSize)>>8))
	for _, s := range strings.Split(text, "\r\n") {
		_, err = c.DrawString(s, pt)
		pt.Y += c.PointToFixed(12 * 1.5)

	}

	return rgba, nil

}
开发者ID:madong-fun,项目名称:golang-study,代码行数:32,代码来源:drawImage.go

示例6: drawBarcode

func drawBarcode(img *image.Gray, unitSize, xPos, yPos float64, num int) {
	drawSO(img, unitSize, xPos, yPos)
	x := xPos + unitSize*4.0

	// Draw reference bar
	x += drawBar(img, unitSize, x, yPos, 0) + unitSize

	// Print the form number below the barcode
	ftContext.SetFontSize(7)
	ftContext.SetSrc(image.NewUniform(color.Black))
	ftContext.DrawString(fmt.Sprintf("%d", num), freetype.Pt(int(x), int(yPos+unitSize*7)))

	// Draw bars
	ds := toBase4(num, 9)
	for i := len(ds) - 1; i >= 0; i-- {
		x += drawBar(img, unitSize, x, yPos, ds[i]) + unitSize
	}

	// Draw checksum bars
	ckBase10 := csumGen(num)
	fmt.Println("ckBase10 = ", ckBase10)
	ck := toBase4(ckBase10, 2)
	fmt.Println("ck = ", ck)
	for i := len(ck) - 1; i >= 0; i-- {
		x += drawBar(img, unitSize, x, yPos, ck[i]) + unitSize
	}

}
开发者ID:GradeDeck,项目名称:gdformgen,代码行数:28,代码来源:main.go

示例7: Example

func Example() {
	// As usual in examples, this ignores all errors. Don't do this in your program.

	// setup and find start point for centering
	s := "Hello, World!"
	size := image.Rect(0, 0, 120, 20)
	dst := image.NewRGBA(size)
	c := freetype.NewContext()
	c.SetFont(font)
	c.SetFontSize(14.0)
	c.SetSrc(image.NewUniform(color.Black))
	c.SetDst(dst)
	start, _ := fontutil.CenterX(c, s, size) // CenterX calls c.SetClip(size)

	// perform draw at start.X + y 16
	c.DrawString(s, start.Add(freetype.Pt(0, 16)))

	// write the image out to a file
	// out, _ := os.Create("helloworld.png")
	// defer out.Close()

	// write image to hash for testing purposes
	out := fnv.New64()
	_ = png.Encode(out, dst)
	fmt.Printf("Hash of compressed image: %x", out.Sum64())
	// Output: Hash of compressed image: fa83a1b8d8abf5f2
}
开发者ID:infogulch,项目名称:fontutil,代码行数:27,代码来源:example_test.go

示例8: GetImage

func (ff *FontFace) GetImage(text string) (img draw.Image, err error) {
	var (
		src image.Image
		bg  image.Image
		dst draw.Image
		pt  fixed.Point26_6
		w   int
		h   int
	)
	src = image.NewUniform(ff.fg)
	bg = image.NewUniform(ff.bg)
	w = int(float32(len(text)) * ff.charw)
	h = int(ff.charh)
	dst = image.NewRGBA(image.Rect(0, 0, w, h))
	draw.Draw(dst, dst.Bounds(), bg, image.ZP, draw.Src)
	ff.context.SetSrc(src)
	ff.context.SetDst(dst)
	ff.context.SetClip(dst.Bounds())
	pt = freetype.Pt(0, int(ff.charh+ff.offy))
	if pt, err = ff.context.DrawString(text, pt); err != nil {
		return
	}
	img = image.NewRGBA(image.Rect(0, 0, int(pt.X/64), int(pt.Y/64)))
	draw.Draw(img, img.Bounds(), dst, image.Pt(0, -int(ff.offy)), draw.Src)
	return
}
开发者ID:kurrik,项目名称:opengl-benchmarks,代码行数:26,代码来源:fontface.go

示例9: 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.PointToFixed(size * spacing)
	}

	return nil
}
开发者ID:dhogborg,项目名称:rtl-gopow,代码行数:34,代码来源:annotater.go

示例10: GetText

func (ff *FontFace) GetText(text string) (t *Texture, err error) {
	var (
		src       image.Image
		bg        image.Image
		dst       draw.Image
		shortened draw.Image
		pt        fixed.Point26_6
		w         int
		h         int
	)
	src = image.NewUniform(ff.fg)
	bg = image.NewUniform(ff.bg)
	w = int(float32(len(text)) * ff.charw)
	h = int(ff.charh)
	dst = image.NewRGBA(image.Rect(0, 0, w, h))
	draw.Draw(dst, dst.Bounds(), bg, image.ZP, draw.Src)
	ff.context.SetSrc(src)
	ff.context.SetDst(dst)
	ff.context.SetClip(dst.Bounds())
	pt = freetype.Pt(0, int(ff.charh))
	if pt, err = ff.context.DrawString(text, pt); err != nil {
		return
	}
	// if err = WritePNG("hello.png", dst); err != nil {
	// 	return
	// }
	shortened = image.NewRGBA(image.Rect(0, 0, int(pt.X/64), h))
	draw.Draw(shortened, shortened.Bounds(), dst, image.ZP, draw.Src)
	t, err = GetTexture(shortened, gl.NEAREST)
	return
}
开发者ID:pikkpoiss,项目名称:twodee,代码行数:31,代码来源:text.go

示例11: main

func main() {
	fontBytes, err := ioutil.ReadFile("luxisr.ttf")
	if err != nil {
		log.Fatal(err)
	}
	font, err := freetype.ParseFont(fontBytes)
	if err != nil {
		log.Fatal(err)
	}

	fg, bg := image.White, image.Black
	rgba := image.NewRGBA(image.Rect(0, 0, width, height))
	draw.Draw(rgba, rgba.Bounds(), bg, image.ZP, draw.Src)
	c := freetype.NewContext()
	c.SetDPI(dpi)
	c.SetFont(font)
	c.SetFontSize(size)
	c.SetClip(rgba.Bounds())
	c.SetDst(rgba)
	c.SetSrc(fg)
	c.SetHinting(freetype.FullHinting)

	count := 0
	l := NewLife(width, height)
	for {
		if count%10 == 0 {
			count = 0
			pt := freetype.Pt(rand.Intn(width-width/4), height/4+rand.Intn(height-height/4))
			c.DrawString("NOPE", pt)
			for x := 0; x < width; x++ {
				for y := 0; y < height; y++ {
					c := rgba.RGBAAt(x, y)
					l.a.Set(x, y, c.R > 0 || c.B > 0 || c.G > 0)
				}
			}
		}
		count++

		for x := 0; x < width; x++ {
			for y := 0; y < height; y++ {
				var c color.Color = color.Black
				if l.a.Alive(x, y) {
					c = rainbow(y)
				}
				rgba.Set(x, y, c)
			}
		}

		//fmt.Println(l)
		sendImage(rgba)
		l.Step()

		time.Sleep(time.Second / 8)
	}
}
开发者ID:nf,项目名称:nope,代码行数:55,代码来源:nope.go

示例12: findOffsetAtIndex

func (w *TextEditLine) findOffsetAtIndex(index int) float64 {
	pt := freetype.Pt(0, 0)
	if index > len(w.text) {
		index = len(w.text)
	}
	if index < 0 {
		index = 0
	}
	adv, _ := w.context.DrawString(w.text[:index], pt)
	return float64(adv.X>>8) * w.scale
}
开发者ID:losinggeneration,项目名称:glop,代码行数:11,代码来源:text_edit_line.go

示例13: DrawYScale

func (a *Annotator) DrawYScale() error {

	log.WithFields(log.Fields{
		"timestart": a.table.TimeStart.String(),
		"timeend":   a.table.TimeEnd.String(),
	}).Debug("annotate Y scale")

	start, end := a.table.TimeStart, a.table.TimeEnd

	// how many samples?
	count := int(math.Floor(float64(a.table.Integrations) / float64(100)))

	uStart := start.Unix()
	uEnd := end.Unix()

	secsPerLabel := int(math.Floor(float64(uEnd-uStart) / float64(count)))
	pxPerLabel := int(math.Floor(float64(a.table.Integrations) / float64(count)))

	log.WithFields(log.Fields{
		"labels":       count,
		"secsPerLabel": secsPerLabel,
		"pxPerLabel":   pxPerLabel,
	}).Debug("annotate Y scale")

	for si := 0; si < count; si++ {

		secs := time.Duration(secsPerLabel * si * int(time.Second))
		px := si * pxPerLabel

		var str string = ""

		if si == 0 {
			str = start.String()
		} else {
			point := start.Add(secs)
			str = point.Format("15:04:05")
		}

		// draw a guideline on the exact time
		for i := 0; i < 75; i++ {
			a.image.Set(i, px, image.White)
		}

		// draw the text, 3 px margin to the line
		pt := freetype.Pt(3, px-3)
		_, _ = a.context.DrawString(str, pt)

	}

	return nil

}
开发者ID:dhogborg,项目名称:rtl-gopow,代码行数:52,代码来源:annotater.go

示例14: WriteText

// Write a text inside the image
func WriteText(text string, f *truetype.Font, img *image.Paletted) {
	// Initialize the context.
	fg := image.Black
	c := freetype.NewContext()
	c.SetDPI(72)
	c.SetFont(f)
	c.SetFontSize(64)
	c.SetClip(img.Bounds())
	c.SetDst(img)
	c.SetSrc(fg)
	// Draw the text.
	pt := freetype.Pt(40, 120)
	c.DrawString(text, pt)
}
开发者ID:maxzerbini,项目名称:packagemain,代码行数:15,代码来源:animatedgif.go

示例15: TextLen

func (ig *ImageGraphics) TextLen(s string, font chart.Font) int {
	c := freetype.NewContext()
	c.SetDPI(dpi)
	c.SetFont(ig.font)
	fontsize := ig.relFontsizeToPixel(font.Size)
	c.SetFontSize(fontsize)

	// really draw it
	width, err := c.DrawString(s, freetype.Pt(0, 0))
	if err != nil {
		return 10 * len(s) // BUG
	}
	return int(width.X+32)>>6 + 1
}
开发者ID:RobinTec,项目名称:chart,代码行数:14,代码来源:image.go


注:本文中的github.com/golang/freetype.Pt函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。