本文整理汇总了Golang中golang.org/x/image/font.Face类的典型用法代码示例。如果您正苦于以下问题:Golang Face类的具体用法?Golang Face怎么用?Golang Face使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Face类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Measure
func Measure(r io.RuneReader, f font.Face) (size fixed.Point26_6, err error) {
var char rune
var prev rune
w := fixed.Int26_6(0)
m := f.Metrics()
size.Y = m.Height + m.Descent
for {
if char, _, err = r.ReadRune(); err != nil {
if err == io.EOF {
err = nil
}
size.X = maxInt26_6(size.X, w)
return
}
if char == '\n' {
size.X = maxInt26_6(size.X, w)
size.Y += m.Height
w, prev = 0, 0
continue
}
if prev != 0 {
w += f.Kern(prev, char)
}
w += advance(f, char)
prev = char
}
}
开发者ID:achille-roussel,项目名称:go-vu,代码行数:32,代码来源:measure.go
示例2: advance
func advance(face font.Face, char rune) (x fixed.Int26_6) {
if x, ok := face.GlyphAdvance(char); ok {
return x
} else {
x, _ = face.GlyphAdvance(utf8.RuneError)
return x
}
}
开发者ID:achille-roussel,项目名称:go-vu,代码行数:8,代码来源:text.go
示例3: glyph
func glyph(face font.Face, char rune, dot fixed.Point26_6) (dr image.Rectangle, mask image.Image, maskp image.Point) {
var ok bool
if dr, mask, maskp, _, ok = face.Glyph(dot, char); !ok {
dr, mask, maskp, _, _ = face.Glyph(dot, utf8.RuneError)
}
return
}
开发者ID:achille-roussel,项目名称:go-vu,代码行数:9,代码来源:text.go
示例4: fromString
func fromString(s string, fc font.Face) []*glyph {
var gs []*glyph
for _, r := range s {
if b, a, ok := fc.GlyphBounds(r); ok {
gs = append(gs, &glyph{r: r, b: b, a: a})
}
}
return gs
}
开发者ID:dskinner,项目名称:material,代码行数:9,代码来源:gen.go
示例5: enumerate
// enumerate returns all glyphs with a valid index.
func enumerate(f *truetype.Font, fc font.Face) []*glyph {
var gs []*glyph
for r := rune(1); r < (1<<16)-1; r++ {
if r == '\uFEFF' {
continue // ignore BOM
}
if f.Index(r) != 0 {
b, a, _ := fc.GlyphBounds(r)
gs = append(gs, &glyph{r: r, b: b, a: a})
}
}
return gs
}
开发者ID:dskinner,项目名称:material,代码行数:14,代码来源:gen.go
示例6: Advance
func (self rightToLeft) Advance(face font.Face, origin fixed.Point26_6, dot fixed.Point26_6, prev rune, char rune) (begin fixed.Point26_6, end fixed.Point26_6) {
if char == '\n' {
dot.X = origin.X
dot.Y += face.Metrics().Height
return dot, dot
}
if prev != 0 {
dot.X -= face.Kern(prev, char)
}
dot.X -= advance(face, char)
return dot, dot
}
开发者ID:achille-roussel,项目名称:go-vu,代码行数:14,代码来源:direction.go
示例7: newGlyphPage
func newGlyphPage(face fnt.Face, r rune) *glyphPage {
// Start the page big enough to hold the initial rune.
b, _, _ := face.GlyphBounds(r)
bounds := rectangle26_6toRect(b)
size := math.Size{W: glyphPageWidth, H: glyphPageHeight}.Max(bounds.Size())
size.W = align(size.W, glyphSizeAlignment)
size.H = align(size.H, glyphSizeAlignment)
page := &glyphPage{
image: image.NewAlpha(image.Rect(0, 0, size.W, size.H)),
size: size,
entries: make(map[rune]glyphEntry),
rowHeight: 0,
}
page.add(face, r)
return page
}
开发者ID:langxj,项目名称:gxui,代码行数:17,代码来源:glyph_page.go
示例8: add
func (p *glyphPage) add(face fnt.Face, r rune) bool {
if _, found := p.entries[r]; found {
panic("Glyph already added to glyph page")
}
b, mask, maskp, _, _ := face.Glyph(fixed.Point26_6{}, r)
bounds := math.CreateRect(b.Min.X, b.Min.Y, b.Max.X, b.Max.Y)
w, h := bounds.Size().WH()
x, y := p.nextPoint.X, p.nextPoint.Y
if x+w > p.size.W {
// Row full, start new line
x = 0
y += p.rowHeight + glyphPadding
p.rowHeight = 0
}
if y+h > p.size.H {
return false // Page full
}
draw.Draw(p.image, image.Rect(x, y, x+w, y+h), mask, maskp, draw.Src)
p.entries[r] = glyphEntry{
offset: math.Point{X: x, Y: y}.Sub(bounds.Min),
bounds: bounds,
}
p.nextPoint = math.Point{X: x + w + glyphPadding, Y: y}
if h > p.rowHeight {
p.rowHeight = h
}
p.tex = nil
return true
}
开发者ID:langxj,项目名称:gxui,代码行数:36,代码来源:glyph_page.go
示例9: Origin
func (self rightToLeft) Origin(face font.Face, bounds fixed.Rectangle26_6) fixed.Point26_6 {
return fixed.Point26_6{
X: bounds.Max.X,
Y: bounds.Min.Y + face.Metrics().Ascent,
}
}
开发者ID:achille-roussel,项目名称:go-vu,代码行数:6,代码来源:direction.go
示例10: MeasureString
// MeasureString returns the rendered width and height of the specified text
// given the current font face.
func MeasureString(ff font.Face, s string) (w float64, h float64) {
d := &font.Drawer{Face: ff}
return float64(d.MeasureString(s) >> 6),
float64(ff.Metrics().Height>>6) * 96.0 / 72.0
}
开发者ID:Alquimista,项目名称:Eyecandy,代码行数:7,代码来源:utils.go
注:本文中的golang.org/x/image/font.Face类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论