示例#1
0
        /// <summary>
        ///  Draws text using the specified client drawing context.
        /// </summary>
        /// <remarks>
        /// To draw text with this method, a textLayout object needs to be created by the application using <see cref="SharpDX.DirectWrite.Factory.CreateTextLayout"/>. After the textLayout object is obtained, the application calls the  IDWriteTextLayout::Draw method  to draw the text, decorations, and inline objects. The actual drawing is done through the callback interface passed in as the textRenderer argument; there, the corresponding DrawGlyphRun API is called.
        /// </remarks>
        /// <param name="clientDrawingContext">An application-defined drawing context. </param>
        /// <param name="renderer">Pointer to the set of callback functions used to draw parts of a text string.</param>
        /// <param name="originX">The x-coordinate of the layout's left side.</param>
        /// <param name="originY">The y-coordinate of the layout's top side.</param>
        /// <returns>If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
        /// <unmanaged>HRESULT Draw([None] void* clientDrawingContext,[None] IDWriteTextRenderer* renderer,[None] FLOAT originX,[None] FLOAT originY)</unmanaged>
        public void Draw(object clientDrawingContext, TextRenderer renderer, float originX, float originY)
        {
            var handle = GCHandle.Alloc(clientDrawingContext);

            try
            {
                this.Draw_(GCHandle.ToIntPtr(handle), TextRendererShadow.ToIntPtr(renderer), originX, originY);
            }
            finally
            {
                if (handle.IsAllocated)
                {
                    handle.Free();
                }
            }
        }
示例#2
0
        /// <summary>
        /// The application implemented rendering callback (<see cref="TextRenderer.DrawInlineObject"/>) can use this to draw the inline object without needing to cast or query the object type. The text layout does not call this method directly.
        /// </summary>
        /// <param name="clientDrawingContext">The drawing context passed to <see cref="SharpDX.DirectWrite.TextLayout.Draw_"/>.  This parameter may be NULL. </param>
        /// <param name="renderer">The same renderer passed to <see cref="SharpDX.DirectWrite.TextLayout.Draw_"/> as the object's containing parent.  This is useful if the inline object is recursive such as a nested layout. </param>
        /// <param name="originX">The x-coordinate at the upper-left corner of the inline object. </param>
        /// <param name="originY">The y-coordinate at the upper-left corner of the inline object. </param>
        /// <param name="isSideways">A Boolean flag that indicates whether the object's baseline runs alongside the baseline axis of the line. </param>
        /// <param name="isRightToLeft">A Boolean flag that indicates whether the object is in a right-to-left context and should be drawn flipped. </param>
        /// <param name="clientDrawingEffect">The drawing effect set in <see cref="SharpDX.DirectWrite.TextLayout.SetDrawingEffect"/>.  Usually this effect is a foreground brush that  is used in glyph drawing. </param>
        /// <returns>If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. </returns>
        /// <unmanaged>HRESULT IDWriteInlineObject::Draw([None] void* clientDrawingContext,[None] IDWriteTextRenderer* renderer,[None] float originX,[None] float originY,[None] BOOL isSideways,[None] BOOL isRightToLeft,[None] IUnknown* clientDrawingEffect)</unmanaged>
        public void Draw(object clientDrawingContext, TextRenderer renderer, float originX, float originY, bool isSideways, bool isRightToLeft, ComObject clientDrawingEffect)
        {
            var    handle = GCHandle.Alloc(clientDrawingContext);
            IntPtr clientDrawingEffectPtr = Utilities.GetIUnknownForObject(clientDrawingEffect);

            try
            {
                this.Draw__(GCHandle.ToIntPtr(handle), TextRendererShadow.ToIntPtr(renderer), originX, originY, isSideways, isRightToLeft,
                            clientDrawingEffectPtr);
            } finally
            {
                if (handle.IsAllocated)
                {
                    handle.Free();
                }
                if (clientDrawingEffectPtr != IntPtr.Zero)
                {
                    Marshal.Release(clientDrawingEffectPtr);
                }
            }
        }