public GFXPath GetTextPath(string txt, Transform2d transform) { GFNGlyph glyph; if (txt == null) { return(null); } GFXPath res = new GFXPath(); foreach (char ch in txt) { if (CharLUT.TryGetValue(ch, out glyph)) { GFXPath glyphpath = glyph.Path.TransformCopy(transform); res.AppendPath(glyphpath); transform = Transform2d.Translate(glyph.DX, 0.0) * transform; //move to next character } } return(res); }
public override void DrawPath(GFXPath path) { MainPainter.DrawPath(path); if (SubPainter != null) { SubPainter.DrawPath(path); } }
public override void FillPathT(GFXPath path) { MainPainter.FillPathT(path); if (SubPainter != null) { SubPainter.FillPathT(path); } }
public void AppendPath(GFXPath path) { if (path != null && path.PathPoints.Count != 0) { PathPoints.AddRange(path.PathPoints); cache = null; } }
public virtual void FillRectangleT(double x1, double y1, double x2, double y2) { GFXPath rc = new GFXPath(); rc.MoveTo(x1, y1); rc.LineTo(x2, y1); rc.LineTo(x2, y2); rc.LineTo(x1, y2); rc.CloseSubPath(); FillPathT(rc); }
public override void DrawText(string txt, double x, double y, double size, double angle, TextAlign align) { if (txt != null) { GFXPath pth = MeasurePainter.GetTextPath(txt, x, y, size, angle, align, null); if (pth == null) { return; } InternalStrokePath(pth, null, false, true); } }
/// <summary> /// Strokes a path using GDI /// </summary> /// <param name="trans"></param> public void InternalStrokePath(GFXPath path, Transform2d trans, bool forceclosed, bool allowmodifypath) { int cx = 0, cy = 0, nx, ny; if (trans == null || trans.IsIdentity) { path.Flatten(flattentol, (x, y, moveto) => { if (moveto) { cx = GFXUtil.FloatToInt(x); cy = GFXUtil.FloatToInt(y); } else { nx = GFXUtil.FloatToInt(x); ny = GFXUtil.FloatToInt(y); DrawLine(nx, ny, cx, cy); //target.Add(nx, ny, cx, cy, currentobject); cx = nx; cy = ny; } }); } else { path.TransformFlatten(flattentol, trans, (x, y, moveto) => { if (moveto) { cx = GFXUtil.FloatToInt(x); cy = GFXUtil.FloatToInt(y); } else { nx = GFXUtil.FloatToInt(x); ny = GFXUtil.FloatToInt(y); //target.Add(nx, ny, cx, cy, currentobject); DrawLine(nx, ny, cx, cy); cx = nx; cy = ny; } }); } }
public GFXPath TransformCopy(Transform2d tr) { GFXPath res = new GFXPath(); double x1, y1, x2, y2, x3, y3, b; bool mirror = tr.Determinant < 0.0; foreach (GFXPathMoveTo mt in PathPoints) { if (mt is GFXPathBezierTo) { var bez = mt as GFXPathBezierTo; tr.Apply(bez.XC1, bez.YC1, out x1, out y1, true); tr.Apply(bez.XC2, bez.YC2, out x2, out y2, true); tr.Apply(bez.X, bez.Y, out x3, out y3, true); res.PathPoints.Add(new GFXPathBezierTo(x1, y1, x2, y2, x3, y3)); } else if (mt is GFXPathArcTo) { var arc = mt as GFXPathArcTo; tr.Apply(arc.X, arc.Y, out x1, out y1, true); b = mirror ? -arc.Bulge : arc.Bulge; res.PathPoints.Add(new GFXPathArcTo(x1, y1, b)); } else if (mt is GFXPathLineTo) { var lin = mt as GFXPathLineTo; tr.Apply(lin.X, lin.Y, out x1, out y1, true); res.PathPoints.Add(new GFXPathLineTo(x1, y1)); } else if (mt is GFXPathCloseSubPath) { var clp = mt as GFXPathCloseSubPath; tr.Apply(clp.X, clp.Y, out x1, out y1, true); res.PathPoints.Add(new GFXPathCloseSubPath(x1, y1)); } else //move to { tr.Apply(mt.X, mt.Y, out x1, out y1, true); res.PathPoints.Add(new GFXPathMoveTo(x1, y1)); } } return(res); }
public override void DrawPathT(GFXPath path) { //InternalStrokePath(path, Transform, false, false); path.EnumerateSegments( (x1, y1, x2, y2) => { //line DrawLineT(x1, y1, x2, y2); }, (x1, y1, x2, y2, bulge) => { //arc DrawArcT(x1, y1, x2, y2, bulge); }, (x1, y1, x2, y2, x3, y3, x4, y4) => { //bezier InternalDrawBezierT(x1, y1, x2, y2, x3, y3, x4, y4); } ); }
private void AppendPathToExtents(bool uselinewidth, bool usetransform, GFXPath pth) { Box2d ext; if (usetransform) { ext = pth.GetTransformedExtents(Transform); } else { ext = pth.Extents; } if (uselinewidth) { AppendWithLineWidth(pth.Extents); } else { RecordedExtents.Append(ext.XMin, ext.YMin, ext.XMax, ext.YMax); } }
public override void DrawPath(GFXPath p) { AppendPathToExtents(false, false, p); }
public override void FillPathT(GFXPath p) { AppendPathToExtents(false, true, p); }
public override void FillPathT(GFXPath path) { InternalStrokePath(path, Transform, true, false); }
public abstract void FillPathT(GFXPath path);
public MetafileRecordFillPath(GFXPath path) { this.path = path; }
public abstract void DrawPathT(GFXPath path);
public MetafileRecordFillPathT(GFXPath path) : base(path) { }
public override void FillPath(GFXPath path) { InternalStrokePath(path, null, true, false); }
private static GFNGlyph ParseGlyph(string val) { string[] atoms = val.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); Stack <double> stack = new Stack <double>(); GFXPath path = new GFXPath(); double num; double? dx = null; double x, y, bulge, xctl1, yctl1, xctl2, yctl2; foreach (string atom in atoms) { if (double.TryParse(atom, NumberStyles.Float, CultureInfo.InvariantCulture, out num)) { stack.Push(num); } else { //not a number, assume operator switch (atom) { case "dx": dx = stack.Pop(); break; case "m": //move to y = stack.Pop(); x = stack.Pop(); path.MoveTo(x, y); break; case "l": //line to y = stack.Pop(); x = stack.Pop(); path.LineTo(x, y); break; case "a": //arc to bulge = stack.Pop(); y = stack.Pop(); x = stack.Pop(); path.ArcTo(x, y, bulge); break; case "c": //curve to y = stack.Pop(); x = stack.Pop(); yctl2 = stack.Pop(); xctl2 = stack.Pop(); yctl1 = stack.Pop(); xctl1 = stack.Pop(); path.BezierTo(xctl1, yctl1, xctl2, yctl2, x, y); break; default: throw new Exception("Invalid font program operator '" + atom + "'"); } } } if (dx == null) { throw new Exception("Glyph missing dx operator"); } return(new GFNGlyph(path, (double)dx)); }
public GFNGlyph(GFXPath path, double dx) { this.Path = path; this.DX = dx; }
public override void FillPathT(GFXPath path) { records.Add(new MetafileRecordFillPathT(path)); }
public override void DrawPath(GFXPath path) { records.Add(new MetafileRecordPath(path)); }