protected override SvgElement GetContainer() { var container = new SvgGroup(); container.Transforms.Add(new SvgTranslate(Left, Top)); container.CustomAttributes.Add("visibility", "hidden"); if (String.IsNullOrEmpty(CssClass)) { container.CustomAttributes.Add("class", "popup " + _popupId); } else { container.CustomAttributes.Add("class", CssClass + " popup " + _popupId); } var rectangle = new SvgRectangle { Height = Height, Width = Width, CornerRadiusX = CornerRadius, CornerRadiusY = CornerRadius }; container.Children.Add(rectangle); return(container); }
/// <summary> /// Gets the rectangle. /// </summary> /// <param name="format">The format.</param> /// <param name="xStart">The x start.</param> /// <param name="yStart">The y start.</param> /// <param name="color">The color.</param> /// <param name="Opacity">The opacity.</param> /// <param name="scaleFactor">The scale factor.</param> /// <returns></returns> public static SvgRectangle GetRectangle(this cursorZoneSpatialSettings format, Int32 xStart, Int32 yStart, Color color, float Opacity = 0.5F, Double scaleFactor = 1) { var rct = new SvgRectangle(); var tmp = format.GetResized(scaleFactor); Int32 newX = Convert.ToInt32((Convert.ToDouble(format.width) / 2) - (Convert.ToDouble(format.width) * (scaleFactor / 2))); Int32 newY = Convert.ToInt32((Convert.ToDouble(format.height) / 2) - (Convert.ToDouble(format.height) * (scaleFactor / 2))); rct.Fill = new SvgColourServer(color); rct.Stroke = new SvgColourServer(Color.White); rct.StrokeWidth = 1; rct.FillOpacity = Opacity; rct.FillRule = SvgFillRule.Inherit; // rct.Font = "Gulliver"; // rct.FontSize = 10; rct.Opacity = Opacity; rct.X = (xStart + newX + tmp.innerLeftPosition).Get_upx(); rct.Y = (yStart + newY + tmp.innerTopPosition).Get_upx(); rct.Width = tmp.innerBoxedWidth; rct.Height = tmp.innerBoxedHeight; return(rct); }
void SetupInitialView() { //background rect var background = new SvgRectangle(); background.Width = Screen.PrimaryScreen.WorkingArea.Width; background.Height = Screen.PrimaryScreen.WorkingArea.Height; background.Fill = new SvgColourServer(Color.White); background.MouseMove += background_MouseMove; background.MouseDown += background_MouseDown; background.MouseUp += background_MouseUp; //add background to svg doc ViewRoot.Children.Add(background); //group containing all rects FRectGroup = new SvgGroup(); FRectGroup.ID = "RectGroup"; FRectGroup.Transforms.Add(new Svg.Transforms.SvgTranslate(0, 0)); ViewRoot.Children.Add(FRectGroup); AddSomeRects(); //clear context as initial stuff will come via dump already FPoshServer.RemoteContext.ClearAll(); }
//selection rect or new rect void background_MouseDown(object sender, MouseArg e) { if (!FSessionParams.ContainsKey(e.SessionID)) { return; } var handler = GetHandler(e.SessionID); if (handler != null) { return; } if (e.Button == 1) //select { handler = new SelectionRectangleHandler(FRects, FSessionParams[e.SessionID].SelectedRects, FRectGroup.Transforms[0], FSessionParams[e.SessionID].Label, FSessionParams[e.SessionID].SelectionRect, e.SessionID); } else if (e.Button == 3) //create new rect { var newRect = new SvgRectangle(); newRect.MouseDown += rect_MouseDown; newRect.MouseMove += rect_MouseMove; newRect.MouseUp += rect_MouseUp; FRectGroup.Children.Add(newRect); FRects.Add(newRect); handler = new RectangleSizeHandler(newRect, e.SessionID, FRectGroup.Transforms[0].Matrix); } else { handler = new MoveAllRectsHandler(FRectGroup, e.SessionID); } FSessionParams[e.SessionID].MouseHandler = handler.MouseDown(sender, ConvertMouseArg(e)); }
public static RectangleDrawable Create(SvgRectangle svgRectangle, SKRect skViewport, DrawableBase?parent, IAssetLoader assetLoader, HashSet <Uri>?references, DrawAttributes ignoreAttributes = DrawAttributes.None) { var drawable = new RectangleDrawable(assetLoader, references) { Element = svgRectangle, Parent = parent, IgnoreAttributes = ignoreAttributes }; drawable.IsDrawable = drawable.CanDraw(svgRectangle, drawable.IgnoreAttributes) && drawable.HasFeatures(svgRectangle, drawable.IgnoreAttributes); if (!drawable.IsDrawable) { return(drawable); } drawable.Path = svgRectangle.ToPath(svgRectangle.FillRule, skViewport); if (drawable.Path is null || drawable.Path.IsEmpty) { drawable.IsDrawable = false; return(drawable); } drawable.Initialize(references); return(drawable); }
private static void SetTrack(Color color, SvgRectangle track) { if (track == null) { return; } track.Visibility = "visible"; track.Fill = new SvgColourServer(color); }
protected virtual SvgElement GetBackground(SvgDocument document, Bitmap bitmap) { var background = new SvgRectangle(); background.Width = document.Width; background.Height = document.Height; background.Fill = new SvgColourServer(Color.Black); return(background); }
public SvgWidget(string name) { Name = name; Background = new SvgRectangle(); Background.CustomAttributes["class"] = "menu"; this.Children.Add(Background); this.Visible = true; }
private void RenderFrame() { var rect = new SvgRectangle(_svgRoot, 0.5, 0.5, _diagramSize.Width, _diagramSize.Height); rect.StrokeWidth = 1; rect.Stroke = "#979797"; rect.Fill = "#FFFFFF"; _svgGraphic.Add(rect); }
public RectangleDrawable(SvgRectangle svgRectangle, SKRect skOwnerBounds, Drawable?root, Drawable?parent, Attributes ignoreAttributes = Attributes.None) : base(svgRectangle, root, parent) { IgnoreAttributes = ignoreAttributes; IsDrawable = CanDraw(svgRectangle, IgnoreAttributes) && HasFeatures(svgRectangle, IgnoreAttributes); if (!IsDrawable) { return; } Path = svgRectangle.ToSKPath(svgRectangle.FillRule, skOwnerBounds, _disposable); if (Path == null || Path.IsEmpty) { IsDrawable = false; return; } IsAntialias = SvgPaintingExtensions.IsAntialias(svgRectangle); TransformedBounds = Path.Bounds; Transform = SvgTransformsExtensions.ToSKMatrix(svgRectangle.Transforms); bool canDrawFill = true; bool canDrawStroke = true; if (SvgPaintingExtensions.IsValidFill(svgRectangle)) { Fill = SvgPaintingExtensions.GetFillSKPaint(svgRectangle, TransformedBounds, ignoreAttributes, _disposable); if (Fill == null) { canDrawFill = false; } } if (SvgPaintingExtensions.IsValidStroke(svgRectangle, TransformedBounds)) { Stroke = SvgPaintingExtensions.GetStrokeSKPaint(svgRectangle, 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); }
private SvgGroup BuildTileGroup(OutputTile tile, Func <float, float> yCoordinateConverter) { var tileGroup = new SvgGroup(); var mediaBoxRect = new SvgRectangle { Width = tile.MediaBox.Width, Height = tile.MediaBox.Height, X = tile.MediaBox.Left, Y = yCoordinateConverter(tile.MediaBox.Top), Stroke = new SvgColourServer(Color.Magenta), Fill = new SvgColourServer(Color.White), StrokeWidth = 1.0f }; var cutBoxRect = new SvgRectangle { Width = tile.CutBox.Width, Height = tile.CutBox.Height, X = tile.CutBox.Left, Y = yCoordinateConverter(tile.CutBox.Top), Stroke = new SvgColourServer(Color.Black), Fill = new SvgColourServer(Color.White), StrokeWidth = 1.0f }; var pageNUmberFontSize = tile.CutBox.Height / 4.0f; var pageNumberText = new SvgText(tile.SourcePage.Number.ToString()) { X = { tile.CutBox.GetCenter().X - 70.0f }, Y = { yCoordinateConverter(tile.CutBox.GetCenter().Y - pageNUmberFontSize / 2.0f) }, FontSize = pageNUmberFontSize, FontFamily = "Courier New", Transforms = { new SvgRotate(tile.MediaRotationAngle, tile.CutBox.GetCenter().X, yCoordinateConverter(tile.CutBox.GetCenter().Y)) } }; var sourceFileText = new SvgText(Path.GetFileNameWithoutExtension(tile.SourceFilePath)) { X = { tile.CutBox.Left + 50.0f }, Y = { yCoordinateConverter(tile.CutBox.Bottom + 20) }, FontSize = 24, FontFamily = "Courier New" }; tileGroup.Children.Add(mediaBoxRect); tileGroup.Children.Add(cutBoxRect); tileGroup.Children.Add(pageNumberText); tileGroup.Children.Add(sourceFileText); return(tileGroup); }
public Rectangle(SvgRectangle svgRectangle) { x = svgRectangle.X.ToDeviceValue(null, UnitRenderingType.Horizontal, svgRectangle); y = svgRectangle.Y.ToDeviceValue(null, UnitRenderingType.Vertical, svgRectangle); width = svgRectangle.Width.ToDeviceValue(null, UnitRenderingType.Horizontal, svgRectangle); height = svgRectangle.Height.ToDeviceValue(null, UnitRenderingType.Vertical, svgRectangle); rx = svgRectangle.CornerRadiusX.ToDeviceValue(null, UnitRenderingType.Horizontal, svgRectangle); ry = svgRectangle.CornerRadiusY.ToDeviceValue(null, UnitRenderingType.Vertical, svgRectangle); isRound = rx > 0f && ry > 0f; bounds = SKRect.Create(x, y, width, height); matrix = SvgHelper.GetSKMatrix(svgRectangle.Transforms); }
private SvgRectangle createDefaultAgeBar(SvgRectangle element, string defaultAgebarId) { SvgRectangle defaultRectangle = new SvgRectangle(); defaultRectangle.X = element.X; defaultRectangle.Y = element.Y; defaultRectangle.Width = element.Width; defaultRectangle.Height = element.Height; defaultRectangle.ID = defaultAgebarId; defaultRectangle.Visible = false; return(defaultRectangle); }
public void TestRectangle() { var svgRectangle = new SvgRectangle() { X = new SvgUnit(SvgUnitType.Percentage, 50), Y = new SvgUnit(SvgUnitType.Percentage, 50), Width = new SvgUnit(SvgUnitType.Percentage, 15), Height = new SvgUnit(SvgUnitType.Percentage, 20) }; CheckPercentageSize(svgRectangle); }
public void DrawRectangle(SvgDocument SvgDocument, float startX, float startY, float width, float height, Color c) { SvgRectangle svgRectangle = new SvgRectangle() { X = startX, Y = startY, Width = width, Height = height, Fill = new SvgColourServer(c) }; SvgDocument.Children.Add(svgRectangle); }
public static Rectangle GetRectangle(SvgRectangle rect) { Rectangle rectangle = new Rectangle() { Height = rect.Height, Width = rect.Width, Fill = GetBrush(rect), }; Canvas.SetLeft(rectangle, rect.Location.X); Canvas.SetTop(rectangle, rect.Location.Y); return(rectangle); }
private string BuildSvg(OutputFile outputFile) { // NOTE! SVG coordinate system is from top to bottom, OutputFile (and PDF) is bottom to top. float YCoordinateConverter(float y) { return(outputFile.SheetSize.Height - y); } const float margin = 10.0f; var svg = new SvgDocument { Width = outputFile.SheetSize.Width + margin * 2, Height = margin + (outputFile.SheetSize.Height + margin) * outputFile.Pages.Count }; foreach (var page in outputFile.Pages.Select((p, i) => new { Page = p, Index = i })) { var sheetLocationX = 0.0f; var sheetLocationY = (outputFile.SheetSize.Height + margin) * page.Index; var sheetGroup = new SvgGroup { // apply transform to the group to position all items inside the group relatively to its upper left corner Transforms = { new SvgTranslate(sheetLocationX, sheetLocationY) } }; var sheetRect = new SvgRectangle { Width = outputFile.SheetSize.Width, Height = outputFile.SheetSize.Height, Stroke = new SvgColourServer(Color.Black), Fill = new SvgColourServer(Color.White), StrokeWidth = 3.0f, X = margin, Y = margin }; sheetGroup.Children.Add(sheetRect); var tileRects = page.Page.Tiles.Select(t => BuildTileGroup(t, YCoordinateConverter)).ToList(); tileRects.ForEach(tr => sheetGroup.Children.Add(tr)); svg.Children.Add(sheetGroup); } using (var stream = new MemoryStream()) { svg.Write(stream); return(Encoding.UTF8.GetString(stream.ToArray())); } }
public static SvgRectangle CreateSvgRectangle(int size, float ratio) { int width = size; int height = (int)(size * ratio); SvgRectangle svg = new SvgRectangle { X = (_radius - width), Y = (_radius - height), Width = width * 2, Height = height * 2 }; return(svg); }
private void PrintCardBackground(SvgDocument document, Color backgroundColor) { var topSideInPixelsWithBleed = CardHeightInPixelsWithBleed; var leftSideInPixelsWithBleed = CardWidthInPixelsWithBleed; var rectangle = new SvgRectangle { Fill = new SvgColourServer(backgroundColor), Width = leftSideInPixelsWithBleed, Height = topSideInPixelsWithBleed, CornerRadiusX = BorderRadius, CornerRadiusY = BorderRadius }; document.Children.Add(rectangle); }
public void AddTask(int from, int length, int cpu, int core, int taskId) { int offset = _coreoffset[cpu] + (core * _cycleWidth); SvgRectangle rectangles = new SvgRectangle { Fill = new SvgColourServer(_taskcolors[taskId % _taskcolors.Length]), FillOpacity = 1, X = _startx + (from * _cycleWidth), Y = offset, Height = _cycleWidth, Width = _cycleWidth * length }; _cores.Add(rectangles); }
protected override SvgElement GetContainer() { var container = base.GetContainer(); var rectangle = new SvgRectangle { Height = Height, Width = Width, CornerRadiusX = CornerRadius, CornerRadiusY = CornerRadius }; container.Children.Add(rectangle); return(container); }
public static SvgDocument NewSvgDocument(int width, int height) { SvgDocument newSvg = new SvgDocument(); newSvg.Width = width; newSvg.Height = height; SvgRectangle background = new SvgRectangle { Width = width, Height = height, Fill = new SvgColourServer(System.Drawing.Color.FromArgb(255, 255, 255)) }; newSvg.Children.Add(background); return(newSvg); }
public void AddCPU(int id, int cores) { SvgRectangle cpu = new SvgRectangle { Fill = new SvgColourServer(_cpus.Count % 2 == 0 ? Color.FromArgb(255, 242, 242, 242) : Color.FromArgb(255, 232, 232, 232)), FillOpacity = 1, X = 0, Y = _cycleWidth * _cores.Count, Height = _cycleWidth * cores, Width = _startx }; int offset = _coreoffset.Last(); _coreoffset.Add(offset + (_cycleWidth * cores)); SvgText cpuText = new SvgText { Text = $"CPU{id}", X = new SvgUnitCollection() { 5 }, Y = new SvgUnitCollection() { (_cycleWidth * _cores.Count) + ((cores * _cycleWidth) / 2) + 8 }, FontSize = 16, FontStyle = SvgFontStyle.Normal }; for (int core = 0; core < cores; core++) { Color col = _cores.Count % 2 == 0 ? Color.FromArgb(255, 255, 255, 255) : Color.FromArgb(255, 242, 242, 242); SvgRectangle rectangles = new SvgRectangle { Fill = new SvgColourServer(col), FillOpacity = 1, X = 0, Y = _cycleWidth * _cores.Count, Height = _cycleWidth, Width = _startx + (_simulationlength * _cycleWidth) }; _cores.Add(rectangles); } _cpus.Add(cpu); _texts.Add(cpuText); }
internal static void SvgRectangle2Pdf(SvgRectangle element, XGraphics graphics) { if (element.Display == "none") { return; } if (element.Fill == SvgPaintServer.None) { var pen = ConvertHelper.Stroke2XPen(element.Stroke, element.StrokeWidth); graphics.DrawRectangle(pen, ConvertHelper.Rectangle2XRect(element.GetRectangle())); } else { var brush = ConvertHelper.Fill2XBrush(element.Fill); graphics.DrawRectangle(brush, ConvertHelper.Rectangle2XRect(element.GetRectangle())); } }
public SessionParameters(string id) { //selection rect SelectionRect = new SvgRectangle(); SelectionRect.FillOpacity = 0.1f; SelectionRect.Stroke = new SvgColourServer(Color.Black); SelectionRect.StrokeWidth = 1; SelectionRect.CustomAttributes["pointer-events"] = "none"; Label = new SvgText(); Label.FontSize = 12; Label.FontFamily = "Lucida Sans Unicode"; Label.Text = id; Label.X = -1000; Label.CustomAttributes["pointer-events"] = "none"; Label.Fill = new SvgColourServer(Color.Black); }
public SvgElement GetPresentation(double width, double height) { if (LayerClass.BackgroundPattern == null) { return(null); } SvgRectangle rect = new SvgRectangle(); rect.Width = (float)width; rect.Height = (float)height; rect.Fill = LayerClass.BackgroundPattern; rect.Stroke = new SvgColourServer(System.Drawing.Color.Black); rect.StrokeWidth = 1; return(rect); }
public void TestApplyStyle() { var document = new SvgDocument(); var rectangle = new SvgRectangle() { X = 0f, Y = 0f, Width = 10f, Height = 10f, }; rectangle.AddStyle("fill", "blue", 0); document.Children.Add(rectangle); document.FlushStyles(true); Assert.IsInstanceOf(typeof(SvgColourServer), rectangle.Fill); Assert.AreEqual(((SvgColourServer)rectangle.Fill).Colour, Color.Blue); }
private float DrawBox( SvgDocument document, SvgUnit x, SvgUnit y, SvgUnit width, IList <string> lines, string cssClass, SvgUnit cornerRadius) { var group = new SvgGroup(); group.Transforms.Add(new SvgTranslate(x, y)); if (!string.IsNullOrEmpty(cssClass)) { group.CustomAttributes.Add("class", cssClass); } document.Children.Add(group); var height = TextLineSpacing * lines.Count + BoxTopMargin * 2; var rectangle = new SvgRectangle { Height = height, Width = width, CornerRadiusX = cornerRadius, CornerRadiusY = cornerRadius }; group.Children.Add(rectangle); for (var lineNumber = 0; lineNumber < lines.Count; lineNumber++) { var text = new SvgText(lines[lineNumber]); text.Transforms.Add(new SvgTranslate(BoxLeftMargin, TextHeight + TextLineSpacing * lineNumber + BoxTopMargin)); text.Children.Add(new SvgTextSpan()); group.Children.Add(text); } return(height); }
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, });
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, });