当前位置: 首页>>代码示例>>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;未经允许,请勿转载。