/// <inheritdoc/> public override void Draw(object dc, ShapeRenderer renderer, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { var record = this.Data.Record ?? r; if (State.Flags.HasFlag(ShapeStateFlags.Visible)) { renderer.Draw(dc, this, dx, dy, db, record); } if (renderer.State.SelectedShape != null) { if (this == renderer.State.SelectedShape) { _start.Draw(dc, renderer, dx, dy, db, record); _end.Draw(dc, renderer, dx, dy, db, record); } else if (_start == renderer.State.SelectedShape) { _start.Draw(dc, renderer, dx, dy, db, record); } else if (_end == renderer.State.SelectedShape) { _end.Draw(dc, renderer, dx, dy, db, record); } } if (renderer.State.SelectedShapes != null) { if (renderer.State.SelectedShapes.Contains(this)) { _start.Draw(dc, renderer, dx, dy, db, record); _end.Draw(dc, renderer, dx, dy, db, record); } } }
/// <summary> /// Draws a <see cref="XLayer"/> using drawing context. /// </summary> /// <param name="dc">The native drawing context.</param> /// <param name="layer">The <see cref="XLayer"/> 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, XLayer layer, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { foreach (var shape in layer.Shapes) { if (shape.State.Flags.HasFlag(State.DrawShapeState.Flags)) { shape.Draw(dc, this, dx, dy, db, r); } } }
/// <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/> public override void Draw(object dc, ShapeRenderer renderer, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { var record = this.Data.Record ?? r; if (State.Flags.HasFlag(ShapeStateFlags.Visible)) { renderer.Draw(dc, this, dx, dy, db, record); base.Draw(dc, renderer, dx, dy, db, record); } }
/// <inheritdoc/> public override void Draw(object dc, ShapeRenderer renderer, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { var record = this.Data.Record ?? r; if (State.Flags.HasFlag(ShapeStateFlags.Visible)) { renderer.Draw(dc, this, dx, dy, db, record); } if (renderer.State.SelectedShape != null) { if (this == renderer.State.SelectedShape) { var points = this.GetPoints(); foreach (var point in points) { point.Draw(dc, renderer, dx, dy, db, record); } } else { var points = this.GetPoints(); foreach (var point in points) { if (point == renderer.State.SelectedShape) { point.Draw(dc, renderer, dx, dy, db, record); } } } } if (renderer.State.SelectedShapes != null) { if (renderer.State.SelectedShapes.Contains(this)) { var points = this.GetPoints(); foreach (var point in points) { point.Draw(dc, renderer, dx, dy, db, record); } } } }
/// <summary> /// Creates a new <see cref="XDatabase"/> instance. /// </summary> /// <param name="name">The database name.</param> /// <param name="fields">The fields collection.</param> /// <param name="idColumnName">The Id column name.</param> /// <returns>The new instance of the <see cref="XDatabase"/> class.</returns> public static XDatabase FromFields(string name, IEnumerable <string[]> fields, string idColumnName = DefaultIdColumnName) { var db = XDatabase.Create(name, idColumnName); var tempColumns = fields.FirstOrDefault().Select(c => XColumn.Create(db, c)); var columns = ImmutableArray.CreateRange <XColumn>(tempColumns); if (columns.Length >= 1 && columns[0].Name == idColumnName) { // Use existing record Id. var tempRecords = fields .Skip(1) .Select(v => XRecord.Create( db, v.FirstOrDefault(), columns, ImmutableArray.CreateRange <XValue>(v.Select(c => XValue.Create(c))))); var records = ImmutableArray.CreateRange <XRecord>(tempRecords); db.Columns = columns; db.Records = records; } else { // Create records with new Id. var tempRecords = fields .Skip(1) .Select(v => XRecord.Create( db, columns, ImmutableArray.CreateRange <XValue>(v.Select(c => XValue.Create(c))))); var records = ImmutableArray.CreateRange <XRecord>(tempRecords); db.Columns = columns; db.Records = records; } return(db); }
/// <inheritdoc/> public override void Draw(object dc, XImage image, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { if (image.Key == null) return; var _dc = dc as DrawingContext; var style = image.Style; if (style == null) return; double thickness = style.Thickness / _state.ZoomX; double half = thickness / 2.0; Tuple<Brush, Pen> styleCached = _styleCache.Get(style); Brush fill; Pen stroke; if (styleCached != null) { fill = styleCached.Item1; stroke = styleCached.Item2; } else { fill = CreateBrush(style.Fill); stroke = CreatePen(style, thickness); _styleCache.Set(style, Tuple.Create(fill, stroke)); } var rect = CreateRect(image.TopLeft, image.BottomRight, dx, dy); DrawRectangleInternal(_dc, half, fill, stroke, image.IsStroked, image.IsFilled, ref rect); var imageCached = _biCache.Get(image.Key); if (imageCached != null) { try { _dc.DrawImage(imageCached, rect); } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } } else { if (_state.ImageCache == null || string.IsNullOrEmpty(image.Key)) return; try { var bytes = _state.ImageCache.GetImage(image.Key); if (bytes != null) { var ms = new System.IO.MemoryStream(bytes); var bi = new BitmapImage(); bi.BeginInit(); bi.StreamSource = ms; bi.EndInit(); bi.Freeze(); _biCache.Set(image.Key, bi); _dc.DrawImage(bi, rect); } } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } } }
/// <inheritdoc/> public override void Draw(object dc, XQuadraticBezier quadraticBezier, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { var _dc = dc as DrawingContext; var style = quadraticBezier.Style; if (style == null) return; double thickness = style.Thickness / _state.ZoomX; double half = thickness / 2.0; Tuple<Brush, Pen> styleCached = _styleCache.Get(style); Brush fill; Pen stroke; if (styleCached != null) { fill = styleCached.Item1; stroke = styleCached.Item2; } else { fill = CreateBrush(style.Fill); stroke = CreatePen(style, thickness); _styleCache.Set(style, Tuple.Create(fill, stroke)); } PathGeometry pg = _quadraticBezierCache.Get(quadraticBezier); if (pg != null) { var pf = pg.Figures[0]; pf.StartPoint = new Point(quadraticBezier.Point1.X + dx, quadraticBezier.Point1.Y + dy); pf.IsFilled = quadraticBezier.IsFilled; var qbs = pf.Segments[0] as QuadraticBezierSegment; qbs.Point1 = new Point(quadraticBezier.Point2.X + dx, quadraticBezier.Point2.Y + dy); qbs.Point2 = new Point(quadraticBezier.Point3.X + dx, quadraticBezier.Point3.Y + dy); qbs.IsStroked = quadraticBezier.IsStroked; } else { var pf = new PathFigure() { StartPoint = new Point(quadraticBezier.Point1.X + dx, quadraticBezier.Point1.Y + dy), IsFilled = quadraticBezier.IsFilled }; var qbs = new QuadraticBezierSegment( new Point(quadraticBezier.Point2.X + dx, quadraticBezier.Point2.Y + dy), new Point(quadraticBezier.Point3.X + dx, quadraticBezier.Point3.Y + dy), quadraticBezier.IsStroked); //bs.Freeze(); pf.Segments.Add(qbs); //pf.Freeze(); pg = new PathGeometry(); pg.Figures.Add(pf); //pg.Freeze(); _quadraticBezierCache.Set(quadraticBezier, pg); } DrawPathGeometryInternal(_dc, half, fill, stroke, quadraticBezier.IsStroked, quadraticBezier.IsFilled, pg); }
/// <inheritdoc/> public override void Draw(object dc, XEllipse ellipse, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { var _dc = dc as DrawingContext; var style = ellipse.Style; if (style == null) return; double thickness = style.Thickness / _state.ZoomX; double half = thickness / 2.0; Tuple<Brush, Pen> styleCached = _styleCache.Get(style); Brush fill; Pen stroke; if (styleCached != null) { fill = styleCached.Item1; stroke = styleCached.Item2; } else { fill = CreateBrush(style.Fill); stroke = CreatePen(style, thickness); _styleCache.Set(style, Tuple.Create(fill, stroke)); } var rect = CreateRect(ellipse.TopLeft, ellipse.BottomRight, dx, dy); double rx = rect.Width / 2.0; double ry = rect.Height / 2.0; var center = new Point(rect.X + rx, rect.Y + ry); DrawEllipseInternal(_dc, half, fill, stroke, ellipse.IsStroked, ellipse.IsFilled, ref center, rx, ry); }
/// <inheritdoc/> public override void Draw(object dc, XLine line, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { var _dc = dc as DrawingContext; var style = line.Style; if (style == null) return; double zoom = _state.ZoomX; double thicknessLine = style.Thickness / zoom; double halfLine = thicknessLine / 2.0; double thicknessStartArrow = style.StartArrowStyle.Thickness / zoom; double halfStartArrow = thicknessStartArrow / 2.0; double thicknessEndArrow = style.EndArrowStyle.Thickness / zoom; double halfEndArrow = thicknessEndArrow / 2.0; // Line style. Tuple<Brush, Pen> styleCached = _styleCache.Get(style); Brush fillLine; Pen strokeLine; if (styleCached != null) { fillLine = styleCached.Item1; strokeLine = styleCached.Item2; } else { fillLine = CreateBrush(style.Fill); strokeLine = CreatePen(style, thicknessLine); _styleCache.Set(style, Tuple.Create(fillLine, strokeLine)); } Point pt1, pt2; DrawLineArrowsInternal(_dc, line, style, halfStartArrow, halfEndArrow, thicknessStartArrow, thicknessEndArrow, dx, dy, out pt1, out pt2); if (line.Style.LineStyle.IsCurved) { DrawLineCurveInternal(_dc, halfLine, strokeLine, line, ref pt1, ref pt2, dx, dy); } else { DrawLineInternal(_dc, halfLine, strokeLine, line.IsStroked, ref pt1, ref pt2); } }
private void Add(XRecord record) { if (record == null) return; record.PropertyChanged += ObserveRecord; if (record.Values != null) { Add(record.Values); } }
/// <inheritdoc/> public override void Draw(object dc, XPath path, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { var canvas = dc as SKCanvas; using (SKPaint brush = ToSKPaintBrush(path.Style.Fill)) using (SKPaint pen = ToSKPaintPen(path.Style, _scaleToPage, _sourceDpi, _targetDpi)) using (var spath = path.Geometry.ToSKPath(dx, dy, _scaleToPage)) { DrawPathInternal(canvas, brush, pen, path.IsStroked, path.IsFilled, spath); } }
/// <inheritdoc/> public override void Draw(object dc, XText text, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { var canvas = dc as SKCanvas; var tbind = text.BindText(db, r); if (string.IsNullOrEmpty(tbind)) return; SKTypefaceStyle style = SKTypefaceStyle.Normal; if (text.Style.TextStyle.FontStyle != null) { if (text.Style.TextStyle.FontStyle.Flags.HasFlag(FontStyleFlags.Bold)) { style |= SKTypefaceStyle.Bold; } if (text.Style.TextStyle.FontStyle.Flags.HasFlag(FontStyleFlags.Italic)) { style |= SKTypefaceStyle.Italic; } if (text.Style.TextStyle.FontStyle.Flags.HasFlag(FontStyleFlags.Underline)) { // TODO: Add support for FontStyleFlags.Underline } if (text.Style.TextStyle.FontStyle.Flags.HasFlag(FontStyleFlags.Strikeout)) { // TODO: Add support for FontStyleFlags.Strikeout } } using (var pen = ToSKPaintBrush(text.Style.Stroke)) using (var tf = SKTypeface.FromFamilyName(text.Style.TextStyle.FontName, style)) { pen.TextEncoding = SKTextEncoding.Utf16; pen.TextSize = _scaleToPage(text.Style.TextStyle.FontSize * _targetDpi / _sourceDpi); var fm = pen.FontMetrics; float offset = -(fm.Top + fm.Bottom); var rect = CreateRect(text.TopLeft, text.BottomRight, dx, dy, _scaleToPage); SKRect bounds = new SKRect(); pen.MeasureText(tbind, ref bounds); SKPoint origin = GetTextOrigin(text.Style, ref rect, ref bounds); canvas.DrawText(tbind, origin.X, origin.Y + offset, pen); } }
/// <inheritdoc/> public override void Draw(object dc, XQuadraticBezier quadraticBezier, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { // TODO: Implement Draw quadratic bezier. }
/// <inheritdoc/> public override void Draw(object dc, XArc arc, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { // TODO: Implement Draw arc. }
/// <inheritdoc/> public override void Draw(object dc, XQuadraticBezier quadraticBezier, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { var canvas = dc as SKCanvas; using (SKPaint brush = ToSKPaintBrush(quadraticBezier.Style.Fill)) using (SKPaint pen = ToSKPaintPen(quadraticBezier.Style, _scaleToPage, _sourceDpi, _targetDpi)) using (var path = new SKPath()) { path.MoveTo( _scaleToPage(quadraticBezier.Point1.X + dx), _scaleToPage(quadraticBezier.Point1.Y + dy)); path.QuadTo( _scaleToPage(quadraticBezier.Point2.X + dx), _scaleToPage(quadraticBezier.Point2.Y + dy), _scaleToPage(quadraticBezier.Point3.X + dx), _scaleToPage(quadraticBezier.Point3.Y + dy)); DrawPathInternal(canvas, brush, pen, quadraticBezier.IsStroked, quadraticBezier.IsFilled, path); } }
/// <inheritdoc/> public override void Draw(object dc, XText text, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { // TODO: Implement Draw text. }
/// <inheritdoc/> public override void Draw(object dc, XImage image, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { var canvas = dc as SKCanvas; var rect = CreateRect(image.TopLeft, image.BottomRight, dx, dy, _scaleToPage); if (image.IsStroked || image.IsFilled) { using (SKPaint brush = ToSKPaintBrush(image.Style.Fill)) using (SKPaint pen = ToSKPaintPen(image.Style, _scaleToPage, _sourceDpi, _targetDpi)) { DrawRectangleInternal(canvas, brush, pen, image.IsStroked, image.IsFilled, ref rect); } } if (_enableImageCache && _biCache.ContainsKey(image.Key)) { canvas.DrawBitmap(_biCache[image.Key], rect); } else { if (State.ImageCache == null || string.IsNullOrEmpty(image.Key)) return; var bytes = State.ImageCache.GetImage(image.Key); if (bytes != null) { var bi = SKBitmap.Decode(bytes); if (_enableImageCache) _biCache[image.Key] = bi; canvas.DrawBitmap(bi, rect); if (!_enableImageCache) bi.Dispose(); } } }
/// <inheritdoc/> public override void Draw(object dc, XImage image, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { // TODO: Implement Draw image. }
public override void Draw(object dc, ShapeRenderer renderer, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { throw new NotImplementedException(); }
/// <inheritdoc/> public override void Draw(object dc, XPath path, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { // TODO: Implement Draw path. }
private void Remove(XRecord record) { if (record == null) return; record.PropertyChanged -= ObserveRecord; if (record.Values != null) { Remove(record.Values); } }
/// <inheritdoc/> public override void Draw(object dc, ShapeRenderer renderer, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { var record = this.Data.Record ?? r; if (State.Flags.HasFlag(ShapeStateFlags.Visible)) { foreach (var shape in Shapes) { shape.Draw(dc, renderer, dx, dy, db, record); } } if (renderer.State.SelectedShape != null) { if (this == renderer.State.SelectedShape) { foreach (var connector in Connectors) { connector.Draw(dc, renderer, dx, dy, db, record); } } else { foreach (var connector in Connectors) { if (connector == renderer.State.SelectedShape) { connector.Draw(dc, renderer, dx, dy, db, record); } } } } if (renderer.State.SelectedShapes != null) { if (renderer.State.SelectedShapes.Contains(this)) { foreach (var connector in Connectors) { connector.Draw(dc, renderer, dx, dy, db, record); } } } }
/// <inheritdoc/> public override void Draw(object dc, XRectangle rectangle, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { var _dc = dc as DrawingContext; var style = rectangle.Style; if (style == null) return; double thickness = style.Thickness / _state.ZoomX; double half = thickness / 2.0; Tuple<Brush, Pen> styleCached = _styleCache.Get(style); Brush fill; Pen stroke; if (styleCached != null) { fill = styleCached.Item1; stroke = styleCached.Item2; } else { fill = CreateBrush(style.Fill); stroke = CreatePen(style, thickness); _styleCache.Set(style, Tuple.Create(fill, stroke)); } var rect = CreateRect(rectangle.TopLeft, rectangle.BottomRight, dx, dy); DrawRectangleInternal(_dc, half, fill, stroke, rectangle.IsStroked, rectangle.IsFilled, ref rect); if (rectangle.IsGrid) { DrawGridInternal(_dc, half, stroke, ref rect, rectangle.OffsetX, rectangle.OffsetY, rectangle.CellWidth, rectangle.CellHeight, true); } }
/// <inheritdoc/> public override void Draw(object dc, XLine line, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { var canvas = dc as SKCanvas; using (SKPaint strokeLine = ToSKPaintPen(line.Style, _scaleToPage, _sourceDpi, _targetDpi)) { SKPoint pt1, pt2; DrawLineArrowsInternal(canvas, line, dx, dy, out pt1, out pt2); if (line.Style.LineStyle.IsCurved) { DrawLineCurveInternal( canvas, strokeLine, line.IsStroked, ref pt1, ref pt2, line.Style.LineStyle.Curvature, line.Style.LineStyle.CurveOrientation, line.Start.Alignment, line.End.Alignment); } else { DrawLineInternal(canvas, strokeLine, line.IsStroked, ref pt1, ref pt2); } } }
/// <inheritdoc/> public override void Draw(object dc, XArc arc, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { var _dc = dc as DrawingContext; var style = arc.Style; if (style == null) return; double thickness = style.Thickness / _state.ZoomX; double half = thickness / 2.0; Tuple<Brush, Pen> styleCached = _styleCache.Get(style); Brush fill; Pen stroke; if (styleCached != null) { fill = styleCached.Item1; stroke = styleCached.Item2; } else { fill = CreateBrush(style.Fill); stroke = CreatePen(style, thickness); _styleCache.Set(style, Tuple.Create(fill, stroke)); } var a = WpfArc.FromXArc(arc); PathGeometry pg = _arcCache.Get(arc); if (pg != null) { var pf = pg.Figures[0]; pf.StartPoint = new Point(a.Start.X + dx, a.Start.Y + dy); pf.IsFilled = arc.IsFilled; var segment = pf.Segments[0] as ArcSegment; segment.Point = new Point(a.End.X + dx, a.End.Y + dy); segment.Size = new Size(a.Radius.Width, a.Radius.Height); segment.IsLargeArc = a.IsLargeArc; segment.IsStroked = arc.IsStroked; } else { var pf = new PathFigure() { StartPoint = new Point(a.Start.X, a.Start.Y), IsFilled = arc.IsFilled }; var segment = new ArcSegment( new Point(a.End.X, a.End.Y), new Size(a.Radius.Width, a.Radius.Height), 0.0, a.IsLargeArc, SweepDirection.Clockwise, arc.IsStroked); //segment.Freeze(); pf.Segments.Add(segment); //pf.Freeze(); pg = new PathGeometry(); pg.Figures.Add(pf); //pg.Freeze(); _arcCache.Set(arc, pg); } DrawPathGeometryInternal(_dc, half, fill, stroke, arc.IsStroked, arc.IsFilled, pg); }
/// <inheritdoc/> public override void Draw(object dc, XRectangle rectangle, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { var canvas = dc as SKCanvas; using (SKPaint brush = ToSKPaintBrush(rectangle.Style.Fill)) using (SKPaint pen = ToSKPaintPen(rectangle.Style, _scaleToPage, _sourceDpi, _targetDpi)) { var rect = CreateRect(rectangle.TopLeft, rectangle.BottomRight, dx, dy, _scaleToPage); DrawRectangleInternal(canvas, brush, pen, rectangle.IsStroked, rectangle.IsFilled, ref rect); if (rectangle.IsGrid) { DrawGridInternal( canvas, pen, ref rect, rectangle.OffsetX, rectangle.OffsetY, rectangle.CellWidth, rectangle.CellHeight, isStroked: true); } } }
/// <inheritdoc/> public override void Draw(object dc, XText text, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { var _dc = dc as DrawingContext; var style = text.Style; if (style == null) return; var tbind = text.BindText(db, r); if (string.IsNullOrEmpty(tbind)) return; double thickness = style.Thickness / _state.ZoomX; double half = thickness / 2.0; Tuple<Brush, Pen> styleCached = _styleCache.Get(style); Brush fill; Pen stroke; if (styleCached != null) { fill = styleCached.Item1; stroke = styleCached.Item2; } else { fill = CreateBrush(style.Fill); stroke = CreatePen(style, thickness); _styleCache.Set(style, Tuple.Create(fill, stroke)); } var rect = CreateRect(text.TopLeft, text.BottomRight, dx, dy); Tuple<string, FormattedText, ShapeStyle> tcache = _textCache.Get(text); FormattedText ft; string ct; if (tcache != null && string.Compare(tcache.Item1, tbind) == 0 && tcache.Item3 == style) { ct = tcache.Item1; ft = tcache.Item2; _dc.DrawText(ft, GetTextOrigin(style, ref rect, ft)); } else { var ci = CultureInfo.InvariantCulture; var fontStyle = System.Windows.FontStyles.Normal; var fontWeight = FontWeights.Regular; if (style.TextStyle.FontStyle != null) { if (style.TextStyle.FontStyle.Flags.HasFlag(Core2D.Style.FontStyleFlags.Italic)) { fontStyle = System.Windows.FontStyles.Italic; } if (style.TextStyle.FontStyle.Flags.HasFlag(Core2D.Style.FontStyleFlags.Bold)) { fontWeight = FontWeights.Bold; } } var tf = new Typeface(new FontFamily(style.TextStyle.FontName), fontStyle, fontWeight, FontStretches.Normal); ft = new FormattedText( tbind, ci, ci.TextInfo.IsRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight, tf, style.TextStyle.FontSize > 0.0 ? style.TextStyle.FontSize : double.Epsilon, stroke.Brush, null, TextFormattingMode.Ideal); if (style.TextStyle.FontStyle != null) { if (style.TextStyle.FontStyle.Flags.HasFlag(Core2D.Style.FontStyleFlags.Underline) || style.TextStyle.FontStyle.Flags.HasFlag(Core2D.Style.FontStyleFlags.Strikeout)) { var decorations = new TextDecorationCollection(); if (style.TextStyle.FontStyle.Flags.HasFlag(Core2D.Style.FontStyleFlags.Underline)) { decorations = new TextDecorationCollection( decorations.Union(TextDecorations.Underline)); } if (style.TextStyle.FontStyle.Flags.HasFlag(Core2D.Style.FontStyleFlags.Strikeout)) { decorations = new TextDecorationCollection( decorations.Union(TextDecorations.Strikethrough)); } ft.SetTextDecorations(decorations); } } _textCache.Set(text, Tuple.Create(tbind, ft, style)); _dc.DrawText(ft, GetTextOrigin(style, ref rect, ft)); } }
/// <inheritdoc/> public override void Draw(object dc, XEllipse ellipse, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { var canvas = dc as SKCanvas; using (SKPaint brush = ToSKPaintBrush(ellipse.Style.Fill)) using (SKPaint pen = ToSKPaintPen(ellipse.Style, _scaleToPage, _sourceDpi, _targetDpi)) { var rect = CreateRect(ellipse.TopLeft, ellipse.BottomRight, dx, dy, _scaleToPage); DrawEllipseInternal(canvas, brush, pen, ellipse.IsStroked, ellipse.IsFilled, ref rect); } }
/// <inheritdoc/> public override void Draw(object dc, XPath path, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { if (path.Geometry == null) return; var _dc = dc as DrawingContext; var style = path.Style; if (style == null) return; double thickness = style.Thickness / _state.ZoomX; double half = thickness / 2.0; Tuple<Brush, Pen> styleCached = _styleCache.Get(style); Brush fill; Pen stroke; if (styleCached != null) { fill = styleCached.Item1; stroke = styleCached.Item2; } else { fill = CreateBrush(style.Fill); stroke = CreatePen(style, thickness); _styleCache.Set(style, Tuple.Create(fill, stroke)); } Tuple<XPathGeometry, StreamGeometry, ShapeStyle> pcache = _pathCache.Get(path); StreamGeometry sg; if (pcache != null && pcache.Item1 == path.Geometry && pcache.Item3 == style) { sg = pcache.Item2; _dc.DrawGeometry(path.IsFilled ? fill : null, path.IsStroked ? stroke : null, sg); } else { sg = path.Geometry.ToStreamGeometry(dx, dy); // TODO: Enable XPath caching, cache is disabled to enable PathHelper to work. //_pathCache.Set(path, Tuple.Create(path.Geometry, sg, style)); _dc.DrawGeometry(path.IsFilled ? fill : null, path.IsStroked ? stroke : null, sg); } }
/// <inheritdoc/> public override void Draw(object dc, XArc arc, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { var canvas = dc as SKCanvas; using (SKPaint brush = ToSKPaintBrush(arc.Style.Fill)) using (SKPaint pen = ToSKPaintPen(arc.Style, _scaleToPage, _sourceDpi, _targetDpi)) using (var path = new SKPath()) { var a = GdiArc.FromXArc(arc); var rect = new SKRect( _scaleToPage(a.X + dx), _scaleToPage(a.Y + dy), _scaleToPage(a.X + dx + a.Width), _scaleToPage(a.Y + dy + a.Height)); path.AddArc(rect, (float)a.StartAngle, (float)a.SweepAngle); DrawPathInternal(canvas, brush, pen, arc.IsStroked, arc.IsFilled, path); } }