// Metrics computes the pixel unit metrics for the glyph. func (f *Face) Metrics(dst *Metrics, ch rune) error { errno := C.FT_Load_Char(f.handle, C.FT_ULong(ch), C.FT_LOAD_DEFAULT) if errno != 0 { return fmt.Errorf("freetype2: %s", errstr(errno)) } m := &f.handle.glyph.metrics /* s := &f.handle.size.metrics invEM := 64.0 / float64(f.handle.units_per_EM) xscale := float64(s.x_ppem) * invEM yscale := float64(s.y_ppem) * invEM dst.Width = int(float64(m.width) * xscale) dst.Height = int(float64(m.height) * yscale) dst.HorizontalBearingX = int(float64(m.horiBearingX) * xscale) dst.HorizontalBearingY = int(float64(m.horiBearingY) * yscale) dst.AdvanceWidth = int(float64(m.horiAdvance) * xscale) dst.VerticalBearingX = int(float64(m.vertBearingX) * xscale) dst.VerticalBearingY = int(float64(m.vertBearingY) * yscale) dst.AdvanceHeight = int(float64(m.vertAdvance) * yscale) */ dst.Width = int(m.width >> 6) dst.Height = int(m.height >> 6) dst.HorizontalBearingX = int(m.horiBearingX >> 6) dst.HorizontalBearingY = int(m.horiBearingY >> 6) dst.AdvanceWidth = int(m.horiAdvance >> 6) dst.VerticalBearingX = int(m.vertBearingX >> 6) dst.VerticalBearingY = int(m.vertBearingY >> 6) dst.AdvanceHeight = int(m.vertAdvance >> 6) return nil }
// Image directly copies the rendered bitmap data for the glyph into dst with // its top-left corner at pt. Currently, only *image.Alpha is supported. func (f *Face) Image(dst draw.Image, pt image.Point, ch rune) error { errno := C.FT_Load_Char(f.handle, C.FT_ULong(ch), C.FT_LOAD_RENDER) if errno != 0 { return fmt.Errorf("freetype2: %s", errstr(errno)) } bitmap := &f.handle.glyph.bitmap if bitmap.pixel_mode != C.FT_PIXEL_MODE_GRAY || bitmap.num_grays != 256 { return fmt.Errorf("freetype2: unsupported pixel mode") } src := imageFromBitmap(bitmap) switch dst.(type) { case *image.Alpha: drawAlpha(dst.(*image.Alpha), pt, src) default: return fmt.Errorf("freetype2: unsupported dst type %T", dst) } return nil }