public static EllipseDrawable Create(SvgEllipse svgEllipse, SKRect skViewport, DrawableBase?parent, IAssetLoader assetLoader, HashSet <Uri>?references, DrawAttributes ignoreAttributes = DrawAttributes.None) { var drawable = new EllipseDrawable(assetLoader, references) { Element = svgEllipse, Parent = parent, IgnoreAttributes = ignoreAttributes }; drawable.IsDrawable = drawable.CanDraw(svgEllipse, drawable.IgnoreAttributes) && drawable.HasFeatures(svgEllipse, drawable.IgnoreAttributes); if (!drawable.IsDrawable) { return(drawable); } drawable.Path = svgEllipse.ToPath(svgEllipse.FillRule, skViewport); if (drawable.Path is null || drawable.Path.IsEmpty) { drawable.IsDrawable = false; return(drawable); } drawable.Initialize(references); return(drawable); }
public ellipseData(SvgEllipse svg) { style = svg.Style; if (style == "") { Color cColor = svg.Stroke; strokeColor = Convert.ToString(cColor.R) + Convert.ToString(cColor.G) + Convert.ToString(cColor.B); strokeWidth = svg.StrokeWidth; Color fColor = svg.Fill; fillColor = Convert.ToString(fColor.R) + Convert.ToString(fColor.G) + Convert.ToString(fColor.B); } else { //get from style attribute extractStyle rStyle = new extractStyle(); rStyle.getStyle(style); Color sCol = ColorTranslator.FromHtml(rStyle.strokeColour); Color fCol = ColorTranslator.FromHtml(rStyle.fillColour); strokeColor = Convert.ToString(sCol.R) + Convert.ToString(sCol.G) + Convert.ToString(sCol.B); strokeWidth = rStyle.strokeWidth; fillColor = Convert.ToString(fCol.R) + Convert.ToString(fCol.G) + Convert.ToString(fCol.B); } cx = Convert.ToDouble(svg.CX); cy = Convert.ToDouble(svg.CY); rx = Convert.ToDouble(svg.RX); ry = Convert.ToDouble(svg.RY); Id = svg.Id; }
private void WriteEllipseAttributes(SvgEllipse svg, EllipseVObject vObject) { WriteBaseRectangleVObjectAttributes(svg, vObject); var rect = vObject.Rectangle; svg.Cx = rect.CenterX; svg.Cy = rect.CenterY; svg.Rx = rect.Width / 2; svg.Ry = rect.Height / 2; var m = new Matrix(); m.RotateAt(rect.Angle, new System.Drawing.PointF(rect.CenterX, rect.CenterY)); svg.Transform = m; svg.StrokeWidth = vObject.BorderWidth; var cm = vObject.GetColorManagement(true); svg.Stroke = ColorManagement.GetPreviewColor(cm, vObject.BorderColor); svg.CustomAttributes.Add(new SvgVoAttribute("border-color", _serializer.Serialize(vObject.BorderColor))); svg.Fill = ColorManagement.GetPreviewColor(cm, vObject.FillColor); svg.CustomAttributes.Add(new SvgVoAttribute("fill-color", _serializer.Serialize(vObject.FillColor))); if (vObject.FixedBorderWidth) { svg.CustomAttributes.Add(new SvgVoAttribute("fixed-border-width", vObject.FixedBorderWidth)); } }
private void ReadEllipseAttributes(EllipseVObject vObject, SvgEllipse svg) { ReadBaseRectangleVObjectAttributes(vObject, svg); using (var advPath = new AdvancedDrawing.Path()) { advPath.DrawEllipse(svg.Cx - svg.Rx, svg.Cy - svg.Ry, svg.Rx * 2, svg.Ry * 2); vObject.Path = Path.FromAdvancedPath(advPath); } vObject.Angle = svg.Transform != null?Utils.GetAngle(svg.Transform.Elements[0], svg.Transform.Elements[1]) : 0; vObject.BorderWidth = svg.StrokeWidth; string borderColor = null; string fillColor = null; foreach (var attr in svg.CustomAttributes) { if (attr.NamespaceUri == XmlNamespace.AurigmaVectorObjects && attr.LocalName == "fixed-border-width") { vObject.FixedBorderWidth = attr.GetValue() == "true"; } else if (attr.NamespaceUri == XmlNamespace.AurigmaVectorObjects && attr.LocalName == "border-color") { borderColor = attr.GetValue(); } else if (attr.NamespaceUri == XmlNamespace.AurigmaVectorObjects && attr.LocalName == "fill-color") { fillColor = attr.GetValue(); } } vObject.BorderColor = !string.IsNullOrEmpty(borderColor) ? _serializer.Deserialize <Color>(borderColor) : new RgbColor(svg.Stroke); vObject.FillColor = !string.IsNullOrEmpty(fillColor) ? _serializer.Deserialize <Color>(fillColor) : new RgbColor(svg.Fill); }
public static EllipseDrawable Create(SvgEllipse svgEllipse, Rect skOwnerBounds, DrawableBase?parent, IAssetLoader assetLoader, Attributes ignoreAttributes = Attributes.None) { var drawable = new EllipseDrawable(assetLoader) { Element = svgEllipse, Parent = parent, IgnoreAttributes = ignoreAttributes }; drawable.IsDrawable = drawable.CanDraw(svgEllipse, drawable.IgnoreAttributes) && drawable.HasFeatures(svgEllipse, drawable.IgnoreAttributes); if (!drawable.IsDrawable) { return(drawable); } drawable.Path = svgEllipse.ToPath(svgEllipse.FillRule, skOwnerBounds); if (drawable.Path is null || drawable.Path.IsEmpty) { drawable.IsDrawable = false; return(drawable); } drawable.IsAntialias = SvgModelExtensions.IsAntialias(svgEllipse); drawable.TransformedBounds = drawable.Path.Bounds; drawable.Transform = SvgModelExtensions.ToMatrix(svgEllipse.Transforms); var canDrawFill = true; var canDrawStroke = true; if (SvgModelExtensions.IsValidFill(svgEllipse)) { drawable.Fill = SvgModelExtensions.GetFillPaint(svgEllipse, drawable.TransformedBounds, assetLoader, ignoreAttributes); if (drawable.Fill is null) { canDrawFill = false; } } if (SvgModelExtensions.IsValidStroke(svgEllipse, drawable.TransformedBounds)) { drawable.Stroke = SvgModelExtensions.GetStrokePaint(svgEllipse, drawable.TransformedBounds, assetLoader, ignoreAttributes); if (drawable.Stroke is null) { canDrawStroke = false; } } if (canDrawFill && !canDrawStroke) { drawable.IsDrawable = false; return(drawable); } // TODO: Transform _skBounds using _skMatrix. drawable.TransformedBounds = drawable.Transform.MapRect(drawable.TransformedBounds); return(drawable); }
public Ellipse(SvgEllipse svgEllipse) { cx = svgEllipse.CenterX.ToDeviceValue(null, UnitRenderingType.Horizontal, svgEllipse); cy = svgEllipse.CenterY.ToDeviceValue(null, UnitRenderingType.Vertical, svgEllipse); rx = svgEllipse.RadiusX.ToDeviceValue(null, UnitRenderingType.Other, svgEllipse); ry = svgEllipse.RadiusY.ToDeviceValue(null, UnitRenderingType.Other, svgEllipse); bounds = SKRect.Create(cx - rx, cy - ry, rx + rx, ry + ry); matrix = SvgHelper.GetSKMatrix(svgEllipse.Transforms); }
public EllipseDrawable(SvgEllipse svgEllipse, SKRect skOwnerBounds, Drawable?root, Drawable?parent, Attributes ignoreAttributes = Attributes.None) : base(svgEllipse, root, parent) { IgnoreAttributes = ignoreAttributes; IsDrawable = CanDraw(svgEllipse, IgnoreAttributes) && HasFeatures(svgEllipse, IgnoreAttributes); if (!IsDrawable) { return; } Path = svgEllipse.ToSKPath(svgEllipse.FillRule, skOwnerBounds, _disposable); if (Path == null || Path.IsEmpty) { IsDrawable = false; return; } IsAntialias = SvgPaintingExtensions.IsAntialias(svgEllipse); TransformedBounds = Path.Bounds; Transform = SvgTransformsExtensions.ToSKMatrix(svgEllipse.Transforms); bool canDrawFill = true; bool canDrawStroke = true; if (SvgPaintingExtensions.IsValidFill(svgEllipse)) { Fill = SvgPaintingExtensions.GetFillSKPaint(svgEllipse, TransformedBounds, ignoreAttributes, _disposable); if (Fill == null) { canDrawFill = false; } } if (SvgPaintingExtensions.IsValidStroke(svgEllipse, TransformedBounds)) { Stroke = SvgPaintingExtensions.GetStrokeSKPaint(svgEllipse, TransformedBounds, ignoreAttributes, _disposable); if (Stroke == null) { canDrawStroke = false; } } if (canDrawFill && !canDrawStroke) { IsDrawable = false; return; } // TODO: Transform _skBounds using _skMatrix. SKMatrix.MapRect(ref Transform, out TransformedBounds, ref TransformedBounds); }
public void DrawEllipse(SvgEllipse svgEllipse, bool ignoreDisplay) { if (!CanDraw(svgEllipse, ignoreDisplay)) { return; } float cx = svgEllipse.CenterX.ToDeviceValue(null, UnitRenderingType.Horizontal, svgEllipse); float cy = svgEllipse.CenterY.ToDeviceValue(null, UnitRenderingType.Vertical, svgEllipse); float rx = svgEllipse.RadiusX.ToDeviceValue(null, UnitRenderingType.Other, svgEllipse); float ry = svgEllipse.RadiusY.ToDeviceValue(null, UnitRenderingType.Other, svgEllipse); if (rx <= 0f || ry <= 0f) { return; } var skRectBounds = SKRect.Create(cx - rx, cy - ry, rx + rx, ry + ry); _skCanvas.Save(); var skMatrix = SkiaUtil.GetSKMatrix(svgEllipse.Transforms); SetTransform(skMatrix); SetClipPath(svgEllipse, _disposable); var skPaintOpacity = SetOpacity(svgEllipse, _disposable); var skPaintFilter = SetFilter(svgEllipse, _disposable); if (SkiaUtil.IsValidFill(svgEllipse)) { var skPaintFill = SkiaUtil.GetFillSKPaint(svgEllipse, _skSize, skRectBounds, _disposable); _skCanvas.DrawOval(cx, cy, rx, ry, skPaintFill); } if (SkiaUtil.IsValidStroke(svgEllipse)) { var skPaintStroke = SkiaUtil.GetStrokeSKPaint(svgEllipse, _skSize, skRectBounds, _disposable); _skCanvas.DrawOval(cx, cy, rx, ry, skPaintStroke); } if (skPaintFilter != null) { _skCanvas.Restore(); } if (skPaintOpacity != null) { _skCanvas.Restore(); } _skCanvas.Restore(); }
public void TestEllipse() { var svgEllipse = new SvgEllipse() { CenterX = new SvgUnit(SvgUnitType.Percentage, 50), CenterY = new SvgUnit(SvgUnitType.Percentage, 50), RadiusX = new SvgUnit(SvgUnitType.Percentage, 15), RadiusY = new SvgUnit(SvgUnitType.Percentage, 5), }; CheckPercentageSize(svgEllipse); }
public static SvgEllipse CreateSvgEllipse(int radius, float ratio) { SvgEllipse svg = new SvgEllipse { CenterX = _radius, CenterY = _radius, RadiusY = radius * ratio, RadiusX = radius }; return(svg); }
public override SvgBasicShape ToSVGLibShape(SvgDoc doc) { var res = new SvgEllipse(doc, center.X.ToString() + "px", center.X.ToString() + "px", rx.ToString() + "px", ry.ToString() + "px" ); res.Fill = System.Drawing.Color.FromArgb(fill.A, fill.R, fill.G, fill.B); res.Stroke = System.Drawing.Color.FromArgb(stroke.A, stroke.R, stroke.G, stroke.B); res.StrokeWidth = w.ToString() + "px"; return(res); }
public static DrawEllipse Create(SvgEllipse svg) { try { float cx = ParseSize(svg.CX, Dpi.X); float cy = ParseSize(svg.CY, Dpi.Y); float rx = ParseSize(svg.RX, Dpi.X); float ry = ParseSize(svg.RY, Dpi.Y); var dobj = new DrawEllipse(cx - rx, cy - ry, rx * 2, ry * 2); dobj.SetStyleFromSvg(svg); return(dobj); } catch (Exception ex) { ErrH.Log("DrawEllipse", "CreateRectangle", ex.ToString(), ErrH._LogPriority.Info); return(null); } }
private void AddEllipse() { if (!IsDocPresent()) { return; } SvgElement ele = GetCurrentSvgElement(); if (ele == null) { return; } SvgEllipse ellipse = m_svg.AddEllipse(ele); AddNodeToTree(ellipse); }
public static DrawableBase?Create(SvgElement svgElement, Rect skOwnerBounds, DrawableBase?parent, IAssetLoader assetLoader, Attributes ignoreAttributes = Attributes.None) { return(svgElement switch { SvgAnchor svgAnchor => AnchorDrawable.Create(svgAnchor, skOwnerBounds, parent, assetLoader, ignoreAttributes), SvgFragment svgFragment => FragmentDrawable.Create(svgFragment, skOwnerBounds, parent, assetLoader, ignoreAttributes), SvgImage svgImage => ImageDrawable.Create(svgImage, skOwnerBounds, parent, assetLoader, ignoreAttributes), SvgSwitch svgSwitch => SwitchDrawable.Create(svgSwitch, skOwnerBounds, parent, assetLoader, ignoreAttributes), SvgUse svgUse => UseDrawable.Create(svgUse, skOwnerBounds, parent, assetLoader, ignoreAttributes), SvgCircle svgCircle => CircleDrawable.Create(svgCircle, skOwnerBounds, parent, assetLoader, ignoreAttributes), SvgEllipse svgEllipse => EllipseDrawable.Create(svgEllipse, skOwnerBounds, parent, assetLoader, ignoreAttributes), SvgRectangle svgRectangle => RectangleDrawable.Create(svgRectangle, skOwnerBounds, parent, assetLoader, ignoreAttributes), SvgGroup svgGroup => GroupDrawable.Create(svgGroup, skOwnerBounds, parent, assetLoader, ignoreAttributes), SvgLine svgLine => LineDrawable.Create(svgLine, skOwnerBounds, parent, assetLoader, ignoreAttributes), SvgPath svgPath => PathDrawable.Create(svgPath, skOwnerBounds, parent, assetLoader, ignoreAttributes), SvgPolyline svgPolyline => PolylineDrawable.Create(svgPolyline, skOwnerBounds, parent, assetLoader, ignoreAttributes), SvgPolygon svgPolygon => PolygonDrawable.Create(svgPolygon, skOwnerBounds, parent, assetLoader, ignoreAttributes), SvgText svgText => TextDrawable.Create(svgText, skOwnerBounds, parent, assetLoader, ignoreAttributes), _ => null, });
public static Drawable?Create(SvgElement svgElement, SKRect skOwnerBounds, Drawable?root, Drawable?parent, Attributes ignoreAttributes = Attributes.None) { return(svgElement switch { SvgAnchor svgAnchor => new AnchorDrawable(svgAnchor, skOwnerBounds, root, parent, ignoreAttributes), SvgFragment svgFragment => new FragmentDrawable(svgFragment, skOwnerBounds, root, parent, ignoreAttributes), SvgImage svgImage => new ImageDrawable(svgImage, skOwnerBounds, root, parent, ignoreAttributes), SvgSwitch svgSwitch => new SwitchDrawable(svgSwitch, skOwnerBounds, root, parent, ignoreAttributes), SvgUse svgUse => new UseDrawable(svgUse, skOwnerBounds, root, parent, ignoreAttributes), SvgCircle svgCircle => new CircleDrawable(svgCircle, skOwnerBounds, root, parent, ignoreAttributes), SvgEllipse svgEllipse => new EllipseDrawable(svgEllipse, skOwnerBounds, root, parent, ignoreAttributes), SvgRectangle svgRectangle => new RectangleDrawable(svgRectangle, skOwnerBounds, root, parent, ignoreAttributes), SvgGroup svgGroup => new GroupDrawable(svgGroup, skOwnerBounds, root, parent, ignoreAttributes), SvgLine svgLine => new LineDrawable(svgLine, skOwnerBounds, root, parent, ignoreAttributes), SvgPath svgPath => new PathDrawable(svgPath, skOwnerBounds, root, parent, ignoreAttributes), SvgPolyline svgPolyline => new PolylineDrawable(svgPolyline, skOwnerBounds, root, parent, ignoreAttributes), SvgPolygon svgPolygon => new PolygonDrawable(svgPolygon, skOwnerBounds, root, parent, ignoreAttributes), SvgText svgText => new TextDrawable(svgText, skOwnerBounds, root, parent, ignoreAttributes), _ => null, });
internal SvgElement ToSvg(VObject vObject) { if (vObject is GridVObject) { var svg = new SvgVoGrid(); WriteGridAttributes(svg, vObject as GridVObject); return(svg); } else if (vObject is PolylineVObject) { var svg = new SvgPolyline(); WritePolylineAttributes(svg, vObject as PolylineVObject); return(svg); } else if (vObject is DashedLineVObject) { var svg = new SvgVoDashLine(); WriteDashLineAttributes(svg, vObject as DashedLineVObject); return(svg); } else if (vObject is LineVObject) { var svg = new SvgLine(); WriteLineAttributes(svg, vObject as LineVObject); return(svg); } else if (vObject is EllipseVObject) { var svg = new SvgEllipse(); WriteEllipseAttributes(svg, vObject as EllipseVObject); return(svg); } else if (vObject is SvgVObject) { var svg = new SvgVoSvg(); WriteSvgAttributes(svg, vObject as SvgVObject); return(svg); } else if (vObject is ImageVObject) { var svg = new SvgVoImage(); WriteImageAttributes(svg, vObject as ImageVObject); return(svg); } else if (vObject is PlainTextVObject) { var svg = new SvgVoPlainText(); WritePlainTextAttributes(svg, vObject as PlainTextVObject); return(svg); } else if (vObject is CurvedTextVObject) { var svg = new SvgVoCurvedText(); WriteCurvedTextAttributes(svg, vObject as CurvedTextVObject); return(svg); } else if (vObject is PathBoundedTextVObject) { var svg = new SvgVoPathBoundedText(); WritePathBoundedTextAttributes(svg, vObject as PathBoundedTextVObject); return(svg); } else if (vObject is BoundedTextVObject) { var svg = new SvgVoBoundedText(); WriteBoundedTextAttributes(svg, vObject as BoundedTextVObject); return(svg); } else if (vObject is AutoScaledTextVObject) { var svg = new SvgVoAutoScaledText(); WriteAutoScaledTextAttributes(svg, vObject as AutoScaledTextVObject); return(svg); } else if (vObject is PlaceholderVObject) { var svg = new SvgVoPlaceholder(); WritePlaceholderAttributes(svg, vObject as PlaceholderVObject); return(svg); } else if (vObject is RectangleVObject) { var svg = new SvgVoRectangle(); WriteRectangleAttributes(svg, vObject as RectangleVObject); return(svg); } else if (vObject is ShapeVObject) { var svg = new SvgVoShape(); WriteShapeAttributes(svg, vObject as ShapeVObject); return(svg); } else { return(null); } }