English 中文(简体)
如何使用WindowsAPICodePack实施大纲对文本的影响?
原标题:How to implement the outline effect on text with WindowsAPICodePack?

I m still struggling on this issue after our other requirements are finished. I found we can use GeometrySink alike classes to implement the outline effect; but I m not familiar with c++; see this article: http://msdn.microsoft.com/en-us/library/dd317121.aspx

More complex shapes can be created by using the ID2D1GeometrySink interface to specify a series of figures composed of lines, curves, and arcs. The ID2D1GeometrySink is passed to the Open method of an ID2D1PathGeometry to generate a complex geometry. ID2D1SimplifiedGeometrySink can also be used with the DirectWrite API to extract path outlines of formatted text for artistic rendering.

如果你有任何建议或想法,请让我知道。

Best regards, Howard

问题回答

http://code.google.com/p/sharpdx/“rel=“nofollow” 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);
        }

    }

我将此变成了通用的XAML大纲文本译本。 感谢张贴。

Cheers, Paul





相关问题
Which non-bold UTF-8 iPhone SDK font can I use here?

Problem: I create a UILabel with this font: label.font = [UIFont systemFontOfSize:15.0f]; Now this system font is bold, but I want to display pretty small text, and the text may also contain very ...

Limiting file upload type

Simple question. Is there a way to only allow txt files upon uploading? I ve looked around and all I find is text/php, which allows PHP. $uploaded_type=="text/php

Extract everything from PDF [closed]

Looking for solution to extract content from a PDF file (using console tool or a library). It will be used on server to produce on-line e-books from uploaded PDF files. Need to extract following ...

Flash & external form fields

Does anybody know if this is possible? I am trying to create a flash movie that will show / preview what I am typing into a field in a normal HTML form. The call to update the flash movie would most ...

Avoiding escape sequence processing in ActionScript?

I need to mimic C# functionality of the @ symbol when it precedes a string. @"C:AFilePath" for example What is the best way to do this? Also there are some sites that will escape larger ...

iPhone: Draw rotated text?

I want to draw some text in a view, rotated 90°. I m pretty new to iPhone development, and poking around the web reveals a number of different solutions. I ve tried a few and usually end up with my ...

Numbering in jQuery

How could I change the text below so that the text within it has a number appended to it. <div class="right">This is some text</div> <div class="right">This is some text</div>...

热门标签