Ejemplo n.º 1
0
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
	}
}
Ejemplo n.º 2
0
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
}
Ejemplo n.º 3
0
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,
	}
}
Ejemplo n.º 4
0
// 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
}