protected override void SetSink(GeometrySink sink) { sink.SetFillMode(FillMode.Winding); sink.BeginFigure(new RawVector2(-35, 85), FigureBegin.Filled); sink.AddLine(new RawVector2(60, 85)); sink.AddBezier(new BezierSegment { Point3 = new RawVector2(72, 58), Point1 = new RawVector2(80, 85), Point2 = new RawVector2(82, 58) }); sink.AddBezier(new BezierSegment { Point3 = new RawVector2(85, 30), Point1 = new RawVector2(100, 58), Point2 = new RawVector2(95, 30) }); sink.AddBezier(new BezierSegment { Point3 = new RawVector2(90, -5), Point1 = new RawVector2(115, 30), Point2 = new RawVector2(115, -5) }); sink.AddBezier(new BezierSegment { Point3 = new RawVector2(85, -39), Point1 = new RawVector2(110, -5), Point2 = new RawVector2(105, -39) }); sink.AddLine(new RawVector2(25, -39)); sink.AddBezier(new BezierSegment { Point3 = new RawVector2(-10, -98), Point1 = new RawVector2(35, -105), Point2 = new RawVector2(0, -105) }); sink.AddLine(new RawVector2(-10, -60)); sink.AddLine(new RawVector2(-35, -16)); sink.EndFigure(FigureEnd.Closed); sink.BeginFigure(new RawVector2(-90, 100), FigureBegin.Filled); sink.AddLine(new RawVector2(-48, 100)); sink.AddLine(new RawVector2(-48, -20)); sink.AddLine(new RawVector2(-90, -20)); sink.EndFigure(FigureEnd.Closed); }
private void DrawFDEBBeziers(float width, float height) { float[] t; for (int i = 0, j = _pt.GetLength(1); i < _pt.GetLength(0); i++) { PathGeometry pLinesGeometry = this.Factory.CreatePathGeometry(); GeometrySink gs = pLinesGeometry.Open(); gs.SetFillMode(FillMode.Winding); gs.BeginFigure(new D2D.Point2F(_pt[i, 0, 0], _pt[i, 0, 1]), FigureBegin.Hollow); gs.AddBezier( new BezierSegment( new Point2F(_pt[i, (int)((j - 1) * 0.33), 0], _pt[i, (int)((j - 1) * .33), 1]), new Point2F(_pt[i, (int)((j - 1) * 0.66), 0], _pt[i, (int)((j - 1) * .66), 1]), new Point2F(_pt[i, (int)(j - 1), 0], _pt[i, (int)(j - 1), 1]) ) ); gs.EndFigure(FigureEnd.Open); gs.Close(); this.RenderTarget.DrawGeometry(pLinesGeometry, neutralBrush, 1f); foreach (Story s in _st) { t = s.GetLocationLines(); if ((int)_pt[i, 0, 1] == (int)t[0] && (int)_pt[i, (int)(j - 1), 1] == (int)t[1]) { PointAndTangent pt = pLinesGeometry.ComputePointAtLength(s.GetEventLocation()[0]); RectangleGeometry pEventsGeometry = this.Factory.CreateRectangleGeometry( new D2D.RectF(pt.Point.X - RECTSIZE, pt.Point.Y - RECTSIZE, pt.Point.X + RECTSIZE, pt.Point.Y + RECTSIZE) ); this.RenderTarget.DrawGeometry(pEventsGeometry, brushes[s.GetLabel()], 0.8f); } } } }
/// <summary> /// Creates and adds set of Cubic Bezier curves to the current path</summary> /// <param name="beziers">Array of Cubic Bezier curves to add</param> public void AddBeziers(params D2dBezierSegment[] beziers) { foreach (var b in beziers) { m_sink.AddBezier(b.ToSharpDX()); } }
public void CubicBezierTo(Point point1, Point point2, Point point3) { _sink.AddBezier(new BezierSegment { Point1 = point1.ToSharpDX(), Point2 = point2.ToSharpDX(), Point3 = point3.ToSharpDX(), }); }
private void DrawFDEBBeziers2(float width, float height, float[,,] _pt) { List <tempEvents> tes = new List <tempEvents>(); float[] t; //foreach (Story s in _st) //{ // t = s.GetLocationLines(); // //this.RenderTarget.DrawRectangle(new D2D.RectF(0.0f, t[0], width, t[1]), neutralBrush, 1.0f, null); // this.RenderTarget.DrawLine(new D2D.Point2F(0.0f, t[0]), new D2D.Point2F(width, t[1]), alternativeBrush, 0.8f); //} for (int i = 0; i < _pt.GetLength(0); i++) { PathGeometry pLinesGeometry = this.Factory.CreatePathGeometry(); GeometrySink gs = pLinesGeometry.Open(); gs.SetFillMode(FillMode.Winding); gs.BeginFigure(new D2D.Point2F(_pt[i, 0, 0], _pt[i, 0, 1]), FigureBegin.Hollow); for (int j = 1; j < _pt.GetLength(1); j += 3) { gs.AddBezier( new BezierSegment( new Point2F(_pt[i, j, 0], _pt[i, j, 1]), new Point2F(_pt[i, j + 1, 0], _pt[i, j + 1, 1]), new Point2F(_pt[i, j + 2, 0], _pt[i, j + 2, 1]) ) ); } gs.EndFigure(FigureEnd.Open); gs.Close(); neutralBrush.Opacity = 0.8f + _kp[i]; if (_showLocationLines) { this.RenderTarget.DrawGeometry(pLinesGeometry, neutralBrush, 0.8f); } foreach (Story s in _st) { t = s.GetLocationLines(); if ((int)_pt[i, 0, 1] == (int)t[0] && (int)_pt[i, (int)(_pt.GetLength(1) - 1), 1] == (int)t[1]) { PointAndTangent pt = pLinesGeometry.ComputePointAtLength((pLinesGeometry.ComputeLength() * s.GetEventLocation()[0]) / width); RectangleGeometry pEventsGeometry = this.Factory.CreateRectangleGeometry( new D2D.RectF(pt.Point.X - RECTSIZE, pt.Point.Y - RECTSIZE, pt.Point.X + RECTSIZE, pt.Point.Y + RECTSIZE) ); tes.Add(new tempEvents(pEventsGeometry, brushes[s.GetLabel()], 0.8f)); } } } //foreach (tempEvents te in tes) // this.RenderTarget.DrawGeometry(te.pEventsGeometry, te.solidColorBrush, te.p); }
/// <summary> /// This method creates the path geometry that represents the up continent in the planet. /// It demonstrates how to substitute clipping by intersecting. /// </summary> private void CreatePlanetUpPath() { // Since clip is required, we must draw to a temporary path, and then intersect it with the ellipse, and save the result in m_pPlanetUpPath. PathGeometry tempPath = this._d2DFactory.CreatePathGeometry(); this._planetUpPath = this._d2DFactory.CreatePathGeometry(); GeometrySink sink = tempPath.Open(); sink.BeginFigure(new Point2F(0.0288963486137668f, 71.2923486227374f), FigureBegin.Filled); // The following AddBezier code are generated by the PowerShell script. sink.AddBezier(new BezierSegment( new Point2F(-0.581304006712504f, 71.029349563583f), new Point2F(8.52890129825862f, 88.2922878076214f), new Point2F(22.0289091594593f, 91.7922752868622f))); sink.AddBezier(new BezierSegment( new Point2F(35.5289170206599f, 95.292262766103f), new Point2F(42.528921096838f, 64.2923736642557f), new Point2F(42.528921096838f, 64.2923736642557f))); sink.AddBezier(new BezierSegment( new Point2F(49.0289248818605f, 71.2923486227374f), new Point2F(59.5289309961277f, 76.2923307359385f), new Point2F(61.52893216075f, 94.7922645547829f))); sink.AddBezier(new BezierSegment( new Point2F(63.5289333253723f, 113.292198373627f), new Point2F(96.5289525416406f, 85.7922967510208f), new Point2F(99.5289542885741f, 86.2922949623409f))); sink.AddBezier(new BezierSegment( new Point2F(102.528956035508f, 86.792293173661f), new Point2F(127.528970593286f, 111.792203739667f), new Point2F(146.028981366043f, 106.792221626466f))); sink.AddBezier(new BezierSegment( new Point2F(164.528992138799f, 101.792239513265f), new Point2F(178.029f, 80.2923164264995f), new Point2F(178.029f, 80.2923164264995f))); sink.AddBezier(new BezierSegment( new Point2F(178.029f, 80.2923164264995f), new Point2F(105.028957491285f, -94.2070593242214f), new Point2F(0.0288963486137668f, 71.2923486227374f))); sink.EndFigure(FigureEnd.Closed); sink.Close(); GeometrySink sink2 = this._planetUpPath.Open(); // Create a clip ellipse. Ellipse clip = new Ellipse(new Point2F(87f, 121f), 100f, 100f); EllipseGeometry clipEllipse = this._d2DFactory.CreateEllipseGeometry(clip); // There's no direct support for clipping path in Direct2D. So we can intersect a path with its clip instead. tempPath.CombineWithGeometry(clipEllipse, CombineMode.Intersect, 0f, sink2); sink2.Close(); }
/// <summary> /// 使用当前的路径填充指定的路径几何。 /// </summary> /// <param name="sink">要填充的路径几何。</param> public override void FillGeometry(GeometrySink sink) { D2D1.BezierSegment bezier = new D2D1.BezierSegment() { Point1 = this.Point1, Point2 = this.Point2, Point3 = this.EndPoint }; sink.AddBezier(bezier); }
public static void CubicTo(this GeometrySink target, float cx1, float cy1, float cx2, float cy2, float x, float y) { var segment = new BezierSegment { Point1 = new Vector2(cx1, cy1), Point2 = new Vector2(cx2, cy2), Point3 = new Vector2(x, y) }; target.AddBezier(segment); }
public void AddPathSegment(GeometrySink canvasPathBuilder, ref bool closed) { canvasPathBuilder.AddBezier(new BezierSegment { Point1 = _control1.ToRaw(), Point2 = _control2.ToRaw(), Point3 = _vertex.ToRaw() }); closed = false; }
/// <summary> /// Adds a cubic bezier curve to the end of the line. /// </summary> /// <param name="controlA">The first control point of the curve.</param> /// <param name="controlB">The second control point of the curve.</param> /// <param name="to">The end point of the curve.</param> /// <returns>This <see cref="IGraphicsPath" />.</returns> public IGraphicsPath AddCubicBezier(Vector2 controlA, Vector2 controlB, Vector2 to) { _sink?.AddBezier( new BezierSegment { Point1 = controlA.ToRawVector2(), Point2 = controlB.ToRawVector2(), Point3 = to.ToRawVector2() }); return(this); }
public void BezierTo(double s1x, double s1y, double s2x, double s2y, double ex, double ey) { var bezier = new BezierSegment { Point1 = Import.Point(s1x, s1y), Point2 = Import.Point(s2x, s2y), Point3 = Import.Point(ex, ey) }; _sink.AddBezier(bezier); }
public void Bezier(CubicBezier bezier) { endOpenFigure(); _sink.BeginFigure(Import.Point(bezier.Start), FigureBegin.Hollow); _sink.AddBezier(new BezierSegment { Point1 = Import.Point(bezier.Span1), Point2 = Import.Point(bezier.Span2), Point3 = Import.Point(bezier.End) }); _sink.EndFigure(FigureEnd.Open); }
private void DrawFDEBBeziers2(float width, float height) { te = new List <tempEvents>(); float[] t; for (int i = 0; i < _pt.GetLength(0); i++) { PathGeometry pLinesGeometry = this.Factory.CreatePathGeometry(); GeometrySink gs = pLinesGeometry.Open(); gs.SetFillMode(FillMode.Winding); gs.BeginFigure(new D2D.Point2F(_pt[i, 0, 0], _pt[i, 0, 1]), FigureBegin.Hollow); for (int j = 1; j < _pt.GetLength(1); j += 3) { gs.AddBezier( new BezierSegment( new Point2F(_pt[i, j, 0], _pt[i, j, 1]), new Point2F(_pt[i, j + 1, 0], _pt[i, j + 1, 1]), new Point2F(_pt[i, j + 2, 0], _pt[i, j + 2, 1]) ) ); } gs.EndFigure(FigureEnd.Open); gs.Close(); neutralBrush.Opacity = 0.8f + _normalizedFrequency[i]; this.RenderTarget.DrawGeometry(pLinesGeometry, neutralBrush, 0.8f); foreach (Story s in _st) { t = s.GetLocationLines(); if ((int)_pt[i, 0, 1] == (int)t[0] && (int)_pt[i, (int)(_pt.GetLength(1) - 1), 1] == (int)t[1]) { PointAndTangent pt = pLinesGeometry.ComputePointAtLength((pLinesGeometry.ComputeLength() * s.GetEventLocation()[0]) / width); RectangleGeometry pEventsGeometry = this.Factory.CreateRectangleGeometry( new D2D.RectF(pt.Point.X - RECTSIZE, pt.Point.Y - RECTSIZE, pt.Point.X + RECTSIZE, pt.Point.Y + RECTSIZE) ); te.Add(new tempEvents(pEventsGeometry, brushes[s.GetLabel()], 0.8f)); } } } }
private void CubicBezierCurve(VectorCommand instruction, bool isRelative) { for (int i = 0; i < instruction.Arguments.Length; i = i + 6) { var p1 = new Vector2(instruction.Arguments[0], instruction.Arguments[1]); var p2 = new Vector2(instruction.Arguments[2], instruction.Arguments[3]); var p3 = new Vector2(instruction.Arguments[4], instruction.Arguments[5]); if (isRelative) { p1 += _previousPoint; p2 += _previousPoint; p3 += _previousPoint; } var bezSegment = new BezierSegment() { Point1 = p1, Point2 = p2, Point3 = p3 }; _sink.AddBezier(bezSegment); } }
char _token; // Non whitespace character returned by ReadToken public PathGeometry parse(string path, Factory1 d2dfactory) { _factory = d2dfactory; _pathGeometry = new PathGeometry(d2dfactory); _figure = _pathGeometry.Open(); //GeometrySink _sink = _pathGeometry.Open(); _formatProvider = CultureInfo.InvariantCulture; _pathString = path; _pathLength = path.Length; _curIndex = 0; _secondLastPoint = new Point(0, 0); _lastPoint = new Point(0, 0); _lastStart = new Point(0, 0); _figureStarted = false; bool first = true; char last_cmd = ' '; while (ReadToken()) // Empty path is allowed in XAML { char cmd = _token; if (first) { if ((cmd != 'M') && (cmd != 'm')) // Path starts with M|m { ThrowBadToken(); } first = false; } switch (cmd) { case 'm': case 'M': // XAML allows multiple points after M/m _lastPoint = ReadPoint(cmd, !AllowComma); _figure.BeginFigure(new SharpDX.Vector2((float)_lastPoint.X, (float)_lastPoint.Y), IsFilled ? FigureBegin.Filled : FigureBegin.Hollow); //_figure.StartPoint = _lastPoint; //_figure.IsFilled = IsFilled; //if (!IsClosed) _figure.Close(); //_figure.IsClosed = !IsClosed; //context.BeginFigure(_lastPoint, IsFilled, !IsClosed); _figureStarted = true; _lastStart = _lastPoint; last_cmd = 'M'; while (IsNumber(AllowComma)) { _lastPoint = ReadPoint(cmd, !AllowComma); //LineSegment _lineSegment = new LineSegment(); //_lineSegment.Point = _lastPoint; _figure.AddLine(new SharpDX.Vector2((float)_lastPoint.X, (float)_lastPoint.Y)); //_figure.Segments.Add(_lineSegment); //context.LineTo(_lastPoint, IsStroked, !IsSmoothJoin); last_cmd = 'L'; } break; case 'l': case 'L': case 'h': case 'H': case 'v': case 'V': EnsureFigure(); do { switch (cmd) { case 'l': _lastPoint = ReadPoint(cmd, !AllowComma); break; case 'L': _lastPoint = ReadPoint(cmd, !AllowComma); break; case 'h': _lastPoint.X += ReadNumber(!AllowComma); break; case 'H': _lastPoint.X = ReadNumber(!AllowComma); break; case 'v': _lastPoint.Y += ReadNumber(!AllowComma); break; case 'V': _lastPoint.Y = ReadNumber(!AllowComma); break; } //LineSegment _lineSegment = new LineSegment(); //_lineSegment.Point = _lastPoint; //_figure.Segments.Add(_lineSegment); _figure.AddLine(new SharpDX.Vector2((float)_lastPoint.X, (float)_lastPoint.Y)); //context.LineTo(_lastPoint, IsStroked, !IsSmoothJoin); }while (IsNumber(AllowComma)); last_cmd = 'L'; break; case 'c': case 'C': // cubic Bezier case 's': case 'S': // smooth cublic Bezier EnsureFigure(); do { Point p; if ((cmd == 's') || (cmd == 'S')) { if (last_cmd == 'C') { p = Reflect(); } else { p = _lastPoint; } _secondLastPoint = ReadPoint(cmd, !AllowComma); } else { p = ReadPoint(cmd, !AllowComma); _secondLastPoint = ReadPoint(cmd, AllowComma); } _lastPoint = ReadPoint(cmd, AllowComma); //BezierSegment _bizierSegment = new BezierSegment(); //_bizierSegment.Point1 = p; //_bizierSegment.Point2 = _secondLastPoint; //_bizierSegment.Point3 = _lastPoint; //_figure.Segments.Add(_bizierSegment); _figure.AddBezier(new BezierSegment() { Point1 = new SharpDX.Vector2((float)p.X, (float)p.Y), Point2 = new SharpDX.Vector2((float)_secondLastPoint.X, (float)_secondLastPoint.Y), Point3 = new SharpDX.Vector2((float)_lastPoint.X, (float)_lastPoint.Y) }); //context.BezierTo(p, _secondLastPoint, _lastPoint, IsStroked, !IsSmoothJoin); last_cmd = 'C'; }while (IsNumber(AllowComma)); break; case 'q': case 'Q': // quadratic Bezier case 't': case 'T': // smooth quadratic Bezier EnsureFigure(); do { if ((cmd == 't') || (cmd == 'T')) { if (last_cmd == 'Q') { _secondLastPoint = Reflect(); } else { _secondLastPoint = _lastPoint; } _lastPoint = ReadPoint(cmd, !AllowComma); } else { _secondLastPoint = ReadPoint(cmd, !AllowComma); _lastPoint = ReadPoint(cmd, AllowComma); } //QuadraticBezierSegment _quadraticBezierSegment = new QuadraticBezierSegment(); //_quadraticBezierSegment.Point1 = _secondLastPoint; //_quadraticBezierSegment.Point2 = _lastPoint; //_figure.Segments.Add(_quadraticBezierSegment); _figure.AddQuadraticBezier(new QuadraticBezierSegment() { Point1 = new SharpDX.Vector2((float)_secondLastPoint.X, (float)_secondLastPoint.Y), Point2 = new SharpDX.Vector2((float)_lastPoint.X, (float)_lastPoint.Y) }); //context.QuadraticBezierTo(_secondLastPoint, _lastPoint, IsStroked, !IsSmoothJoin); last_cmd = 'Q'; }while (IsNumber(AllowComma)); break; case 'a': case 'A': EnsureFigure(); do { // A 3,4 5, 0, 0, 6,7 double w = ReadNumber(!AllowComma); double h = ReadNumber(AllowComma); double rotation = ReadNumber(AllowComma); bool large = ReadBool(); bool sweep = ReadBool(); _lastPoint = ReadPoint(cmd, AllowComma); //ArcSegment _arcSegment = new ArcSegment(); //_arcSegment.Point = _lastPoint; //_arcSegment.Size = new Size(w, h); //_arcSegment.RotationAngle = rotation; //_arcSegment.IsLargeArc = large; //_arcSegment.SweepDirection = sweep ? SweepDirection.Clockwise : SweepDirection.Counterclockwise; //_figure.Segments.Add(_arcSegment); _figure.AddArc(new ArcSegment() { Point = new SharpDX.Vector2((float)_lastPoint.X, (float)_lastPoint.Y), Size = new SharpDX.Size2F((float)w, (float)h), RotationAngle = (float)rotation, ArcSize = large ? ArcSize.Large : ArcSize.Small, SweepDirection = sweep ? SweepDirection.Clockwise : SweepDirection.CounterClockwise }); //context.ArcTo( // _lastPoint, // new Size(w, h), // rotation, // large, // sweep ? SweepDirection.Clockwise : SweepDirection.Counterclockwise, // IsStroked, // !IsSmoothJoin // ); }while (IsNumber(AllowComma)); last_cmd = 'A'; break; case 'z': case 'Z': EnsureFigure(); //_figure.IsClosed = IsClosed; //context.SetClosedState(IsClosed); _figure.EndFigure(IsClosed ? FigureEnd.Closed : FigureEnd.Open); _figureStarted = false; last_cmd = 'Z'; _lastPoint = _lastStart; // Set reference point to be first point of current figure break; default: ThrowBadToken(); break; } } //if (null != _figure) //{ // _pathGeometry = new PathGeometry(d2dfactory); // _pathGeometry.Figures.Add(_figure); //} _figure.Close(); //_sink.Close(); return(_pathGeometry); }
/// <summary> /// This method creates the path geometry that represents the star's outline. /// The data of the path is created in Expression Blend first, /// and then use a PowerShell script to translate the XAML to C# code. /// </summary> private void CreateStarOutline() { this._starOutline = this._d2DFactory.CreatePathGeometry(); GeometrySink sink = this._starOutline.Open(); sink.BeginFigure(new Point2F(55.7775869362862f, 8.51374572801038f), FigureBegin.Filled); // The following AddBezier code are generated by the PowerShell script. sink.AddBezier(new BezierSegment( new Point2F(56.9435916193468f, 9.34704511572823f), new Point2F(53.1105762246886f, 6.5137471975463f), new Point2F(52.4435735457851f, 16.0137402172507f))); sink.AddBezier(new BezierSegment( new Point2F(51.7775708708979f, 25.513733236955f), new Point2F(44.4435414150087f, 26.513732502187f), new Point2F(42.9435353904881f, 26.8470322572889f))); sink.AddBezier(new BezierSegment( new Point2F(41.4435293659675f, 27.1803320123907f), new Point2F(28.4438771550624f, 22.0137358086429f), new Point2F(22.2772523878566f, 30.5137295631152f))); sink.AddBezier(new BezierSegment( new Point2F(16.1105276202493f, 39.0137233175875f), new Point2F(21.7772503796831f, 48.0137167046759f), new Point2F(21.1105477019846f, 54.5137119286841f))); sink.AddBezier(new BezierSegment( new Point2F(20.4439450246876f, 61.0137071526923f), new Point2F(6.61048946495231f, 64.3467047037107f), new Point2F(3.77717808543619f, 67.0137027440846f))); sink.AddBezier(new BezierSegment( new Point2F(0.943866705920101f, 69.6807007844584f), new Point2F(-0.889540657650585f, 73.5136979680928f), new Point2F(0.443864697746569f, 77.6806949063147f))); sink.AddBezier(new BezierSegment( new Point2F(1.77717005274209f, 81.8466918452714f), new Point2F(8.94379883629487f, 88.8466867018956f), new Point2F(8.9438988366965f, 88.8466867018956f))); sink.AddBezier(new BezierSegment( new Point2F(11.2772082080391f, 91.3466848649757f), new Point2F(10.7772061998656f, 100.680678006652f), new Point2F(8.44389682852298f, 102.1806769045f))); sink.AddBezier(new BezierSegment( new Point2F(6.11048745677877f, 103.680675802348f), new Point2F(-2.38954668217117f, 114.180668087284f), new Point2F(1.61046938321705f, 120.680663311292f))); sink.AddBezier(new BezierSegment( new Point2F(5.61048544860525f, 127.180658535301f), new Point2F(11.6105095466876f, 126.846658780713f), new Point2F(15.9439269511259f, 128.513657555855f))); sink.AddBezier(new BezierSegment( new Point2F(20.2772443551626f, 130.180656330997f), new Point2F(21.7772503796831f, 136.346651800417f), new Point2F(21.4439490410347f, 137.846650698265f))); sink.AddBezier(new BezierSegment( new Point2F(21.1105477019846f, 139.346649596113f), new Point2F(18.4439369919935f, 151.013641023576f), new Point2F(19.9439430165141f, 154.513638451888f))); sink.AddBezier(new BezierSegment( new Point2F(21.4439490410347f, 158.0136358802f), new Point2F(23.7772584123772f, 159.84663453337f), new Point2F(23.7772584123772f, 159.84663453337f))); sink.AddBezier(new BezierSegment( new Point2F(24.9439630982493f, 162.180632818422f), new Point2F(30.110583849108f, 162.513632573744f), new Point2F(34.2773005840213f, 161.346633431218f))); sink.AddBezier(new BezierSegment( new Point2F(38.4435173169264f, 160.180634287958f), new Point2F(44.1105400775651f, 161.846633063834f), new Point2F(44.1105400775651f, 161.846633063834f))); sink.AddBezier(new BezierSegment( new Point2F(53.9435795703057f, 169.013627797752f), new Point2F(50.2775648463774f, 173.346624614003f), new Point2F(54.4435815784792f, 180.013619715305f))); sink.AddBezier(new BezierSegment( new Point2F(58.6105983145974f, 186.680614816607f), new Point2F(63.6106183963326f, 185.346615796787f), new Point2F(66.7776311161037f, 184.846616164171f))); sink.AddBezier(new BezierSegment( new Point2F(69.9436438318585f, 184.346616531555f), new Point2F(77.4436739544614f, 178.846620572779f), new Point2F(79.6106826578854f, 178.180621062134f))); sink.AddBezier(new BezierSegment( new Point2F(81.7776913613095f, 177.513621552225f), new Point2F(86.6107107723148f, 178.846620572779f), new Point2F(86.6107107723148f, 178.846620572779f))); sink.AddBezier(new BezierSegment( new Point2F(96.7777516065153f, 189.930612428611f), new Point2F(102.943776371311f, 190.013612367625f), new Point2F(105.943788420352f, 189.680612612303f))); sink.AddBezier(new BezierSegment( new Point2F(108.943800469394f, 189.346612857715f), new Point2F(115.277825908936f, 185.013616041465f), new Point2F(116.610831262726f, 180.513619347921f))); sink.AddBezier(new BezierSegment( new Point2F(117.943836616517f, 176.013622654377f), new Point2F(122.110853352635f, 173.346624614003f), new Point2F(122.943856698252f, 173.180624735974f))); sink.AddBezier(new BezierSegment( new Point2F(123.777860047886f, 173.01362485868f), new Point2F(124.777864064233f, 170.846626450923f), new Point2F(131.277890170489f, 173.180624735974f))); sink.AddBezier(new BezierSegment( new Point2F(137.777916276744f, 175.513623021761f), new Point2F(144.943945057887f, 175.680622899054f), new Point2F(149.777964472909f, 173.346624614003f))); sink.AddBezier(new BezierSegment( new Point2F(154.610983883914f, 171.013626328216f), new Point2F(153.277978530124f, 163.180632083654f), new Point2F(153.277978530124f, 161.18063355319f))); sink.AddBezier(new BezierSegment( new Point2F(153.277978530124f, 159.180635022726f), new Point2F(153.110977859394f, 155.51363771712f), new Point2F(156.277990579165f, 151.180640900869f))); sink.AddBezier(new BezierSegment( new Point2F(159.44400329492f, 146.846644085354f), new Point2F(171.611052161814f, 145.013645432183f), new Point2F(171.611052161814f, 145.013645432183f))); sink.AddBezier(new BezierSegment( new Point2F(180.444087638208f, 142.680647146397f), new Point2F(179.111082284417f, 136.180651922389f), new Point2F(179.944085630034f, 133.346654004721f))); sink.AddBezier(new BezierSegment( new Point2F(180.778088979668f, 130.513656086319f), new Point2F(174.611064210855f, 119.01366453615f), new Point2F(174.611064210855f, 119.01366453615f))); sink.AddBezier(new BezierSegment( new Point2F(174.611064210855f, 119.01366453615f), new Point2F(175.778068897932f, 112.846669067465f), new Point2F(176.611072243549f, 111.846669802232f))); sink.AddBezier(new BezierSegment( new Point2F(177.444075589167f, 110.846670537f), new Point2F(189.778125126791f, 103.680675802348f), new Point2F(190.444127801678f, 96.6806809457234f))); sink.AddBezier(new BezierSegment( new Point2F(191.111130480582f, 89.6806860890991f), new Point2F(181.111090317111f, 83.1806908650909f), new Point2F(179.111082284417f, 81.6806919672428f))); sink.AddBezier(new BezierSegment( new Point2F(177.111074251723f, 80.1806930693948f), new Point2F(172.944057515605f, 76.8466955191112f), new Point2F(175.611068227202f, 70.6807000496904f))); sink.AddBezier(new BezierSegment( new Point2F(178.2780789388f, 64.5137045810045f), new Point2F(183.944101695422f, 52.013713765604f), new Point2F(176.444071572819f, 47.1807173167376f))); sink.AddBezier(new BezierSegment( new Point2F(168.944041450217f, 42.3470208683855f), new Point2F(162.111014006517f, 43.846719766454f), new Point2F(157.110993924782f, 40.8470219705374f))); sink.AddBezier(new BezierSegment( new Point2F(152.110973843047f, 37.8470241748413f), new Point2F(154.110981875741f, 28.1804312775493f), new Point2F(152.61097585122f, 22.8470351963607f))); sink.AddBezier(new BezierSegment( new Point2F(151.1109698267f, 17.5137391150987f), new Point2F(149.610963802179f, 17.0137394824827f), new Point2F(145.943949074234f, 14.5137413194026f))); sink.AddBezier(new BezierSegment( new Point2F(142.277934350306f, 12.0137431563225f), new Point2F(131.943892845376f, 16.1804400947648f), new Point2F(127.777876113274f, 17.1804393599969f))); sink.AddBezier(new BezierSegment( new Point2F(123.610859377156f, 18.1803386253024f), new Point2F(121.277850007018f, 15.5137405846346f), new Point2F(121.277850007018f, 15.5137405846346f))); sink.AddBezier(new BezierSegment( new Point2F(107.443794444873f, -2.65294606705621f), new Point2F(110.2778058272f, 2.34715025903049f), new Point2F(106.110789091082f, 0.347051728639904f))); sink.AddBezier(new BezierSegment( new Point2F(101.943772354964f, -1.65294680182417f), new Point2F(93.5027384529787f, 5.64394783664748f), new Point2F(93.5027384529787f, 5.64394783664748f))); sink.AddBezier(new BezierSegment( new Point2F(91.9237321111667f, 7.53884644433565f), new Point2F(90.3437257653383f, 9.43364505209733f), new Point2F(88.5837186965675f, 10.6619441495818f))); sink.AddBezier(new BezierSegment( new Point2F(86.8237116277967f, 11.8902432470663f), new Point2F(84.8837038360835f, 12.4519428343472f), new Point2F(82.7476952571661f, 12.2606429749083f))); sink.AddBezier(new BezierSegment( new Point2F(80.6106866742325f, 12.0692431155429f), new Point2F(78.2776773040948f, 11.1248438094578f), new Point2F(76.082668488213f, 9.90264470749116f))); sink.AddBezier(new BezierSegment( new Point2F(73.8886596763476f, 8.68044560552456f), new Point2F(71.8326514187381f, 7.18044670767652f), new Point2F(69.1666407111568f, 6.23594740166484f))); sink.AddBezier(new BezierSegment( new Point2F(66.4996299995592f, 5.29154809557971f), new Point2F(63.2216168339736f, 4.90264838133097f), new Point2F(60.8886074638359f, 5.37484803437354f))); sink.AddBezier(new BezierSegment( new Point2F(58.5555980936983f, 5.84704768741611f), new Point2F(57.1665925149922f, 7.18044670767652f), new Point2F(55.7775869362862f, 8.51374572801038f))); sink.EndFigure(FigureEnd.Closed); sink.Close(); }
public static void CreateFromString([NotNull] Font font, [CanBeNull] string str, [NotNull] GeometrySink sink) { if (string.IsNullOrEmpty(str)) { return; } Guard.ArgumentNotNull(font, nameof(font)); var fontFace = font.FontFace; const int noError = 0; const int factorX = 1 << 10; const int factorY = -factorX; var currentOrigin = Vector2.Zero; var outlineFuncs = new OutlineFuncs(MoveTo, LineTo, QuadraticBezierTo, CubicBezierTo, factorX, 0); foreach (var ch in str) { if (ch == '\r') { continue; } if (ch == ' ') { // TODO: hack! currentOrigin.X += FontHelper.PointsToPixels(font.Size) / 2; continue; } if (ch == '\n') { currentOrigin.Y += FontHelper.PointsToPixels(font.Size); continue; } var glyphIndex = fontFace.GetCharIndex(ch); fontFace.LoadGlyph(glyphIndex, LoadFlags.Render, LoadTarget.Normal); var outline = fontFace.Glyph.Outline; sink.BeginFigure(currentOrigin); outline.Decompose(outlineFuncs, IntPtr.Zero); sink.EndFigure(FigureEnd.Closed); var metrics = fontFace.Glyph.Metrics; var charSize = fontFace.GetCharSize(glyphIndex, metrics, null, 1, 1); currentOrigin.X += charSize.X; } int MoveTo(ref FTVector p2, IntPtr user) { sink.EndFigure(FigureEnd.Closed); sink.BeginFigure(currentOrigin + new Vector2(factorX * p2.X.ToSingle(), factorY * p2.Y.ToSingle())); return(noError); } int LineTo(ref FTVector p2, IntPtr user) { sink.AddLine(currentOrigin + new Vector2(factorX * p2.X.ToSingle(), factorY * p2.Y.ToSingle())); return(noError); } int QuadraticBezierTo(ref FTVector cp, ref FTVector p2, IntPtr user) { var bezier = new QuadraticBezierSegment { Point1 = currentOrigin + new Vector2(factorX * cp.X.ToSingle(), factorY * cp.Y.ToSingle()), Point2 = currentOrigin + new Vector2(factorX * p2.X.ToSingle(), factorY * p2.Y.ToSingle()) }; sink.AddQuadraticBezier(bezier); return(noError); } int CubicBezierTo(ref FTVector cp1, ref FTVector cp2, ref FTVector p2, IntPtr user) { var bezier = new BezierSegment { Point1 = currentOrigin + new Vector2(factorX * cp1.X.ToSingle(), factorY * cp1.Y.ToSingle()), Point2 = currentOrigin + new Vector2(factorX * cp2.X.ToSingle(), factorY * cp2.Y.ToSingle()), Point3 = currentOrigin + new Vector2(factorX * p2.X.ToSingle(), factorY * p2.Y.ToSingle()) }; sink.AddBezier(bezier); return(noError); } }
char _token; // Non whitespace character returned by ReadToken public PathGeometry parse(string path, Factory1 d2dfactory) { _factory = d2dfactory; _pathGeometry = new PathGeometry(d2dfactory); _figure = _pathGeometry.Open(); //GeometrySink _sink = _pathGeometry.Open(); _formatProvider = CultureInfo.InvariantCulture; _pathString = path; _pathLength = path.Length; _curIndex = 0; _secondLastPoint = new Point(0, 0); _lastPoint = new Point(0, 0); _lastStart = new Point(0, 0); _figureStarted = false; bool first = true; char last_cmd = ' '; while (ReadToken()) // Empty path is allowed in XAML { char cmd = _token; if (first) { if ((cmd != 'M') && (cmd != 'm')) // Path starts with M|m { ThrowBadToken(); } first = false; } switch (cmd) { case 'm': case 'M': // XAML allows multiple points after M/m _lastPoint = ReadPoint(cmd, !AllowComma); _figure.BeginFigure(new SharpDX.Vector2((float)_lastPoint.X, (float)_lastPoint.Y), IsFilled ? FigureBegin.Filled : FigureBegin.Hollow); //_figure.StartPoint = _lastPoint; //_figure.IsFilled = IsFilled; //if (!IsClosed) _figure.Close(); //_figure.IsClosed = !IsClosed; //context.BeginFigure(_lastPoint, IsFilled, !IsClosed); _figureStarted = true; _lastStart = _lastPoint; last_cmd = 'M'; while (IsNumber(AllowComma)) { _lastPoint = ReadPoint(cmd, !AllowComma); //LineSegment _lineSegment = new LineSegment(); //_lineSegment.Point = _lastPoint; _figure.AddLine(new SharpDX.Vector2((float)_lastPoint.X, (float)_lastPoint.Y)); //_figure.Segments.Add(_lineSegment); //context.LineTo(_lastPoint, IsStroked, !IsSmoothJoin); last_cmd = 'L'; } break; case 'l': case 'L': case 'h': case 'H': case 'v': case 'V': EnsureFigure(); do { switch (cmd) { case 'l': _lastPoint = ReadPoint(cmd, !AllowComma); break; case 'L': _lastPoint = ReadPoint(cmd, !AllowComma); break; case 'h': _lastPoint.X += ReadNumber(!AllowComma); break; case 'H': _lastPoint.X = ReadNumber(!AllowComma); break; case 'v': _lastPoint.Y += ReadNumber(!AllowComma); break; case 'V': _lastPoint.Y = ReadNumber(!AllowComma); break; } //LineSegment _lineSegment = new LineSegment(); //_lineSegment.Point = _lastPoint; //_figure.Segments.Add(_lineSegment); _figure.AddLine(new SharpDX.Vector2((float)_lastPoint.X, (float)_lastPoint.Y)); //context.LineTo(_lastPoint, IsStroked, !IsSmoothJoin); } while (IsNumber(AllowComma)); last_cmd = 'L'; break; case 'c': case 'C': // cubic Bezier case 's': case 'S': // smooth cublic Bezier EnsureFigure(); do { Point p; if ((cmd == 's') || (cmd == 'S')) { if (last_cmd == 'C') { p = Reflect(); } else { p = _lastPoint; } _secondLastPoint = ReadPoint(cmd, !AllowComma); } else { p = ReadPoint(cmd, !AllowComma); _secondLastPoint = ReadPoint(cmd, AllowComma); } _lastPoint = ReadPoint(cmd, AllowComma); //BezierSegment _bizierSegment = new BezierSegment(); //_bizierSegment.Point1 = p; //_bizierSegment.Point2 = _secondLastPoint; //_bizierSegment.Point3 = _lastPoint; //_figure.Segments.Add(_bizierSegment); _figure.AddBezier(new BezierSegment() { Point1 = new SharpDX.Vector2((float)p.X, (float)p.Y), Point2 = new SharpDX.Vector2((float)_secondLastPoint.X, (float)_secondLastPoint.Y), Point3 = new SharpDX.Vector2((float)_lastPoint.X, (float)_lastPoint.Y) }); //context.BezierTo(p, _secondLastPoint, _lastPoint, IsStroked, !IsSmoothJoin); last_cmd = 'C'; } while (IsNumber(AllowComma)); break; case 'q': case 'Q': // quadratic Bezier case 't': case 'T': // smooth quadratic Bezier EnsureFigure(); do { if ((cmd == 't') || (cmd == 'T')) { if (last_cmd == 'Q') { _secondLastPoint = Reflect(); } else { _secondLastPoint = _lastPoint; } _lastPoint = ReadPoint(cmd, !AllowComma); } else { _secondLastPoint = ReadPoint(cmd, !AllowComma); _lastPoint = ReadPoint(cmd, AllowComma); } //QuadraticBezierSegment _quadraticBezierSegment = new QuadraticBezierSegment(); //_quadraticBezierSegment.Point1 = _secondLastPoint; //_quadraticBezierSegment.Point2 = _lastPoint; //_figure.Segments.Add(_quadraticBezierSegment); _figure.AddQuadraticBezier(new QuadraticBezierSegment() { Point1 = new SharpDX.Vector2((float)_secondLastPoint.X, (float)_secondLastPoint.Y), Point2 = new SharpDX.Vector2((float)_lastPoint.X, (float)_lastPoint.Y) }); //context.QuadraticBezierTo(_secondLastPoint, _lastPoint, IsStroked, !IsSmoothJoin); last_cmd = 'Q'; } while (IsNumber(AllowComma)); break; case 'a': case 'A': EnsureFigure(); do { // A 3,4 5, 0, 0, 6,7 double w = ReadNumber(!AllowComma); double h = ReadNumber(AllowComma); double rotation = ReadNumber(AllowComma); bool large = ReadBool(); bool sweep = ReadBool(); _lastPoint = ReadPoint(cmd, AllowComma); //ArcSegment _arcSegment = new ArcSegment(); //_arcSegment.Point = _lastPoint; //_arcSegment.Size = new Size(w, h); //_arcSegment.RotationAngle = rotation; //_arcSegment.IsLargeArc = large; //_arcSegment.SweepDirection = sweep ? SweepDirection.Clockwise : SweepDirection.Counterclockwise; //_figure.Segments.Add(_arcSegment); _figure.AddArc(new ArcSegment() { Point = new SharpDX.Vector2((float)_lastPoint.X, (float)_lastPoint.Y), Size = new SharpDX.Size2F((float)w, (float)h), RotationAngle = (float)rotation, ArcSize = large ? ArcSize.Large : ArcSize.Small, SweepDirection = sweep ? SweepDirection.Clockwise : SweepDirection.CounterClockwise }); //context.ArcTo( // _lastPoint, // new Size(w, h), // rotation, // large, // sweep ? SweepDirection.Clockwise : SweepDirection.Counterclockwise, // IsStroked, // !IsSmoothJoin // ); } while (IsNumber(AllowComma)); last_cmd = 'A'; break; case 'z': case 'Z': EnsureFigure(); //_figure.IsClosed = IsClosed; //context.SetClosedState(IsClosed); _figure.EndFigure(IsClosed ? FigureEnd.Closed : FigureEnd.Open); _figureStarted = false; last_cmd = 'Z'; _lastPoint = _lastStart; // Set reference point to be first point of current figure break; default: ThrowBadToken(); break; } } //if (null != _figure) //{ // _pathGeometry = new PathGeometry(d2dfactory); // _pathGeometry.Figures.Add(_figure); //} _figure.Close(); //_sink.Close(); return _pathGeometry; }
/// <summary> /// This method creates the path geometry that represents the down continent in the planet. /// It demonstrates how to substitute clipping by intersecting. /// </summary> private void CreatePlanetDownPath() { // Since clip is required, we must draw to a temporary path, and then intersect it with the ellipse, and save the result in m_pPlanetUpPath. PathGeometry tempPath = this._d2DFactory.CreatePathGeometry(); this._planetDownPath = this._d2DFactory.CreatePathGeometry(); GeometrySink sink = tempPath.Open(); sink.BeginFigure(new Point2F(0.0288963486137668f, 71.2923486227374f), FigureBegin.Filled); // The following AddBezier code are generated by the PowerShell script. sink.AddBezier(new BezierSegment( new Point2F(0.715499175522696f, -0.486801532710843f), new Point2F(26.1927417195169f, 14.0124923433061f), new Point2F(48.6926998092458f, 17.5124667261123f))); sink.AddBezier(new BezierSegment( new Point2F(71.1926578989747f, 21.0124411089184f), new Point2F(94.1926150573642f, 39.512305703751f), new Point2F(93.192616920043f, 53.512703231316f))); sink.AddBezier(new BezierSegment( new Point2F(92.1926187827217f, 67.5126007625406f), new Point2F(123.192561039681f, 82.5124909745669f), new Point2F(123.192561039681f, 82.5124909745669f))); sink.AddBezier(new BezierSegment( new Point2F(123.192561039681f, 82.5124909745669f), new Point2F(134.192540550216f, 62.0126410181309f), new Point2F(121.6925638337f, 45.0122654481606f))); sink.AddBezier(new BezierSegment( new Point2F(109.192587117184f, 28.0123898745307f), new Point2F(99.6926048126313f, 2.01258017368507f), new Point2F(122.692561971021f, 21.5124374493193f))); sink.AddBezier(new BezierSegment( new Point2F(145.69251912941f, 41.0122947249536f), new Point2F(151.692507953338f, 62.5126373585318f), new Point2F(149.192512610035f, 67.0126044221397f))); sink.AddBezier(new BezierSegment( new Point2F(146.692517266732f, 71.5125714857476f), new Point2F(159.192493983248f, 73.5125568473511f), new Point2F(147.192516335392f, 84.5124763361704f))); sink.AddBezier(new BezierSegment( new Point2F(135.192538687537f, 95.5123958249898f), new Point2F(108.692588048523f, 102.012348250201f), new Point2F(108.692588048523f, 102.012348250201f))); sink.AddBezier(new BezierSegment( new Point2F(108.692588048523f, 102.012348250201f), new Point2F(-5.30719960610358f, 132.012128674254f), new Point2F(0.19280014914486f, 0.0125948120815593f))); sink.EndFigure(FigureEnd.Closed); sink.Close(); GeometrySink sink2 = this._planetDownPath.Open(); // Create a clip ellipse. Ellipse clip = new Ellipse(new Point2F(95f, 1f), 100f, 100f); EllipseGeometry clipEllipse = this._d2DFactory.CreateEllipseGeometry(clip); // There's no direct support for clipping path in Direct2D. So we can intersect a path with its clip instead. tempPath.CombineWithGeometry(clipEllipse, CombineMode.Intersect, 0f, sink2); sink2.Close(); }
protected override void OnCreateDeviceIndependentResources(Direct2DFactory factory) { base.OnCreateDeviceIndependentResources(factory); this._leftMountainGeometry = factory.CreatePathGeometry(); using (GeometrySink sink = this._leftMountainGeometry.Open()) { sink.SetFillMode(FillMode.Winding); sink.BeginFigure(new PointF(346, 255), FigureBegin.Filled); sink.AddLines( new PointF[] { new PointF(267, 177), new PointF(236, 192), new PointF(212, 160), new PointF(156, 255), new PointF(346, 255) }); sink.EndFigure(FigureEnd.Closed); sink.Close(); } this._rightMountainGeometry = factory.CreatePathGeometry(); using (GeometrySink sink = this._rightMountainGeometry.Open()) { sink.SetFillMode(FillMode.Winding); sink.BeginFigure(new PointF(575, 263), FigureBegin.Filled); sink.AddLines( new PointF[] { new PointF(481, 146), new PointF(449, 181), new PointF(433, 159), new PointF(401, 214), new PointF(381, 199), new PointF(323, 263), new PointF(575, 263) }); sink.EndFigure(FigureEnd.Closed); sink.Close(); } this._sunGeometry = factory.CreatePathGeometry(); using (GeometrySink sink = this._sunGeometry.Open()) { sink.SetFillMode(FillMode.Winding); sink.BeginFigure(new PointF(270, 255), FigureBegin.Filled); sink.AddArc( new ArcSegment( new PointF(440, 255), // end point new SizeF(85, 85), 0.0f, // rotation angle SweepDirection.Clockwise, ArcSize.Small)); sink.EndFigure(FigureEnd.Closed); sink.BeginFigure(new PointF(299, 182), FigureBegin.Hollow); sink.AddBezier( new BezierSegment( new PointF(299, 182), new PointF(294, 176), new PointF(285, 178) )); sink.AddBezier( new BezierSegment( new PointF(276, 179), new PointF(272, 173), new PointF(272, 173) )); sink.EndFigure(FigureEnd.Open); sink.BeginFigure( new PointF(354, 156), FigureBegin.Hollow ); sink.AddBezier( new BezierSegment( new PointF(354, 156), new PointF(358, 149), new PointF(354, 142) )); sink.AddBezier( new BezierSegment( new PointF(349, 134), new PointF(354, 127), new PointF(354, 127) )); sink.EndFigure(FigureEnd.Open); sink.BeginFigure( new PointF(322, 164), FigureBegin.Hollow ); sink.AddBezier( new BezierSegment( new PointF(322, 164), new PointF(322, 156), new PointF(314, 152) )); sink.AddBezier( new BezierSegment( new PointF(306, 149), new PointF(305, 141), new PointF(305, 141) )); sink.EndFigure(FigureEnd.Open); sink.BeginFigure( new PointF(385, 164), FigureBegin.Hollow ); sink.AddBezier( new BezierSegment( new PointF(385, 164), new PointF(392, 161), new PointF(394, 152) )); sink.AddBezier( new BezierSegment( new PointF(395, 144), new PointF(402, 141), new PointF(402, 142) )); sink.EndFigure(FigureEnd.Open); sink.BeginFigure( new PointF(408, 182), FigureBegin.Hollow ); sink.AddBezier( new BezierSegment( new PointF(408, 182), new PointF(416, 184), new PointF(422, 178) )); sink.AddBezier( new BezierSegment( new PointF(428, 171), new PointF(435, 173), new PointF(435, 173) )); sink.EndFigure(FigureEnd.Open); sink.Close(); } this._riverGeometry = factory.CreatePathGeometry(); using (GeometrySink sink = this._riverGeometry.Open()) { sink.SetFillMode(FillMode.Winding); sink.BeginFigure( new PointF(183, 392), FigureBegin.Filled ); sink.AddBezier( new BezierSegment( new PointF(238, 284), new PointF(472, 345), new PointF(356, 303) )); sink.AddBezier( new BezierSegment( new PointF(237, 261), new PointF(333, 256), new PointF(333, 256) )); sink.AddBezier( new BezierSegment( new PointF(335, 257), new PointF(241, 261), new PointF(411, 306) )); sink.AddBezier( new BezierSegment( new PointF(574, 350), new PointF(288, 324), new PointF(296, 392) )); sink.EndFigure(FigureEnd.Open); sink.Close(); } }
// FIXME another example of type switching. Cant put d2d code on other side of bridge in eg UGeometryBase abstraction // and also, using a factory to create the UGeometryBase will make d2d specific versions. // IDEA This is possible: Use factory (DI?) and check the Uxxx instances when passed to this type of class, and recreate // a portion of the Uxxx if it doesnt match D2D? Factory could be configured for d2d/ogl etc. This links in with cacheing // code too? Not sure if this will static compile :/ thats kinda the point... we'd need the Uxxx.ICreateStuff to be a specific // D2D interface...could subclass... would check if(ICreateStuff is D2DCreator) as d2dcreator else Icreatestuff=new d2dcreator... void AppendGeometry(GeometrySink sink, UGeometryBase geo) { if (geo is UArc) { UArc arc = geo as UArc; sink.AddArc(new ArcSegment() { SweepDirection = arc.sweepClockwise ? SweepDirection.Clockwise : SweepDirection.CounterClockwise, RotationAngle = -arc.rotation, ArcSize = arc.reflex ? ArcSize.Large : ArcSize.Small, Point = D2DTr.tr(arc.endPoint), Size = D2DTr.tr(arc.arcSize) }); } //else if (geo is UEasyArc) //{ // UEasyArc arc = geo as UEasyArc; // var eco = geo.Retreive<D2DDraw>(() => // { // var cp = gcpt(); // return EllipseLib.EasyEllipse.ConvertEndPoint(new EllipseLib.EasyEllipse.EasyEllipseInput() // { // resolution = arc.resolution, // t1 = arc.startAngle, // t2 = arc.endAngle, // rx = arc.arcSize.width, // ry = arc.arcSize.height, // rotation = arc.rotation, // start_x = cp.X, // start_y = cp.Y // }); // }) as EllipseLib.EasyEllipse.EECOut; // sink.AddArc(new ArcSegment() // { // SweepDirection = eco.clockwise ? SweepDirection.Clockwise : SweepDirection.CounterClockwise, // RotationAngle = -arc.rotation, // ArcSize = eco.reflex ? ArcSize.Large : ArcSize.Small, // Point = new SharpDXLib.DrawingPointF(eco.x, eco.y), // Size = D2DTr.tr(arc.arcSize) // }); //} else if (geo is ULine) { ULine line = geo as ULine; sink.AddLine(D2DTr.tr(line.endPoint)); } else if (geo is UBeizer) { UBeizer beizer = geo as UBeizer; sink.AddBezier(new BezierSegment() { Point1 = D2DTr.tr(beizer.controlPoint1), Point2 = D2DTr.tr(beizer.controlPoint2), Point3 = D2DTr.tr(beizer.endPoint) }); } else { throw new NotImplementedException(); } }