public static PathF AsScaledPath( this PathF target, float scale) { var scaledPath = new PathF(target); var transform = AffineTransform.GetScaleInstance(scale, scale); scaledPath.Transform(transform); return(scaledPath); }
public PathF(PathF path) : this() { _operations.AddRange(path._operations); _points = new List <PointF>(path._points); _arcAngles.AddRange(path._arcAngles); _arcClockwise.AddRange(path._arcClockwise); _subPathCount = path._subPathCount; _subPathsClosed = new List <bool>(path._subPathsClosed); }
public static string ToDefinitionString(this PathF path, float ppu = 1) { var writer = new StringWriter(); for (var i = 0; i < path.OperationCount; i++) { var type = path.GetSegmentType(i); var points = path.GetPointsForSegment(i); if (type == PathOperation.Move) { writer.Write("M"); WritePoint(writer, points[0], ppu); } else if (type == PathOperation.Line) { writer.Write(" L"); WritePoint(writer, points[0], ppu); } else if (type == PathOperation.Quad) { writer.Write(" Q"); WritePoint(writer, points[0], ppu); writer.Write(" "); WritePoint(writer, points[1], ppu); } else if (type == PathOperation.Cubic) { writer.Write(" C"); WritePoint(writer, points[0], ppu); writer.Write(" "); WritePoint(writer, points[1], ppu); writer.Write(" "); WritePoint(writer, points[2], ppu); } else if (type == PathOperation.Close) { writer.Write(" Z "); } } return(writer.ToString()); }
private void ArcTo(bool isRelative) { var startPoint = _relativePoint ?? default; var rx = NextValue; var ry = NextValue; var r = NextValue; var largeArcFlag = NextBoolValue; var sweepFlag = NextBoolValue; var endPoint = NewPoint(NextValue, NextValue, isRelative, false); var arcPath = new PathF(startPoint); arcPath.SVGArcTo(rx, ry, r, largeArcFlag, sweepFlag, endPoint.X, endPoint.Y, startPoint.X, startPoint.Y); for (int s = 0; s < arcPath.OperationCount; s++) { var segmentType = arcPath.GetSegmentType(s); var pointsInSegment = arcPath.GetPointsForSegment(s); if (segmentType == PathOperation.Move) { // do nothing } else if (segmentType == PathOperation.Line) { _path.LineTo(pointsInSegment[0]); } else if (segmentType == PathOperation.Cubic) { _path.CurveTo(pointsInSegment[0], pointsInSegment[1], pointsInSegment[2]); } else if (segmentType == PathOperation.Quad) { _path.QuadTo(pointsInSegment[0], pointsInSegment[1]); } } _relativePoint = _path.LastPoint; }
public PathF BuildPath(string pathAsString) { try { _lastCommand = '~'; _lastCurveControlPoint = null; _path = null; _commandStack.Clear(); _relativePoint = new PointF(0, 0); _closeWhenDone = false; #if DEBUG_PATH Logger.Debug(aPathString); #endif pathAsString = pathAsString.Replace("Infinity", "0"); pathAsString = Regex.Replace(pathAsString, "([a-zA-Z])", " $1 "); pathAsString = pathAsString.Replace("-", " -"); pathAsString = pathAsString.Replace(" E -", "E-"); pathAsString = pathAsString.Replace(" e -", "e-"); #if DEBUG_PATH Logger.Debug(aPathString); #endif string[] args = pathAsString.Split(new[] { ' ', '\r', '\n', '\t', ',' }, StringSplitOptions.RemoveEmptyEntries); for (int i = args.Length - 1; i >= 0; i--) { string entry = args[i]; char c = entry[0]; if (char.IsLetter(c)) { if (entry.Length > 1) { entry = entry.Substring(1); if (char.IsLetter(entry[0])) { if (entry.Length > 1) { _commandStack.Push(entry.Substring(1)); #if DEBUG_PATH Logger.Debug(vEntry.Substring(1)); #endif } _commandStack.Push(entry[0].ToInvariantString()); #if DEBUG_PATH Logger.Debug(vEntry[0].ToString()); #endif } else { _commandStack.Push(entry); #if DEBUG_PATH Logger.Debug(vEntry); #endif } } _commandStack.Push(c.ToInvariantString()); #if DEBUG_PATH Logger.Debug(vChar.ToString()); #endif } else { _commandStack.Push(entry); #if DEBUG_PATH Logger.Debug(vEntry); #endif } } while (_commandStack.Count > 0) { if (_path == null) { _path = new PathF(); } string topCommand = _commandStack.Pop(); var firstLetter = topCommand[0]; if (IsCommand(firstLetter)) { HandleCommand(topCommand); } else { _commandStack.Push(topCommand); HandleCommand(_lastCommand.ToString()); } } if (_path != null && !_path.Closed) { if (_closeWhenDone) { _path.Close(); } } } catch (Exception exc) { #if DEBUG Logger.Debug("=== An error occured parsing the path. ===", exc); Logger.Debug(pathAsString); throw; #endif } return(_path); }
public List <PathF> ConvertToPaths(PathF aPath, string text, ITextAttributes textAttributes, float ppu, float zoom) { return(new List <PathF>()); }
public bool PointIsOnPathSegment(PathF path, int segmentIndex, PointF point, float ppu, float zoom, float strokeWidth) { throw new NotImplementedException(); }
public bool PathContainsPoint(PathF path, PointF point, float ppu, float zoom, float strokeWidth) { throw new NotImplementedException(); }
public RectangleF GetPathBoundsWhenRotated(PointF center, PathF path, float angle) { throw new NotImplementedException(); }
public RectangleF GetPathBounds(PathF path) { throw new NotImplementedException(); }
public void LayoutText(PathF path, string text, ITextAttributes textAttributes, LayoutLine callback) { // Do nothing }
protected abstract void NativeDrawPath(PathF path);
public void ClipPath(PathF path, WindingMode windingMode = WindingMode.NonZero) { _commands.Add(canvas => canvas.ClipPath(path, windingMode)); }
public void FillPath(PathF path, WindingMode windingMode) { _commands.Add(canvas => canvas.FillPath(path, windingMode)); }
public void DrawPath(PathF path) { _commands.Add(canvas => canvas.DrawPath(path)); }