private void Add(SKDocument pdf, XContainer container) { using (var canvas = pdf.BeginPage((float)container.Template.Width, (float)container.Template.Height)) { _presenter.Render(canvas, _renderer, container, 0, 0); } }
/// <inheritdoc/> void IProjectExporter.Save(string path, XContainer container) { var template = new Template(); var drawing = new Drawing(template); Add(drawing, container); drawing.Save(path); }
/// <summary> /// Draws a <see cref="XContainer"/> using drawing context. /// </summary> /// <param name="dc">The native drawing context.</param> /// <param name="container">The <see cref="XContainer"/> object.</param> /// <param name="dx">The X coordinate offset.</param> /// <param name="dy">The Y coordinate offset.</param> /// <param name="db">The properties database.</param> /// <param name="r">The data record.</param> public virtual void Draw(object dc, XContainer container, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { foreach (var layer in container.Layers) { if (layer.IsVisible) { Draw(dc, layer, dx, dy, db, r); } } }
/// <inheritdoc/> void IProjectExporter.Save(string path, XContainer container) { using (var stream = new SKFileWStream(path)) { using (var pdf = SKDocument.CreatePdf(stream, _targetDpi)) { Add(pdf, container); pdf.Close(); } } }
/// <inheritdoc/> public override void Render(object dc, ShapeRenderer renderer, XContainer container, double dx, double dy) { renderer.Fill(dc, dx, dy, container.Width, container.Height, container.Background); var db = container.Data == null ? default(ImmutableArray<XProperty>) : container.Data.Properties; var r = container.Data == null ? default(XRecord) : container.Data.Record; if (container.Template != null) { renderer.Draw(dc, container.Template, dx, dy, db, r); } renderer.Draw(dc, container, dx, dy, db, r); }
private void Add(Drawing drawing, XContainer container) { var width = container.Template.Width; var height = container.Template.Height; var page = new Page(width, height); drawing.Pages.Add(page); if (container.Template.Background.A > 0) { Fill(page, 0, 0, width, height, container.Template.Background); } Draw(page, container.Template, 0.0, 0.0, container.Data.Properties, container.Data.Record); Draw(page, container, 0.0, 0.0, container.Data.Properties, container.Data.Record); }
/// <summary> /// Creates a new <see cref="XLayer"/> instance. /// </summary> /// <param name="name">The layer name.</param> /// <param name="owner">The layer owner.</param> /// <param name="isVisible">The flag indicating whether layer is visible.</param> /// <returns>The new instance of the <see cref="XLayer"/>.</returns> public static XLayer Create(string name = "Layer", XContainer owner = null, bool isVisible = true) { return new XLayer() { Name = name, Owner = owner, IsVisible = isVisible }; }
private void Remove(XContainer container) { if (container == null) return; container.PropertyChanged -= ObservePage; if (container.Background != null) { container.Background.PropertyChanged -= ObserveTemplateBackgroud; } if (container.Layers != null) { Remove(container.Layers); } if (container.Data != null) { Remove(container.Data); } if (container.WorkingLayer != null) { container.WorkingLayer.InvalidateLayer -= ObserveInvalidateLayer; } if (container.HelperLayer != null) { container.HelperLayer.InvalidateLayer -= ObserveInvalidateLayer; } }
/// <summary> /// Renders a container using provided drawing context. /// </summary> /// <param name="dc">The drawing context.</param> /// <param name="renderer">The shape renderer.</param> /// <param name="container">The container to render.</param> /// <param name="dx">The X coordinate offset.</param> /// <param name="dy">The Y coordinate offset.</param> public abstract void Render(object dc, ShapeRenderer renderer, XContainer container, double dx, double dy);
/// <summary> /// Creates a new <see cref="XContainer"/> template instance. /// </summary> /// <param name="name">The template name.</param> /// <param name="width">The template width.</param> /// <param name="height">The template height.</param> /// <returns>The new instance of the <see cref="XContainer"/>.</returns> public static XContainer CreateTemplate(string name = "Template", double width = 840, double height = 600) { var template = new XContainer() { Name = name }; template.Background = ArgbColor.Create(0x00, 0xFF, 0xFF, 0xFF); template.Width = width; template.Height = height; var builder = template.Layers.ToBuilder(); builder.Add(XLayer.Create("TemplateLayer1", template)); builder.Add(XLayer.Create("TemplateLayer2", template)); builder.Add(XLayer.Create("TemplateLayer3", template)); template.Layers = builder.ToImmutable(); template.CurrentLayer = template.Layers.FirstOrDefault(); template.WorkingLayer = XLayer.Create("TemplateWorking", template); template.HelperLayer = XLayer.Create("TemplateHelper", template); return template; }
/// <summary> /// Creates a new <see cref="XContainer"/> page instance. /// </summary> /// <param name="name">The page name.</param> /// <returns>The new instance of the <see cref="XContainer"/>.</returns> public static XContainer CreatePage(string name = "Page") { var page = new XContainer() { Name = name }; var builder = page.Layers.ToBuilder(); builder.Add(XLayer.Create("Layer1", page)); builder.Add(XLayer.Create("Layer2", page)); builder.Add(XLayer.Create("Layer3", page)); page.Layers = builder.ToImmutable(); page.CurrentLayer = page.Layers.FirstOrDefault(); page.WorkingLayer = XLayer.Create("Working", page); page.HelperLayer = XLayer.Create("Helper", page); return page; }
public void SetSelected_Layer() { var target = new XProject(); var page = new XContainer(); var layer = XLayer.Create("Layer1", page); target.SetSelected(layer); Assert.Equal(layer, page.CurrentLayer); }