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


Golang Font.FUnitsPerEm方法代码示例

本文整理汇总了Golang中github.com/golang/freetype/truetype.Font.FUnitsPerEm方法的典型用法代码示例。如果您正苦于以下问题:Golang Font.FUnitsPerEm方法的具体用法?Golang Font.FUnitsPerEm怎么用?Golang Font.FUnitsPerEm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/golang/freetype/truetype.Font的用法示例。


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

示例1: 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(fixed.Int26_6(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:julianshen,项目名称:draw2d,代码行数:11,代码来源:text.go

示例2: widthOfString

// https://code.google.com/p/plotinum/source/browse/vg/font.go#160
func widthOfString(font *truetype.Font, size float64, s string) float64 {
	// scale converts truetype.FUnit to float64
	scale := size / float64(font.FUnitsPerEm())

	width := 0
	prev, hasPrev := truetype.Index(0), false
	for _, rune := range s {
		index := font.Index(rune)
		if hasPrev {
			width += int(font.Kern(fixed.Int26_6(font.FUnitsPerEm()), prev, index))
		}
		width += int(font.HMetric(fixed.Int26_6(font.FUnitsPerEm()), index).AdvanceWidth)
		prev, hasPrev = index, true
	}

	return float64(width) * scale
}
开发者ID:Ganners,项目名称:go-tile-server,代码行数:18,代码来源:draw.go


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