Ejemplo n.º 1
0
        private void DrawStringByPixels(string s, Font font, Brush brush, SizeF textSize, RectangleF layoutRectangle, StringFormat format)
        {
            layoutRectangle = layoutRectangle.ScaleRect(PageUnitScale);

            PointF textLocation = layoutRectangle.Location;

            if (format != null)
            {
                if (layoutRectangle.IsEmpty)
                    UpdateTextLocationByPoint(ref textLocation, textSize, format);
                else
                    UpdateTextLocationByRectangle(ref textLocation, layoutRectangle, textSize, format);
            }

            RectangleF textRectangle = new RectangleF(textLocation, textSize);

            PointF fillLocation = textLocation;

            using (Bitmap bitmap = new Bitmap((int)textSize.Width + 1, (int)textSize.Height + 1))
            {
                if (TextRenderingHint == TextRenderingHint.ClearTypeGridFit)
                {
                    FillTextBackground(bitmap, textLocation, textSize);
                }

                using (Graphics gdi = Graphics.FromImage(bitmap))
                {
                    gdi.TextRenderingHint = TextRenderingHint;
                    gdi.DrawString(s, font, brush, new RectangleF(PointF.Empty, textSize), format);
                }

                DrawStringImage(bitmap, textLocation, textSize);
            }
        }