Exemplo n.º 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 Vector2(baselineOriginX, baselineOriginY),
                glyphRun,
                brush,
                measuringMode);

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

            return(Result.Ok);
        }
Exemplo n.º 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;
        }
Exemplo n.º 3
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;
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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;
                    }
                }
            }
Exemplo n.º 6
0
        /// <summary>
        /// Initialize a new HMC5883L device connected through I2C
        /// </summary>
        /// <param name="sensor">I2C Device, like UnixI2cDevice or Windows10I2cDevice</param>
        /// <param name="gain">Gain Setting</param>
        /// <param name="measuringMode">The Mode of Measuring</param>
        /// <param name="outputRate">Typical Data Output Rate (Hz)</param>
        public Hmc5883l(I2cDevice sensor, Gain gain = Gain.Gain1090, MeasuringMode measuringMode = MeasuringMode.Continuous, OutputRate outputRate = OutputRate.Rate15)
        {
            _sensor        = sensor;
            _gain          = (byte)gain;
            _measuringMode = (byte)measuringMode;
            _outputRate    = (byte)outputRate;

            Initialize();
        }
 public CanvasGlyphRun(Vector2 baselineOrigin, GlyphRun glyphRun, GlyphRunDescription glyphRunDescription,
                       Brush foregroundBrush, MeasuringMode measuringMode)
 {
     BaselineOrigin      = baselineOrigin;
     GlyphRun            = glyphRun;
     GlyphRunDescription = glyphRunDescription;
     ForegroundBrush     = foregroundBrush;
     MeasuringMode       = measuringMode;
 }
Exemplo n.º 8
0
 public CanvasText(string text, TextFormat textFormat, RectangleF layoutRect, Brush defaultForegroundBrush,
                   DrawTextOptions options, MeasuringMode measuringMode)
 {
     Text                   = text;
     TextFormat             = textFormat;
     LayoutRect             = layoutRect;
     DefaultForegroundBrush = defaultForegroundBrush;
     Options                = options;
     MeasuringMode          = measuringMode;
 }
Exemplo n.º 9
0
        /// <summary>
        /// Initialize a new HMC5883L device connected through I2C
        /// </summary>
        /// <param name="sensor">I2C Device, like UnixI2cDevice or Windows10I2cDevice</param>
        /// <param name="gain">Gain Setting</param>
        /// <param name="measuringMode">The Mode of Measuring</param>
        /// <param name="outputRate">Typical Data Output Rate (Hz)</param>
        /// <param name="samplesAmount">Number of samples averaged per measurement output</param>
        /// <param name="measurementConfig">Measurement configuration</param>
        public Hmc5883l(
            I2cDevice sensor,
            Gain gain = Gain.Gain1090,
            MeasuringMode measuringMode = MeasuringMode.Continuous,
            OutputRate outputRate       = OutputRate.Rate15,
            SamplesAmount samplesAmount = SamplesAmount.One,
            MeasurementConfiguration measurementConfig = MeasurementConfiguration.Normal)
        {
            _sensor            = sensor;
            _gain              = (byte)gain;
            _measuringMode     = (byte)measuringMode;
            _outputRate        = (byte)outputRate;
            _samplesAmount     = (byte)samplesAmount;
            _measurementConfig = (byte)measurementConfig;

            Initialize();
        }
        public override Result DrawGlyphRun(
            object clientDrawingContext,
            float baselineOriginX,
            float baselineOriginY,
            MeasuringMode measuringMode,
            GlyphRun glyphRun,
            GlyphRunDescription glyphRunDescription,
            ComObject clientDrawingEffect)
        {
            var brush = clientDrawingEffect as Brush ?? _defaultBrush;

            if (brush == null)
            {
                throw new NullReferenceException("No brush is set as a drawing effect for this glyph run and no default brush was given.");
            }

            var             textBrush       = brush as TextBrush;
            SolidColorBrush backgroundBrush = textBrush?.Background;

            if (backgroundBrush != null)
            {
                // Get width of text
                float totalWidth = 0;

                foreach (float advance in glyphRun.Advances)
                {
                    totalWidth += advance;
                }

                // Get height of text
                var fontMetrics = glyphRun.FontFace.Metrics;
                var adjust      = glyphRun.FontSize / fontMetrics.DesignUnitsPerEm;
                var ascent      = adjust * fontMetrics.Ascent;
                var descent     = adjust * fontMetrics.Descent;
                var rect        = new RawRectangleF(baselineOriginX,
                                                    baselineOriginY - ascent,
                                                    baselineOriginX + totalWidth,
                                                    baselineOriginY + descent);

                // Fill Rectangle
                _renderTarget.FillRectangle(rect, backgroundBrush);
            }

            _renderTarget.DrawGlyphRun(new Vector2(baselineOriginX, baselineOriginY), glyphRun, brush, measuringMode);
            return(Result.Ok);
        }
Exemplo n.º 11
0
        public Qmc5883(II2cBus i2cBus, byte address = 0x0D,
                       Gain gain = Gain.Gain1090,
                       MeasuringMode measuringMode = MeasuringMode.Continuous,
                       OutputRate outputRate       = OutputRate.Rate15,
                       SamplesAmount samplesAmount = SamplesAmount.One,
                       MeasurementConfiguration measurementConfig = MeasurementConfiguration.Normal)
        {
            i2cPeripheral = new I2cPeripheral(i2cBus, address);

            base.gain              = (byte)gain;
            base.measuringMode     = (byte)measuringMode;
            base.outputRate        = (byte)outputRate;
            sampleAmount           = (byte)samplesAmount;
            base.measurementConfig = (byte)measurementConfig;

            Initialize();
        }
Exemplo n.º 12
0
        /// <summary>
        /// Initialize a new HMC5883L device connected through I2C
        /// </summary>
        /// <param name="i2cDevice">The I2C device used for communication.</param>
        /// <param name="gain">Gain Setting</param>
        /// <param name="measuringMode">The Mode of Measuring</param>
        /// <param name="outputRate">Typical Data Output Rate (Hz)</param>
        /// <param name="samplesAmount">Number of samples averaged per measurement output</param>
        /// <param name="measurementConfig">Measurement configuration</param>
        public Hmc5883l(
            I2cDevice i2cDevice,
            Gain gain = Gain.Gain1090,
            MeasuringMode measuringMode = MeasuringMode.Continuous,
            OutputRate outputRate       = OutputRate.Rate15,
            SamplesAmount samplesAmount = SamplesAmount.One,
            MeasurementConfiguration measurementConfig = MeasurementConfiguration.Normal)
        {
            _i2cDevice         = i2cDevice ?? throw new ArgumentNullException(nameof(i2cDevice));
            _gain              = (byte)gain;
            _measuringMode     = (byte)measuringMode;
            _outputRate        = (byte)outputRate;
            _samplesAmount     = (byte)samplesAmount;
            _measurementConfig = (byte)measurementConfig;

            Initialize();
        }
Exemplo n.º 13
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;
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Draws the given text on the screen.
        /// </summary>
        /// <param name="textToDraw">The text to draw.</param>
        /// <param name="textFormat">The TextFormat to be used.</param>
        /// <param name="targetRectangle">The target rectangle.</param>
        /// <param name="brush">The brush.</param>
        /// <param name="drawOptions">Some draw options to be passed to Direct2D.</param>
        /// <param name="measuringMode">Sets the measuring mode to be passed to Direct2D.</param>
        public void DrawText(
            string textToDraw, TextFormatResource textFormat, RectangleF targetRectangle, BrushResource brush,
            DrawTextOptions drawOptions = DrawTextOptions.None,
            MeasuringMode measuringMode = MeasuringMode.Natural)
        {
            if (_renderTarget == null)
            {
                return;
            }

            textToDraw.EnsureNotNull(nameof(textToDraw));
            targetRectangle.EnsureNotEmpty(nameof(targetRectangle));
            brush.EnsureNotNull(nameof(brush));

            _renderTarget.DrawText(
                textToDraw,
                textFormat.GetTextFormat(this.Device),
                targetRectangle,
                brush.GetBrush(this.Device),
                (D2D.DrawTextOptions)drawOptions, (Vortice.DCommon.MeasuringMode)measuringMode);
        }
Exemplo n.º 15
0
        public Qmc5883(string i2cBus, byte address = 0x0D,
                       Gain gain = Gain.Gain1090,
                       MeasuringMode measuringMode = MeasuringMode.Continuous,
                       OutputRate outputRate       = OutputRate.Rate15,
                       SamplesAmount samplesAmount = SamplesAmount.One,
                       MeasurementConfiguration measurementConfig = MeasurementConfiguration.Normal)
        {
            var settings   = new I2cConnectionSettings(address, 100_000); //The slave's address and the bus speed.
            var controller = I2cController.FromName(i2cBus);

            i2cPeripheral = controller.GetDevice(settings);
            //i2cPeripheral = new I2cPeripheral(i2cBus, address);

            base.gain              = (byte)gain;
            base.measuringMode     = (byte)measuringMode;
            base.outputRate        = (byte)outputRate;
            sampleAmount           = (byte)samplesAmount;
            base.measurementConfig = (byte)measurementConfig;

            Initialize();
        }
Exemplo n.º 16
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;
        }
Exemplo n.º 17
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);
        }
    internal unsafe void __MarshalFrom(ref __Native @ref)
    {
        GlyphRun = new GlyphRun();
        GlyphRun.__MarshalFrom(ref @ref.GlyphRun);

        if (@ref.GlyphRunDescription == null)
        {
            GlyphRunDescription = null;
        }
        else
        {
            GlyphRunDescription = new GlyphRunDescription();
            GlyphRunDescription.__MarshalFrom(ref *@ref.GlyphRunDescription);
        }

        BaselineOriginX  = @ref.BaselineOriginX;
        BaselineOriginY  = @ref.BaselineOriginY;
        RunColor         = @ref.RunColor;
        PaletteIndex     = @ref.PaletteIndex;
        GlyphImageFormat = @ref.GlyphImageFormat;
        MeasuringMode    = @ref.MeasuringMode;
    }
Exemplo n.º 19
0
        /// <summary>
        /// Draws the given text on the screen.
        /// </summary>
        /// <param name="textToDraw">The text to draw.</param>
        /// <param name="textFormat">The TextFormat to be used.</param>
        /// <param name="targetRectangle">The target rectangle.</param>
        /// <param name="brush">The brush.</param>
        /// <param name="drawOptions">Some draw options to be passed to Direct2D.</param>
        /// <param name="measuringMode">Sets the measuring mode to be passed to Direct2D.</param>
        public void DrawText(
            string textToDraw, TextFormatResource textFormat, RectangleF targetRectangle, BrushResource brush,
            DrawTextOptions drawOptions = DrawTextOptions.None,
            MeasuringMode measuringMode = MeasuringMode.Natural)
        {
            if (m_renderTarget == null)
            {
                return;
            }

            textToDraw.EnsureNotNull(nameof(textToDraw));
            targetRectangle.EnsureNotEmpty(nameof(targetRectangle));
            brush.EnsureNotNull(nameof(brush));

            D2D.DrawTextOptions drawOptionsD2D   = (D2D.DrawTextOptions)drawOptions;
            D2D.MeasuringMode   measuringModeD2D = (D2D.MeasuringMode)measuringMode;

            m_renderTarget.DrawText(
                textToDraw,
                textFormat.GetTextFormat(m_device),
                targetRectangle.ToDXRectangle(),
                brush.GetBrush(m_device),
                drawOptionsD2D);
        }
Exemplo n.º 20
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;
            }
        }
Exemplo n.º 21
0
 /// <summary>	
 /// Draws a run of glyphs to a bitmap target at the specified position.	
 /// </summary>	
 /// <remarks>	
 /// You can use the IDWriteBitmapRenderTarget::DrawGlyphRun to render to a bitmap from a custom text renderer that you implement.  The custom text renderer should call this method from within the <see cref="M:SharpDX.DirectWrite.TextRenderer.DrawGlyphRun(System.IntPtr,System.Single,System.Single,SharpDX.DirectWrite.MeasuringMode,SharpDX.DirectWrite.GlyphRun,SharpDX.DirectWrite.GlyphRunDescription,SharpDX.ComObject)" /> callback method as shown in the following code. 	
 /// <code> STDMETHODIMP GdiTextRenderer::DrawGlyphRun( __maybenull void* clientDrawingContext, FLOAT baselineOriginX, FLOAT baselineOriginY, DWRITE_MEASURING_MODE measuringMode, __in DWRITE_GLYPH_RUN const* glyphRun, __in DWRITE_GLYPH_RUN_DESCRIPTION const* glyphRunDescription, IUnknown* clientDrawingEffect )	
 /// { HRESULT hr = S_OK; // Pass on the drawing call to the render target to do the real work. RECT dirtyRect = {0}; hr = pRenderTarget_-&gt;DrawGlyphRun( baselineOriginX, baselineOriginY, measuringMode, glyphRun, pRenderingParams_, RGB(0,200,255), &amp;dirtyRect ); return hr;	
 /// } </code>	
 /// 
 /// The baselineOriginX, baslineOriginY, measuringMethod, and glyphRun parameters are provided (as arguments) when the callback method is invoked.  The renderingParams, textColor and blackBoxRect are not. Default rendering params can be retrieved by using the <see cref="M:SharpDX.DirectWrite.Factory.CreateMonitorRenderingParams(System.IntPtr,SharpDX.DirectWrite.RenderingParams@)" /> method.  	
 /// </remarks>	
 /// <param name="baselineOriginX">The horizontal position of the baseline origin, in DIPs, relative to the upper-left corner of the DIB. </param>
 /// <param name="baselineOriginY">The vertical position of the baseline origin, in DIPs, relative to the upper-left corner of the DIB. </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">The structure containing the properties of the glyph run. </param>
 /// <param name="renderingParams">The object that controls rendering behavior. </param>
 /// <param name="textColor">The foreground color of the text. </param>
 /// <returns>If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. </returns>
 /// <unmanaged>HRESULT IDWriteBitmapRenderTarget::DrawGlyphRun([None] float baselineOriginX,[None] float baselineOriginY,[None] DWRITE_MEASURING_MODE measuringMode,[In] const DWRITE_GLYPH_RUN* glyphRun,[None] IDWriteRenderingParams* renderingParams,[None] COLORREF textColor,[Out, Optional] RECT* blackBoxRect)</unmanaged>
 public void DrawGlyphRun(float baselineOriginX, float baselineOriginY, MeasuringMode measuringMode, GlyphRun glyphRun, RenderingParams renderingParams, RawColor4 textColor)
 {
     RawRectangle temp;
     DrawGlyphRun(baselineOriginX, baselineOriginY, measuringMode, glyphRun, renderingParams, textColor, out temp);
 }
Exemplo n.º 22
0
        public void DrawText(string text, IDWriteTextFormat textFormat, Rect layoutRect, ID2D1Brush defaultFillBrush, DrawTextOptions options = DrawTextOptions.None, MeasuringMode measuringMode = MeasuringMode.Natural)
        {
            Guard.NotNullOrEmpty(text, nameof(text));

            DrawText(text, text.Length, textFormat, layoutRect, defaultFillBrush, options, measuringMode);
        }
Exemplo n.º 23
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);
        }
Exemplo n.º 24
0
 /// <summary>
 /// Creates a glyph run analysis object, which encapsulates information used to render a glyph run.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="glyphRun">A structure that contains the properties of the glyph run (font face, advances, and so on).</param>
 /// <param name="pixelsPerDip">Number of physical pixels per DIP (device independent pixel). For example, if rendering onto a 96 DPI bitmap then pixelsPerDip is 1. If rendering onto a 120 DPI bitmap then pixelsPerDip is 1.25.</param>
 /// <param name="transform">Optional transform applied to the glyphs and their positions. This transform is applied after the scaling specified the emSize and pixelsPerDip.</param>
 /// <param name="renderingMode">A value that specifies the rendering mode, which must be one of the raster rendering modes (that is, not default and not outline).</param>
 /// <param name="measuringMode">Specifies the measuring mode to use with glyphs.</param>
 /// <param name="baselineOriginX">The horizontal position (X-coordinate) of the baseline origin, in DIPs.</param>
 /// <param name="baselineOriginY">Vertical position (Y-coordinate) of the baseline origin, in DIPs.</param>
 /// <remarks>
 /// The glyph run analysis object contains the results of analyzing the glyph run, including the positions of all the glyphs and references to all of the rasterized glyphs in the font cache.
 /// </remarks>
 /// <unmanaged>HRESULT IDWriteFactory::CreateGlyphRunAnalysis([In] const DWRITE_GLYPH_RUN* glyphRun,[None] float pixelsPerDip,[In, Optional] const DWRITE_MATRIX* transform,[None] DWRITE_RENDERING_MODE renderingMode,[None] DWRITE_MEASURING_MODE measuringMode,[None] float baselineOriginX,[None] float baselineOriginY,[Out] IDWriteGlyphRunAnalysis** glyphRunAnalysis)</unmanaged>
 public GlyphRunAnalysis(Factory factory, GlyphRun glyphRun, float pixelsPerDip, RawMatrix3x2?transform, RenderingMode renderingMode, MeasuringMode measuringMode, float baselineOriginX, float baselineOriginY)
 {
     factory.CreateGlyphRunAnalysis(glyphRun, pixelsPerDip, transform, renderingMode, measuringMode, baselineOriginX, baselineOriginY, this);
 }
Exemplo n.º 25
0
 public void DrawGlyphRun(IntPtr clientDrawingContext, float baselineOriginX, float baselineOriginY, GlyphOrientationAngle orientationAngle, MeasuringMode measuringMode, GlyphRun glyphRun, ref GlyphRunDescription glyphRunDescription, IUnknown clientDrawingEffect) => DrawGlyphRun_(clientDrawingContext, baselineOriginX, baselineOriginY, orientationAngle, measuringMode, glyphRun, ref glyphRunDescription, clientDrawingEffect);
Exemplo n.º 26
0
 public unsafe void DrawGlyphRun(
     IntPtr clientDrawingContext,
     float baselineOriginX,
     float baselineOriginY,
     MeasuringMode measuringMode,
     in GlyphRun glyphRun,
Exemplo 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);
            }
        }
Exemplo n.º 28
0
 /// <summary>
 /// Draws the specified text using the format information provided by an <see cref="T:SharpDX.DirectWrite.TextFormat" /> object.
 /// </summary>
 /// <remarks>
 /// To create an <see cref="T:SharpDX.DirectWrite.TextFormat" /> object, create an <see cref="T:SharpDX.DirectWrite.Factory" /> and call its {{CreateTextFormat}} method. This method doesn't return an error code if it fails. To determine whether a drawing operation (such as {{DrawText}}) failed, check the result returned by the <see cref="M:SharpDX.Direct2D1.RenderTarget.EndDraw(System.Int64@,System.Int64@)" /> or <see cref="M:SharpDX.Direct2D1.RenderTarget.Flush(System.Int64@,System.Int64@)" /> methods.
 /// </remarks>
 /// <param name="text">A reference to an array of Unicode characters to draw.  </param>
 /// <param name="textFormat">An object that describes formatting details of the text to draw, such as the font, the font size, and flow direction.   </param>
 /// <param name="layoutRect">The size and position of the area in which the text is drawn.  </param>
 /// <param name="defaultForegroundBrush">The brush used to paint the text. </param>
 /// <param name="options">A value that indicates whether the text should be snapped to pixel boundaries and whether the text should be clipped to the layout rectangle. The default value is <see cref="F:SharpDX.Direct2D1.DrawTextOptions.None" />, which indicates that text should be snapped to pixel boundaries and it should not be clipped to the layout rectangle. </param>
 /// <param name="measuringMode">A value that indicates how glyph metrics are used to measure text when it is formatted.  The default value is DWRITE_MEASURING_MODE_NATURAL.  </param>
 /// <unmanaged>void ID2D1RenderTarget::DrawTextA([In, Buffer] const wchar_t* string,[None] int stringLength,[In] IDWriteTextFormat* textFormat,[In] const D2D1_RECT_F* layoutRect,[In] ID2D1Brush* defaultForegroundBrush,[None] D2D1_DRAW_TEXT_OPTIONS options,[None] DWRITE_MEASURING_MODE measuringMode)</unmanaged>
 public void DrawText(string text, TextFormat textFormat, RawRectangleF layoutRect, Brush defaultForegroundBrush, DrawTextOptions options, MeasuringMode measuringMode)
 {
     DrawText(text, text.Length, textFormat, layoutRect, defaultForegroundBrush, options, measuringMode);
 }
Exemplo n.º 29
0
 /// <summary>
 /// Creates a glyph run analysis object, which encapsulates information used to render a glyph run.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="glyphRun">A structure that contains the properties of the glyph run (font face, advances, and so on).</param>
 /// <param name="pixelsPerDip">Number of physical pixels per DIP (device independent pixel). For example, if rendering onto a 96 DPI bitmap then pixelsPerDip is 1. If rendering onto a 120 DPI bitmap then pixelsPerDip is 1.25.</param>
 /// <param name="renderingMode">A value that specifies the rendering mode, which must be one of the raster rendering modes (that is, not default and not outline).</param>
 /// <param name="measuringMode">Specifies the measuring mode to use with glyphs.</param>
 /// <param name="baselineOriginX">The horizontal position (X-coordinate) of the baseline origin, in DIPs.</param>
 /// <param name="baselineOriginY">Vertical position (Y-coordinate) of the baseline origin, in DIPs.</param>
 /// <remarks>
 /// The glyph run analysis object contains the results of analyzing the glyph run, including the positions of all the glyphs and references to all of the rasterized glyphs in the font cache.
 /// </remarks>
 /// <unmanaged>HRESULT IDWriteFactory::CreateGlyphRunAnalysis([In] const DWRITE_GLYPH_RUN* glyphRun,[None] float pixelsPerDip,[In, Optional] const DWRITE_MATRIX* transform,[None] DWRITE_RENDERING_MODE renderingMode,[None] DWRITE_MEASURING_MODE measuringMode,[None] float baselineOriginX,[None] float baselineOriginY,[Out] IDWriteGlyphRunAnalysis** glyphRunAnalysis)</unmanaged>
 public GlyphRunAnalysis(Factory factory, GlyphRun glyphRun, float pixelsPerDip, RenderingMode renderingMode, MeasuringMode measuringMode, float baselineOriginX, float baselineOriginY)
     : this(factory, glyphRun, pixelsPerDip, null, renderingMode, measuringMode, baselineOriginX, baselineOriginY)
 {
 }
Exemplo n.º 30
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);
        }
            private static unsafe int DrawGlyphRunImpl(IntPtr thisObject, IntPtr clientDrawingContextPtr, float baselineOriginX, float baselineOriginY, MeasuringMode measuringMode, GlyphRun.__Native *glyphRunNative, GlyphRunDescription.__Native *glyphRunDescriptionNative, IntPtr clientDrawingEffectPtr)
            {
                try
                {
                    IDWriteTextRendererShadow shadow   = ToShadow <IDWriteTextRendererShadow>(thisObject);
                    IDWriteTextRenderer       callback = (IDWriteTextRenderer)shadow.Callback;

                    using (var glyphRun = new GlyphRun())
                    {
                        glyphRun.__MarshalFrom(ref *glyphRunNative);

                        var glyphRunDescription = new GlyphRunDescription();
                        glyphRunDescription.__MarshalFrom(ref *glyphRunDescriptionNative);

                        callback.DrawGlyphRun(clientDrawingContextPtr,
                                              baselineOriginX,
                                              baselineOriginY,
                                              measuringMode,
                                              glyphRun,
                                              ref glyphRunDescription,
                                              clientDrawingEffectPtr == IntPtr.Zero ? null : (IUnknown)Marshal.GetObjectForIUnknown(clientDrawingEffectPtr));
                    }
                    return(Result.Ok.Code);
                }
                catch (Exception ex)
                {
                    return(Result.GetResultFromException(ex).Code);
                }
            }
Exemplo n.º 32
0
 /// <summary>	
 /// Draws the specified text using the format information provided by an <see cref="T:SharpDX.DirectWrite.TextFormat" /> object. 	
 /// </summary>	
 /// <remarks>	
 /// To create an <see cref="T:SharpDX.DirectWrite.TextFormat" /> object, create an <see cref="T:SharpDX.DirectWrite.Factory" /> and call its {{CreateTextFormat}} method. This method doesn't return an error code if it fails. To determine whether a drawing operation (such as {{DrawText}}) failed, check the result returned by the <see cref="M:SharpDX.Direct2D1.RenderTarget.EndDraw(System.Int64@,System.Int64@)" /> or <see cref="M:SharpDX.Direct2D1.RenderTarget.Flush(System.Int64@,System.Int64@)" /> methods.  	
 /// </remarks>	
 /// <param name="text">A reference to an array of Unicode characters to draw.  </param>
 /// <param name="textFormat">An object that describes formatting details of the text to draw, such as the font, the font size, and flow direction.   </param>
 /// <param name="layoutRect">The size and position of the area in which the text is drawn.  </param>
 /// <param name="defaultForegroundBrush">The brush used to paint the text. </param>
 /// <param name="options">A value that indicates whether the text should be snapped to pixel boundaries and whether the text should be clipped to the layout rectangle. The default value is <see cref="F:SharpDX.Direct2D1.DrawTextOptions.None" />, which indicates that text should be snapped to pixel boundaries and it should not be clipped to the layout rectangle. </param>
 /// <param name="measuringMode">A value that indicates how glyph metrics are used to measure text when it is formatted.  The default value is DWRITE_MEASURING_MODE_NATURAL.  </param>
 /// <unmanaged>void ID2D1RenderTarget::DrawTextA([In, Buffer] const wchar_t* string,[None] int stringLength,[In] IDWriteTextFormat* textFormat,[In] const D2D1_RECT_F* layoutRect,[In] ID2D1Brush* defaultForegroundBrush,[None] D2D1_DRAW_TEXT_OPTIONS options,[None] DWRITE_MEASURING_MODE measuringMode)</unmanaged>
 public void DrawText(string text, TextFormat textFormat, RawRectangleF layoutRect, Brush defaultForegroundBrush, DrawTextOptions options, MeasuringMode measuringMode)
 {
     DrawText(text, text.Length, textFormat, layoutRect, defaultForegroundBrush, options, measuringMode);
 }
Exemplo n.º 33
0
 /// <summary>
 /// Creates a glyph run analysis object, which encapsulates information used to render a glyph run.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="glyphRun">A structure that contains the properties of the glyph run (font face, advances, and so on).</param>
 /// <param name="pixelsPerDip">Number of physical pixels per DIP (device independent pixel). For example, if rendering onto a 96 DPI bitmap then pixelsPerDip is 1. If rendering onto a 120 DPI bitmap then pixelsPerDip is 1.25.</param>
 /// <param name="transform">Optional transform applied to the glyphs and their positions. This transform is applied after the scaling specified the emSize and pixelsPerDip.</param>
 /// <param name="renderingMode">A value that specifies the rendering mode, which must be one of the raster rendering modes (that is, not default and not outline).</param>
 /// <param name="measuringMode">Specifies the measuring mode to use with glyphs.</param>
 /// <param name="baselineOriginX">The horizontal position (X-coordinate) of the baseline origin, in DIPs.</param>
 /// <param name="baselineOriginY">Vertical position (Y-coordinate) of the baseline origin, in DIPs.</param>
 /// <remarks>
 /// The glyph run analysis object contains the results of analyzing the glyph run, including the positions of all the glyphs and references to all of the rasterized glyphs in the font cache.
 /// </remarks>
 /// <unmanaged>HRESULT IDWriteFactory::CreateGlyphRunAnalysis([In] const DWRITE_GLYPH_RUN* glyphRun,[None] float pixelsPerDip,[In, Optional] const DWRITE_MATRIX* transform,[None] DWRITE_RENDERING_MODE renderingMode,[None] DWRITE_MEASURING_MODE measuringMode,[None] float baselineOriginX,[None] float baselineOriginY,[Out] IDWriteGlyphRunAnalysis** glyphRunAnalysis)</unmanaged>
 public GlyphRunAnalysis(Factory factory, GlyphRun glyphRun, float pixelsPerDip, RawMatrix3x2? transform, RenderingMode renderingMode, MeasuringMode measuringMode, float baselineOriginX, float baselineOriginY)
 {
     factory.CreateGlyphRunAnalysis(glyphRun, pixelsPerDip, transform, renderingMode, measuringMode, baselineOriginX, baselineOriginY, this);
 }
Exemplo n.º 34
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);
        }
Exemplo n.º 35
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);
 }
Exemplo n.º 36
0
 /// <summary>
 /// Creates a glyph run analysis object, which encapsulates information used to render a glyph run.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="glyphRun">A structure that contains the properties of the glyph run (font face, advances, and so on).</param>
 /// <param name="pixelsPerDip">Number of physical pixels per DIP (device independent pixel). For example, if rendering onto a 96 DPI bitmap then pixelsPerDip is 1. If rendering onto a 120 DPI bitmap then pixelsPerDip is 1.25.</param>
 /// <param name="renderingMode">A value that specifies the rendering mode, which must be one of the raster rendering modes (that is, not default and not outline).</param>
 /// <param name="measuringMode">Specifies the measuring mode to use with glyphs.</param>
 /// <param name="baselineOriginX">The horizontal position (X-coordinate) of the baseline origin, in DIPs.</param>
 /// <param name="baselineOriginY">Vertical position (Y-coordinate) of the baseline origin, in DIPs.</param>
 /// <remarks>
 /// The glyph run analysis object contains the results of analyzing the glyph run, including the positions of all the glyphs and references to all of the rasterized glyphs in the font cache.
 /// </remarks>
 /// <unmanaged>HRESULT IDWriteFactory::CreateGlyphRunAnalysis([In] const DWRITE_GLYPH_RUN* glyphRun,[None] float pixelsPerDip,[In, Optional] const DWRITE_MATRIX* transform,[None] DWRITE_RENDERING_MODE renderingMode,[None] DWRITE_MEASURING_MODE measuringMode,[None] float baselineOriginX,[None] float baselineOriginY,[Out] IDWriteGlyphRunAnalysis** glyphRunAnalysis)</unmanaged>
 public GlyphRunAnalysis(Factory factory, GlyphRun glyphRun, float pixelsPerDip, RenderingMode renderingMode, MeasuringMode measuringMode, float baselineOriginX, float baselineOriginY)
     : this(factory, glyphRun, pixelsPerDip, null, renderingMode, measuringMode, baselineOriginX, baselineOriginY)
 {
 }
Exemplo n.º 37
0
 /// <unmanaged>HRESULT ID2D1CommandSink::DrawGlyphRun([In] D2D_POINT_2F baselineOrigin,[In] const DWRITE_GLYPH_RUN* glyphRun,[In, Optional] const DWRITE_GLYPH_RUN_DESCRIPTION* glyphRunDescription,[In] ID2D1Brush* foregroundBrush,[In] DWRITE_MEASURING_MODE measuringMode)</unmanaged>	
 public void DrawGlyphRun(RawVector2 baselineOrigin, DirectWrite.GlyphRun glyphRun, DirectWrite.GlyphRunDescription glyphRunDescription, Brush foregroundBrush, MeasuringMode measuringMode)
 {
     DrawGlyphRun_(baselineOrigin, glyphRun, glyphRunDescription, foregroundBrush, measuringMode);
 }
Exemplo n.º 38
0
        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());
        }
Exemplo n.º 39
0
        /// <summary>
        /// Draws a run of glyphs to a bitmap target at the specified position.
        /// </summary>
        /// <remarks>
        /// You can use the IDWriteBitmapRenderTarget::DrawGlyphRun to render to a bitmap from a custom text renderer that you implement.  The custom text renderer should call this method from within the <see cref="M:SharpDX.DirectWrite.TextRenderer.DrawGlyphRun(System.IntPtr,System.Single,System.Single,SharpDX.DirectWrite.MeasuringMode,SharpDX.DirectWrite.GlyphRun,SharpDX.DirectWrite.GlyphRunDescription,SharpDX.ComObject)" /> callback method as shown in the following code.
        /// <code> STDMETHODIMP GdiTextRenderer::DrawGlyphRun( __maybenull void* clientDrawingContext, FLOAT baselineOriginX, FLOAT baselineOriginY, DWRITE_MEASURING_MODE measuringMode, __in DWRITE_GLYPH_RUN const* glyphRun, __in DWRITE_GLYPH_RUN_DESCRIPTION const* glyphRunDescription, IUnknown* clientDrawingEffect )
        /// { HRESULT hr = S_OK; // Pass on the drawing call to the render target to do the real work. RECT dirtyRect = {0}; hr = pRenderTarget_-&gt;DrawGlyphRun( baselineOriginX, baselineOriginY, measuringMode, glyphRun, pRenderingParams_, RGB(0,200,255), &amp;dirtyRect ); return hr;
        /// } </code>
        ///
        /// The baselineOriginX, baslineOriginY, measuringMethod, and glyphRun parameters are provided (as arguments) when the callback method is invoked.  The renderingParams, textColor and blackBoxRect are not. Default rendering params can be retrieved by using the <see cref="M:SharpDX.DirectWrite.Factory.CreateMonitorRenderingParams(System.IntPtr,SharpDX.DirectWrite.RenderingParams@)" /> method.
        /// </remarks>
        /// <param name="baselineOriginX">The horizontal position of the baseline origin, in DIPs, relative to the upper-left corner of the DIB. </param>
        /// <param name="baselineOriginY">The vertical position of the baseline origin, in DIPs, relative to the upper-left corner of the DIB. </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">The structure containing the properties of the glyph run. </param>
        /// <param name="renderingParams">The object that controls rendering behavior. </param>
        /// <param name="textColor">The foreground color of the text. </param>
        /// <returns>If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. </returns>
        /// <unmanaged>HRESULT IDWriteBitmapRenderTarget::DrawGlyphRun([None] float baselineOriginX,[None] float baselineOriginY,[None] DWRITE_MEASURING_MODE measuringMode,[In] const DWRITE_GLYPH_RUN* glyphRun,[None] IDWriteRenderingParams* renderingParams,[None] COLORREF textColor,[Out, Optional] RECT* blackBoxRect)</unmanaged>
        public void DrawGlyphRun(float baselineOriginX, float baselineOriginY, MeasuringMode measuringMode, GlyphRun glyphRun, RenderingParams renderingParams, Color4 textColor)
        {
            Rectangle temp;

            DrawGlyphRun(baselineOriginX, baselineOriginY, measuringMode, glyphRun, renderingParams, textColor, out temp);
        }
Exemplo n.º 40
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());
            }
Exemplo n.º 41
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;
 }
 /// <summary>
 /// <see cref="IDWriteTextLayout.Draw(IntPtr, IDWriteTextRenderer, float, float)"/> calls this function to instruct the client to render a run of glyphs.
 /// </summary>
 /// <param name="clientDrawingContext">The drawing context passed to <see cref="IDWriteTextLayout.Draw(IntPtr, IDWriteTextRenderer, float, float)"/>.</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">The <see cref="GlyphRun"/> instance to render.</param>
 /// <param name="glyphRunDescription">The <see cref="GlyphRunDescription"/> 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>
 public virtual void DrawGlyphRun(IntPtr clientDrawingContext, float baselineOriginX, float baselineOriginY, MeasuringMode measuringMode, GlyphRun glyphRun, GlyphRunDescription glyphRunDescription, IUnknown clientDrawingEffect)
 {
 }