0

他の要件が完了した後も、この問題についてまだ苦労しています。GeometrySink 同様のクラスを使用してアウトライン効果を実装できることがわかりました。しかし、私は c++ に慣れていません。この記事を参照してください: http://msdn.microsoft.com/en-us/library/dd317121.aspx

ID2D1GeometrySink インターフェイスを使用して、直線、曲線、円弧で構成される一連の図形を指定すると、より複雑な形状を作成できます。ID2D1GeometrySink は、複雑なジオメトリを生成するために ID2D1PathGeometry の Open メソッドに渡されます。ID2D1SimplifiedGeometrySink を DirectWrite API と共に使用して、芸術的なレンダリングのために書式設定されたテキストのパス アウトラインを抽出することもできます。

ご提案やアイデアがありましたら、お知らせください。

よろしく、 ハワード

4

2 に答える 2

1

SharpDXを使用しています。ここにコードのスニペットがあります (これは進行中の作業であり、レンダリングしたばかりですが、おそらくあなたが探しているものです)。

   public class OutlineTextRender : SharpDX.DirectWrite.TextRenderer
    {
        readonly Factory _factory;
        readonly RenderTarget _surface;
        readonly Brush _brush;

        public OutlineTextRender(RenderTarget surface, Brush brush)
        {
            _factory = surface.Factory;
            _surface = surface;
            _brush = brush;
        }

        public Result DrawGlyphRun(object clientDrawingContext, float baselineOriginX, float baselineOriginY, MeasuringMode measuringMode, SharpDX.DirectWrite.GlyphRun glyphRun, SharpDX.DirectWrite.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, (glyphRun.BidiLevel % 2) > 0, sink);

                    sink.Close();
                }

                Matrix matrix = Matrix.Identity;
                matrix = matrix * Matrix.Translation(baselineOriginX, baselineOriginY, 0);

                TransformedGeometry transformedGeometry = new TransformedGeometry(_factory, path, matrix);

                _surface.DrawGeometry(transformedGeometry, _brush);

            }
            return new Result();
        }

        public Result DrawInlineObject(object clientDrawingContext, float originX, float originY, SharpDX.DirectWrite.InlineObject inlineObject, bool isSideways, bool isRightToLeft, ComObject clientDrawingEffect)
        {
            return new Result();
        }

        public Result DrawStrikethrough(object clientDrawingContext, float baselineOriginX, float baselineOriginY, ref SharpDX.DirectWrite.Strikethrough strikethrough, ComObject clientDrawingEffect)
        {
            return new Result();
        }

        public Result DrawUnderline(object clientDrawingContext, float baselineOriginX, float baselineOriginY, ref SharpDX.DirectWrite.Underline underline, ComObject clientDrawingEffect)
        {
            return new Result();
        }

        public SharpDX.DirectWrite.Matrix GetCurrentTransform(object clientDrawingContext)
        {
            return new SharpDX.DirectWrite.Matrix();
        }

        public float GetPixelsPerDip(object clientDrawingContext)
        {
            return 0;
        }

        public bool IsPixelSnappingDisabled(object clientDrawingContext)
        {
            return true; ;
        }

        public IDisposable Shadow
        {
            get
            {
                return null;
            }
            set
            {
               // throw new NotImplementedException();
            }
        }

        public void Dispose()
        {

        }
    }

    public void strokeText(string text, float x, float y, float maxWidth)
    {
        // http://msdn.microsoft.com/en-us/library/windows/desktop/dd756692(v=vs.85).aspx

        // FIXME make field
        SharpDX.DirectWrite.Factory factory = new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Shared);

        TextFormat format = new TextFormat(factory, "Verdana", 50);
        SharpDX.DirectWrite.TextLayout layout = new SharpDX.DirectWrite.TextLayout(factory, text, format, 50, 1000);





        using (var brush = new SolidColorBrush(_surface, CurrentColor))
        {
            var render = new OutlineTextRender(_surface, brush);

            layout.Draw(render, x, y);

            //_surface.DrawTextLayout(new DrawingPointF(x, y), layout, brush);

         //   _surface.DrawGlyphRun(new DrawingPointF(x, y), run, brush, MeasuringMode.Natural);
        }

    }
于 2012-04-29T14:41:04.657 に答える
0

これを一般的な XAML アウトライン テキスト レンダラーに変えました。投稿していただきありがとうございます。

https://blogs.msdn.microsoft.com/theuxblog/2016/07/09/outline-text-from-a-windows-10-store-xaml-app-using-sharpdx/

乾杯、ポール

于 2016-07-09T20:12:23.793 に答える