示例#1
0
文件: ICanvas.cs 项目: yard/NGraphics
 public static void DrawLine(this ICanvas canvas, Point start, Point end, Pen pen)
 {
     var p = new Path { Pen = pen };
     p.MoveTo(start,false);
     p.LineTo(end);
     p.Draw(canvas);
 }
示例#2
0
        public BaseBrush GetBrush(Dictionary<string, string> styleAttributes,Dictionary<string, XElement> defs, Pen pen)
        {
            BaseBrush baseBrush = null;

              var fillOpacity = GetString(styleAttributes, "fill-opacity");
              if (!string.IsNullOrWhiteSpace(fillOpacity))
              {
            if (baseBrush == null)
              baseBrush = new SolidBrush();
            var sb = baseBrush as SolidBrush;
            if (sb != null)
              sb.Color = sb.Color.WithAlpha(_valuesParser.ReadNumber(fillOpacity));
              }

              var fillRule = GetString(styleAttributes, "fill-rule");
              if (!string.IsNullOrWhiteSpace(fillRule))
              {
            if (baseBrush == null)
              baseBrush = new SolidBrush();
            var sb = baseBrush as SolidBrush;
            if (sb != null)
            {
              if (fillRule.Equals("evenodd"))
              {
            sb.FillMode = FillMode.EvenOdd;
              }
            }
              }

              var fill = GetString(styleAttributes, "fill").Trim();
              if (string.IsNullOrEmpty(fill))
              {
            // No change
              }
              else if (fill == "none")
              {
            baseBrush = null;
              }
              else
              {
            Color color;
            if (Colors.TryParse(fill, out color))
            {
              var sb = baseBrush as SolidBrush;
              if (sb == null)
              {
            baseBrush = new SolidBrush(color);
              }
              else
              {
            if (sb.Color.Alpha == 1 || pen == null)
              sb.Color = color;
            else
              sb.Color = color.WithAlpha(sb.Color.Alpha);
              }
            }
            else
            {
              var urlM = _fillUrlRe.Match(fill);
              if (urlM.Success)
              {
            var id = urlM.Groups[1].Value.Trim();
            XElement defE;
            if (defs.TryGetValue(id, out defE))
            {
              switch (defE.Name.LocalName)
              {
                case "linearGradient":
                  baseBrush = CreateLinearGradientBrush(defE);
                  break;
                case "radialGradient":
                  baseBrush = CreateRadialGradientBrush(defE);
                  break;
                default:
                  throw new NotSupportedException("Fill " + defE.Name);
              }
            }
            else
            {
              throw new Exception("Invalid fill url reference: " + id);
            }
              }
              else
              {
            throw new NotSupportedException("Fill " + fill);
              }
            }
              }

              var opacity = GetString(styleAttributes, "opacity");
              if (!string.IsNullOrWhiteSpace(opacity))
              {
            var sb = baseBrush as SolidBrush;
            if (sb != null)
            sb.Color = sb.Color.WithAlpha(_valuesParser.ReadNumber(opacity));
              }

              return baseBrush;
        }
示例#3
0
        public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left,
            Pen pen = null, BaseBrush brush = null)
        {
            if (brush == null)
            return;

              var paint = GetFontPaint(font, alignment);
              var w = paint.MeasureText(text);
              var fm = paint.GetFontMetrics();
              var h = fm.Ascent + fm.Descent;
              var point = frame.Position;
              var fr = new Rect(point, new Size(w, h));
              AddBrushPaint(paint, brush, fr);
              graphics.DrawText(text, (float) point.X, (float) point.Y, paint);
        }
示例#4
0
        public void DrawPath(IEnumerable<PathOperation> ops, Pen pen = null, BaseBrush brush = null)
        {
            using (var path = new Path())
              {
            var bb = new BoundingBoxBuilder();

            foreach (var op in ops)
            {
              var moveTo = op as MoveTo;
              if (moveTo != null)
              {
            var start = moveTo.Start;
            var end = moveTo.End;

            path.MoveTo((float) start.X, (float) start.Y);

            bb.Add(start);
            bb.Add(end);
            continue;
              }
              var lineTo = op as LineTo;
              if (lineTo != null)
              {
            var start = lineTo.Start;
            var end = lineTo.End;
            path.LineTo((float) start.X, (float) start.Y);
            path.LineTo((float) end.X, (float) end.Y);
            bb.Add(start);
            bb.Add(end);
            continue;
              }
              var at = op as ArcTo;
              if (at != null)
              {
            var p = at.Point;
            path.LineTo((float) p.X, (float) p.Y);
            bb.Add(p);
            continue;
              }
              var curveTo = op as CurveTo;
              if (curveTo != null)
              {
            var end = curveTo.End;
            var firstControlPoint = curveTo.FirstControlPoint;
            var secondControlPoint = curveTo.SecondControlPoint;

            path.CubicTo((float) firstControlPoint.X, (float) firstControlPoint.Y, (float) secondControlPoint.X,
              (float) secondControlPoint.Y, (float) end.X, (float) end.Y);

            bb.Add(firstControlPoint);
            bb.Add(secondControlPoint);
            bb.Add(end);
            continue;
              }
              var cp = op as ClosePath;
              if (cp != null)
              {
            path.Close();
            continue;
              }

              throw new NotSupportedException("Path Op " + op);
            }

            var frame = bb.BoundingBox;

            if (brush != null)
            {
              var solidBrush = brush as SolidBrush;

              if (solidBrush != null)
              {
            path.SetFillType(GetPathFillType(((SolidBrush)brush).FillMode));
              }

              var brushPaint = GetBrushPaint(brush, frame);
              graphics.DrawPath(path, brushPaint);
            }
            if (pen != null)
            {
              var penPaint = GetPenPaint(pen);
              graphics.DrawPath(path, penPaint);
            }
              }
        }
示例#5
0
 public void DrawEllipse(Rect frame, Pen pen = null, BaseBrush brush = null)
 {
 }
示例#6
0
 public void DrawRectangle(Rect frame, Pen pen = null, BaseBrush brush = null)
 {
 }
示例#7
0
        CGPathDrawingMode SetPenAndBrush(Pen pen, BaseBrush baseBrush)
        {
            var mode = CGPathDrawingMode.Fill;

            var sb = baseBrush as SolidBrush;

            if (sb != null) {
                if (sb.FillMode == FillMode.EvenOdd) {
                    mode = CGPathDrawingMode.EOFill;
                }
            }

            if (baseBrush != null) {
                SetBrush (baseBrush);
                if (pen != null) {
                    mode = CGPathDrawingMode.FillStroke;

                    if (sb != null) {
                        if (sb.FillMode == FillMode.EvenOdd) {
                            mode = CGPathDrawingMode.EOFillStroke;
                        }
                    }
                }
            }
            if (pen != null) {
                SetPen (pen);
                if (baseBrush == null)
                    mode = CGPathDrawingMode.Stroke;
            }
            return mode;
        }
示例#8
0
        void DrawElement(Func<Rect> add, Pen pen = null, BaseBrush brush = null)
        {
            if (pen == null && brush == null)
                return;

            var lgb = brush as LinearGradientBrush;
            if (lgb != null) {
                var cg = CreateGradient (lgb.Stops);
                context.SaveState ();
                var frame = add ();
                context.Clip ();
                CGGradientDrawingOptions options = CGGradientDrawingOptions.DrawsBeforeStartLocation | CGGradientDrawingOptions.DrawsAfterEndLocation;
                var size = frame.Size;
                var start = Conversions.GetCGPoint (lgb.Absolute ? lgb.Start : frame.Position + lgb.Start * size);
                var end = Conversions.GetCGPoint (lgb.Absolute ? lgb.End : frame.Position + lgb.End * size);
                context.DrawLinearGradient (cg, start, end, options);
                context.RestoreState ();
                brush = null;
            }

            var rgb = brush as RadialGradientBrush;
            if (rgb != null) {
                var cg = CreateGradient (rgb.Stops);
                context.SaveState ();
                var frame = add ();
                context.Clip ();
                CGGradientDrawingOptions options = CGGradientDrawingOptions.DrawsBeforeStartLocation | CGGradientDrawingOptions.DrawsAfterEndLocation;
                var size = frame.Size;
                var start = Conversions.GetCGPoint (rgb.GetAbsoluteCenter (frame));
                var r = (nfloat)rgb.GetAbsoluteRadius (frame).Max;
                var end = Conversions.GetCGPoint (rgb.GetAbsoluteFocus (frame));
                context.DrawRadialGradient (cg, start, 0, end, r, options);
                context.RestoreState ();
                brush = null;
            }

            if (pen != null || brush != null)
            {
                var mode = SetPenAndBrush (pen, brush);

                add ();
                context.DrawPath (mode);
            }
        }
示例#9
0
   private void AddElements(IList<IDrawable> list, IEnumerable<XElement> es, Pen inheritPen,
 BaseBrush inheritBaseBrush)
   {
       foreach (var e in es)
       AddElement(list, e, inheritPen, inheritBaseBrush);
   }
示例#10
0
 D2D1.StrokeStyle GetStrokeStyle(Pen pen)
 {
     return null;
 }
示例#11
0
 D2D1.Brush GetBrush(Pen pen)
 {
     if (pen == null) return null;
     return new D2D1.SolidColorBrush (renderTarget, pen.Color.ToColor4 ());
 }
示例#12
0
 public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, BaseBrush brush = null)
 {
     var layout = new DW.TextLayout (factories.DWFactory, text, GetTextFormat (font), (float)frame.Width, (float)frame.Height);
     var h = layout.Metrics.Height;
       //todo : : Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
       //renderTarget.DrawTextLayout ((frame.TopLeft - h*Point.OneY.Y).ToVector2 (), layout, GetBrush (frame, brush));
 }
示例#13
0
 public void DrawRectangle(Rect frame, Pen pen = null, BaseBrush brush = null)
 {
     var p = GetBrush (pen);
     var b = GetBrush (frame, brush);
     if (b != null) {
         renderTarget.FillRectangle (frame.ToRectangleF (), b);
     }
     if (p != null) {
         renderTarget.DrawRectangle (frame.ToRectangleF (), p, (float)pen.Width, GetStrokeStyle (pen));
     }
 }
示例#14
0
        public void DrawPath(IEnumerable<PathOperation> ops, Pen pen = null, BaseBrush brush = null)
        {
            var bb = new BoundingBoxBuilder ();
            var s = new D2D1.PathGeometry (factories.D2DFactory);
            var figureDepth = 0;
            using (var sink = s.Open ()) {
                foreach (var op in ops) {
                    if (op is MoveTo) {
                        while (figureDepth > 0) {
                            sink.EndFigure (D2D1.FigureEnd.Open);
                            figureDepth--;
                        }
                        var mt = ((MoveTo)op);
                        sink.BeginFigure (Conversions.ToVector2 (mt.Start), D2D1.FigureBegin.Filled);
                        figureDepth++;
                        bb.Add (mt.Start);
                    }
                    else if (op is LineTo) {
                        var lt = ((LineTo)op);
                        sink.AddLine (lt.Start.ToVector2());
                        sink.AddLine (lt.End.ToVector2());
                        bb.Add (lt.Start);
                        bb.Add (lt.End);
                    }
                    else if (op is ArcTo) {
                        var ar = ((ArcTo)op);
                        // TODO: Direct2D Arcs
                        //sink.AddArc (new D2D1.ArcSegment {
                        //	Size = Conversions.ToSize2F (ar.Radius),
                        //	Point = Conversions.ToVector2 (ar.Point),
                        //	SweepDirection = ar.SweepClockwise ? D2D1.SweepDirection.Clockwise : D2D1.SweepDirection.CounterClockwise,
                        //});
                        sink.AddLine (Conversions.ToVector2 (ar.Point));
                        bb.Add (ar.Point);
                    }
                    else if (op is CurveTo) {
                        var ct = ((CurveTo)op);
                        sink.AddBezier (new D2D1.BezierSegment {
                            Point1 = Conversions.ToVector2 (ct.FirstControlPoint),
                            Point2 = Conversions.ToVector2 (ct.SecondControlPoint),
                            Point3 = Conversions.ToVector2 (ct.End),
                        });
            bb.Add(ct.FirstControlPoint);
            bb.Add(ct.SecondControlPoint);
            bb.Add(ct.End);
              }
                    else if (op is ClosePath) {
                        sink.EndFigure (D2D1.FigureEnd.Closed);
                        figureDepth--;
                    }
                    else {
                        // TODO: More path operations
                    }
                }
                while (figureDepth > 0) {
                    sink.EndFigure (D2D1.FigureEnd.Open);
                    figureDepth--;
                }
                sink.Close ();
            }

            var p = GetBrush (pen);
            var b = GetBrush (bb.BoundingBox, brush);

            if (b != null) {
                renderTarget.FillGeometry (s, b);
            }
            if (p != null) {
                renderTarget.DrawGeometry (s, p, (float)pen.Width, GetStrokeStyle (pen));
            }
        }
示例#15
0
 public void DrawEllipse(Rect frame, Pen pen = null, BaseBrush brush = null)
 {
     var p = GetBrush (pen);
     var b = GetBrush (frame, brush);
     var c = frame.Center;
     var s = new D2D1.Ellipse (new Vector2 ((float)c.X, (float)c.Y), (float)(frame.Width / 2.0), (float)(frame.Height / 2.0));
     if (b != null) {
         renderTarget.FillEllipse (s, b);
     }
     if (p != null) {
         renderTarget.DrawEllipse (s, p, (float)pen.Width, GetStrokeStyle (pen));
     }
 }
示例#16
0
        public void DrawRectangle(Rect frame, Pen pen = null, BaseBrush baseBrush = null)
        {
            if (pen == null && baseBrush == null)
                return;

            DrawElement (() => {
                context.AddRect (Conversions.GetCGRect (frame));
                return frame;
            }, pen, baseBrush);
        }
示例#17
0
        public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, BaseBrush brush = null)
        {
            if (string.IsNullOrEmpty (text))
                return;
            if (font == null)
                throw new ArgumentNullException ("font");

            SetBrush (brush);

            string fontName = font.Name;
            Array availableFonts =
                #if __IOS__
                UIKit.UIFont.FontNamesForFamilyName(fontName);
                #else
                AppKit.NSFontManager.SharedFontManager.AvailableMembersOfFontFamily (fontName).ToArray ();
                #endif
            if (availableFonts != null && availableFonts.Length > 0)
                context.SelectFont (font.Name, (nfloat)font.Size, CGTextEncoding.MacRoman);
            else
                context.SelectFont ("Georgia", (nfloat)font.Size, CGTextEncoding.MacRoman);

            context.ShowTextAtPoint ((nfloat)frame.X, (nfloat)frame.Y, text);

            //			using (var atext = new NSMutableAttributedString (text)) {
            //
            //				atext.AddAttributes (new CTStringAttributes {
            //					ForegroundColor = new CGColor (1, 0, 0, 1),
            //				}, new NSRange (0, text.Length));
            //
            //				using (var ct = new CTFramesetter (atext))
            //				using (var path = CGPath.FromRect (Conversions.GetCGRect (frame)))
            //				using (var tframe = ct.GetFrame (new NSRange (0, atext.Length), path, null))
            //					tframe.Draw (context);
            //			}
        }
示例#18
0
 private void ApplyStyle(string style, ref Pen pen, ref BaseBrush baseBrush)
 {
     var stylesDictionary = _stylesParser.ParseStyleValues(style);
       pen = _stylesParser.GetPen(stylesDictionary);
       baseBrush = _stylesParser.GetBrush(stylesDictionary, defs, pen);
 }
示例#19
0
        void SetPen(Pen pen)
        {
            switch (pen.LineJoin)
            {
            case SvgStrokeLineJoin.Round:
                context.SetLineJoin (CGLineJoin.Round);
                break;
            case SvgStrokeLineJoin.Bevel:
                context.SetLineJoin (CGLineJoin.Bevel);
                break;
            case SvgStrokeLineJoin.Miter:
                context.SetLineJoin (CGLineJoin.Miter);
                break;
            }

            switch (pen.LineCap)
            {
            case SvgStrokeLineCap.Round:
                context.SetLineCap (CGLineCap.Round);
                break;
            case SvgStrokeLineCap.Square:
                context.SetLineCap (CGLineCap.Square);
                break;
            default:
                context.SetLineCap (CGLineCap.Butt);
                break;
            }

            context.SetStrokeColor ((nfloat)pen.Color.Red, (nfloat)pen.Color.Green, (nfloat)pen.Color.Blue, (nfloat)pen.Color.Alpha);
            context.SetLineWidth ((nfloat)pen.Width);
        }
示例#20
0
        private void AddElement(IList<IDrawable> list, XElement e, Pen inheritPen, BaseBrush inheritBaseBrush)
        {
            Element element = null;

              var styleAttributedDictionary = e.Attributes().ToDictionary(k => k.Name.LocalName, v => v.Value);

              var pen = _stylesParser.GetPen(styleAttributedDictionary);
              var baseBrush = _stylesParser.GetBrush(styleAttributedDictionary,defs, pen);

              var style = ReadString(e.Attribute("style"));

              if (!string.IsNullOrWhiteSpace(style))
              {
            ApplyStyle(style, ref pen, ref baseBrush);
              }

              pen = pen ?? inheritPen;
              baseBrush = baseBrush ?? inheritBaseBrush;

              //var id = ReadString (e.Attribute ("id"));

              //
              // Elements
              //
              switch (e.Name.LocalName)
              {
            case "text":
            {
              var x = _valuesParser.ReadNumber(e.Attribute("x"));
              var y = _valuesParser.ReadNumber(e.Attribute("y"));
              var text = e.Value.Trim();
              var font = new Font();
              element = new Text(text, new Rect(new Point(x, y), new Size(double.MaxValue, double.MaxValue)), font,
            TextAlignment.Left, pen, baseBrush);
            }
              break;
            case "rect":
            {
              var x = _valuesParser.ReadNumber(e.Attribute("x"));
              var y = _valuesParser.ReadNumber(e.Attribute("y"));
              var width = _valuesParser.ReadNumber(e.Attribute("width"));
              var height = _valuesParser.ReadNumber(e.Attribute("height"));
              element = new Rectangle(new Point(x, y), new Size(width, height), pen, baseBrush);
            }
              break;
            case "ellipse":
            {
              var cx = _valuesParser.ReadNumber(e.Attribute("cx"));
              var cy = _valuesParser.ReadNumber(e.Attribute("cy"));
              var rx = _valuesParser.ReadNumber(e.Attribute("rx"));
              var ry = _valuesParser.ReadNumber(e.Attribute("ry"));
              element = new Ellipse(new Point(cx - rx, cy - ry), new Size(2*rx, 2*ry), pen, baseBrush);
            }
              break;
            case "circle":
            {
              var cx = _valuesParser.ReadNumber(e.Attribute("cx"));
              var cy = _valuesParser.ReadNumber(e.Attribute("cy"));
              var rr = _valuesParser.ReadNumber(e.Attribute("r"));
              element = new Ellipse(new Point(cx - rr, cy - rr), new Size(2*rr, 2*rr), pen, baseBrush);
            }
              break;
            case "path":
            {
              var dA = e.Attribute("d");
              if (dA != null && !string.IsNullOrWhiteSpace(dA.Value))
              {
            var p = new Path(pen, baseBrush);
            SvgPathParser.Parse(p, dA.Value);
            element = p;
              }
            }
              break;
            case "g":
            {
              var g = new Group();
              AddElements(g.Children, e.Elements(), pen, baseBrush);
              element = g;
            }
              break;
            case "use":
            {
              var href = ReadString(e.Attributes().FirstOrDefault(x => x.Name.LocalName == "href"));
              if (!string.IsNullOrWhiteSpace(href))
              {
            XElement useE;
            if (defs.TryGetValue(href.Trim().Replace("#", ""), out useE))
            {
              var useList = new List<IDrawable>();
              AddElement(useList, useE, pen, baseBrush);
              element = useList.OfType<Element>().FirstOrDefault();
            }
              }
            }
              break;
            case "title":
              Graphic.Title = ReadString(e);
              break;
            case "description":
              Graphic.Description = ReadString(e);
              break;
            case "defs":
              // Already read in earlier pass
              break;
            case "namedview":
            case "metadata":
            case "SVGTestCase":
            case "switch":
            break;
            default:
              throw new NotSupportedException("SVG element \"" + e.Name.LocalName + "\" is not supported");
              }

              if (element != null) {
            element.Id = ReadString(e.Attribute("id"));
              }

              if (element != null)
              {
            element.Transform = ReadTransform(ReadString(e.Attribute("transform")));
            list.Add(element);
              }
        }
示例#21
0
 public void DrawPath(IEnumerable<PathOperation> ops, Pen pen = null, BaseBrush brush = null)
 {
 }
示例#22
0
文件: ICanvas.cs 项目: yard/NGraphics
 public static void DrawPath(this ICanvas canvas, Action<Path> draw, Pen pen = null, BaseBrush brush = null)
 {
     var p = new Path(pen, brush);
     draw(p);
     p.Draw(canvas);
 }
示例#23
0
 public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, BaseBrush brush = null)
 {
 }
示例#24
0
文件: ICanvas.cs 项目: yard/NGraphics
 public static void DrawRectangle(this ICanvas canvas, double x, double y, double width, double height, Pen pen = null, BaseBrush brush = null)
 {
     canvas.DrawRectangle(new Rect(x, y, width, height), pen, brush);
 }
示例#25
0
 public void DrawEllipse(Rect frame, Pen pen = null, BaseBrush brush = null)
 {
     if (brush != null)
       {
     var paint = GetBrushPaint(brush, frame);
     graphics.DrawOval(frame.GetRectF(), paint);
       }
       if (pen != null)
       {
     var paint = GetPenPaint(pen);
     graphics.DrawOval(frame.GetRectF(), paint);
       }
 }
示例#26
0
文件: ICanvas.cs 项目: yard/NGraphics
 public static void DrawRectangle(this ICanvas canvas, Point position, Size size, Pen pen = null, BaseBrush brush = null)
 {
     canvas.DrawRectangle(new Rect(position, size), pen, brush);
 }
示例#27
0
 public void DrawRectangle(Rect frame, Pen pen = null, BaseBrush brush = null)
 {
     if (brush != null)
       {
     var paint = GetBrushPaint(brush, frame);
     graphics.DrawRect((float) (frame.X), (float) (frame.Y), (float) (frame.X + frame.Width),
       (float) (frame.Y + frame.Height), paint);
       }
       if (pen != null)
       {
     var paint = GetPenPaint(pen);
     graphics.DrawRect((float) (frame.X), (float) (frame.Y), (float) (frame.X + frame.Width),
       (float) (frame.Y + frame.Height), paint);
       }
 }
示例#28
0
        public void DrawPath(IEnumerable<PathOperation> ops, Pen pen = null, BaseBrush baseBrush = null)
        {
            if (pen == null && baseBrush == null)
                return;

            DrawElement (() => {
                var bb = new BoundingBoxBuilder();

                var lines = new List<CGPoint>();

                foreach (var op in ops) {
                    var moveTo = op as MoveTo;
                    if (moveTo != null) {
                        var start = moveTo.Start;
                        var end = moveTo.End;
                        context.MoveTo ((nfloat)start.X, (nfloat)start.Y);
                        context.MoveTo ((nfloat)end.X, (nfloat)end.Y);
                        bb.Add (start);
                        bb.Add (end);
                        continue;
                    }
                    var lt = op as LineTo;
                    if (lt != null) {
                        var start = lt.Start;
                        var end = lt.End;

                        context.AddLineToPoint((float)start.X, (float)start.Y);
                        context.AddLineToPoint((float)end.X, (float)end.Y);

                        bb.Add (start);
                        bb.Add (end);
                        continue;
                    }
                    var at = op as ArcTo;
                    if (at != null) {
                        var p = at.Point;
                        var pp = Conversions.GetPoint (context.GetPathCurrentPoint ());
                        Point c1, c2;
                        at.GetCircles (pp, out c1, out c2);
                        context.AddLineToPoint ((nfloat)p.X, (nfloat)p.Y);
                        bb.Add (p);
                        continue;
                    }
                    var curveTo = op as CurveTo;
                    if (curveTo != null) {
                        var end = curveTo.End;
                        var control1 = curveTo.FirstControlPoint;
                        var control2 = curveTo.SecondControlPoint;

                        context.AddCurveToPoint ((nfloat)control1.X, (nfloat)control1.Y, (nfloat)control2.X, (nfloat)control2.Y, (nfloat)end.X, (nfloat)end.Y);

                        bb.Add (control1);
                        bb.Add (control2);
                        bb.Add (end);
                        continue;
                    }
                    var cp = op as ClosePath;

                    if (cp != null) {
                        context.ClosePath ();
                        continue;
                    }

                    throw new NotSupportedException ("Path Op " + op);
                }

                return bb.BoundingBox;

            }, pen, baseBrush);
        }
示例#29
0
 private Paint GetPenPaint(Pen pen)
 {
     var paint = new Paint(PaintFlags.AntiAlias);
       paint.SetStyle(Paint.Style.Stroke);
       paint.SetARGB(pen.Color.A, pen.Color.R, pen.Color.G, pen.Color.B);
       paint.StrokeWidth = (float) pen.Width;
       return paint;
 }
示例#30
0
        public Pen GetPen(Dictionary<string, string> styleAttributes)
        {
            Pen pen = null;

              var strokeWidth = GetString(styleAttributes, "stroke-width");
              if (!string.IsNullOrWhiteSpace(strokeWidth))
              {
            if (pen == null)
              pen = new Pen();
            pen.Width = _valuesParser.ReadNumber(strokeWidth);
              }

              var strokeOpacity = GetString(styleAttributes, "stroke-opacity");
              if (!string.IsNullOrWhiteSpace(strokeOpacity))
              {
            if (pen == null)
              pen = new Pen();
            pen.Color = pen.Color.WithAlpha(_valuesParser.ReadNumber(strokeOpacity));
              }

              var linejoin = GetString(styleAttributes, "stroke-linejoin");
              if (!string.IsNullOrWhiteSpace(linejoin))
              {
            if (pen == null)
              pen = new Pen();

            switch (linejoin)
            {
              case "round":
            pen.LineJoin = SvgStrokeLineJoin.Round;
            break;
              case "bevel":
            pen.LineJoin = SvgStrokeLineJoin.Bevel;
            break;
              case "miter":
            pen.LineJoin = SvgStrokeLineJoin.Miter;
            break;
            }
              }

              var lineCap = GetString(styleAttributes, "stroke-linecap");
              if (!string.IsNullOrWhiteSpace(lineCap))
              {
            if (pen == null)
              pen = new Pen();

            switch (lineCap)
            {
              case "round":
            pen.LineCap = SvgStrokeLineCap.Round;
            break;
              case "butt":
            pen.LineCap = SvgStrokeLineCap.Butt;
            break;
            }
              }

              var stroke = GetString(styleAttributes, "stroke").Trim();

              if (string.IsNullOrEmpty(stroke))
              {
            // No change
              }
              else if (stroke == "none")
              {
            pen = null;
              }
              else
              {
            if (pen == null)
              pen = new Pen();
            Color color;
            if (Colors.TryParse(stroke, out color))
            {
              if (pen.Color.Alpha == 1)
            pen.Color = color;
              else
            pen.Color = color.WithAlpha(pen.Color.Alpha);
            }
              }

              var opacity = GetString(styleAttributes, "opacity");
              if (!string.IsNullOrWhiteSpace(opacity))
              {
            if (pen != null) {
            pen.Color = pen.Color.WithAlpha(_valuesParser.ReadNumber(opacity));
            }
              }

              return pen;
        }