Пример #1
0
        public static void DrawGlyphRun(this DrawingContext drawingContext, Brush foreground, GlyphRun glyphRun,
            Point position, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment)
        {
            var boundingBox = glyphRun.ComputeInkBoundingBox();

            switch (horizontalAlignment)
            {
                case HorizontalAlignment.Center:
                    position.X -= boundingBox.Width / 2d;
                    break;
                case HorizontalAlignment.Right:
                    position.X -= boundingBox.Width;
                    break;
                default:
                    break;
            }

            switch (verticalAlignment)
            {
                case VerticalAlignment.Center:
                    position.Y -= boundingBox.Height / 2d;
                    break;
                case VerticalAlignment.Bottom:
                    position.Y -= boundingBox.Height;
                    break;
                default:
                    break;
            }

            drawingContext.PushTransform(new TranslateTransform(position.X - boundingBox.X, position.Y - boundingBox.Y));
            drawingContext.DrawGlyphRun(foreground, glyphRun);
            drawingContext.Pop();
        }
        /// <summary>
        /// Draw a GlyphRun.
        /// </summary>
        /// <param name="foregroundBrush">Foreground brush to draw GlyphRun with. </param>
        /// <param name="glyphRun"> The GlyphRun to draw. </param>
        public override void DrawGlyphRun(Brush foregroundBrush, GlyphRun glyphRun)
        {
            if ((foregroundBrush != null) && (glyphRun != null))
            {
                // The InkBoundingBox + the Origin produce the true InkBoundingBox.
                Rect rectangle = glyphRun.ComputeInkBoundingBox();

                if (!rectangle.IsEmpty)
                {
                    rectangle.Offset((Vector)glyphRun.BaselineOrigin);
                    AddBounds(ref rectangle);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Draw a GlyphRun.
        /// </summary>
        /// <param name="foregroundBrush">Foreground brush to draw GlyphRun with. </param>
        /// <param name="glyphRun"> The GlyphRun to draw. </param>
        /// <exception cref="ObjectDisposedException">
        /// This call is illegal if this object has already been closed or disposed.
        /// </exception>
        public override void DrawGlyphRun(Brush foregroundBrush, GlyphRun glyphRun)
        {
            if (glyphRun != null)
            {
                // The InkBoundingBox + the Origin produce the true InkBoundingBox.
                Rect rectangle = glyphRun.ComputeInkBoundingBox();

                if (!rectangle.IsEmpty)
                {
                    rectangle.Offset((Vector)glyphRun.BaselineOrigin);
                    DrawGeometry(Brushes.Black, null /* pen */, new RectangleGeometry(rectangle));
                }
            }
        }
        /// <summary>
        /// Draw a GlyphRun.
        /// </summary>
        /// <param name="foregroundBrush">Foreground brush to draw GlyphRun with. </param>
        /// <param name="glyphRun"> The GlyphRun to draw. </param>
        /// <exception cref="ObjectDisposedException">
        /// This call is illegal if this object has already been closed or disposed.
        /// </exception>
        public override void DrawGlyphRun(Brush foregroundBrush, GlyphRun glyphRun)
        {
            if (!IsCurrentLayerNoOp && (glyphRun != null))
            {
                // The InkBoundingBox + the Origin produce the true InkBoundingBox.
                Rect rectangle = glyphRun.ComputeInkBoundingBox();

                if (!rectangle.IsEmpty)
                {
                    rectangle.Offset((Vector)glyphRun.BaselineOrigin);

                    _contains |= rectangle.Contains(_point);

                    // If we've hit, stop walking.
                    if (_contains)
                    {
                        StopWalking();
                    }
                }
            }
        }
        /// <summary>
        /// Draw a GlyphRun. 
        /// </summary> 
        /// <param name="foregroundBrush">Foreground brush to draw GlyphRun with. </param>
        /// <param name="glyphRun"> The GlyphRun to draw. </param> 
        /// <exception cref="ObjectDisposedException">
        /// This call is illegal if this object has already been closed or disposed.
        /// </exception>
        public override void DrawGlyphRun(Brush foregroundBrush, GlyphRun glyphRun) 
        {
            if (glyphRun != null) 
            { 
                // The InkBoundingBox + the Origin produce the true InkBoundingBox.
                Rect rectangle = glyphRun.ComputeInkBoundingBox(); 

                if (!rectangle.IsEmpty)
                {
                    rectangle.Offset((Vector)glyphRun.BaselineOrigin); 
                    DrawGeometry(Brushes.Black, null /* pen */, new RectangleGeometry(rectangle));
                } 
            } 
        }
        /// <summary>
        /// Draw a GlyphRun.
        /// </summary>
        /// <param name="foregroundBrush">Foreground brush to draw GlyphRun with. </param>
        /// <param name="glyphRun"> The GlyphRun to draw. </param>
        /// <exception cref="ObjectDisposedException">
        /// This call is illegal if this object has already been closed or disposed.
        /// </exception>
        public override void DrawGlyphRun(Brush foregroundBrush, GlyphRun glyphRun)
        {
            if (!IsCurrentLayerNoOp && (glyphRun != null))
            {
                // The InkBoundingBox + the Origin produce the true InkBoundingBox.
                Rect rectangle = glyphRun.ComputeInkBoundingBox();

                if (!rectangle.IsEmpty)
                {
                    rectangle.Offset((Vector)glyphRun.BaselineOrigin);

                    _contains |= rectangle.Contains(_point);

                    // If we've hit, stop walking.
                    if (_contains)
                    {
                        StopWalking();
                    }
                }
            }
        }
Пример #7
0
        /// <summary> 
        /// Draw glyphrun
        /// </summary>
        /// <param name="drawingContext">The drawing context to draw into </param>
        /// <param name="foregroundBrush"> 
        /// The foreground brush of the glyphrun. Pass in "null" to draw the
        /// glyph run with the foreground in TextRunProperties. 
        /// </param> 
        /// <param name="glyphRun">The GlyphRun to be drawn </param>
        /// <returns>bounding rectangle of drawn glyphrun</returns> 
        /// <Remarks>
        /// TextEffect drawing code may use a different foreground brush for the text.
        /// </Remarks>
        internal Rect DrawGlyphRun( 
            DrawingContext  drawingContext,
            Brush           foregroundBrush, 
            GlyphRun        glyphRun 
            )
        { 
            Debug.Assert(_shapeable != null);

            Rect inkBoundingBox = glyphRun.ComputeInkBoundingBox();
 
            if (!inkBoundingBox.IsEmpty)
            { 
                // glyph run's ink bounding box is relative to its origin 
                inkBoundingBox.X += glyphRun.BaselineOrigin.X;
                inkBoundingBox.Y += glyphRun.BaselineOrigin.Y; 
            }

            if (drawingContext != null)
            { 
                int pushCount = 0;              // the number of push we do
                try 
                { 
                    if (_textEffects != null)
                    { 
                        // we need to push in the same order as they are set
                        for (int i = 0; i < _textEffects.Count; i++)
                        {
                            // get the text effect by its index 
                            TextEffect textEffect = _textEffects[i];
 
                            if (textEffect.Transform != null && textEffect.Transform != Transform.Identity) 
                            {
                                drawingContext.PushTransform(textEffect.Transform); 
                                pushCount++;
                            }

                            if (textEffect.Clip != null) 
                            {
                                drawingContext.PushClip(textEffect.Clip); 
                                pushCount++; 
                            }
 
                            if (textEffect.Foreground != null)
                            {
                                // remember the out-most non-null brush
                                // this brush will be used to draw the glyph run 
                                foregroundBrush = textEffect.Foreground;
                            } 
                        } 
                    }
 
                    _shapeable.Draw(drawingContext, foregroundBrush, glyphRun);
                }
                finally
                { 
                    for (int i = 0; i < pushCount; i++)
                    { 
                        drawingContext.Pop(); 
                    }
                } 
            }

            return inkBoundingBox;
        } 
        /// <summary>
        /// Draw a GlyphRun. 
        /// </summary> 
        /// <param name="foregroundBrush">Foreground brush to draw GlyphRun with. </param>
        /// <param name="glyphRun"> The GlyphRun to draw. </param> 
        public override void DrawGlyphRun(Brush foregroundBrush, GlyphRun glyphRun)
        {
            if ((foregroundBrush != null) && (glyphRun != null))
            { 
                // The InkBoundingBox + the Origin produce the true InkBoundingBox.
                Rect rectangle = glyphRun.ComputeInkBoundingBox(); 
 
                if (!rectangle.IsEmpty)
                { 
                    rectangle.Offset((Vector)glyphRun.BaselineOrigin);
                    AddBounds(ref rectangle);
                }
            } 
        }