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


Golang Font.FUnitsPerEm方法代碼示例

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


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

示例1: Render

// Render draws rune r front the specified font at the specified dpi and scale.  It returns a
// grayscale image that is just large enough to contain the rune.
func Render(font *truetype.Font, r rune, dpi, scale float64) (*image.Gray, error) {
	glyph := truetype.NewGlyphBuf()
	index := font.Index(r)
	glyph.Load(font, font.FUnitsPerEm(), index, truetype.FullHinting)
	ctx := freetype.NewContext()
	boxer := makeBoundingBoxer()
	ctx.SetSrc(image.NewUniform(color.White))
	ctx.SetDst(boxer)
	ctx.SetClip(boxer.largeBounds)
	ctx.SetFontSize(250)
	ctx.SetDPI(dpi)
	ctx.SetFont(font)
	if err := glyph.Load(font, font.FUnitsPerEm(), font.Index(r), truetype.FullHinting); err != nil {
		return nil, fmt.Errorf("Unable to load glyph: %v\n", err)
	}
	var rp raster.Point
	rp.X = ctx.PointToFix32(0)
	rp.Y = ctx.PointToFix32(100)
	ctx.DrawString(string(r), rp)
	boxer.complete()

	g := gift.New(
		gift.Resize(int(float64(boxer.Bounds().Dx())*scale+0.5), int(float64(boxer.Bounds().Dy())*scale+0.5), gift.CubicResampling),
	)
	dst := image.NewGray(g.Bounds(boxer.Bounds()))
	g.Draw(dst, boxer)
	return dst, nil
}
開發者ID:runningwild,項目名稱:glop,代碼行數:30,代碼來源:glyph.go

示例2: Extents

// Extents returns the FontExtents for a font.
// TODO needs to read this https://developer.apple.com/fonts/TrueType-Reference-Manual/RM02/Chap2.html#intro
func Extents(font *truetype.Font, size float64) FontExtents {
	bounds := font.Bounds(font.FUnitsPerEm())
	scale := size / float64(font.FUnitsPerEm())
	return FontExtents{
		Ascent:  float64(bounds.YMax) * scale,
		Descent: float64(bounds.YMin) * scale,
		Height:  float64(bounds.YMax-bounds.YMin) * scale,
	}
}
開發者ID:stephenwithav,項目名稱:draw2d,代碼行數:11,代碼來源:text.go

示例3: printRuneInfo

func printRuneInfo(canvas *Canvas, font *truetype.Font, r rune) {
	index := font.Index(r)
	scale := int32(50)
	hmetric := font.HMetric(scale, index)
	vmetric := font.VMetric(scale, index)

	println("Index:", index)
	println("FUnitsPerEm:", font.FUnitsPerEm())
	println("Scale:", scale)
	println("HMetric:", hmetric)
	println("VMetric:", vmetric)
}
開發者ID:zach-klippenstein,項目名稱:gofontviewer,代碼行數:12,代碼來源:fontviewer.go

示例4: Text

// Text takes an image and, using the freetype package, writes text in the
// position specified on to the image. A color.Color, a font size and a font
// must also be specified.
// Finally, the (x, y) coordinate advanced by the text extents is returned.
//
// Note that the ParseFont helper function can be used to get a *truetype.Font
// value without having to import freetype-go directly.
//
// If you need more control over the 'context' used to draw text (like the DPI),
// then you'll need to ignore this convenience method and use your own.
func (im *Image) Text(x, y int, clr color.Color, fontSize float64,
	font *truetype.Font, text string) (int, int, error) {

	// Create a solid color image
	textClr := image.NewUniform(clr)

	// Set up the freetype context... mostly boiler plate
	c := ftContext(font, fontSize)
	c.SetClip(im.Bounds())
	c.SetDst(im)
	c.SetSrc(textClr)

	// Now let's actually draw the text...
	pt := freetype.Pt(x, y+int(font.FUnitsPerEm()))
	newpt, err := c.DrawString(text, pt)
	if err != nil {
		return 0, 0, err
	}

	// i think this is right...
	return int(newpt.X / 256), int(newpt.Y / 256), nil
}
開發者ID:droundy,項目名稱:xgbutil,代碼行數:32,代碼來源:text.go

示例5: ExpectedSize

func ExpectedSize(font *truetype.Font, s string) (int32, int32, error) {

	c := freetype.NewContext()
	c.SetDPI(dpi)
	c.SetFont(font)
	c.SetFontSize(size)

	scale := size / float64(font.FUnitsPerEm())

	prev := font.Index(rune(s[0]))
	width := int32(font.HMetric(font.FUnitsPerEm(), prev).AdvanceWidth)
	for _, char := range s[1:] {
		index := font.Index(char)
		width += int32(font.Kerning(font.FUnitsPerEm(), prev, index) +
			font.HMetric(font.FUnitsPerEm(), index).AdvanceWidth)
		prev = index
	}
	width = int32(float64(width) * scale)

	bounds := font.Bounds(font.FUnitsPerEm())
	height := int32(float64(bounds.YMax-bounds.YMin) * scale)

	return width, height, nil
}
開發者ID:romovs,項目名稱:viscum,代碼行數:24,代碼來源:fonts.go

示例6: TextMaxExtents

// Returns the max width and height extents of a string given a font.
// This is calculated by determining the number of pixels in an "em" unit
// for the given font, and multiplying by the number of characters in 'text'.
// Since a particular character may be smaller than one "em" unit, this has
// a tendency to overestimate the extents.
// It is provided because I do not know how to calculate the precise extents
// using freetype-go.
// TODO: This does not currently account for multiple lines. It may never do so.
func TextMaxExtents(font *truetype.Font, fontSize float64,
	text string) (width int, height int) {

	emSquarePix := int(font.FUnitsPerEm())
	return len(text) * emSquarePix, emSquarePix
}
開發者ID:droundy,項目名稱:xgbutil,代碼行數:14,代碼來源:text.go


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