public void DrawBitmap(IBitmap bitmap, CanvasRectangleF dest, CanvasRectangleF source) { _canvas?.DrawBitmap((SKBitmap)bitmap.EngineElement, source.ToSKRect(), dest.ToSKRect(), new SKPaint() { FilterQuality = this.InterpolationMode.ToSKFilterQuality() }); }
public DisplayCharacterRanges(Graphics graphics, System.Drawing.Font font, StringFormat format, string text) { _rectF = new CanvasRectangleF[text.Length]; int c = 0; float xOffset = 0; for (int l = 0; l < text.Length; l += 32, c += 32) { string t = text.Substring(l, Math.Min(32, text.Length - l)); CharacterRange[] ranges = new CharacterRange[t.Length]; for (int i = 0; i < t.Length; i++) { ranges[i] = new CharacterRange(i, 1); } format.SetMeasurableCharacterRanges(ranges); SizeF size = graphics.MeasureString(t, font); Region[] regions = graphics.MeasureCharacterRanges(t, font, new RectangleF(0, 0, size.Width, size.Height), format); for (int i = 0; i < regions.Length; i++) { var bounds = regions[i].GetBounds(graphics); _rectF[c + i] = new CanvasRectangleF(bounds.X, bounds.Y, bounds.Width, bounds.Height); _rectF[c + i].Left += xOffset; regions[i].Dispose(); } xOffset = _rectF[c + t.Length - 1].Left + _rectF[c + t.Length - 1].Width; } }
public CanvasRectangleF(CanvasRectangleF rectangle) { this.Left = rectangle.Left; this.Top = rectangle.Top; this.Width = rectangle.Width; this.Height = rectangle.Height; }
public void FillPath(IDisplay display, IGraphicsPath path) { //display.GraphicsContext.SmoothingMode = (SmoothingMode)this.Smoothingmode; if (_gradient != null) { CanvasRectangleF rect = (_rectType == GradientRectType.Feature ? path.GetBounds() : new CanvasRectangleF(0, 0, display.iWidth, display.iHeight)); using (var brush = _gradient.CreateNewLinearGradientBrush(rect)) { display.Canvas.FillPath(brush, path); } } //if (_outlineSymbol != null) //{ // if (_outlineSymbol is ILineSymbol) // ((ILineSymbol)_outlineSymbol).DrawPath(display, path); // else if (_outlineSymbol is SymbolCollection) // { // foreach (SymbolCollectionItem item in ((SymbolCollection)_outlineSymbol).Symbols) // { // if (!item.Visible) continue; // if (item.Symbol is ILineSymbol) // { // ((ILineSymbol)item.Symbol).DrawPath(display, path); // } // } // } //} }
public void FillRectangle(IBrushCollection brushCollection, CanvasRectangleF rectangleF) { foreach (var brush in brushCollection.Brushes) { _canvas?.DrawRect(rectangleF.ToSKRect(), GetSKPaint(brush)); } }
static public RectangleF ToGdiRectangleF(this CanvasRectangleF canvasRectangleF) { return(new RectangleF( canvasRectangleF.Left, canvasRectangleF.Top, canvasRectangleF.Width, canvasRectangleF.Height)); }
public void DrawBitmap(IBitmap bitmap, CanvasRectangleF dest, CanvasRectangleF source) { CheckUsability(); _graphics.DrawImage((Bitmap)bitmap.EngineElement, dest.ToGdiRectangleF(), source.ToGdiRectangleF(), System.Drawing.GraphicsUnit.Pixel); }
public void FillRectangle(IBrushCollection brushCollection, CanvasRectangleF rectangleF) { CheckUsability(); foreach (var brush in brushCollection.Brushes) { _graphics.FillRectangle((Brush)brush.EngineElement, rectangleF.ToGdiRectangleF()); } }
public void DrawRectangle(IPen pen, CanvasRectangleF rectangleF) { CheckUsability(); _graphics.DrawRectangle((Pen)pen.EngineElement, rectangleF.Left, rectangleF.Top, rectangleF.Width, rectangleF.Height); }
private void listBox1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { try { if (editStyle == EditStyle.dash) { LineDashStyle style = (LineDashStyle)listBox1.Items[e.Index]; using (var bitmap = Current.Engine.CreateBitmap(e.Bounds.Width, e.Bounds.Height)) using (var canvas = bitmap.CreateCanvas()) using (var pen = Current.Engine.CreatePen(ArgbColor.Black, 2)) { if (style == (LineDashStyle)_style) { using (var brush = Current.Engine.CreateSolidBrush(ArgbColor.Yellow)) { canvas.FillRectangle(brush, new CanvasRectangle(0, 0, e.Bounds.Width, e.Bounds.Height)); } } pen.DashStyle = style; canvas.DrawLine(pen, 5, bitmap.Height / 2, bitmap.Width - 10, bitmap.Height / 2); e.Graphics.DrawImage(bitmap.ToGdiBitmap(), e.Bounds.Left, e.Bounds.Top); } } else if (editStyle == EditStyle.hatch) { HatchStyle style = (HatchStyle)listBox1.Items[e.Index]; using (var bitmap = Current.Engine.CreateBitmap(e.Bounds.Width, e.Bounds.Height)) using (var canvas = bitmap.CreateCanvas()) using (var hbrush = Current.Engine.CreateHatchBrush(style, ArgbColor.Black, ArgbColor.Transparent)) { if (style == (HatchStyle)_style) { using (var brush = Current.Engine.CreateSolidBrush(ArgbColor.Yellow)) { canvas.FillRectangle(brush, new CanvasRectangle(0, 0, e.Bounds.Width, e.Bounds.Height)); } } CanvasRectangleF rect = new CanvasRectangleF(5, 5, bitmap.Width - 10, bitmap.Height - 10); using (var pen = Current.Engine.CreatePen(ArgbColor.Black, 1)) { canvas.DrawRectangle(pen, rect); } canvas.FillRectangle(hbrush, rect); e.Graphics.DrawImage(bitmap.ToGdiBitmap(), e.Bounds.Left, e.Bounds.Top); } } } catch { } }
public SkiaLinearGradientBrush(CanvasRectangleF rect, ArgbColor col1, ArgbColor col2, float angle) { var center = rect.Center; angle = angle * (float)(Math.PI / 180.0); var angleRect = new SKRect(center.X - rect.Width * (float)Math.Cos(angle), center.Y - rect.Width * (float)Math.Sin(angle), center.X + rect.Width * (float)Math.Cos(angle), center.Y + rect.Width * (float)Math.Sin(angle)); _skPaint = new SKPaint() { Shader = SKShader.CreateLinearGradient( new SKPoint(angleRect.Left, angleRect.Top), new SKPoint(angleRect.Right, angleRect.Bottom), new SKColor[] { col1.ToSKColor(), col2.ToSKColor() }, new float[] { 0, 1 }, SKShaderTileMode.Clamp) }; }
public void DrawBitmap(IBitmap bitmap, CanvasPointF[] points, CanvasRectangleF source, float opacity = 1) { CheckUsability(); var imageAttributes = CreateImageAttributes(opacity); if (imageAttributes != null) { _graphics.DrawImage((Bitmap)bitmap.EngineElement, points.Take(3).ToGdiPointFArray(), source.ToGdiRectangleF(), System.Drawing.GraphicsUnit.Pixel, imageAttr: imageAttributes); } else { _graphics.DrawImage((Bitmap)bitmap.EngineElement, points.Take(3).ToGdiPointFArray(), source.ToGdiRectangleF(), System.Drawing.GraphicsUnit.Pixel); } }
public void DrawBitmap(IBitmap bitmap, CanvasPointF[] points, CanvasRectangleF source, float opacity = 1) { // ToDo: Nicht korrekt!! //var dest = new CanvasRectangleF(points[0].X, points[0].Y, points[1].X - points[0].X, points[2].Y - points[0].Y); // siehe: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/graphics/skiasharp/transforms/3d-rotation var skMatrix = ComputeMatrix(new SKSize(source.Width, source.Height), points[0].ToSKPoint(), points[1].ToSKPoint(), points[2].ToSKPoint(), points.Length > 3 ? (SKPoint?)points[3].ToSKPoint() : null); _canvas?.SetMatrix(skMatrix); _canvas?.DrawBitmap((SKBitmap)bitmap.EngineElement, 0f, 0f, new SKPaint() { FilterQuality = this.InterpolationMode.ToSKFilterQuality(), Color = SKColors.Black.WithAlpha((byte)(255 * opacity)) }); _canvas?.ResetMatrix(); }
public void DrawText(string text, IFont font, IBrush brush, CanvasRectangleF rectangleF) { CheckUsability(); _graphics.DrawString(text, (Font)font.EngineElement, (Brush)brush.EngineElement, rectangleF.ToGdiRectangleF()); }
public List <IAnnotationPolygonCollision> AnnotationPolygon(IDisplay display, IGeometry geometry, TextSymbolAlignment symbolAlignment) { if (_font == null || _text == null || display.Canvas == null) { return(null); } List <IAnnotationPolygonCollision> polygons = new List <IAnnotationPolygonCollision>(); if (geometry is IPoint) { #region IPoint double x = ((IPoint)geometry).X; double y = ((IPoint)geometry).Y; display.World2Image(ref x, ref y); var annotationPolygon = AnnotationPolygon(display, (float)x, (float)y, symbolAlignment); annotationPolygon.Rotate((float)x, (float)y, Angle); polygons.Add(annotationPolygon); #endregion } else if (geometry is IMultiPoint) { #region IMultipoint IMultiPoint pColl = (IMultiPoint)geometry; for (int i = 0; i < pColl.PointCount; i++) { double x = pColl[i].X; double y = pColl[i].Y; display.World2Image(ref x, ref y); var annotationPolygon = AnnotationPolygon(display, (float)x, (float)y, symbolAlignment); annotationPolygon.Rotate((float)x, (float)y, Angle); polygons.Add(annotationPolygon); } #endregion } else if (geometry is IDisplayPath) { if (String.IsNullOrEmpty(_text)) { return(null); } IDisplayPath path = (IDisplayPath)geometry; #region Text On Path var format = StringFormatFromAlignment(_align); IDisplayCharacterRanges ranges = this.MeasureCharacterWidth(display); float sizeW = ranges.Width; float stat0 = path.Chainage, stat1 = stat0 + sizeW, stat = stat0; if (stat0 < 0) { return(null); } #region Richtung des Textes CanvasPointF?p1_ = path.PointAt(stat0); //SpatialAlgorithms.Algorithm.DisplayPathPoint(path, stat0); CanvasPointF?p2_ = path.PointAt(stat1); //SpatialAlgorithms.Algorithm.DisplayPathPoint(path, stat1); if (!p1_.HasValue || !p2_.HasValue) { return(null); } if (p1_.Value.X > p2_.Value.X) { #region Swap Path Direction path.ChangeDirection(); stat = stat0 = path.Length - stat1; stat1 = stat0 + sizeW; #endregion } #endregion AnnotationPolygonCollection charPolygons = new AnnotationPolygonCollection(); float x, y, angle; for (int i = 0; i < _text.Length; i++) { CanvasRectangleF cSize = ranges[i]; int counter = 0; while (true) { CanvasPointF?p1 = path.PointAt(stat); //SpatialAlgorithms.Algorithm.DisplayPathPoint(path, stat); CanvasPointF?p2 = path.PointAt(stat + cSize.Width); if (!p1.HasValue || !p2.HasValue) { return(null); } angle = (float)(Math.Atan2(p2.Value.Y - p1.Value.Y, p2.Value.X - p1.Value.X) * 180.0 / Math.PI); //float ccc = 0f; //angle = 0f; //for (float xxx = 0f; xxx <= cSize.Width; xxx += cSize.Width / 10f, ccc += 1f) //{ // p2 = path.PointAt(stat + xxx/*cSize.Width*/); //SpatialAlgorithms.Algorithm.DisplayPathPoint(path, stat + cSize.Width); // if (p1 == null || p2 == null) // return null; // angle += (float)(Math.Atan2(((PointF)p2).Y - ((PointF)p1).Y, ((PointF)p2).X - ((PointF)p1).X) * 180.0 / Math.PI); //} //angle /= ccc; x = p1.Value.X; y = p1.Value.Y; AnnotationPolygon polygon = null; switch (format.LineAlignment) { case StringAlignment.Near: polygon = new Symbology.AnnotationPolygon((float)x + .1f * cSize.Width, (float)y + .2f * cSize.Height, .8f * cSize.Width, .6f * cSize.Height); break; case StringAlignment.Far: polygon = new Symbology.AnnotationPolygon((float)x + .1f * cSize.Width, (float)y - .8f * cSize.Height, .8f * cSize.Width, .6f * cSize.Height); break; default: polygon = new Symbology.AnnotationPolygon((float)x + .1f * cSize.Width, (float)y - .6f * cSize.Height / 2f, .8f * cSize.Width, .6f * cSize.Height); break; } polygon.Rotate((float)x, (float)y, Angle + angle); if (charPolygons.CheckCollision(polygon)) { stat += cSize.Width / 10.0f; counter++; if (counter > 7) { return(null); } continue; } charPolygons.Add(polygon); //using (System.Drawing.Drawing2D.GraphicsPath grpath = new System.Drawing.Drawing2D.GraphicsPath()) //{ // grpath.StartFigure(); // grpath.AddLine(polygon[0], polygon[1]); // grpath.AddLine(polygon[1], polygon[2]); // grpath.AddLine(polygon[2], polygon[3]); // grpath.CloseFigure(); // display.GraphicsContext.FillPath(Brushes.Aqua, grpath); //} break; } stat += cSize.Width;// +_font.Height * 0.1f; } if (charPolygons.Count > 0) { #region Glättung //for (int i = 1; i < charPolygons.Count - 1; i++) //{ // double angle0 = ((AnnotationPolygon)charPolygons[i - 1]).Angle; // double angle2 = ((AnnotationPolygon)charPolygons[i + 1]).Angle; // ((AnnotationPolygon)charPolygons[i]).Angle = (angle0 + angle2) * 0.5; // float x0 = ((AnnotationPolygon)charPolygons[i - 1]).X1; // float y0 = ((AnnotationPolygon)charPolygons[i - 1]).Y1; // float x2 = ((AnnotationPolygon)charPolygons[i + 1]).X1; // float y2 = ((AnnotationPolygon)charPolygons[i + 1]).Y1; // ((AnnotationPolygon)charPolygons[i]).X1 = (x0 + x2) * 0.5f; // ((AnnotationPolygon)charPolygons[i]).Y1 = (y0 + y2) * 0.5f; //} #endregion polygons.Add(charPolygons); path.AnnotationPolygonCollision = charPolygons; } #endregion } else if (geometry is IPolyline) { IPolyline pLine = (IPolyline)geometry; for (int iPath = 0; iPath < pLine.PathCount; iPath++) { IPath path = pLine[iPath]; if (path.PointCount == 0) { continue; } #region Simple Method IPoint p1 = path[0], p2; for (int iPoint = 1; iPoint < path.PointCount; iPoint++) { p2 = path[iPoint]; double angle = -Math.Atan2(p2.Y - p1.Y, p2.X - p1.X) * 180.0 / Math.PI; if (display.DisplayTransformation.UseTransformation) { angle -= display.DisplayTransformation.DisplayRotation; } if (angle < 0) { angle += 360; } if (angle > 90 && angle < 270) { angle -= 180; } var format = StringFormatFromAlignment(_align); double x, y; if (format.Alignment == StringAlignment.Center) { x = p1.X * 0.5 + p2.X * 0.5; y = p1.Y * 0.5 + p2.Y * 0.5; } else if (format.Alignment == StringAlignment.Far) { x = p2.X; y = p2.Y; } else { x = p1.X; y = p1.Y; } display.World2Image(ref x, ref y); var annotationPolygon = AnnotationPolygon(display, (float)x, (float)y, symbolAlignment); annotationPolygon.Rotate((float)x, (float)y, Angle); polygons.Add(annotationPolygon); p1 = p2; } #endregion } } return(polygons.Count > 0 ? polygons : null); }
public IBrush CreateNewLinearGradientBrush(CanvasRectangleF rect) { return(Current.Engine.CreateLinearGradientBrush(rect, _col1, _col2, _angle)); }
public void DrawRectangle(IPen pen, CanvasRectangleF rectangleF) { _canvas?.DrawRect(rectangleF.ToSKRect(), GetSKPaint(pen)); }
public void FillRectangle(IBrush brush, CanvasRectangleF rectangleF) { _canvas?.DrawRect(rectangleF.ToSKRect(), GetSKPaint(brush)); }
override protected void DrawAtPoint(IDisplay display, IPoint point, string text, float angle, IDrawTextFormat format, int level) { if (_font != null) { //point.X+=_xOffset; //point.Y+=_yOffset; try { display.Canvas.TranslateTransform(new CanvasPointF((float)point.X, (float)point.Y)); if (angle != 0 || _angle != 0 || _rotation != 0) { display.Canvas.RotateTransform(angle + _angle + _rotation); } if (level < 0 || level == 0) { var size = display.Canvas.MeasureText(text, _font); var rect = new CanvasRectangleF(0f, 0f, size.Width, size.Height); switch (format.Alignment) { case StringAlignment.Center: rect.Offset(-size.Width / 2, 0f); break; case StringAlignment.Far: rect.Offset(-size.Width, 0f); break; } switch (format.LineAlignment) { case StringAlignment.Center: rect.Offset(0f, -size.Height / 2); break; case StringAlignment.Far: rect.Offset(0f, -size.Height); break; } display.Canvas.SmoothingMode = (SmoothingMode)this.Smoothingmode; display.Canvas.FillRectangle(_outlinebrush, rect); display.Canvas.SmoothingMode = SmoothingMode.None; } if (level < 0 || level == 1) { display.Canvas.TextRenderingHint = (this.Smoothingmode == SymbolSmoothing.None) ? TextRenderingHint.SystemDefault : TextRenderingHint.AntiAlias; DrawString(display.Canvas, text, _font, _brush, _xOffset, _yOffset, format); display.Canvas.TextRenderingHint = TextRenderingHint.SystemDefault; } } finally { display.Canvas.ResetTransform(); } } }
public GdiLinearGradientBrush(CanvasRectangleF rect, ArgbColor col1, ArgbColor col2, float angle) { _brush = new LinearGradientBrush(rect.ToGdiRectangleF(), col1.ToGdiColor(), col2.ToGdiColor(), angle); }
public IBrush CreateLinearGradientBrush(CanvasRectangleF rect, ArgbColor col1, ArgbColor col2, float angle) { return(new SkiaLinearGradientBrush(rect, col1, col2, angle)); }
public void DrawText(string text, IFont font, IBrush brush, CanvasRectangleF rectangleF) { DrawMultilineText(text.RemoveReturns(), rectangleF.Center.ToSKPoint(), GetSKPaint(font, (SKPaint)brush.EngineElement)); }
static public SKRect ToSKRect(this CanvasRectangleF rect) { return new SKRect(rect.Left, rect.Top, rect.Left + rect.Width, rect.Top + rect.Height); }
public void FillRectangle(IBrush brush, CanvasRectangleF rectangleF) { CheckUsability(); _graphics.FillRectangle((Brush)brush.EngineElement, rectangleF.ToGdiRectangleF()); }