private Transform2d GetTextPositionTransform(GFNFont fnt, string txt, double x, double y, double size, double angle, TextAlign align, Transform2d t) { //computes the transformation needed to transform text drawn at origo to get to the wanted position Transform2d res = Transform2d.Translate(x, y); if (angle != 0.0) { res = Transform2d.Rotate(angle) * res; } if (align != TextAlign.BaseLeft) { double dx, dy; GetTextAlignDXDY(fnt, txt, size, align, out dx, out dy); res = Transform2d.Translate(dx, dy) * res; } res = Transform2d.Scale(size / fnt.CapHeight) * res; if (t != null) { return(res * t); } return(res); }
public static void EllipticArcToBeziers(double cx, double cy, double aradius, double bradius, double tilt, double startangle, double sweepangle, List <double> xy) { int cnt = xy.Count; double startpar = EllipseAngleToParam(startangle, aradius, bradius); double endpar = EllipseAngleToParam(startangle + sweepangle, aradius, bradius); if (sweepangle >= MathUtil.Deg360) { //full ellipse endpar = startpar + MathUtil.Deg360; } else if (sweepangle <= -MathUtil.Deg360) { endpar = startpar - MathUtil.Deg360; } else if (sweepangle > 0.0) //ccw { if (endpar <= startpar) { endpar += MathUtil.Deg360; } } else //cw { if (endpar >= startpar) { endpar -= MathUtil.Deg360; } } double sweepparam = endpar - startpar; double bulge = GetArcBulgeFromSweepAngle(sweepparam); ArcToBeziers(Math.Cos(startpar), Math.Sin(startpar), Math.Cos(endpar), Math.Sin(endpar), bulge, xy); //transform bezier circular arc to elliptical arc Transform2d tr = Transform2d.Stretch(aradius, bradius) * Transform2d.Rotate(tilt) * Transform2d.Translate(cx, cy); for (int l = cnt; l < xy.Count; l += 2) { double tx, ty; tr.Apply(xy[l], xy[l + 1], out tx, out ty, true); xy[l] = tx; xy[l + 1] = ty; } }