Ejemplo n.º 1
0
        /// <summary>
        /// Draw glyph run to the drawing surface
        /// </summary>
        internal sealed override void Draw(
            DrawingContext drawingContext,
            Brush foregroundBrush,
            GlyphRun glyphRun
            )
        {
            if (drawingContext == null)
            {
                throw new ArgumentNullException("drawingContext");
            }

            glyphRun.EmitBackground(drawingContext, _properties.BackgroundBrush);

            drawingContext.DrawGlyphRun(
                foregroundBrush != null ? foregroundBrush : _properties.ForegroundBrush,
                glyphRun
                );
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Draw all formatted glyphruns
        /// </summary>
        /// <returns>drawing bounding box</returns>
        public Rect Draw(
            DrawingContext drawingContext,
            Point currentOrigin
            )
        {
            Rect inkBoundingBox = Rect.Empty;

            Debug.Assert(_glyphs != null);

            foreach (Glyphs glyphs in _glyphs)
            {
                GlyphRun glyphRun = glyphs.CreateGlyphRun(currentOrigin, _rightToLeft);
                Rect     boundingBox;

                if (glyphRun != null)
                {
                    boundingBox = glyphRun.ComputeInkBoundingBox();

                    if (drawingContext != null)
                    {
                        // Emit glyph run background.
                        glyphRun.EmitBackground(drawingContext, glyphs.BackgroundBrush);

                        drawingContext.PushGuidelineY1(currentOrigin.Y);
                        try
                        {
                            drawingContext.DrawGlyphRun(glyphs.ForegroundBrush, glyphRun);
                        }
                        finally
                        {
                            drawingContext.Pop();
                        }
                    }
                }
                else
                {
                    boundingBox = Rect.Empty;
                }

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

                // accumulate overall ink bounding box
                inkBoundingBox.Union(boundingBox);

                if (_rightToLeft)
                {
                    currentOrigin.X -= glyphs.Width;
                }
                else
                {
                    currentOrigin.X += glyphs.Width;
                }
            }

            return(inkBoundingBox);
        }