示例#1
0
        //****************************************************************
        // Painting - Methods for painting a PText.
        //****************************************************************

        /// <summary>
        /// Overridden.  See <see cref="PNode.Paint">PNode.Paint</see>.
        /// </summary>
        protected override void Paint(XnaPiccolo.Util.PPaintContext paintContext)
        {
            //Font font = new Font("Arial", 12);
            //XnaGraphics gg = paintContext.Graphics;
            //gg.DrawString("Before BasePaint", font, Brushes.Red, new PointF(10, 50));
            //gg.Flush();

            base.Paint(paintContext);

            if (text != null && textBrush != null && font != null)
            {
                XnaGraphics g = paintContext.Graphics;

                float renderedFontSize = font.MeasureString(text).Y * 1.0f;
                //float renderedFontSize = font.SizeInPoints * paintContext.Scale;
                if (renderedFontSize < PUtil.GreekThreshold)
                {
                    // .NET bug: DrawString throws a generic gdi+ exception when
                    // the scaled font size is very small.  So, we will render
                    // the text as a simple rectangle for small fonts
                    g.FillRectangle(textBrush, Bounds);
                }
                else if (renderedFontSize < PUtil.MaxFontSize)
                {
                    SpriteFont renderFont = font;

                    // The font needs to be adjusted for printing.
                    if (g.DpiY != GRAPHICS.DpiY)
                    {
                        float fPrintedFontRatio = GRAPHICS.DpiY / 100;
                        //renderFont = new Font(font.Name, font.Size * fPrintedFontRatio,
                        //	font.Style, font.Unit);
                    }

                    g.DrawString(text, renderFont, textBrush, Bounds, stringFormat);
                }
            }
        }