本文整理匯總了Golang中code/google/com/p/freetype-go/freetype/raster.Point.X方法的典型用法代碼示例。如果您正苦於以下問題:Golang Point.X方法的具體用法?Golang Point.X怎麽用?Golang Point.X使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類code/google/com/p/freetype-go/freetype/raster.Point
的用法示例。
在下文中一共展示了Point.X方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: DrawString
// DrawString draws s at p and returns p advanced by the text extent. The text
// is placed so that the left edge of the em square of the first character of s
// and the baseline intersect at p. The majority of the affected pixels will be
// above and to the right of the point, but some may be below or to the left.
// For example, drawing a string that starts with a 'J' in an italic font may
// affect pixels below and left of the point.
// p is a raster.Point and can therefore represent sub-pixel positions.
func (c *Context) DrawString(s string, p raster.Point) (raster.Point, error) {
if c.font == nil {
return raster.Point{}, errors.New("freetype: DrawText called with a nil font")
}
prev, hasPrev := truetype.Index(0), false
for _, rune := range s {
index := c.font.Index(rune)
if hasPrev {
p.X += raster.Fix32(c.font.Kerning(c.scale, prev, index)) << 2
}
mask, offset, err := c.glyph(index, p)
if err != nil {
return raster.Point{}, err
}
p.X += raster.Fix32(c.font.HMetric(c.scale, index).AdvanceWidth) << 2
glyphRect := mask.Bounds().Add(offset)
dr := c.clip.Intersect(glyphRect)
if !dr.Empty() {
mp := image.Point{0, dr.Min.Y - glyphRect.Min.Y}
draw.DrawMask(c.dst, dr, c.src, image.ZP, mask, mp, draw.Over)
}
prev, hasPrev = index, true
}
return p, nil
}
示例2: 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
}
示例3: TextLen
func (ig *ImageGraphics) TextLen(s string, font chart.Font) int {
c := freetype.NewContext()
c.SetDPI(dpi)
c.SetFont(ig.font)
c.SetFontSize(ig.relFontsizeToPixel(font.Size))
var p raster.Point
prev, hasPrev := truetype.Index(0), false
for _, rune := range s {
index := ig.font.Index(rune)
if hasPrev {
p.X += c.FUnitToFix32(int(ig.font.Kerning(prev, index)))
}
p.X += c.FUnitToFix32(int(ig.font.HMetric(index).AdvanceWidth))
prev, hasPrev = index, true
}
return int((p.X + 127) / 256)
}
示例4: 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)
scale := int32(fontsize * dpi * (64.0 / 72.0))
var p raster.Point
prev, hasPrev := truetype.Index(0), false
for _, rune := range s {
index := ig.font.Index(rune)
if hasPrev {
p.X += raster.Fix32(ig.font.Kerning(scale, prev, index)) << 2
}
p.X += raster.Fix32(ig.font.HMetric(scale, index).AdvanceWidth) << 2
prev, hasPrev = index, true
}
return int((p.X + 127) / 256)
}