Esempio n. 1
0
        public override Result DrawStrikethrough(object clientDrawingContext, float baselineOriginX, float baselineOriginY, ref Strikethrough strikethrough, ComObject clientDrawingEffect)
        {
            PathGeometry pg   = new PathGeometry(this.factory);
            GeometrySink sink = pg.Open();

            Vector2 topLeft = new Vector2(0.0f, strikethrough.Offset);

            sink.BeginFigure(topLeft, FigureBegin.Filled);
            topLeft.X += strikethrough.Width;
            sink.AddLine(topLeft);
            topLeft.Y += strikethrough.Thickness;
            sink.AddLine(topLeft);
            topLeft.X -= strikethrough.Width;
            sink.AddLine(topLeft);
            sink.EndFigure(FigureEnd.Closed);
            sink.Close();


            TransformedGeometry tg = new TransformedGeometry(this.factory, pg, Matrix3x2.Translation(baselineOriginX, baselineOriginY) * Matrix3x2.Scaling(1.0f, -1.0f));

            pg.Dispose();
            sink.Dispose();

            this.AddGeometry(tg);
            return(Result.Ok);
        }
Esempio n. 2
0
        public Result DrawUnderline(object clientDrawingContext, float baselineOriginX, float baselineOriginY, ref Underline underline, ComObject clientDrawingEffect)
        {
            var rect = new SharpDX.RectangleF(0, underline.Offset, underline.Width, underline.Offset + underline.Thickness);
            var rectangleGeometry = new RectangleGeometry(_d2DFactory, rect);
            var matrix            = new Matrix3x2()
            {
                M11 = 1,
                M12 = 0,
                M21 = 0,
                M22 = 1,
                M31 = baselineOriginX,
                M32 = baselineOriginY
            };
            var transformedGeometry = new TransformedGeometry(_d2DFactory, rectangleGeometry, matrix);

            var brushColor = new Color4(1, 0, 0, 0);

            if (clientDrawingEffect != null && clientDrawingEffect is ColorDrawingEffect)
            {
                brushColor = (clientDrawingEffect as ColorDrawingEffect).Color;
            }

            var brush = new SolidColorBrush(_renderTarget, brushColor);

            _renderTarget.DrawGeometry(transformedGeometry, brush);
            _renderTarget.FillGeometry(transformedGeometry, brush);

            rectangleGeometry.Dispose();
            transformedGeometry.Dispose();
            brush.Dispose();

            return(SharpDX.Result.Ok);
        }
        public void RenderFilledElements(PlotRendererD2D canvas, System.Windows.Rect chartArea, System.Windows.Media.MatrixTransform PrimitiveTransform)
        {
            GeometryAndFlag gnf = null;

            if (!_geometryByFactory.TryGetValue(canvas.D2DFactory.NativePointer, out gnf) || gnf.RecalcGeometry)
            {
                CalculateGeometry(canvas.D2DFactory, chartArea);
            }
            if (_geometryByFactory.TryGetValue(canvas.D2DFactory.NativePointer, out gnf))
            {
                int colorIndex = 0;
                foreach (var childGeometry in gnf.FilledGeometry)
                {
                    System.Windows.Media.Color fillColor = _colors[colorIndex].Item2;
                    if (fillColor != System.Windows.Media.Colors.Transparent)
                    {
                        //Brush brush = IsDashed ? (Brush)(ChartUtilities.CreateHatch50(fillColor, new Size(2, 2))) : (Brush)(new SolidColorBrush(fillColor));
                        var brush = new SolidColorBrush(canvas.RenderTarget, fillColor.ToD2D());
                        var transformedGeometry = new TransformedGeometry(canvas.D2DFactory, childGeometry, PrimitiveTransform.ToD2D());
                        canvas.RenderTarget.FillGeometry(transformedGeometry, brush);
                    }
                    ++colorIndex;
                }
            }
        }
Esempio n. 4
0
        public Result DrawGlyphRun(object clientDrawingContext, float baselineOriginX, float baselineOriginY, MeasuringMode measuringMode, GlyphRun glyphRun, GlyphRunDescription glyphRunDescription, ComObject clientDrawingEffect)
        {
            var pathGeometry = new PathGeometry(_d2DFactory);
            var geometrySink = pathGeometry.Open();

            var fontFace = glyphRun.FontFace;

            if (glyphRun.Indices.Length > 0)
            {
                fontFace.GetGlyphRunOutline(glyphRun.FontSize, glyphRun.Indices, glyphRun.Advances, glyphRun.Offsets, glyphRun.IsSideways, glyphRun.BidiLevel % 2 != 0, geometrySink);
            }
            geometrySink.Close();
            geometrySink.Dispose();
            fontFace.Dispose();

            var matrix = new Matrix3x2()
            {
                M11 = 1,
                M12 = 0,
                M21 = 0,
                M22 = 1,
                M31 = baselineOriginX,
                M32 = baselineOriginY
            };

            var transformedGeometry = new TransformedGeometry(_d2DFactory, pathGeometry, matrix);

            _renderTarget.DrawGeometry(transformedGeometry, PenBrush, PenWidth, PenStyle);
            _renderTarget.FillGeometry(transformedGeometry, FontBrush);

            pathGeometry.Dispose();
            transformedGeometry.Dispose();

            return(SharpDX.Result.Ok);
        }
Esempio n. 5
0
        public Result DrawStrikethrough(object clientDrawingContext, float baselineOriginX, float baselineOriginY, ref Strikethrough strikethrough, ComObject clientDrawingEffect)
        {
            var rect = new SharpDX.RectangleF(0, strikethrough.Offset, strikethrough.Width, strikethrough.Offset + strikethrough.Thickness);
            var rectangleGeometry = new RectangleGeometry(_d2DFactory, rect);
            var matrix            = new Matrix3x2()
            {
                M11 = 1,
                M12 = 0,
                M21 = 0,
                M22 = 1,
                M31 = baselineOriginX,
                M32 = baselineOriginY
            };
            var transformedGeometry = new TransformedGeometry(_d2DFactory, rectangleGeometry, matrix);

            var brushColor = (Color4)Color.Black;

            if (clientDrawingEffect != null && clientDrawingEffect is ColorDrawingEffect)
            {
                brushColor = (Color4)(clientDrawingEffect as ColorDrawingEffect).Color;
            }

            var brush = new SolidColorBrush(_renderTarget, brushColor);

            _renderTarget.DrawGeometry(transformedGeometry, brush);
            _renderTarget.FillGeometry(transformedGeometry, brush);

            rectangleGeometry.Dispose();
            transformedGeometry.Dispose();
            brush.Dispose();

            return(Result.Ok);
        }
Esempio n. 6
0
        public override Result DrawUnderline(object clientDrawingContext, float baselineOriginX, float baselineOriginY, ref Underline underline, ComObject clientDrawingEffect)
        {
            using (PathGeometry pg = new PathGeometry(this.factory))
            {
                using (GeometrySink sink = pg.Open())
                {
                    Vector2 topLeft = new Vector2(0.0f, underline.Offset);
                    sink.BeginFigure(topLeft, FigureBegin.Filled);
                    topLeft.X += underline.Width;
                    sink.AddLine(topLeft);
                    topLeft.Y += underline.Thickness;
                    sink.AddLine(topLeft);
                    topLeft.X -= underline.Width;
                    sink.AddLine(topLeft);
                    sink.EndFigure(FigureEnd.Closed);
                    sink.Close();

                    Matrix3x2           mat = Matrix3x2.Translation(baselineOriginX, baselineOriginY) * Matrix3x2.Scaling(1.0f, -1.0f);
                    TransformedGeometry tg  = new TransformedGeometry(this.factory, pg, *(RawMat *)&mat);

                    this.AddGeometry(tg);
                    return(Result.Ok);
                }
            }
        }
        public override Result DrawGlyphRun(object clientDrawingContext, float baselineOriginX, float baselineOriginY, MeasuringMode measuringMode, GlyphRun glyphRun, GlyphRunDescription glyphRunDescription, ComObject clientDrawingEffect)
        {
            using (PathGeometry path = new PathGeometry(_factory))
                using (GeometrySink sink = path.Open())
                {
                    glyphRun.FontFace.GetGlyphRunOutline(glyphRun.FontSize, glyphRun.Indices, glyphRun.Advances, glyphRun.Offsets, glyphRun.IsSideways, false, sink);
                    sink.Close();

                    var translation = Matrix3x2.Translation(baselineOriginX, baselineOriginY);
                    var outline     = new TransformedGeometry(_factory, path, translation);
                    using (var strokeStyle = new StrokeStyle(_factory, new StrokeStyleProperties {
                        LineJoin = LineJoin.Round
                    }))
                    {
                        for (int i = 1; i < 8; i++)
                        {
                            var color = Color.White;
                            color.A /= (byte)Math.Ceiling(i / 1.5);
                            using (var brush = new SolidColorBrush(_surface, color))
                            {
                                _surface.DrawGeometry(outline, brush, i, strokeStyle);
                            }
                        }
                    }
                }

            return(new Result());
        }
        public void DrawGlyphRun(float baselineOriginX, float baselineOriginY, Graphics.Direct2D.MeasuringMode measuringMode, GlyphRun glyphRun, GlyphRunDescription glyphRunDescription, ClientDrawingEffect clientDrawingEffect)
        {
            using (PathGeometry pathGeometry = _factory.CreatePathGeometry())
            {
                using (GeometrySink sink = pathGeometry.Open())
                {
                    glyphRun.FontFace.GetGlyphRunOutline(
                        glyphRun.EmSize,
                        glyphRun.GlyphIndices,
                        glyphRun.GlyphAdvances,
                        glyphRun.GlyphOffsets,
                        glyphRun.IsSideways,
                        glyphRun.BidiLevel != 0,
                        sink);
                    sink.Close();
                }

                CustomGeometrySink customSink = new CustomGeometrySink();
                pathGeometry.Stream(customSink);
                customSink.Close();
                System.Diagnostics.Debug.WriteLine(customSink.ToString());

                Matrix3x2 matrix = new Matrix3x2(1, 0, 0, 1, baselineOriginX, baselineOriginY);
                using (TransformedGeometry transformedGeometry = _factory.CreateTransformedGeometry(pathGeometry, matrix))
                {
                    _renderTarget.DrawGeometry(_outlineBrush, 5, transformedGeometry);
                    _renderTarget.FillGeometry(_fillBrush, transformedGeometry);
                }
            }
        }
Esempio n. 9
0
            public override Result DrawGlyphRun(object clientDrawingContext, float baselineOriginX, float baselineOriginY, MeasuringMode measuringMode, GlyphRun glyphRun, GlyphRunDescription glyphRunDescription, ComObject clientDrawingEffect)
            {
                using (PathGeometry path = new PathGeometry(renderer.factory2d))
                {
                    using (GeometrySink sink = path.Open())
                    {
                        glyphRun.FontFace.GetGlyphRunOutline(glyphRun.FontSize, glyphRun.Indices, glyphRun.Advances, glyphRun.Offsets, glyphRun.Advances.Length, glyphRun.IsSideways, (glyphRun.BidiLevel % 2) > 0, sink);
                        sink.Close();
                    }

                    var matrix = new Matrix3x2()
                    {
                        M11 = 1,
                        M12 = 0,
                        M21 = 0,
                        M22 = 1,
                        M31 = baselineOriginX,
                        M32 = baselineOriginY
                    };

                    TransformedGeometry transformedGeometry = new TransformedGeometry(renderer.factory2d, path, matrix);
                    renderer.rtv2d.DrawGeometry(transformedGeometry, renderer.brush2dOutline);
                    Utilities.Dispose(ref transformedGeometry);
                }

                return(new Result());
            }
Esempio n. 10
0
        public void RenderUnfilledElements(PlotRendererD2D canvas, System.Windows.Rect chartArea, System.Windows.Media.MatrixTransform PrimitiveTransform)
        {
            var storedTransform = canvas.RenderTarget.Transform;

            //canvas.RenderTarget.Transform = PrimitiveTransform.ToD2D();

            //for(int segmentIndex = 0; segmentIndex < _lineColors.Count; ++segmentIndex) {
            //  var brush = canvas.RenderTarget.CreateSolidColorBrush(_lineColors[segmentIndex].ToD2D());
            //  canvas.RenderTarget.DrawLine(Points[segmentIndex * 2].ToD2D(), Points[segmentIndex * 2 + 1].ToD2D(), brush, (float)LineThickness);
            //}
            //canvas.RenderTarget.Transform = storedTransform;


            if (this.LineColor != System.Windows.Media.Colors.Transparent && LineThickness > 0)
            {
                GeometryAndFlag gnf = null;
                if (!_geometryByFactory.TryGetValue(canvas.D2DFactory.NativePointer, out gnf) || gnf.RecalcGeometry)
                {
                    CalculateGeometry(canvas.D2DFactory, chartArea);
                }
                if (_geometryByFactory.TryGetValue(canvas.D2DFactory.NativePointer, out gnf))
                {
                    var transformedGeometry = new TransformedGeometry(canvas.D2DFactory, gnf.UnfilledGeometry, PrimitiveTransform.ToD2D());

                    var brush = new SolidColorBrush(canvas.RenderTarget, LineColor.ToD2D());

                    canvas.RenderTarget.DrawGeometry(transformedGeometry, brush, (float)LineThickness);
                }
            }
        }
        public void DrawUnderline(float baselineOriginX, float baselineOriginY, Underline underline, ClientDrawingEffect clientDrawingEffect)
        {
            RectF rect = new RectF(0, underline.Offset, underline.Width, underline.Thickness);

            using (RectangleGeometry rectangleGeometry = _factory.CreateRectangleGeometry(rect))
            {
                SolidColorBrush brush = null;
                if (clientDrawingEffect != null)
                {
                    ColorDrawingEffect drawingEffect = clientDrawingEffect as ColorDrawingEffect;
                    if (drawingEffect != null)
                    {
                        brush = _renderTarget.CreateSolidColorBrush(drawingEffect.Color);
                    }
                }

                Matrix3x2 matrix = new Matrix3x2(1, 0, 0, 1, baselineOriginX, baselineOriginY);
                using (TransformedGeometry transformedGeometry = _factory.CreateTransformedGeometry(rectangleGeometry, matrix))
                {
                    _renderTarget.FillGeometry(brush == null ? _defaultBrush : brush, transformedGeometry);
                }
                if (brush != null)
                {
                    brush.Dispose();
                }
            }
        }
Esempio n. 12
0
        public Result DrawUnderline(object clientDrawingContext, float baselineOriginX, float baselineOriginY, ref Underline underline, ComObject clientDrawingEffect)
        {
            var rect = new SharpDX.RectangleF(0, underline.Offset, underline.Width, underline.Offset + underline.Thickness);
            var rectangleGeometry = new RectangleGeometry(_d2DFactory, rect);

            RawMatrix3x2 matrix = new RawMatrix3x2(
                1.0f, 0.0f,
                0.0f, 1.0f,
                baselineOriginX, baselineOriginY
                );


            var transformedGeometry = new TransformedGeometry(_d2DFactory, rectangleGeometry, matrix);

            var brushColor = (Color4)Color.Black;

            if (clientDrawingEffect != null && clientDrawingEffect is ColorDrawingEffect)
            {
                brushColor = (Color4)(clientDrawingEffect as ColorDrawingEffect).Color;
            }

            var brush = new SolidColorBrush(_renderTarget, brushColor);

            _renderTarget.DrawGeometry(transformedGeometry, brush);
            _renderTarget.FillGeometry(transformedGeometry, brush);

            rectangleGeometry.Dispose();
            transformedGeometry.Dispose();
            brush.Dispose();

            return(SharpDX.Result.Ok);
        }
Esempio n. 13
0
        private void Initialize()
        {
            /// 実装
            this.isVisible = true;

            this.x = 0;
            this.y = 0;

            var path = new PathGeometry(this.d2dDevice.Factory);

            this.firstPoint  = new Vector2(0f, 0f);
            this.secondPoint = new Vector2(MAX_X / this.n, 0f);
            this.thirdPoint  = new Vector2(MAX_X / 2 / this.n, MAX_Y / this.n);

            var sink = path.Open();

            sink.BeginFigure(this.firstPoint, FigureBegin.Filled);
            sink.AddLines(new SharpDX.Mathematics.Interop.RawVector2[] { this.secondPoint, this.thirdPoint });

            sink.EndFigure(FigureEnd.Closed);
            sink.Close();

            this.enemyPath = new TransformedGeometry(this.d2dDevice.Factory, path, Matrix3x2.Identity);

            this.enemyBrush = new SolidColorBrush(this.d2dDeviceContext, Color.Black);
        }
Esempio n. 14
0
 /// <summary>
 /// 更新当前轮廓路径。
 /// </summary>
 private void UpdatePath()
 {
     if (this.path != null)
     {
         this.path.Dispose();
     }
     this.path   = new TransformedGeometry(factory, this.originalPath, this.matrix);
     this.bounds = this.path.GetBounds();
 }
Esempio n. 15
0
 public void Transform()//变换,包括移动
 {
     if (this.transformGeo != null)
     {
         this.transformGeo.Dispose();
     }
     if (matrix.IsIdentity == false)
     {
         this.transformGeo = new TransformedGeometry(factory, this.orginGeomtery, this.matrix);
     }
 }
Esempio n. 16
0
        public Result DrawGlyphRun(object clientDrawingContext, float baselineOriginX, float baselineOriginY, MeasuringMode measuringMode, GlyphRun glyphRun, GlyphRunDescription glyphRunDescription, ComObject clientDrawingEffect)
        {
            if (clientDrawingEffect != null && clientDrawingEffect is SolidColorBrush)
            {
                SolidColorBrush brushx = clientDrawingEffect as SolidColorBrush;
                _renderTarget.DrawGlyphRun(new Vector2(baselineOriginX, baselineOriginY), glyphRun, brushx, measuringMode);
                return(Result.Ok);
            }

            var pathGeometry = new PathGeometry(_d2DFactory);
            var geometrySink = pathGeometry.Open();

            var fontFace = glyphRun.FontFace;

            if (glyphRun.Indices.Length > 0)
            {
                fontFace.GetGlyphRunOutline(glyphRun.FontSize, glyphRun.Indices, glyphRun.Advances, glyphRun.Offsets, glyphRun.IsSideways, glyphRun.BidiLevel % 2 != 0, geometrySink);
            }
            geometrySink.Close();
            geometrySink.Dispose();
            fontFace.Dispose();

            var matrix = new Matrix3x2()
            {
                M11 = 1,
                M12 = 0,
                M21 = 0,
                M22 = 1,
                M31 = baselineOriginX,
                M32 = baselineOriginY
            };

            var transformedGeometry = new TransformedGeometry(_d2DFactory, pathGeometry, matrix);

            var             brushColor = (Color4)Color.Black;
            SolidColorBrush brush      = null;

            if (clientDrawingEffect != null && clientDrawingEffect is ColorDrawingEffect)
            {
                brushColor = (clientDrawingEffect as ColorDrawingEffect).Color;
            }

            brush = new SolidColorBrush(_renderTarget, brushColor);

            //   _renderTarget.DrawGeometry(transformedGeometry, brush);
            _renderTarget.FillGeometry(transformedGeometry, brush);

            pathGeometry.Dispose();
            transformedGeometry.Dispose();
            brush.Dispose();

            return(SharpDX.Result.Ok);
        }
Esempio n. 17
0
        public void DrawUnderline(float baselineOriginX, float baselineOriginY, Underline underline, ClientDrawingEffect clientDrawingEffect)
        {
            RectF rect = new RectF(0, underline.Offset, underline.Width, underline.Thickness);

            using (RectangleGeometry rectangleGeometry = _factory.CreateRectangleGeometry(rect))
            {
                Matrix3x2 matrix = new Matrix3x2(1, 0, 0, 1, baselineOriginX, baselineOriginY);
                using (TransformedGeometry transformedGeometry = _factory.CreateTransformedGeometry(rectangleGeometry, matrix))
                {
                    _renderTarget.DrawGeometry(_outlineBrush, 5, transformedGeometry);
                    _renderTarget.FillGeometry(_fillBrush, transformedGeometry);
                }
            }
        }
Esempio n. 18
0
 public void RenderUnfilledElements(PlotRendererD2D canvas, System.Windows.Rect chartArea, System.Windows.Media.MatrixTransform PrimitiveTransform)
 {
     if (Points.Count > 0 && LineColor != System.Windows.Media.Colors.Transparent && LineThickness > 0)
     {
         GeometryAndFlag gnf = null;
         if (!_geometryByFactory.TryGetValue(canvas.D2DFactory.NativePointer, out gnf) || gnf.RecalcGeometry || gnf.Rect != chartArea)
         {
             CalculateGeometry(canvas.D2DFactory, chartArea);
         }
         if (_geometryByFactory.TryGetValue(canvas.D2DFactory.NativePointer, out gnf))
         {
             var transformedGeometry = new TransformedGeometry(canvas.D2DFactory, gnf.UnfilledGeometry, PrimitiveTransform.ToD2D());
             var brush = new SolidColorBrush(canvas.RenderTarget, LineColor.ToD2D());
             canvas.RenderTarget.DrawGeometry(transformedGeometry, brush, (float)LineThickness);
         }
     }
 }
        /// <summary>
        /// 返回指定拼图碎片的阴影位图。
        /// </summary>
        /// <param name="piece">要获取阴影位图的拼图碎片。</param>
        /// <returns>指定拼图碎片的阴影位图。</returns>
        private Tuple <Bitmap, Vector2> GetShadow(JigsawPiece piece)
        {
            Tuple <Bitmap, Vector2> tuple;

            if (!shadowCache.TryGetValue(piece.OriginalPath, out tuple))
            {
                // 移除已被释放的拼图碎片。
                Geometry disposedGeom = null;
                if ((disposedGeom = shadowCache.Keys.FirstOrDefault(g => g.IsDisposed)) != null)
                {
                    shadowCache.Remove(disposedGeom);
                }
                RectangleF bounds = piece.OriginalPath.GetBounds();
                Size2      size   = new Size2((int)bounds.Width + ShadowPadding * 2, (int)bounds.Height + ShadowPadding * 2);
                using (Bitmap1 source = DeviceManager.CreateBitmap(size))
                {
                    Bitmap1 target = DeviceManager.CreateBitmap(size);
                    // 设置特效的输入。
                    shadowEffect.SetInput(0, source, true);
                    // 阴影的偏移。
                    Vector2 offset = new Vector2(bounds.Left - ShadowPadding, bounds.Top - ShadowPadding);
                    using (TransformedGeometry tGeom = new TransformedGeometry(this.DeviceContext.Factory,
                                                                               piece.OriginalPath, Matrix3x2.Translation(-offset.X, -offset.Y)))
                    {
                        // 将拼图碎片绘制到位图上。
                        this.DeviceContext.Target = source;
                        this.DeviceContext.BeginDraw();
                        this.DeviceContext.Clear(Color.Transparent);
                        this.DeviceContext.FillGeometry(tGeom, blackBrush);
                        this.DeviceContext.EndDraw();

                        // 将添加特效后的拼图碎片绘制到位图上。
                        this.DeviceContext.Target = target;
                        this.DeviceContext.BeginDraw();
                        this.DeviceContext.DrawImage(shadowEffect);
                        this.DeviceContext.EndDraw();

                        tuple = new Tuple <Bitmap, Vector2>(target, offset);
                        shadowCache.Add(piece.OriginalPath, tuple);
                    }
                }
            }
            return(tuple);
        }
        public void DrawGlyphRun(float baselineOriginX, float baselineOriginY, Graphics.Direct2D.MeasuringMode measuringMode, GlyphRun glyphRun, GlyphRunDescription glyphRunDescription, ClientDrawingEffect clientDrawingEffect)
        {
            using (PathGeometry pathGeometry = _factory.CreatePathGeometry())
            {
                using (GeometrySink sink = pathGeometry.Open())
                {
                    glyphRun.FontFace.GetGlyphRunOutline(
                        glyphRun.EmSize,
                        glyphRun.GlyphIndices,
                        glyphRun.GlyphAdvances,
                        glyphRun.GlyphOffsets,
                        glyphRun.IsSideways,
                        glyphRun.BidiLevel != 0,
                        sink);
                    sink.Close();
                }

                CustomGeometrySink customSink = new CustomGeometrySink();
                pathGeometry.Stream(customSink);
                customSink.Close();
                System.Diagnostics.Debug.WriteLine(customSink.ToString());

                SolidColorBrush brush = null;
                if (clientDrawingEffect != null)
                {
                    ColorDrawingEffect drawingEffect = clientDrawingEffect as ColorDrawingEffect;
                    if (drawingEffect != null)
                    {
                        brush = _renderTarget.CreateSolidColorBrush(drawingEffect.Color);
                    }
                }

                Matrix3x2 matrix = new Matrix3x2(1, 0, 0, 1, baselineOriginX, baselineOriginY);
                using (TransformedGeometry transformedGeometry = _factory.CreateTransformedGeometry(pathGeometry, matrix))
                {
                    _renderTarget.FillGeometry(brush == null ? _defaultBrush : brush, transformedGeometry);
                }
                if (brush != null)
                {
                    brush.Dispose();
                }
            }
        }
Esempio n. 21
0
        public Result DrawGlyphRun(object clientDrawingContext, float baselineOriginX, float baselineOriginY, MeasuringMode measuringMode, GlyphRun glyphRun, GlyphRunDescription glyphRunDescription, ComObject clientDrawingEffect)
        {
            var pathGeometry = new PathGeometry(_d2DFactory);
            var geometrySink = pathGeometry.Open();

            float[]       advances;
            GlyphOffset[] offsets;
            var           indecies = glyphRun.ToArrays(out advances, out offsets);

            var result = glyphRun.FontFace.GetGlyphRunOutline(glyphRun.FontSize, indecies, advances, offsets, glyphRun.IsSideways, glyphRun.BidiLevel % 2 != 0, geometrySink);

            geometrySink.Close();
            var matrix = new Matrix3x2()
            {
                M11 = 1,
                M12 = 0,
                M21 = 0,
                M22 = 1,
                M31 = baselineOriginX,
                M32 = baselineOriginY
            };

            var transformedGeometry = new TransformedGeometry(_d2DFactory, pathGeometry, matrix);

            var brushColor = new Color4(1, 0, 0, 0);

            if (clientDrawingEffect != null && clientDrawingEffect is ColorDrawingEffect)
            {
                brushColor = (clientDrawingEffect as ColorDrawingEffect).Color;
            }

            var brush = new SolidColorBrush(_renderTarget, brushColor);

            _renderTarget.DrawGeometry(transformedGeometry, brush);
            _renderTarget.FillGeometry(transformedGeometry, brush);

            pathGeometry.Dispose();
            transformedGeometry.Dispose();
            brush.Dispose();

            return(SharpDX.Result.Ok);
        }
Esempio n. 22
0
        public override SharpDX.Result DrawGlyphRun(object clientDrawingContext, float baselineOriginX, float baselineOriginY, MeasuringMode measuringMode, GlyphRun glyphRun, GlyphRunDescription glyphRunDescription, SharpDX.ComObject clientDrawingEffect)
        {
            PathGeometry pg = new PathGeometry(this.factory);

            GeometrySink sink = pg.Open();

            glyphRun.FontFace.GetGlyphRunOutline(glyphRun.FontSize, glyphRun.Indices, glyphRun.Advances, glyphRun.Offsets, glyphRun.IsSideways, glyphRun.BidiLevel % 2 == 1, sink as SimplifiedGeometrySink);

            sink.Close();

            TransformedGeometry tg = new TransformedGeometry(this.factory, pg, Matrix3x2.Translation(baselineOriginX, baselineOriginY));

            pg.Dispose();

            //Transform from baseline

            this.AddGeometry(tg);

            return(SharpDX.Result.Ok);
        }
Esempio n. 23
0
        public Result DrawGlyphRun(object clientDrawingContext, float baselineOriginX, float baselineOriginY,
                                   MeasuringMode measuringMode, GlyphRun glyphRun, GlyphRunDescription glyphRunDescription,
                                   ComObject clientDrawingEffect)
        {
            using (var path = new PathGeometry(_factory))
                using (var sink = path.Open())
                {
                    glyphRun.FontFace.GetGlyphRunOutline(glyphRun.FontSize, glyphRun.Indices, glyphRun.Advances,
                                                         glyphRun.Offsets, glyphRun.IsSideways, (glyphRun.BidiLevel % 2) > 0, sink);
                    sink.Close();

                    var matrix = new Matrix3x2(1.0f, 0.0f, 0.0f, 1.0f, Location.X + baselineOriginX, Location.Y + baselineOriginY);
                    using (var transformedGeometry = new TransformedGeometry(_factory, path, matrix))
                    {
                        Renderer.Context2D.AntialiasMode = AntialiasMode.Aliased;
                        Renderer.Context2D.DrawGeometry(transformedGeometry, OutlineBrush, StrokeWidth);
                        Renderer.Context2D.AntialiasMode = AntialiasMode.PerPrimitive;
                        Renderer.Context2D.FillGeometry(transformedGeometry, FillBrush);
                    }
                }
            return(Result.Ok);
        }
Esempio n. 24
0
        public Result DrawStrikethrough(object clientDrawingContext, float baselineOriginX, float baselineOriginY, ref Strikethrough strikethrough, ComObject clientDrawingEffect)
        {
            var rect = new SharpDX.RectangleF(0, strikethrough.Offset, strikethrough.Width, strikethrough.Offset + strikethrough.Thickness);
            var rectangleGeometry = new RectangleGeometry(_d2DFactory, rect);
            var matrix            = new Matrix3x2()
            {
                M11 = 1,
                M12 = 0,
                M21 = 0,
                M22 = 1,
                M31 = baselineOriginX,
                M32 = baselineOriginY
            };
            var transformedGeometry = new TransformedGeometry(_d2DFactory, rectangleGeometry, matrix);

            _renderTarget.DrawGeometry(transformedGeometry, FontBrush);
            _renderTarget.FillGeometry(transformedGeometry, FontBrush);

            rectangleGeometry.Dispose();
            transformedGeometry.Dispose();

            return(Result.Ok);
        }
Esempio n. 25
0
        public override void DrawGeometry(Brush brush, Pen pen, Geometry geometry, Avalonia.Media.Matrix transform)
        {
            Direct2D1StreamGeometry platformGeometry = (Direct2D1StreamGeometry)geometry.PlatformImpl;

            using (TransformedGeometry d2dGeometry = new TransformedGeometry(
                       this.factory,
                       platformGeometry.Direct2DGeometry,
                       transform.ToSharpDX()))
            {
                if (brush != null)
                {
                    this.target.FillGeometry(d2dGeometry, brush.ToSharpDX(this.target));
                }

                if (pen != null)
                {
                    this.target.DrawGeometry(
                        d2dGeometry,
                        pen.Brush.ToSharpDX(this.target),
                        (float)pen.Thickness);
                }
            }
        }
Esempio n. 26
0
        public Result DrawStrikethrough(object clientDrawingContext, float baselineOriginX, float baselineOriginY, ref Strikethrough strikethrough, ComObject clientDrawingEffect)
        {
            var rect = new SharpDX.RectangleF(0, strikethrough.Offset, strikethrough.Width, strikethrough.Offset + strikethrough.Thickness);

            using (var rectangleGeometry = new RectangleGeometry(_d2DFactory, rect))
            {
                var matrix = new Matrix3x2()
                {
                    M11 = 1,
                    M12 = 0,
                    M21 = 0,
                    M22 = 1,
                    M31 = baselineOriginX,
                    M32 = baselineOriginY
                };
                using (var transformedGeometry = new TransformedGeometry(_d2DFactory, rectangleGeometry, matrix))
                {
                    _dc.DrawGeometry(transformedGeometry, _outlineBrush);
                    _dc.FillGeometry(transformedGeometry, _fillBrush);
                }
            }
            return(Result.Ok);
        }
Esempio n. 27
0
        public override SharpDX.Result DrawGlyphRun(object clientDrawingContext, float baselineOriginX, float baselineOriginY, MeasuringMode measuringMode, GlyphRun glyphRun, GlyphRunDescription glyphRunDescription, SharpDX.ComObject clientDrawingEffect)
        {
            Color4 c = Color4.White;

            if (clientDrawingEffect != null)
            {
                if (clientDrawingEffect is SharpDX.Direct2D1.SolidColorBrush)
                {
                    var sb = (SharpDX.Direct2D1.SolidColorBrush)clientDrawingEffect;
                    c = sb.Color;
                }
            }

            if (glyphRun.Indices.Length > 0)
            {
                PathGeometry pg = new PathGeometry(this.factory);

                GeometrySink sink = pg.Open();

                glyphRun.FontFace.GetGlyphRunOutline(glyphRun.FontSize, glyphRun.Indices, glyphRun.Advances, glyphRun.Offsets, glyphRun.IsSideways, glyphRun.BidiLevel % 2 == 1, sink as SimplifiedGeometrySink);
                sink.Close();

                TransformedGeometry tg = new TransformedGeometry(this.factory, pg, Matrix3x2.Translation(baselineOriginX, baselineOriginY) * Matrix3x2.Scaling(1.0f, -1.0f));

                pg.Dispose();
                sink.Dispose();
                //Transform from baseline

                this.AddGeometry(tg);

                return(SharpDX.Result.Ok);
            }
            else
            {
                return(SharpDX.Result.Ok);
            }
        }
        public void RenderUnfilledElements(PlotRendererD2D canvas, System.Windows.Rect chartArea, System.Windows.Media.MatrixTransform PrimitiveTransform)
        {
            GeometryAndFlag gnf = null;

            if (!_geometryByFactory.TryGetValue(canvas.D2DFactory.NativePointer, out gnf) || gnf.RecalcGeometry)
            {
                CalculateGeometry(canvas.D2DFactory, chartArea);
            }
            if (_geometryByFactory.TryGetValue(canvas.D2DFactory.NativePointer, out gnf))
            {
                int colorIndex = 0;
                foreach (var childGeometry in gnf.UnfilledGeometry)
                {
                    System.Windows.Media.Color lineColor = _colors[colorIndex].Item1;
                    if (lineColor != System.Windows.Media.Colors.Transparent)
                    {
                        var brush = new SolidColorBrush(canvas.RenderTarget, lineColor.ToD2D());
                        var transformedGeometry = new TransformedGeometry(canvas.D2DFactory, childGeometry, PrimitiveTransform.ToD2D());
                        canvas.RenderTarget.DrawGeometry(transformedGeometry, brush, (float)LineThickness);
                    }
                    ++colorIndex;
                }
            }
        }
Esempio n. 29
0
        public Result DrawGlyphRun(object clientDrawingContext, float baselineOriginX, float baselineOriginY, MeasuringMode measuringMode, GlyphRun glyphRun, GlyphRunDescription glyphRunDescription, ComObject clientDrawingEffect)
        {
            using (var pathGeometry = new PathGeometry(_d2DFactory))
            {
                using (var geometrySink = pathGeometry.Open())
                {
                    using (var fontFace = glyphRun.FontFace)
                    {
                        if (glyphRun.Indices.Length > 0)
                        {
                            fontFace.GetGlyphRunOutline(glyphRun.FontSize, glyphRun.Indices, glyphRun.Advances, glyphRun.Offsets,
                                                        glyphRun.Indices.Length, glyphRun.IsSideways, glyphRun.BidiLevel % 2 != 0, geometrySink);
                        }
                    }
                    geometrySink.Close();
                }


                var matrix = new Matrix3x2()
                {
                    M11 = 1,
                    M12 = 0,
                    M21 = 0,
                    M22 = 1,
                    M31 = baselineOriginX,
                    M32 = baselineOriginY
                };

                using (var transformedGeometry = new TransformedGeometry(_d2DFactory, pathGeometry, matrix))
                {
                    _dc.DrawGeometry(transformedGeometry, _outlineBrush);
                    _dc.FillGeometry(transformedGeometry, _fillBrush);
                }
            }
            return(SharpDX.Result.Ok);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="StreamGeometryImpl"/> class.
 /// </summary>
 /// <param name="source">The source geometry.</param>
 /// <param name="geometry">An existing Direct2D <see cref="TransformedGeometry"/>.</param>
 public TransformedGeometryImpl(TransformedGeometry geometry, GeometryImpl source)
     : base(geometry)
 {
     SourceGeometry = source;
 }
Esempio n. 31
0
        internal void Fill(DrawingLayer drawingLayer, Brushes.Brush brush)
        {
            var bounds = GetBoundsInverted();
            drawingLayer.PushState();
            
            BrushHelper.PrepareBrush(brush, drawingLayer, bounds, GetCurrentTransform(), Matrix3x2.Identity);

            if (m_transformedGeometry != null)
            {
                m_transformedGeometry.Dispose();
                m_transformedGeometry = null;
            }

            m_transformedGeometry = new TransformedGeometry(InternalRenderTargetResourceOwner.InternalRenderTarget.Factory, 
                                                            GetInternalGeometry(),
                                                            GetCurrentTransform());

            if (m_mesh == null)
                drawingLayer.D2DRenderTarget.InternalRenderTarget.FillGeometry(m_transformedGeometry, brush.InternalBrush);
            else
            {
                drawingLayer.D2DRenderTarget.InternalRenderTarget.AntialiasMode = AntialiasMode.Aliased;
                drawingLayer.D2DRenderTarget.InternalRenderTarget.FillMesh(m_mesh, brush.InternalBrush);
            }

            drawingLayer.PopState();
        }
Esempio n. 32
0
        public virtual void Dispose()
        {
            if(m_mesh != null)
            {
                m_mesh.Dispose();
                m_mesh = null;
            }

            if(m_transformedGeometry != null)
            {
                m_transformedGeometry.Dispose();
                m_transformedGeometry = null;
            }
        }