public virtual double[] GetTextBounds(string txt, double x, double y, double size, double angle, TextAlign align) { double w, h; GFNFont fnt = FindFont(Font); GetTextSize(txt, fnt.CapHeight, out w, out h); var t = GetTextPositionTransform(fnt, txt, x, y, size, angle, align, Transform2d.Identity); /* * double d = fnt.GetDescent(fnt.CapHeight); * double a = fnt.GetAscent(fnt.CapHeight); */ double top = fnt.GetAscent(fnt.CapHeight); double bot = top - h; double[] res = new double[8] { 0, bot, w, bot, w, top, 0, top }; t.Apply(res[0], res[1], out res[0], out res[1], true); t.Apply(res[2], res[3], out res[2], out res[3], true); t.Apply(res[4], res[5], out res[4], out res[5], true); t.Apply(res[6], res[7], out res[6], out res[7], true); return(res); }
/// <summary> /// Computes how the font should be moved from baseline left to obey a specified alignment /// </summary> private void GetTextAlignDXDY(GFNFont fnt, string txt, double size, TextAlign align, out double dx, out double dy) { dx = 0.0; dy = 0.0; double w, h; //y align: if ((align & TextAlignAtom.TEXT_BOTTOM) != 0) { dy = fnt.GetDescent(size); } else if ((align & TextAlignAtom.TEXT_CENTER_Y) != 0) { dy = -size * 0.5; } else if ((align & TextAlignAtom.TEXT_TOP) != 0) { dy = -fnt.GetAscent(size); } //else align is baseline, dy=0.0 //x align: if ((align & TextAlignAtom.TEXT_RIGHT) != 0) { InternalGetTextSize(fnt, txt, size, out w, out h); dx = -w; } else if ((align & TextAlignAtom.TEXT_CENTER_X) != 0) { InternalGetTextSize(fnt, txt, size, out w, out h); dx = -w * 0.5; } //else align is left, dx=0.0 and we're done }
public virtual void GetFontDim(double size, out double linespace_pixels, out double ascent_pixels, out double descent_pixels, out bool filled) { GFNFont fnt = FindFont(Font); linespace_pixels = fnt.GetLineSpacing(size); ascent_pixels = fnt.GetAscent(size); descent_pixels = fnt.GetDescent(size); filled = fnt.Filled; }