Пример #1
0
        public Result DrawGlyphRun(
            object clientDrawingContext,
            float baselineOriginX,
            float baselineOriginY,
            MeasuringMode measuringMode,
            GlyphRun glyphRun,
            GlyphRunDescription glyphRunDescription,
            ComObject clientDrawingEffect)
        {
            var wrapper = clientDrawingEffect as BrushWrapper;

            // TODO: Work out how to get the size below rather than passing new Size().
            var brush = (wrapper == null) ?
                _foreground :
                _context.CreateBrush(wrapper.Brush, new Size()).PlatformBrush;

            _renderTarget.DrawGlyphRun(
                new RawVector2 { X = baselineOriginX, Y = baselineOriginY },
                glyphRun,
                brush,
                measuringMode);

            if (wrapper != null)
            {
                brush.Dispose();
            }

            return Result.Ok;
        }
Пример #2
0
        public Result DrawGlyphRun(
            object clientDrawingContext, 
            float baselineOriginX, 
            float baselineOriginY, 
            MeasuringMode measuringMode, 
            GlyphRun glyphRun, 
            GlyphRunDescription glyphRunDescription, 
            ComObject clientDrawingEffect)
        {
            var wrapper = clientDrawingEffect as BrushWrapper;
            var brush = (wrapper == null) ?
                this.foreground :
                wrapper.Brush.ToDirect2D(this.renderTarget);

            this.renderTarget.DrawGlyphRun(
                new Vector2(baselineOriginX, baselineOriginY),
                glyphRun,
                brush,
                measuringMode);

            if (wrapper != null)
            {
                brush.Dispose();
            }

            return Result.Ok;
        }
Пример #3
0
            private static int DrawGlyphRunImpl(IntPtr thisObject, IntPtr clientDrawingContextPtr, float baselineOriginX, float baselineOriginY, MeasuringMode measuringMode,
                                                IntPtr glyphRunPtr, IntPtr glyphRunDescriptionPtr, IntPtr clientDrawingEffectPtr)
            {
                unsafe
                {
                    var shadow   = ToShadow <TextRendererShadow>(thisObject);
                    var callback = (TextRenderer)shadow.Callback;

                    // Read GlyphRun
                    var glyphRunData = default(GlyphRun.__Native);
                    Utilities.Read(glyphRunPtr, ref glyphRunData);
                    using (var glyphRun = new GlyphRun())
                    {
                        glyphRun.__MarshalFrom(ref glyphRunData);

                        // Read GlyphRunDescription
                        var glyphRunDescriptionData = default(GlyphRunDescription.__Native);
                        Utilities.Read(glyphRunDescriptionPtr, ref glyphRunDescriptionData);
                        var glyphRunDescription = new GlyphRunDescription();
                        glyphRunDescription.__MarshalFrom(ref glyphRunDescriptionData);

                        return
                            (callback.DrawGlyphRun(GCHandle.FromIntPtr(clientDrawingContextPtr).Target, baselineOriginX,
                                                   baselineOriginY, measuringMode, glyphRun, glyphRunDescription,
                                                   (ComObject)Utilities.GetObjectForIUnknown(clientDrawingEffectPtr)).Code);
                    }
                }
            }
Пример #4
0
            private static int DrawGlyphRunImpl(IntPtr thisObject, IntPtr clientDrawingContextPtr, float baselineOriginX, float baselineOriginY, MeasuringMode measuringMode,
                                         IntPtr glyphRunPtr, IntPtr glyphRunDescriptionPtr, IntPtr clientDrawingEffectPtr)
            {
                unsafe
                {
                    var shadow = ToShadow<TextRendererShadow>(thisObject);
                    var callback = (TextRenderer) shadow.Callback;

                    // Read GlyphRun
                    var glyphRunData = default(GlyphRun.__Native);
                    Utilities.Read(glyphRunPtr, ref glyphRunData);
                    using (var glyphRun = new GlyphRun())
                    {
                        glyphRun.__MarshalFrom(ref glyphRunData);

                        // Read GlyphRunDescription
                        var glyphRunDescriptionData = default(GlyphRunDescription.__Native);
                        Utilities.Read(glyphRunDescriptionPtr, ref glyphRunDescriptionData);
                        var glyphRunDescription = new GlyphRunDescription();
                        glyphRunDescription.__MarshalFrom(ref glyphRunDescriptionData);

                        return
                            callback.DrawGlyphRun(GCHandle.FromIntPtr(clientDrawingContextPtr).Target, baselineOriginX,
                                                  baselineOriginY, measuringMode, glyphRun, glyphRunDescription,
                                                  (ComObject) Utilities.GetObjectForIUnknown(clientDrawingEffectPtr)).Code;
                    }
                }
            }
Пример #5
0
        public override Result DrawGlyphRun(object clientDrawingContext, float baselineOriginX, float baselineOriginY, MeasuringMode measuringMode, GlyphRun glyphRun, GlyphRunDescription glyphRunDescription, ComObject clientDrawingEffect)
        {
            SolidColorBrush sb = defaultBrush;
            if (clientDrawingEffect != null && clientDrawingEffect is SolidColorBrush)
            {
                sb = (SolidColorBrush)clientDrawingEffect;
            }

            try
            {
                this.renderTarget.DrawGlyphRun(new Vector2(baselineOriginX, baselineOriginY), glyphRun, sb, measuringMode);
                return Result.Ok;
            }
            catch
            {
                return Result.Fail;
            }
        }
Пример #6
0
            public override SharpDX.Result DrawGlyphRun(object clientDrawingContext, float baselineOriginX, float baselineOriginY, D2D1.MeasuringMode measuringMode,
                                                        DW.GlyphRun glyphRun, DW.GlyphRunDescription glyphRunDescription, ComObject effect)
            {
                var sb = _defaultBrush;

                if (effect != null && effect is D2D1.SolidColorBrush solidColorBrush)
                {
                    sb = solidColorBrush;
                }
                try
                {
                    _renderTarget.DrawGlyphRun(new Vector2(baselineOriginX, baselineOriginY), glyphRun, sb, measuringMode);
                    return(SharpDX.Result.Ok);
                }
                catch
                {
                    return(SharpDX.Result.Fail);
                }
            }
Пример #7
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);

            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;
        }
Пример #8
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();

                //Transform from baseline

                this.AddGeometry(tg);

                return SharpDX.Result.Ok;
            }
            else
            {
                return SharpDX.Result.Ok;
            }
        }
Пример #9
0
        public Result DrawGlyphRun(object clientDrawingContext, float baselineOriginX, float baselineOriginY, D2D.MeasuringMode measuringMode, DW.GlyphRun glyphRun, DW.GlyphRunDescription glyphRunDescription, ComObject clientDrawingEffect)
        {
            D2D.RenderTarget render = clientDrawingContext as D2D.RenderTarget;
            if (render == null)
            {
                return(SharpDX.Result.Ok);
            }

            D2D.SolidColorBrush foreBrush = this.factory.GetSolidColorBrush(this.DefaultFore);
            bool isDrawGlyphRun           = true;

            if (clientDrawingEffect != null)
            {
                var drawingForeBrush = clientDrawingEffect as D2D.SolidColorBrush;
                var selectedEffect   = clientDrawingEffect as SelectedEffect;
                var drawingEffect    = clientDrawingEffect as DrawingEffect;

                if (drawingForeBrush != null)
                {
                    foreBrush = drawingForeBrush;
                }
                else if (selectedEffect != null)
                {
                    foreBrush = this.factory.GetSolidColorBrush(selectedEffect.Fore);
                }
                else if (drawingEffect != null)
                {
                    if (drawingEffect.Stroke == HilightType.Url)
                    {
                        foreBrush = this.factory.GetSolidColorBrush(drawingEffect.Fore);
                    }
                }
            }

            if (isDrawGlyphRun)
            {
                render.DrawGlyphRun(new Vector2(baselineOriginX, baselineOriginY),
                                    glyphRun,
                                    foreBrush,
                                    measuringMode);
            }

            return(SharpDX.Result.Ok);
        }
Пример #10
0
 /// <summary>	
 ///  IDWriteTextLayout::Draw calls this function to instruct the client to render a run of glyphs. 	
 /// </summary>	
 /// <remarks>	
 /// The <see cref="SharpDX.DirectWrite.TextLayout.Draw_"/> function calls this callback function with all the information about glyphs to render. The application implements this callback by mostly delegating the call to the underlying platform's graphics API such as {{Direct2D}} to draw glyphs on the drawing context. An application that uses GDI can implement this callback in terms of the <see cref="BitmapRenderTarget.DrawGlyphRun(float,float,MeasuringMode,SharpDX.DirectWrite.GlyphRun,SharpDX.DirectWrite.RenderingParams,SharpDX.Color4)"/> method.	
 /// </remarks>	
 /// <param name="clientDrawingContext">The application-defined drawing context passed to  <see cref="SharpDX.DirectWrite.TextLayout.Draw_"/>.</param>
 /// <param name="baselineOriginX">The pixel location (X-coordinate) at the baseline origin of the glyph run.</param>
 /// <param name="baselineOriginY">The pixel location (Y-coordinate) at the baseline origin of the glyph run.</param>
 /// <param name="measuringMode"> The measuring method for glyphs in the run, used with the other properties to determine the rendering mode.</param>
 /// <param name="glyphRun">Pointer to the glyph run instance to render. </param>
 /// <param name="glyphRunDescription">A pointer to the optional glyph run description instance which contains properties of the characters  associated with this run.</param>
 /// <param name="clientDrawingEffect">Application-defined drawing effects for the glyphs to render. Usually this argument represents effects such as the foreground brush filling the interior of text.</param>
 /// <returns>If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
 /// <unmanaged>HRESULT DrawGlyphRun([None] void* clientDrawingContext,[None] FLOAT baselineOriginX,[None] FLOAT baselineOriginY,[None] DWRITE_MEASURING_MODE measuringMode,[In] const DWRITE_GLYPH_RUN* glyphRun,[In] const DWRITE_GLYPH_RUN_DESCRIPTION* glyphRunDescription,[None] IUnknown* clientDrawingEffect)</unmanaged>
 public virtual Result DrawGlyphRun(object clientDrawingContext, float baselineOriginX, float baselineOriginY, MeasuringMode measuringMode, GlyphRun glyphRun, GlyphRunDescription glyphRunDescription, ComObject clientDrawingEffect)
 {
     return Result.NotImplemented;
 }
Пример #11
0
 /// <summary>
 ///  IDWriteTextLayout::Draw calls this function to instruct the client to render a run of glyphs.
 /// </summary>
 /// <remarks>
 /// The <see cref="SharpDX.DirectWrite.TextLayout.Draw_"/> function calls this callback function with all the information about glyphs to render. The application implements this callback by mostly delegating the call to the underlying platform's graphics API such as {{Direct2D}} to draw glyphs on the drawing context. An application that uses GDI can implement this callback in terms of the <see cref="BitmapRenderTarget.DrawGlyphRun(float,float,MeasuringMode,SharpDX.DirectWrite.GlyphRun,SharpDX.DirectWrite.RenderingParams,RawColor4)"/> method.
 /// </remarks>
 /// <param name="clientDrawingContext">The application-defined drawing context passed to  <see cref="SharpDX.DirectWrite.TextLayout.Draw_"/>.</param>
 /// <param name="baselineOriginX">The pixel location (X-coordinate) at the baseline origin of the glyph run.</param>
 /// <param name="baselineOriginY">The pixel location (Y-coordinate) at the baseline origin of the glyph run.</param>
 /// <param name="measuringMode"> The measuring method for glyphs in the run, used with the other properties to determine the rendering mode.</param>
 /// <param name="glyphRun">Pointer to the glyph run instance to render. </param>
 /// <param name="glyphRunDescription">A pointer to the optional glyph run description instance which contains properties of the characters  associated with this run.</param>
 /// <param name="clientDrawingEffect">Application-defined drawing effects for the glyphs to render. Usually this argument represents effects such as the foreground brush filling the interior of text.</param>
 /// <returns>If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
 /// <unmanaged>HRESULT DrawGlyphRun([None] void* clientDrawingContext,[None] FLOAT baselineOriginX,[None] FLOAT baselineOriginY,[None] DWRITE_MEASURING_MODE measuringMode,[In] const DWRITE_GLYPH_RUN* glyphRun,[In] const DWRITE_GLYPH_RUN_DESCRIPTION* glyphRunDescription,[None] IUnknown* clientDrawingEffect)</unmanaged>
 public virtual Result DrawGlyphRun(object clientDrawingContext, float baselineOriginX, float baselineOriginY, MeasuringMode measuringMode, GlyphRun glyphRun, GlyphRunDescription glyphRunDescription, ComObject clientDrawingEffect)
 {
     return(Result.NotImplemented);
 }
Пример #12
0
        public override Result DrawGlyphRun(object clientDrawingContext, float baselineOriginX, float baselineOriginY,
                                            D2D1.MeasuringMode measuringMode, DW.GlyphRun glyphRun, DW.GlyphRunDescription glyphRunDescription,
                                            ComObject clientDrawingEffect)
        {
            using (var pathGeometry = new D2D1.PathGeometry(_renderTarget.Factory))
            {
                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
                };

                var sw = _renderTarget.StrokeWidth;
                using (var transformedGeometry =
                           new D2D1.TransformedGeometry(_renderTarget.Factory, pathGeometry, matrix))
                {
                    _renderTarget.StrokeWidth = _strokeWidth;
                    _renderTarget.DrawGeometry(transformedGeometry, _strokeBrush);
                    _renderTarget.FillGeometry(transformedGeometry, _fillBrush);
                }
                _renderTarget.StrokeWidth = sw;
            }

            return(SharpDX.Result.Ok);
        }
Пример #13
0
 public override Result DrawGlyphRun(object clientDrawingContext, float baselineOriginX, float baselineOriginY, MeasuringMode measuringMode, DW.GlyphRun glyphRun, DW.GlyphRunDescription glyphRunDescription, ComObject clientDrawingEffect)
 {
     try {
         TextBrush textBrush = _textBrush;
         if (clientDrawingEffect != null && clientDrawingEffect is TextBrush)
         {
             textBrush = (TextBrush)clientDrawingEffect;
         }
         using (textBrush) {
             _renderTarget.DrawGlyphRun(new Vector2(baselineOriginX - 1, baselineOriginY - 1), glyphRun, textBrush.BGBrush, measuringMode);
             _renderTarget.DrawGlyphRun(new Vector2(baselineOriginX + 1, baselineOriginY + 1), glyphRun, textBrush.BGBrush, measuringMode);
             _renderTarget.DrawGlyphRun(new Vector2(baselineOriginX, baselineOriginY), glyphRun, textBrush.FGBrush, measuringMode);
         }
         return(Result.Ok);
     } catch {
         return(Result.Fail);
     }
 }