コード例 #1
0
ファイル: CustomTextRenderer.cs プロジェクト: numo16/SharpDX
        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);

            var  brushColor = (Color4)Color.Black;

            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;
        }
コード例 #2
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);
                }
            }
        }
コード例 #3
0
ファイル: OutlineRenderer.cs プロジェクト: sebllll/dx11-vvvv
        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();

                //Transform from baseline

                this.AddGeometry(tg);

                return SharpDX.Result.Ok;
            }
            else
            {
                return SharpDX.Result.Ok;
            }
        }
コード例 #4
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();
		}
コード例 #5
0
		/// <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;
		}
コード例 #6
0
ファイル: OutlineRenderer.cs プロジェクト: sebllll/dx11-vvvv
        public override Result DrawUnderline(object clientDrawingContext, float baselineOriginX, float baselineOriginY, ref Underline underline, ComObject clientDrawingEffect)
        {
            PathGeometry pg = new PathGeometry(this.factory);
            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();

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

            this.AddGeometry(tg);
            return Result.Ok;
        }
コード例 #7
0
ファイル: CustomTextRenderer.cs プロジェクト: numo16/SharpDX
        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;
        }
コード例 #8
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;
        }