/// <summary>
            /// Initialize a new instance of the UseClearTypeGridFit class.
            /// </summary>
            /// <param name="graphics">Graphics instance.</param>
            public UseClearTypeGridFit(Graphics graphics)
            {
                g = graphics;
                oldTextRenderingHint = g.TextRenderingHint;
                g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

            }
        /// <summary>
        /// Initialize a new instance of the UseClearTypeGridFit class.
        /// </summary>
        /// <param name="g">Graphics instance.</param>
        public UseClearTypeGridFit(Graphics g)
        {
            _g = g;
            _old = _g.TextRenderingHint;
            _g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

        }
示例#3
0
 /// <summary>
 /// Saves a string of text to a file as an image, the format is determined by the file extension.
 /// Supported extensions are *.jpg,*.jpeg,*.gif,*.bmp,*.png,*.tiff
 /// </summary>
 public static void Save(string FileName, string Text, Font TextFont, Color TextColor, Color BackgroundColor, TextRenderingHint RenderingHint)
 {
     ImageFormat objFormat;
     switch(StringFunctions.AllAfter(FileName,".").ToLower())
     {
         case "jpg":
         case "jpeg":
             objFormat = ImageFormat.Jpeg;
             break;
         case "gif":
             objFormat = ImageFormat.Gif;
             break;
         case "bmp":
             objFormat = ImageFormat.Bmp;
             break;
         case "png":
             objFormat = ImageFormat.Png;
             break;
         case "tiff":
             objFormat = ImageFormat.Tiff;
             break;
         default:
             objFormat = ImageFormat.Jpeg;
             break;
     }
     Bitmap bmp = GetBitmap(Text,TextFont,TextColor,BackgroundColor,RenderingHint);
     FileStream fs = new FileStream(FileName,FileMode.Create);
     bmp.Save(fs,objFormat);
     bmp.Dispose();
     fs.Close();
 }
	// Constructor, which saves away all of the important information.
	// We assume that the lock on the "graphics" object is held by the caller.
	internal GraphicsContainer(Graphics graphics)
			{
				// Push this container onto the stack.
				this.graphics = graphics;
				next = graphics.stackTop;
				graphics.stackTop = this;

				// Save the graphics state information.
				clip = graphics.Clip;
				if(clip != null)
				{
					clip = clip.Clone();
				}
				compositingMode = graphics.CompositingMode;
				compositingQuality = graphics.CompositingQuality;
				interpolationMode = graphics.InterpolationMode;
				pageScale = graphics.PageScale;
				pageUnit = graphics.PageUnit;
				pixelOffsetMode = graphics.PixelOffsetMode;
				renderingOrigin = graphics.RenderingOrigin;
				smoothingMode = graphics.SmoothingMode;
				textContrast = graphics.TextContrast;
				textRenderingHint = graphics.TextRenderingHint;
				if (graphics.transform == null)
				{
					transform = null;
				}
				else
				{
					transform = Matrix.Clone(graphics.transform);
				}
			}
 public TextRenderingHintGraphics(
     Graphics graphics,
     TextRenderingHint newTextRenderingHint)
 {
     _graphics = graphics;
     _oldTextRenderingHint = graphics.TextRenderingHint;
     _graphics.TextRenderingHint = newTextRenderingHint;
 }
示例#6
0
		private Graphics(int xSize, int ySize, PixelFormat pixelFormat, IntPtr native) {
			this.xSizePixels = xSize;
			this.ySizePixels = ySize;
			this.pixelFormat = pixelFormat;
			this.native = native;
			this.textRenderingHint = TextRenderingHint.SystemDefault;
			this.Clip = new Region();
		}
示例#7
0
 public void DrawFavicon(String text, String fontName, Color fontColor, Color backgroundColor,
     FontStyle fontStyle, TextRenderingHint hint)
 {
     using (var graphics = Graphics.FromImage(this.bitmap))
     {
         graphics.TextRenderingHint = hint;
         FillBackground(graphics, backgroundColor);
         DrawText(graphics, text, fontName, fontColor, fontStyle);
     }
 }
        /// <summary>
        /// Initialize a new instance of the GraphicsSmooth class.
        /// </summary>
        /// <param name="graphics">Graphics context.</param>
        /// <param name="textHint">Temporary text rendering hint to apply.</param>
        public GraphicsTextHint(Graphics graphics, TextRenderingHint textHint)
        {
            // Cache graphics instance
            _graphics = graphics;

            // Remember current text hint
            _textHint = _graphics.TextRenderingHint;

            // Apply new text hint
            _graphics.TextRenderingHint = textHint;
        }
示例#9
0
		/// <summary>
		/// Initializes a new instance of the <see cref="NuGenGrfxMode"/> class.
		/// </summary>
		/// <exception cref="ArgumentNullException">
		/// <para><paramref name="grfx"/> is <see langword="null"/>.</para>
		/// </exception>
		public NuGenGrfxMode(Graphics grfx)
		{
			if (grfx == null)
			{
				throw new ArgumentNullException("grfx");
			}

			_grfx = grfx;

			_oldPixelOffsetMode = _grfx.PixelOffsetMode;
			_oldSmoothingMode = _grfx.SmoothingMode;
			_oldTextRenderingHint = _grfx.TextRenderingHint;
		}
	// Constructor.
	protected ToolkitGraphicsBase(IToolkit toolkit)
			{
				this.toolkit = toolkit;
				clip = null;
				compositingMode = CompositingMode.SourceOver;
				compositingQuality = CompositingQuality.Default;
				interpolationMode = InterpolationMode.Default;
				pixelOffsetMode = PixelOffsetMode.Default;
				renderingOrigin = new Point(0, 0);
				smoothingMode = SmoothingMode.Default;
				textContrast = 4;
				textRenderingHint = TextRenderingHint.SystemDefault;
				dirtyFlags = DirtyFlags.All;
			}
示例#11
0
        /// <summary>
        /// Initialize a new instance of the UseClearTypeGridFit class.
        /// </summary>
        /// <param name="graphics">Graphics instance.</param>
        public UseClearTypeGridFit(Graphics graphics)
        {
            if (graphics == null)
            {
                throw new ArgumentNullException("graphics",
                    string.Format(System.Globalization.CultureInfo.InvariantCulture,
                    FAFOS.Properties.Resources.IDS_ArgumentException,
                    "graphics"));
            }

            this.m_graphics = graphics;
            this.m_textRenderingHint = this.m_graphics.TextRenderingHint;
            this.m_graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
        }
 /// <summary>
 /// Initialize a new instance of the TextMemento class.
 /// </summary>
 /// <param name="text">Text to draw.</param>
 /// <param name="font">Drawing font.</param>
 /// <param name="sizeF">Size of measured text.</param>
 /// <param name="format">String formatting.</param>
 /// <param name="hint">Drawing hint.</param>
 /// <param name="disposeFont">Should the font be disposed.</param>
 internal AccurateTextMemento(string text,
                              Font font,
                              SizeF sizeF,
                              StringFormat format,
                              TextRenderingHint hint,
                              bool disposeFont)
 {
     _text = text;
     _size = new Size((int)sizeF.Width + 1, (int)sizeF.Height + 1);
     _font = font;
     _format = format;
     _hint = hint;
     _disposeFont = disposeFont;
 }
示例#13
0
        /// <summary>
        /// Pixel accurate measure of the specified string when drawn with the specified Font object.
        /// </summary>
        /// <param name="g">Graphics instance used to measure text.</param>
        /// <param name="rtl">Right to left setting for control.</param>
        /// <param name="text">String to measure.</param>
        /// <param name="font">Font object that defines the text format of the string.</param>
        /// <param name="trim">How to trim excess text.</param>
        /// <param name="align">How to align multine text.</param>
        /// <param name="prefix">How to process prefix characters.</param>
        /// <param name="hint">Rendering hint.</param>
        /// <param name="composition">Should draw on a composition element.</param>
        /// <param name="disposeFont">Dispose of font when finished with it.</param>
        /// <returns>A memento used to draw the text.</returns>
        public static AccurateTextMemento MeasureString(Graphics g,
                                                        RightToLeft rtl,
                                                        string text,
                                                        Font font,
                                                        PaletteTextTrim trim,
                                                        PaletteRelativeAlign align,
                                                        PaletteTextHotkeyPrefix prefix,
                                                        TextRenderingHint hint,
                                                        bool composition,
                                                        bool disposeFont)
        {
            Debug.Assert(g != null);
            Debug.Assert(text != null);
            Debug.Assert(font != null);

            if (g == null) throw new ArgumentNullException("g");
            if (text == null) throw new ArgumentNullException("text");
            if (font == null) throw new ArgumentNullException("font");

            // An empty string cannot be drawn, so uses the empty memento
            if (text.Length == 0)
                return AccurateTextMemento.Empty;

            // Create the format object used when measuring and drawing
            StringFormat format = new StringFormat();
            format.FormatFlags = StringFormatFlags.NoClip;

            // Ensure that text reflects reversed RTL setting
            if (rtl == RightToLeft.Yes)
                format.FormatFlags = StringFormatFlags.DirectionRightToLeft;

            // How do we position text horizontally?
            switch (align)
            {
                case PaletteRelativeAlign.Near:
                    format.Alignment = (rtl == RightToLeft.Yes) ? StringAlignment.Far : StringAlignment.Near;
                    break;
                case PaletteRelativeAlign.Center:
                    format.Alignment = StringAlignment.Center;
                    break;
                case PaletteRelativeAlign.Far:
                    format.Alignment = (rtl == RightToLeft.Yes) ? StringAlignment.Near : StringAlignment.Far;
                    break;
                default:
                    // Should never happen!
                    Debug.Assert(false);
                    break;
            }

            // Do we need to trim text that is too big?
            switch (trim)
            {
                case PaletteTextTrim.Character:
                    format.Trimming = StringTrimming.Character;
                    break;
                case PaletteTextTrim.EllipsisCharacter:
                    format.Trimming = StringTrimming.EllipsisCharacter;
                    break;
                case PaletteTextTrim.EllipsisPath:
                    format.Trimming = StringTrimming.EllipsisPath;
                    break;
                case PaletteTextTrim.EllipsisWord:
                    format.Trimming = StringTrimming.EllipsisWord;
                    break;
                case PaletteTextTrim.Word:
                    format.Trimming = StringTrimming.Word;
                    break;
                case PaletteTextTrim.Hide:
                    format.Trimming = StringTrimming.None;
                    break;
                default:
                    // Should never happen!
                    Debug.Assert(false);
                    break;
            }

            // Setup the correct prefix processing
            switch (prefix)
            {
                case PaletteTextHotkeyPrefix.None:
                    format.HotkeyPrefix = HotkeyPrefix.None;
                    break;
                case PaletteTextHotkeyPrefix.Hide:
                    format.HotkeyPrefix = HotkeyPrefix.Hide;
                    break;
                case PaletteTextHotkeyPrefix.Show:
                    format.HotkeyPrefix = HotkeyPrefix.Show;
                    break;
                default:
                    // Should never happen!
                    Debug.Assert(false);
                    break;
            }

            // Replace tab characters with a fixed four spaces
            text = text.Replace("\t", "    ");

            // Perform actual measure of the text
            using (GraphicsTextHint graphicsHint = new GraphicsTextHint(g, hint))
            {
                SizeF textSize = Size.Empty;

                try
                {
                    textSize = g.MeasureString(text, font, int.MaxValue, format);

                    if (composition)
                        textSize.Width += GLOW_EXTRA_WIDTH;
                }
                catch {}

                // Return a memento with drawing details
                return new AccurateTextMemento(text, font, textSize, format, hint, disposeFont);
            }
        }
示例#14
0
 /// <summary>
 /// Constructor
 /// </summary>
 public LayoutText()
 {
     Name = "Text Box";
     _font = new Font("Arial", 10);
     _color = Color.Black;
     _text = "Text Box";
     _textHint = TextRenderingHint.AntiAliasGridFit;
     ResizeStyle = ResizeStyle.HandledInternally;
     _contentAlignment = ContentAlignment.TopLeft;
 }
示例#15
0
 /// <summary>
 /// Renders the specified HTML into a new image of unknown size that will be determined by max width/height and HTML layout.<br/>
 /// If <paramref name="maxWidth"/> is zero the html will use all the required width, otherwise it will perform line 
 /// wrap as specified in the html<br/>
 /// If <paramref name="maxHeight"/> is zero the html will use all the required height, otherwise it will clip at the
 /// given max height not rendering the html below it.<br/>
 /// The generated image have transparent background that the html is rendered on.<br/>
 /// GDI+ text rending can be controlled by providing <see cref="TextRenderingHint"/>.<br/>
 /// See "Rendering to image" remarks section on <see cref="HtmlRender"/>.<br/>
 /// </summary>
 /// <param name="html">HTML source to render</param>
 /// <param name="maxWidth">optional: the max width of the rendered html, if not zero and html cannot be layout within the limit it will be clipped</param>
 /// <param name="maxHeight">optional: the max height of the rendered html, if not zero and html cannot be layout within the limit it will be clipped</param>
 /// <param name="textRenderingHint">optional: (default - SingleBitPerPixelGridFit)</param>
 /// <param name="cssData">optional: the style to use for html rendering (default - use W3 default style)</param>
 /// <param name="stylesheetLoad">optional: can be used to overwrite stylesheet resolution logic</param>
 /// <param name="imageLoad">optional: can be used to overwrite image resolution logic</param>
 /// <returns>the generated image of the html</returns>
 public static Image RenderToImageGdiPlus(string html, int maxWidth = 0, int maxHeight = 0, TextRenderingHint textRenderingHint = TextRenderingHint.AntiAlias, CssData cssData = null,
     EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad = null, EventHandler<HtmlImageLoadEventArgs> imageLoad = null)
 {
     return RenderToImageGdiPlus(html, Size.Empty, new Size(maxWidth, maxHeight), textRenderingHint, cssData, stylesheetLoad, imageLoad);
 }
示例#16
0
        public void TextRenderer_DrawText_InvokeIDeviceContextStringFontPointColor_Success(TextRenderingHint textRenderingHint, string text, Font font, Point pt, Color foreColor)
        {
            using var image            = new Bitmap(10, 10);
            using Graphics graphics    = Graphics.FromImage(image);
            graphics.TextRenderingHint = textRenderingHint;
            TextRenderer.DrawText(graphics, text, font, pt, foreColor);

            // Call again to test caching.
            TextRenderer.DrawText(graphics, text, font, pt, foreColor);
        }
示例#17
0
        public void Build(System.Drawing.Font font, TextRenderingHint hint, string filename)
        {
            //new Glyph(97, font, hint);

            //Create Glyphs
            _glyphs.Clear();
            for (int i = 33; i < 256; i++)
            {
                _glyphs.Add(new Glyph(i, font, hint));
            }

            //Create Texture
            bool allFit;
            int startWidth = 128;
            int startHeight = 128;
            BitmapPacker root;
            do
            {
                allFit = true;
                root = new BitmapPacker();
                root.Rect = new System.Drawing.Rectangle(0, 0, startWidth, startHeight);
                foreach (var glyph in _glyphs)
                {
                    if (glyph.Bitmap != null)
                    {
                        var bp = root.Insert(glyph.Bitmap);
                        if (bp == null)
                        {
                            if (startWidth > startHeight)
                            {
                                startHeight *= 2;
                            }
                            else
                            {
                                startWidth *= 2;
                            }
                            allFit = false;
                            break;
                        }
                        else
                        {
                            glyph.Info.X1 = (byte)bp.Rect.X;
                            glyph.Info.Y1 = (byte)bp.Rect.Y;
                            glyph.Info.X2 = (byte)bp.Rect.Right;
                            glyph.Info.Y2 = (byte)bp.Rect.Bottom;
                        }
                    }
                }
            } while (!allFit);

            Bitmap result = new Bitmap(root.Rect.Width, root.Rect.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            root.Render(result);
            result.Save(filename + ".png");

            CalculateKernings();

            using (var fs = new FileStream(filename + ".info", FileMode.Create))
            {
                using (var bw = new BinaryWriter(fs))
                {
                    foreach (var g in _glyphs)
                    {
                        bw.Write(g.Info.X1);
                        bw.Write(g.Info.Y1);
                        bw.Write(g.Info.X2);
                        bw.Write(g.Info.Y2);
                        bw.Write(g.Info.YOffset);
                    }
                    bw.Write(_kerning);
                }
            }
        }
示例#18
0
 public void setTextRenderHint(TextRenderingHint textRenderHint)
 {
     this.textRenderHint = textRenderHint;
 }
示例#19
0
 // Token: 0x060003A6 RID: 934 RVA: 0x000023A5 File Offset: 0x000005A5
 static void smethod_17(Graphics graphics_0, TextRenderingHint textRenderingHint_0)
 {
     graphics_0.TextRenderingHint = textRenderingHint_0;
 }
 public TextRenderingHintGraphics(Graphics graphics, TextRenderingHint newTextRenderingHint)
 {
     this._graphics = graphics;
     this._oldTextRenderingHint = graphics.TextRenderingHint;
     this._graphics.TextRenderingHint = newTextRenderingHint;
 }
示例#21
0
        /// <summary>
        /// Returns a Bitmap object representing the supplied text
        /// </summary>
        private static Bitmap GetBitmap(string Text, Font TextFont, Color TextColor, Color BackgroundColor, TextRenderingHint RenderingHint)
        {
            // we initialise these here because it's needed to calculate the width
            // and height of the provided text.  the 1,1 is only a temporary
            // measurement
            Bitmap   bmp     = new Bitmap(1, 1);
            Graphics graphic = System.Drawing.Graphics.FromImage(bmp);

            // measure the text
            StringFormat stringformat = new StringFormat(StringFormat.GenericTypographic);
            int          height       = Convert.ToInt32(graphic.MeasureString(Text, TextFont, new PointF(0, 0), stringformat).Height) + 6;
            int          width        = Convert.ToInt32(graphic.MeasureString(Text, TextFont, new PointF(0, 0), stringformat).Width);

            // add some padding for the width - i think the kerning is throwing
            // it off by a little.  5% seems to work well, and the +10 is necessary
            // if the string is only a few letters
            width += Convert.ToInt32(0.1 * width) + 10;

            // recreate our bmp and graphic objects with the new measurements
            bmp = new Bitmap(width, height);
            //bmp.SetResolution(600,600);

            graphic = System.Drawing.Graphics.FromImage(bmp);

            // our background colour
            graphic.Clear(BackgroundColor);

            // aliasing mode
            graphic.TextRenderingHint = RenderingHint;

            /*
             * the different aliasing modes:
             * ---------------------------------------------------------------------------------
             * graphic.TextRenderingHint = TextRenderingHint.SystemDefault;
             * - each character is drawn using its glyph bitmap, with the system default rendering hint
             *
             * graphic.TextRenderingHint = TextRenderingHint.AntiAlias;
             * - each character is drawn using its antialiased glyph bitmap without hinting
             *
             * graphic.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
             * - each character is drawn using its antialiased glyph bitmap with hinting
             *
             * graphic.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
             * - each character is drawn using its glyph CT bitmap with hinting
             *
             * graphic.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
             * - each character is drawn using its glyph bitmap
             *
             * graphic.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit;
             * - each character is drawn using its glyph bitmap
             */

            // our brush which is the writing colour
            SolidBrush brush = new SolidBrush(TextColor);

            /*
             * alternate brushes
             * -------------------------------------------------------------------------------
             * System.Drawing.Drawing2D.HatchBrush
             * System.Drawing.Drawing2D.LinearGradientBrush
             * System.Drawing.Drawing2D.PathGradientBrush
             * System.Drawing.SolidBrush
             * System.Drawing.TextureBrush
             */

            // create our graphic
            graphic.DrawString(Text, TextFont, brush, new Rectangle(0, 3, width, height));

            // dispose of our objects
            TextFont.Dispose();
            stringformat.Dispose();
            graphic.Dispose();
            return(bmp);
        }
示例#22
0
        /// <summary>
        /// Creates a bitmap from a Windows font.
        /// </summary>
        /// <param name="backgroundColour">The background colour.</param>
        /// <param name="textColour">The text colour.</param>
        /// <param name="font">The font to convert.</param>
        /// <returns></returns>
        static public Bitmap CreateFontBitmap(Font font, Color backgroundColour, Color textColour)
        {
            // Ensure the font will be drawn cleanly without anti-aliasing
            TextRenderingHint renderingHint = TextRenderingHint.SingleBitPerPixelGridFit;

            List <Bitmap>    glyphBitmaps = new List <Bitmap>();
            List <Rectangle> glyphRects   = new List <Rectangle>();

            int fontWidth   = 0;
            int fontHeight  = 0;
            int fontYOffset = font.Height;

            Brush backgroundBrush = new SolidBrush(backgroundColour);
            Brush textBrush       = new SolidBrush(textColour);

            string output;

            // Get dimensions of each glyph based on actual drawn pixels, rather
            // than rely .NET's dimensions.  At the same time we create a separate
            // bitmap for each glyph that we will use later to create the final composite
            // of the font
            for (int i = 32; i < 127; ++i)
            {
                output = ((char)i).ToString();

                // Draw glyph to temporary bitmap
                Bitmap glyphBmp = new Bitmap((int)font.Size * 2, (int)font.Size * 2);
                glyphBitmaps.Add(glyphBmp);

                Graphics glyphGfx = Graphics.FromImage(glyphBmp);
                glyphGfx.TextRenderingHint = renderingHint;
                glyphGfx.FillRectangle(backgroundBrush, new Rectangle(0, 0, glyphBmp.Width, glyphBmp.Height));
                glyphGfx.DrawString(output, font, textBrush, new PointF(0, 0));

                // Get the dimensions of the glyph
                Rectangle rect = GetGlyphDimensions(glyphBmp, textColour);
                glyphRects.Add(rect);

                // Remember the dimensions of the glyph if this is the largest yet observed -
                // this will give us the dimensions of the font
                if (rect.Width > fontWidth)
                {
                    fontWidth = rect.Width;
                }
                if (rect.Height + rect.Y > fontHeight)
                {
                    fontHeight = rect.Height + rect.Y;
                }

                // The fontYOffset value stores the y co-ordinate of the minimum drawn
                // pixel from the top of the glyph.  It tells us how much wasted space
                // there is between the top of what .NET considers to be the glyph
                // and the actual pixel data.  At the end of the loop we have a value
                // that tells us amount of wasted space that is valid for every glyph
                // in the font
                if (fontYOffset > rect.Y)
                {
                    fontYOffset = rect.Y;
                }
            }

            // Ensure that our value for the height of the font is not made incorrect
            // by the amount of wasted space above the glyphs
            fontHeight -= fontYOffset;

            // Now that we know exactly how big the font is, we can create
            // a bitmap to store the font composite
            int bmpWidth  = (int)(fontWidth * 32);
            int bmpHeight = (int)(fontHeight * 8);

            Bitmap bmp = new Bitmap(bmpWidth, bmpHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            // Create and prepare graphics object to draw with
            Graphics gfx = Graphics.FromImage(bmp);

            gfx.FillRectangle(backgroundBrush, new Rectangle(0, 0, bmp.Width, bmp.Height));

            // Copy all font glyphs to the bitmap
            int glyph = 0;

            for (int y = 1; y < 4; ++y)
            {
                for (int x = 0; x < 32; ++x)
                {
                    // Stop if we have no more glyphs to draw
                    if (glyph >= glyphRects.Count)
                    {
                        break;
                    }

                    // Only draw the glyph if it has any content
                    if (glyphRects[glyph].Width > 0)
                    {
                        // Calculate the area to copy from.  We only copy the glyph itself,
                        // not the surrounding padding, so that when we paste it to the composite
                        // the glyph is left-aligned
                        int sourceX      = glyphRects[glyph].X;
                        int sourceY      = fontYOffset;
                        int sourceWidth  = glyphRects[glyph].Width;
                        int sourceHeight = fontHeight;

                        // Calculate the area to copy to.  All glyphs are drawn in a regular grid
                        int destX      = x * fontWidth;
                        int destY      = y * fontHeight;
                        int destWidth  = sourceWidth;
                        int destHeight = sourceHeight;

                        Rectangle sourceRect = new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight);
                        Rectangle destRect   = new Rectangle(destX, destY, destWidth, destHeight);

                        // Perform the copy
                        gfx.DrawImage(glyphBitmaps[glyph], destRect, sourceRect, GraphicsUnit.Pixel);
                    }

                    glyph++;
                }
            }

            return(bmp);
        }
示例#23
0
        public override void Draw(Graphics g)
        {
            base.Draw(g);
            PointF     P    = ToPointF(ControlPoints[0]);
            SizeF      sf   = g.MeasureString(Text, TextFont, 1000, format);
            RectangleF Rect = new RectangleF(P.X, P.Y, sf.Width + 4, sf.Height + 4);
            ArrayList  al   = new ArrayList();

            al.Add(new PointF(Rect.Left, Rect.Top + RoundWidth));
            al.Add(new PointF(Rect.Left + RoundWidth, Rect.Top));

            al.Add(new PointF(Rect.Right - RoundWidth, Rect.Top));
            al.Add(new PointF(Rect.Right, Rect.Top + RoundWidth));

            al.Add(new PointF(Rect.Right, Rect.Bottom - RoundWidth));
            al.Add(new PointF(Rect.Right - RoundWidth, Rect.Bottom));

            al.Add(new PointF(Rect.Left + RoundWidth, Rect.Bottom));
            al.Add(new PointF(Rect.Left, Rect.Bottom - RoundWidth));
            al.Add(al[0]);

            if (StickHeight > 0)
            {
                float OffsetX = 0;
                float OffsetY = 0;
                int   Index   = 1;
                switch (StickAlignment)
                {
                case StickAlignment.LeftTop:
                    OffsetX = StickHeight;
                    OffsetY = StickHeight;
                    break;

                case StickAlignment.LeftCenter:
                    break;

                case StickAlignment.LeftBottom:
                    OffsetX = StickHeight;
                    OffsetY = -Rect.Height - StickHeight;
                    Index   = 7;
                    break;

                case StickAlignment.CenterTop:
                    break;

                case StickAlignment.CenterCenter:
                    break;

                case StickAlignment.CenterBottom:
                    break;

                case StickAlignment.RightTop:
                    OffsetX = -Rect.Width - StickHeight;
                    OffsetY = StickHeight;
                    Index   = 3;
                    break;

                case StickAlignment.RightCenter:
                    break;

                case StickAlignment.RightBottom:
                    OffsetX = -Rect.Width - StickHeight;
                    OffsetY = -Rect.Height - StickHeight;
                    Index   = 5;
                    break;
                }
                al = OffsetPoint(al, OffsetX, OffsetY);
                al.Insert(Index, P);
                Rect.Offset(OffsetX, OffsetY);
            }

            PointF[] ps = (PointF[])al.ToArray(typeof(PointF));
            if (ShadowWidth > 0)
            {
                PointF[] pss = (PointF[])ps.Clone();
                OffsetPoint(pss, ShadowWidth, ShadowWidth);
                g.FillPolygon(new SolidBrush(Color.FromArgb(64, Color.Black)), pss);
            }

            if (BackBrush.Color != Color.Empty)
            {
                g.FillPolygon(BackBrush.GetBrush(GetMaxRect()), ps);
            }

            if (LinePen.Color != Color.Empty)
            {
                g.DrawLines(LinePen.GetPen(), ps);
            }

            TextRenderingHint trh = g.TextRenderingHint;

            g.TextRenderingHint = TextRenderingHint.AntiAlias;
            g.DrawString(Text, TextFont, TextBrush.GetBrush(), Rect, format);
            g.TextRenderingHint = trh;
        }
示例#24
0
 extern public static void TextRenderingHint_Set(IntPtr graphics, TextRenderingHint textRenderingHint);
示例#25
0
        private void DrawLabel(Placement placement, string labelStr, double value, float labelPos, float rotateLabelAngle, Font font, Color color, FontUnit fontUnit)
        {
            StringFormat stringFormat = new StringFormat();

            stringFormat.Alignment     = StringAlignment.Center;
            stringFormat.LineAlignment = StringAlignment.Near;
            float          num            = GetPositionFromValue(value);
            MarkerPosition markerPosition = new MarkerPosition((float)Math.Round(num), value, placement);

            if (MarkerPosition.IsExistsInArray(labels, markerPosition))
            {
                return;
            }
            if (labelStr.Length > 0)
            {
                labels.Add(markerPosition);
            }
            GaugeGraphics graph = Common.Graph;

            using (Brush brush2 = new SolidBrush(color))
            {
                Font resizedFont = GetResizedFont(font, fontUnit);
                try
                {
                    float num2 = 0f;
                    if (ParentGauge.GetOrientation() == GaugeOrientation.Vertical)
                    {
                        num2 = 90f;
                    }
                    SizeF  size = graph.MeasureString(labelStr, resizedFont);
                    float  contactPointOffset = Utils.GetContactPointOffset(size, rotateLabelAngle - num2);
                    PointF absolutePoint      = graph.GetAbsolutePoint(GetPoint(num, labelPos));
                    switch (placement)
                    {
                    case Placement.Inside:
                        if (ParentGauge.GetOrientation() == GaugeOrientation.Vertical)
                        {
                            absolutePoint.X -= contactPointOffset;
                        }
                        else
                        {
                            absolutePoint.Y -= contactPointOffset;
                        }
                        break;

                    case Placement.Outside:
                        if (ParentGauge.GetOrientation() == GaugeOrientation.Vertical)
                        {
                            absolutePoint.X += contactPointOffset;
                        }
                        else
                        {
                            absolutePoint.Y += contactPointOffset;
                        }
                        break;
                    }
                    RectangleF rectangleF = new RectangleF(absolutePoint, new SizeF(0f, 0f));
                    rectangleF.Inflate(size.Width / 2f, size.Height / 2f);
                    Matrix transform = graph.Transform;
                    Matrix matrix    = graph.Transform.Clone();
                    try
                    {
                        if (rotateLabelAngle == 0f)
                        {
                            if (base.ShadowOffset != 0f)
                            {
                                using (Brush brush = graph.GetShadowBrush())
                                {
                                    RectangleF layoutRectangle = rectangleF;
                                    layoutRectangle.Offset(base.ShadowOffset, base.ShadowOffset);
                                    graph.DrawString(labelStr, resizedFont, brush, layoutRectangle, stringFormat);
                                }
                            }
                            graph.DrawString(labelStr, resizedFont, brush2, rectangleF, stringFormat);
                            return;
                        }
                        TextRenderingHint textRenderingHint = graph.TextRenderingHint;
                        try
                        {
                            if (textRenderingHint == TextRenderingHint.ClearTypeGridFit)
                            {
                                graph.TextRenderingHint = TextRenderingHint.AntiAlias;
                            }
                            if (base.ShadowOffset != 0f)
                            {
                                using (Brush brush3 = graph.GetShadowBrush())
                                {
                                    using (Matrix matrix2 = matrix.Clone())
                                    {
                                        matrix2.Translate(base.ShadowOffset, base.ShadowOffset);
                                        matrix2.RotateAt(rotateLabelAngle, absolutePoint);
                                        graph.Transform = matrix2;
                                        graph.DrawString(labelStr, resizedFont, brush3, rectangleF, stringFormat);
                                    }
                                }
                            }
                            matrix.RotateAt(rotateLabelAngle, absolutePoint);
                            graph.Transform = matrix;
                            graph.DrawString(labelStr, resizedFont, brush2, rectangleF, stringFormat);
                        }
                        finally
                        {
                            graph.TextRenderingHint = textRenderingHint;
                        }
                    }
                    finally
                    {
                        matrix.Dispose();
                        graph.Transform = transform;
                    }
                }
                finally
                {
                    if (resizedFont != font)
                    {
                        resizedFont.Dispose();
                    }
                }
            }
        }
示例#26
0
        /// <summary>
        /// This gets called to instruct the element to draw itself in the appropriate spot of the graphics object
        /// </summary>
        /// <param name="g">The graphics object to draw to</param>
        /// <param name="printing">Boolean, true if printing to an actual print document</param>
        public override void Draw(Graphics g, bool printing)
        {
            GraphicsPath GP     = new GraphicsPath();
            StringFormat format = new StringFormat();

            format.LineAlignment = StringAlignment.Near;
            format.Alignment     = StringAlignment.Near;

            if (_layoutMap == null || _layoutMap.Scale == 0)
            {
                return;
            }

            // Sets up the pens and brushes
            Brush scaleBrush = new SolidBrush(_color);
            Pen   scalePen   = new Pen(scaleBrush);

            // Calculates the width of one break in greographic units
            float unitLegnth    = g.MeasureString(_unitText, _font).Width * 2;
            float widthNoUnit   = Size.Width - unitLegnth;
            long  geoBreakWidth = Convert.ToInt64((widthNoUnit / 100 * _layoutMap.Scale) / GetConversionFactor(_unit.ToString()) / _numBreaks);

            // If the geobreakWidth is less than 1 we return and don't draw anything
            if (geoBreakWidth < 1)
            {
                return;
            }

            // Save the old transform
            Matrix oldTransform = g.Transform;

            g.TranslateTransform(Location.X, Location.Y);
            TextRenderingHint oldHint = g.TextRenderingHint;

            g.TextRenderingHint = _textHint;

            double n = Math.Pow(10, geoBreakWidth.ToString(CultureInfo.InvariantCulture).Length - 1);

            geoBreakWidth = Convert.ToInt64(Math.Floor(geoBreakWidth / n) * n);
            long  breakWidth = Convert.ToInt64((1D * geoBreakWidth / _layoutMap.Scale) * GetConversionFactor(_unit.ToString()) * 100D);
            float fontHeight = g.MeasureString(geoBreakWidth.ToString(CultureInfo.InvariantCulture), _font).Height;
            float leftStart  = g.MeasureString(Math.Abs(geoBreakWidth).ToString(CultureInfo.InvariantCulture), _font).Width / 2F;

            // Decides if a break should be drawn before the zero
            int startBreak = 0;

            if (_breakBeforeZero)
            {
                startBreak = -1;
            }

            // CGX
            g.SetClip(Rectangle, CombineMode.Union);
            // fin CGX

            g.DrawLine(scalePen, leftStart, fontHeight * 1.6f, leftStart + (breakWidth * _numBreaks), fontHeight * 1.6f);

            //g.DrawString("1 : " + String.Format("{0:0, }", Map.Scale), _font, scaleBrush, leftStart - (g.MeasureString(Math.Abs(geoBreakWidth * startBreak).ToString(), _font).Width / 2), fontHeight * 2.5F);
            //CGX
            PointF pointScale = new PointF(leftStart - (g.MeasureString(Math.Abs(geoBreakWidth * startBreak).ToString(), _font).Width / 2), fontHeight * 2.5F);

            GP.AddString("1 : " + String.Format("{0:0 }", Map.Scale), _font.FontFamily, (int)_font.Style, _font.SizeInPoints * 96F / 72F, pointScale, format);

            for (int i = startBreak; i <= _numBreaks + startBreak; i++)
            {
                PointF pUp   = new PointF(leftStart, fontHeight + (fontHeight * 1.1f));
                PointF pDown = new PointF(leftStart, fontHeight * 1.1f);

                g.DrawLine(scalePen, leftStart, fontHeight * 1.1f, leftStart, fontHeight + (fontHeight * 1.1f));
                GP.AddString(Math.Abs(geoBreakWidth * i).ToString(CultureInfo.InvariantCulture), _font.FontFamily, (int)_font.Style, _font.SizeInPoints * 96F / 72F, new PointF(leftStart - (g.MeasureString(Math.Abs(geoBreakWidth * i).ToString(), _font).Width / 2), 0), format);
                leftStart = leftStart + breakWidth;
            }
            GP.AddString(_unitText, _font.FontFamily, (int)_font.Style, _font.SizeInPoints * 96F / 72F, new PointF(leftStart - breakWidth + (fontHeight / 2), fontHeight * 1.1f), format);

            g.FillPath(new SolidBrush(_color), GP);
            GP.Dispose();

            //Restore the old transform
            g.Transform         = oldTransform;
            g.TextRenderingHint = oldHint;
        }
示例#27
0
        /// <summary>
        /// Saves a string of text to a file as an image, the format is determined by the file extension.
        /// Supported extensions are *.jpg,*.jpeg,*.gif,*.bmp,*.png,*.tiff
        /// </summary>
        public static void Save(string FileName, string Text, Font TextFont, Color TextColor, Color BackgroundColor, TextRenderingHint RenderingHint)
        {
            ImageFormat objFormat;

            switch (StringFunctions.AllAfter(FileName, ".").ToLower())
            {
            case "jpg":
            case "jpeg":
                objFormat = ImageFormat.Jpeg;
                break;

            case "gif":
                objFormat = ImageFormat.Gif;
                break;

            case "bmp":
                objFormat = ImageFormat.Bmp;
                break;

            case "png":
                objFormat = ImageFormat.Png;
                break;

            case "tiff":
                objFormat = ImageFormat.Tiff;
                break;

            default:
                objFormat = ImageFormat.Jpeg;
                break;
            }
            Bitmap     bmp = GetBitmap(Text, TextFont, TextColor, BackgroundColor, RenderingHint);
            FileStream fs  = new FileStream(FileName, FileMode.Create);

            bmp.Save(fs, objFormat);
            bmp.Dispose();
            fs.Close();
        }
示例#28
0
        /// <summary>
        /// Outputs a string of text to a stream as a Jpeg image
        /// </summary>
        public static void Save(Stream OutputStream, string Text, Font TextFont, Color TextColor, Color BackgroundColor, TextRenderingHint RenderingHint)
        {
            Bitmap bmp = GetBitmap(Text, TextFont, TextColor, BackgroundColor, RenderingHint);

            bmp.Save(OutputStream, ImageFormat.Jpeg);
            bmp.Dispose();
        }
示例#29
0
        public static Icon GenerateTrayIcon(string iconText)
        {
            float iconWidth   = Globals.DpiScale < 1.25 ? 16 * Globals.DpiScale : 32 * Globals.DpiScale;
            float iconHeight  = Globals.DpiScale < 1.25 ? 16 * Globals.DpiScale : 32 * Globals.DpiScale;
            float fontSize    = Globals.DpiScale < 1.25 ? 16 * Globals.DpiScale : 32 * Globals.DpiScale;
            float iconPadding = Globals.DpiScale < 1.25 ? 4 * Globals.DpiScale : 8 * Globals.DpiScale;
            float alignmentX  = 0; // = Globals.DpiScale < 1.25 ? 5 * Globals.DpiScale : 10 * Globals.DpiScale;
            float alignmentY  = 0; // = Globals.DpiScale < 1.25 ? 5 * Globals.DpiScale : 10 * Globals.DpiScale;

            TextRenderingHint hinting = TextRenderingHint.ClearTypeGridFit;

            if (Settings.Default.TrayIconOverrideAutoSettings)
            {
                iconWidth  = Settings.Default.TrayIconWidth;
                iconHeight = Settings.Default.TrayIconHeight;
                fontSize   = Settings.Default.TrayIconFontStyle.Size;
                alignmentX = Settings.Default.TrayIconXAlignment;
                alignmentY = Settings.Default.TrayIconYAlignment;

                if (iconWidth == 0)
                {
                    iconWidth = 1;
                }
                if (iconHeight == 0)
                {
                    iconHeight = 1;
                }

                switch (Settings.Default.TrayIconTextRenderingHinting)
                {
                case 0:
                    hinting = TextRenderingHint.SystemDefault;
                    break;

                case 1:
                    hinting = TextRenderingHint.ClearTypeGridFit;
                    break;

                case 2:
                    hinting = TextRenderingHint.AntiAliasGridFit;
                    break;

                case 3:
                    hinting = TextRenderingHint.SingleBitPerPixelGridFit;
                    break;

                default:
                    hinting = Globals.DpiScale < 1.25 ? TextRenderingHint.ClearTypeGridFit : TextRenderingHint.AntiAliasGridFit;
                    break;
                }
            }

            using (Bitmap bitmap = new Bitmap((int)iconWidth, (int)iconHeight, PixelFormat.Format32bppArgb))
            {
                Font  font      = Settings.Default.TrayIconOverrideAutoSettings ? Settings.Default.TrayIconFontStyle : new Font("Segoe UI Semibold", fontSize, FontStyle.Regular);
                Color textColor = Settings.Default.TrayIconColorText;

                switch (iconText)
                {
                case "M":
                case "X":
                    textColor = GetColorByPercentage(0);
                    break;

                case "T":
                    textColor = Globals.DefaultColor;
                    break;

                default:
                    textColor = Settings.Default.TrayIconColorTextIsGradient ? GetColorByPercentage(Globals.AudioHandler.FriendlyVolume) : Settings.Default.TrayIconColorText;
                    break;
                }

                bitmap.MakeTransparent(Color.Transparent);
                using (Graphics graphics = Graphics.FromImage(bitmap))
                {
                    graphics.Clear(Color.Transparent);
                    graphics.SmoothingMode     = SmoothingMode.AntiAlias;
                    graphics.TextRenderingHint = hinting;
                    font = FindBestFitFont(graphics, iconText, font, bitmap.Size, iconPadding);
                    SizeF size = graphics.MeasureString(iconText, font).ToSize();
                    graphics.DrawString(iconText, font, new SolidBrush(textColor), ((iconWidth - size.Width) / 2) + alignmentX, ((iconHeight - size.Height) / 2) + alignmentY);
                    using (Icon tmpIcon = Icon.FromHandle(bitmap.GetHicon()))
                    {
                        Icon newIcon = (Icon)tmpIcon.Clone();
                        DestroyIcon(tmpIcon.Handle);
                        return(newIcon);
                    }
                }
            }
        }
示例#30
0
 /// <summary>
 /// 新建SpriteFontX..
 /// </summary>
 /// <param name="font">字体</param>
 /// <param name="gds"> 建纹理时用到的IGraphicsDeviceService</param>
 /// <param name="trh"> 指定文本呈现的质量</param>
 public SpriteFontX(Font font, IGraphicsDeviceService gds, TextRenderingHint trh = TextRenderingHint.AntiAliasGridFit)
 {
     Initialize(font, gds, trh);
 }
 public static void _SpriteFontXInitialize(SpriteFontX __instance, Font font, IGraphicsDeviceService gds, TextRenderingHint trh)
 {
 }
示例#32
0
 /// <summary>
 /// 新建SpriteFontX..
 /// </summary>
 /// <param name="fontName">字体名字</param>
 /// <param name="size">    字体大小</param>
 /// <param name="gds">     建纹理时用到的IGraphicsDeviceService</param>
 /// <param name="trh">     指定文本呈现的质量</param>
 public SpriteFontX(String fontName, Single size, IGraphicsDeviceService gds, TextRenderingHint trh = TextRenderingHint.AntiAliasGridFit)
 {
     Initialize(new Font(fontName, size), gds, trh);
 }
 /// <summary>
 /// Initialize a new instance of the UseClearTypeGridFit class.
 /// </summary>
 /// <param name="g">Graphics instance.</param>
 public UseClearTypeGridFit(Graphics g)
 {
     _g   = g;
     _old = _g.TextRenderingHint;
     _g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
 }
示例#34
0
 /// <summary>
 /// Renders the specified HTML into a new image of unknown size that will be determined by max width/height and HTML layout.<br/>
 /// If <paramref name="maxWidth"/> is zero the html will use all the required width, otherwise it will perform line
 /// wrap as specified in the html<br/>
 /// If <paramref name="maxHeight"/> is zero the html will use all the required height, otherwise it will clip at the
 /// given max height not rendering the html below it.<br/>
 /// The generated image have transparent background that the html is rendered on.<br/>
 /// GDI+ text rending can be controlled by providing <see cref="TextRenderingHint"/>.<br/>
 /// See "Rendering to image" remarks section on <see cref="HtmlRender"/>.<br/>
 /// </summary>
 /// <param name="html">HTML source to render</param>
 /// <param name="maxWidth">optional: the max width of the rendered html, if not zero and html cannot be layout within the limit it will be clipped</param>
 /// <param name="maxHeight">optional: the max height of the rendered html, if not zero and html cannot be layout within the limit it will be clipped</param>
 /// <param name="textRenderingHint">optional: (default - SingleBitPerPixelGridFit)</param>
 /// <param name="cssData">optional: the style to use for html rendering (default - use W3 default style)</param>
 /// <param name="stylesheetLoad">optional: can be used to overwrite stylesheet resolution logic</param>
 /// <param name="imageLoad">optional: can be used to overwrite image resolution logic</param>
 /// <returns>the generated image of the html</returns>
 public static Image RenderToImageGdiPlus(string html, int maxWidth = 0, int maxHeight = 0, TextRenderingHint textRenderingHint = TextRenderingHint.AntiAlias, CssData cssData = null,
                                          EventHandler <HtmlStylesheetLoadEventArgs> stylesheetLoad = null, EventHandler <HtmlImageLoadEventArgs> imageLoad = null)
 {
     return(RenderToImageGdiPlus(html, Size.Empty, new Size(maxWidth, maxHeight), textRenderingHint, cssData, stylesheetLoad, imageLoad));
 }
示例#35
0
        public void TextRenderer_DrawText_InvokeIDeviceContextStringFontRectangleColorColorTextFormatFlags_Success(TextRenderingHint textRenderingHint, string text, Font font, Rectangle rectangle, Color foreColor, Color backColor, TextFormatFlags flags)
        {
            using var image            = new Bitmap(10, 10);
            using Graphics graphics    = Graphics.FromImage(image);
            graphics.TextRenderingHint = textRenderingHint;
            TextRenderer.DrawText(graphics, text, font, rectangle, foreColor, backColor, flags);

            // Call again to test caching.
            TextRenderer.DrawText(graphics, text, font, rectangle, foreColor, backColor, flags);
        }
示例#36
0
        /// <summary>
        /// Renders the specified HTML into a new image of unknown size that will be determined by min/max width/height and HTML layout.<br/>
        /// If <paramref name="maxSize.Width"/> is zero the html will use all the required width, otherwise it will perform line
        /// wrap as specified in the html<br/>
        /// If <paramref name="maxSize.Height"/> is zero the html will use all the required height, otherwise it will clip at the
        /// given max height not rendering the html below it.<br/>
        /// If <paramref name="minSize"/> (Width/Height) is above zero the rendered image will not be smaller than the given min size.<br/>
        /// The generated image have transparent background that the html is rendered on.<br/>
        /// GDI+ text rending can be controlled by providing <see cref="TextRenderingHint"/>.<br/>
        /// See "Rendering to image" remarks section on <see cref="HtmlRender"/>.<br/>
        /// </summary>
        /// <param name="html">HTML source to render</param>
        /// <param name="minSize">optional: the min size of the rendered html (zero - not limit the width/height)</param>
        /// <param name="maxSize">optional: the max size of the rendered html, if not zero and html cannot be layout within the limit it will be clipped (zero - not limit the width/height)</param>
        /// <param name="textRenderingHint">optional: (default - SingleBitPerPixelGridFit)</param>
        /// <param name="cssData">optional: the style to use for html rendering (default - use W3 default style)</param>
        /// <param name="stylesheetLoad">optional: can be used to overwrite stylesheet resolution logic</param>
        /// <param name="imageLoad">optional: can be used to overwrite image resolution logic</param>
        /// <returns>the generated image of the html</returns>
        public static Image RenderToImageGdiPlus(string html, Size minSize, Size maxSize, TextRenderingHint textRenderingHint = TextRenderingHint.AntiAlias, CssData cssData = null,
                                                 EventHandler <HtmlStylesheetLoadEventArgs> stylesheetLoad = null, EventHandler <HtmlImageLoadEventArgs> imageLoad           = null)
        {
            if (string.IsNullOrEmpty(html))
            {
                return(new Bitmap(0, 0, PixelFormat.Format32bppArgb));
            }

            using (var container = new HtmlContainer())
            {
                container.AvoidAsyncImagesLoading = true;
                container.AvoidImagesLateLoading  = true;
                container.UseGdiPlusTextRendering = true;

                if (stylesheetLoad != null)
                {
                    container.StylesheetLoad += stylesheetLoad;
                }
                if (imageLoad != null)
                {
                    container.ImageLoad += imageLoad;
                }
                container.SetHtml(html, cssData);

                var finalSize = MeasureHtmlByRestrictions(container, minSize, maxSize);
                container.MaxSize = finalSize;

                // create the final image to render into by measured size
                var image = new Bitmap(finalSize.Width, finalSize.Height, PixelFormat.Format32bppArgb);

                // render HTML into the image
                using (var g = Graphics.FromImage(image))
                {
                    g.TextRenderingHint = textRenderingHint;
                    container.PerformPaint(g);
                }

                return(image);
            }
        }
示例#37
0
 /// <summary>
 ///     Initialize a new instance of the UseClearTypeGridFit class.
 /// </summary>
 /// <param name="g"> Graphics instance. </param>
 public UseClearTypeGridFit(Graphics g)
 {
     this._g   = g;
     this._old = this._g.TextRenderingHint;
     this._g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
 }
示例#38
0
 public UseClearTypeGridFit(Graphics graphics_1)
 {
     this.graphics_0                   = graphics_1;
     this.textRenderingHint_0          = this.graphics_0.TextRenderingHint;
     this.graphics_0.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
 }
示例#39
0
        private void AddString(string text, Font font, Brush brush, TextRenderingHint textRenderingHint)
        {
            using (Graphics g = Graphics.FromImage(_bitmap))
            {
                g.TextRenderingHint = textRenderingHint;

                StringFormat sf = StringFormat.GenericTypographic;
                sf.FormatFlags = StringFormatFlags.MeasureTrailingSpaces;

                foreach (var c in text)
                {
                    if (_glyphCoords.ContainsKey(c))
                        continue;

                    string s = c.ToString();
                    var size = g.MeasureString(s, font, PointF.Empty, sf);
                    Size integerSize = new Size((int)size.Width + 1, (int)size.Height + 1);
                    g.DrawString(s, font, brush, _lastTextureCoord, sf);
                    var rc = new Rectangle(_lastTextureCoord, integerSize);

                    _glyphCoords.Add(c, new GlyphInfo { GlyphRect = rc, RealSize = size });

                    _lastTextureCoord.X += rc.Width;
                    _maxY = Math.Max(_maxY, rc.Bottom);

                    if (_lastTextureCoord.X > _bitmap.Width)
                    {
                        _lastTextureCoord.X = 1;
                        _lastTextureCoord.Y = _maxY + 1;
                    }
                }
            }
        }
示例#40
0
        public void Render(Graphics graphics, MyPoint origin, int zoom)
        {
            float len = 5.0f;

            // Restore rendering hint and smoothing mode when done
            TextRenderingHint oldHint = graphics.TextRenderingHint;
            SmoothingMode     oldMode = graphics.SmoothingMode;

            graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
            graphics.SmoothingMode     = SmoothingMode.AntiAlias;

            foreach (DistancePair pair in _list)
            {
                MyPointF p0 = (MyPointF)(WorldToScreen(pair.WorldPos0, zoom) - origin);
                MyPointF p1 = (MyPointF)(WorldToScreen(pair.WorldPos1, zoom) - origin);

                MyPointF dir = p1 - p0;
                MyPointF pp  = new MyPointF(-dir.Y, dir.X).Normalize();                 // perpendicular direction

                // Draw circle around p0 and p1
                MyPointF center = p0 + dir * 0.5f;
                if (pair.DrawCircle)
                {
                    float radius = dir.GetLength() * 0.5f;
                    graphics.DrawEllipse(Pens.Gray, center.X - radius, center.Y - radius, radius * 2.0f, radius * 2.0f);
                }

                // Draw line between p0 and p1
                graphics.DrawLine(Pens.Black, p0, p1);

                // Draw border line at p0
                graphics.DrawLine(Pens.Black, p0 + pp * len, p0 - pp * len);

                // Draw border line at p1
                graphics.DrawLine(Pens.Black, p1 + pp * len, p1 - pp * len);

                // Draw text
                string text = Units.Provider.DistanceString(pair.Distance);

                // The y-direction runs from top to bottom
                double angle = Math.Atan2(dir.X, -dir.Y);

                if (angle > Math.PI)
                {
                    angle -= Math.PI;
                }

                if (angle < 0)
                {
                    angle += Math.PI;
                }

                angle -= Math.PI / 2.0;

                float cos = (float)Math.Cos(angle);
                float sin = (float)Math.Sin(angle);

                SizeF textSize = graphics.MeasureString(text, _font);

                // Setup rotation matrix from angle and position
                graphics.Transform = new Matrix(cos, sin, -sin, cos, center.X, center.Y);
                graphics.DrawString(text, _font, Brushes.Black, -textSize.Width * 0.5f, -textSize.Height);
                graphics.ResetTransform();
            }

            // Restore rendering hint and smoothing mode
            graphics.TextRenderingHint = oldHint;
            graphics.SmoothingMode     = oldMode;
        }
示例#41
0
        /// <summary>
        /// Renders the specified HTML into a new image of the requested size.<br/>
        /// The HTML will be layout by the given size but will be clipped if cannot fit.<br/>
        /// The generated image have transparent background that the html is rendered on.<br/>
        /// GDI+ text rending can be controlled by providing <see cref="TextRenderingHint"/>.<br/>
        /// See "Rendering to image" remarks section on <see cref="HtmlRender"/>.<br/>
        /// </summary>
        /// <param name="html">HTML source to render</param>
        /// <param name="size">The size of the image to render into, layout html by width and clipped by height</param>
        /// <param name="textRenderingHint">optional: (default - SingleBitPerPixelGridFit)</param>
        /// <param name="cssData">optional: the style to use for html rendering (default - use W3 default style)</param>
        /// <param name="stylesheetLoad">optional: can be used to overwrite stylesheet resolution logic</param>
        /// <param name="imageLoad">optional: can be used to overwrite image resolution logic</param>
        /// <returns>the generated image of the html</returns>
        public static Image RenderToImageGdiPlus(string html, Size size, TextRenderingHint textRenderingHint = TextRenderingHint.AntiAlias, CssData cssData = null,
            EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad = null, EventHandler<HtmlImageLoadEventArgs> imageLoad = null)
        {
            var image = new Bitmap(size.Width, size.Height, PixelFormat.Format32bppArgb);

            using (var g = Graphics.FromImage(image))
            {
                g.TextRenderingHint = textRenderingHint;
                RenderHtml(g, html, PointF.Empty, size, cssData, true, stylesheetLoad, imageLoad);
            }

            return image;
        }
示例#42
0
 public TextRenderingEventArgs(TextRenderingHint textRenderingHint)
 {
     _textRenderingHint = textRenderingHint;
 }
示例#43
0
        /// <summary>
        /// Renders the specified HTML into a new image of unknown size that will be determined by min/max width/height and HTML layout.<br/>
        /// If <paramref name="maxSize.Width"/> is zero the html will use all the required width, otherwise it will perform line 
        /// wrap as specified in the html<br/>
        /// If <paramref name="maxSize.Height"/> is zero the html will use all the required height, otherwise it will clip at the
        /// given max height not rendering the html below it.<br/>
        /// If <paramref name="minSize"/> (Width/Height) is above zero the rendered image will not be smaller than the given min size.<br/>
        /// The generated image have transparent background that the html is rendered on.<br/>
        /// GDI+ text rending can be controlled by providing <see cref="TextRenderingHint"/>.<br/>
        /// See "Rendering to image" remarks section on <see cref="HtmlRender"/>.<br/>
        /// </summary>
        /// <param name="html">HTML source to render</param>
        /// <param name="minSize">optional: the min size of the rendered html (zero - not limit the width/height)</param>
        /// <param name="maxSize">optional: the max size of the rendered html, if not zero and html cannot be layout within the limit it will be clipped (zero - not limit the width/height)</param>
        /// <param name="textRenderingHint">optional: (default - SingleBitPerPixelGridFit)</param>
        /// <param name="cssData">optional: the style to use for html rendering (default - use W3 default style)</param>
        /// <param name="stylesheetLoad">optional: can be used to overwrite stylesheet resolution logic</param>
        /// <param name="imageLoad">optional: can be used to overwrite image resolution logic</param>
        /// <returns>the generated image of the html</returns>
        public static Image RenderToImageGdiPlus(string html, Size minSize, Size maxSize, TextRenderingHint textRenderingHint = TextRenderingHint.AntiAlias, CssData cssData = null,
            EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad = null, EventHandler<HtmlImageLoadEventArgs> imageLoad = null)
        {
            if (string.IsNullOrEmpty(html))
                return new Bitmap(0, 0, PixelFormat.Format32bppArgb);

            using (var container = new HtmlContainer())
            {
                container.AvoidAsyncImagesLoading = true;
                container.AvoidImagesLateLoading = true;
                container.UseGdiPlusTextRendering = true;

                if (stylesheetLoad != null)
                    container.StylesheetLoad += stylesheetLoad;
                if (imageLoad != null)
                    container.ImageLoad += imageLoad;
                container.SetHtml(html, cssData);

                var finalSize = MeasureHtmlByRestrictions(container, minSize, maxSize);
                container.MaxSize = finalSize;

                // create the final image to render into by measured size
                var image = new Bitmap(finalSize.Width, finalSize.Height, PixelFormat.Format32bppArgb);

                // render HTML into the image
                using (var g = Graphics.FromImage(image))
                {
                    g.TextRenderingHint = textRenderingHint;
                    container.PerformPaint(g);
                }

                return image;
            }
        }
示例#44
0
 public DotNetFont( Font font, TextRenderingHint textRenderingHint )
 {
     _font = font;
     _textRenderingHint = textRenderingHint;
 }
示例#45
0
		internal static extern Status GdipGetTextRenderingHint(IntPtr graphics, out TextRenderingHint mode);
		internal GraphicsState(Graphics graphics, Matrix matrix, bool resetState)
		{
			_compositingMode = graphics.CompositingMode;
			_compositingQuality = graphics.CompositingQuality;
			_clip = graphics.ScaledClip;
			_baseClip = graphics.NativeObject.getClip();
			_interpolationMode = graphics.InterpolationMode;
			_pageScale = graphics.PageScale;
			_pageUnit = graphics.PageUnit;
			_pixelOffsetMode = graphics.PixelOffsetMode;
			
			// FIXME: render orign is not implemented yet
			//_renderingOrigin = new Point( g.RenderingOrigin.X, g.RenderingOrigin.Y );

			_smoothingMode = graphics.SmoothingMode;
			_transform = graphics.Transform;
			_baseTransform = graphics.BaseTransform;

			_textContrast = graphics.TextContrast;
			_textRenderingHint = graphics.TextRenderingHint;

			if (resetState)
				ResetState(graphics, matrix);
		}
示例#47
0
 /// <summary>
 /// Creates a new instance using the specified settings.
 /// </summary>
 /// <param name="compositingQuality"></param>
 /// <param name="interpolationMode"></param>
 /// <param name="pixelOffsetMode"></param>
 /// <param name="smoothingMode"></param>
 /// <param name="textRenderingHint"></param>
 /// <param name="textContrast"></param>
 internal GraphicsSettings(
         CompositingQuality compositingQuality,
         InterpolationMode interpolationMode,
         PixelOffsetMode pixelOffsetMode,
         SmoothingMode smoothingMode,
         TextRenderingHint textRenderingHint,
         int textContrast)
 {
     _compositingQuality = compositingQuality;
     _interpolationMode = interpolationMode;
     _pixelOffsetMode = pixelOffsetMode;
     _smoothingMode = smoothingMode;
     _textContrast = textContrast;
     _textRenderingHint = textRenderingHint;
 }
示例#48
0
 public static extern void TextRenderingHint_Set(IntPtr graphics, TextRenderingHint textRenderingHint);
示例#49
0
 internal static extern GpStatus GdipGetTextRenderingHint(GpGraphics graphics, out TextRenderingHint mode);
        public static void Run()
        {
            Console.WriteLine("Running example SupportOfTextRenderingHint");
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages();

            string[] files = new string[] {
                "TextHintTest.cdr",
                "TextHintTest.cmx",
                "TextHintTest.emf",
                "TextHintTest.wmf",
                "TextHintTest.odg",
                "TextHintTest.svg"
            };
            TextRenderingHint[] textRenderingHints = new TextRenderingHint[] {
                TextRenderingHint.AntiAlias, TextRenderingHint.AntiAliasGridFit,
                TextRenderingHint.ClearTypeGridFit, TextRenderingHint.SingleBitPerPixel, TextRenderingHint.SingleBitPerPixelGridFit
            };
            foreach (string fileName in files)
            {
                using (Image image = Image.Load(dataDir + fileName))
                {
                    VectorRasterizationOptions vectorRasterizationOptions;
                    if (image is CdrImage)
                    {
                        vectorRasterizationOptions = new CdrRasterizationOptions();
                    }
                    else if (image is CmxImage)
                    {
                        vectorRasterizationOptions = new CmxRasterizationOptions();
                    }
                    else if (image is EmfImage)
                    {
                        vectorRasterizationOptions = new EmfRasterizationOptions();
                    }
                    else if (image is WmfImage)
                    {
                        vectorRasterizationOptions = new WmfRasterizationOptions();
                    }
                    else if (image is OdgImage)
                    {
                        vectorRasterizationOptions = new OdgRasterizationOptions();
                    }
                    else if (image is SvgImage)
                    {
                        vectorRasterizationOptions = new SvgRasterizationOptions();
                    }
                    else
                    {
                        throw new Exception("This is image is not supported in this example");
                    }
                    vectorRasterizationOptions.PageSize = image.Size;
                    foreach (TextRenderingHint textRenderingHint in textRenderingHints)
                    {
                        string outputFileName = dataDir + "image_" + textRenderingHint + "_" + fileName + ".png";
                        vectorRasterizationOptions.TextRenderingHint = textRenderingHint;
                        image.Save(outputFileName, new PngOptions()
                        {
                            VectorRasterizationOptions = vectorRasterizationOptions
                        });
                    }
                }
            }

            Console.WriteLine("Finished example SupportOfTextRenderingHint");
        }
示例#51
0
 /// <summary>
 /// Deserialization Constructor
 /// </summary>
 /// <param name="info"></param>
 /// <param name="context"></param>
 protected GlyphText(SerializationInfo info, StreamingContext context) : base(info, context)
 {
     _font = (GlyphFont)info.GetValue("Font", typeof(GlyphFont));
     _textRenderingHint = (System.Drawing.Text.TextRenderingHint)info.GetValue("TextRenderingHint", typeof(System.Drawing.Text.TextRenderingHint));
 }
 public ToolStripTextRenderingHintGraphics(Graphics G, TextRenderingHint NewTextRenderingHint)
 {
     this._G = G;
     this._OldTextRenderingHint = G.TextRenderingHint;
     this._G.TextRenderingHint  = NewTextRenderingHint;
 }
示例#53
0
 public IFont CreateFont( string familyName, int size, FontStyle style, TextRenderingHint renderingHint )
 {
     Font font = new Font( familyName, size, style );
     return new DotNetFont( font, renderingHint );
 }
示例#54
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            using (
                Brush backBrush = new LinearGradientBrush(
                    _cellBounds, Color.Gainsboro, Color.White, LinearGradientMode.ForwardDiagonal))
            {
                using (Brush borderBrush = new SolidBrush(Color.LightSteelBlue))
                {
                    using (Pen borderPen = new Pen(borderBrush))
                    {
                        int startingIndex = _scrollBar.Value * _visibleColumnsCount;

                        for (int y = 0; y < _visibleRowsCount; y++)
                        {
                            e.Graphics.TranslateTransform(0, y * MAX_HEIGHT);

                            for (int x = 0; x < _visibleColumnsCount; x++)
                            {
                                int index = startingIndex + ((y * _visibleColumnsCount) + x);

                                e.Graphics.FillRectangle(backBrush, _cellBounds);

                                if (_artworkFactory != null)
                                {
                                    Bitmap bmp = null;

                                    if (_artworkControlType == ArtworkControlType.Land)
                                    {
                                        if (!_cache.TryGetValue(index, out bmp))
                                        {
                                            bmp = _artworkFactory.GetLand <Bitmap>(index);
                                            _cache.Add(index, bmp);
                                        }
                                    }
                                    else
                                    {
                                        if (!_cache.TryGetValue(index, out bmp))
                                        {
                                            bmp = _artworkFactory.GetStatic <Bitmap>(index);
                                            _cache.Add(index, bmp);
                                        }
                                    }

                                    if (bmp != null)
                                    {
                                        e.Graphics.DrawImageUnscaledAndClipped(bmp, _cellBounds);
                                    }
                                }

                                e.Graphics.DrawRectangle(borderPen, _cellBounds);
                                e.Graphics.TranslateTransform(MAX_WIDTH, 0);
                            }

                            e.Graphics.ResetTransform();
                        }

                        e.Graphics.ResetTransform();
                    }
                }
            }

            if (_artworkFactory == null)
            {
                TextRenderingHint textRenderingHint = e.Graphics.TextRenderingHint;
                e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

                using (Brush backBrush = new SolidBrush(Color.Red))
                {
                    using (Brush foreBrush = new SolidBrush(Color.Maroon))
                    {
                        using (StringFormat format = new StringFormat())
                        {
                            format.LineAlignment = StringAlignment.Center;
                            format.Alignment     = StringAlignment.Center;

                            e.Graphics.DrawString(
                                "ArtworkControl.Factory is not set.", Font, backBrush, new RectangleF(0, 0, Width, Height), format);
                            e.Graphics.DrawString(
                                "ArtworkControl.Factory is not set.", Font, foreBrush, new RectangleF(1, 1, Width, Height), format);
                        }
                    }
                }

                e.Graphics.TextRenderingHint = textRenderingHint;
            }

            using (Brush borderBrush = new SolidBrush(Color.LightSteelBlue))
            {
                using (Pen borderPen = new Pen(borderBrush))
                {
                    e.Graphics.DrawRectangle(borderPen, new Rectangle(0, 0, Width - 1, Height - 1));
                }
            }
        }
示例#55
0
 public void saveGraphics(NetGraphics netG)
 {
     if (netG == null )
     {
         return;
     }
     if (netG.g != null )
     {
         this.Transform = netG.g.Transform;
         this.Clip = netG.g.Clip;
         this.SmoothingMode = netG.g.SmoothingMode;
         this.PixelOffsetMode = netG.g.PixelOffsetMode;
         this.TextRenderingHint = netG.g.TextRenderingHint;
         this.InterpolationMode = netG.g.InterpolationMode;
         this.CompositingMode = netG.g.CompositingMode;
         savedGraphics = true;
     }
     if (netG.pen != null && netG.brush != null)
     {
         pen = (Pen)netG.pen.Clone();
         brush = (Brush)netG.brush.Clone();
     }
 }
示例#56
0
        /// <summary>
        /// Pixel accurate measure of the specified string when drawn with the specified Font object.
        /// </summary>
        /// <param name="g">Graphics instance used to measure text.</param>
        /// <param name="rtl">Right to left setting for control.</param>
        /// <param name="text">String to measure.</param>
        /// <param name="font">Font object that defines the text format of the string.</param>
        /// <param name="trim">How to trim excess text.</param>
        /// <param name="align">How to align multi-line text.</param>
        /// <param name="prefix">How to process prefix characters.</param>
        /// <param name="hint">Rendering hint.</param>
        /// <param name="composition">Should draw on a composition element.</param>
        /// <param name="glowing">When on composition draw with glowing.</param>
        /// <param name="disposeFont">Dispose of font when finished with it.</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <returns>A memento used to draw the text.</returns>
        public static AccurateTextMemento MeasureString(Graphics g,
                                                        RightToLeft rtl,
                                                        string text,
                                                        Font font,
                                                        PaletteTextTrim trim,
                                                        PaletteRelativeAlign align,
                                                        PaletteTextHotkeyPrefix prefix,
                                                        TextRenderingHint hint,
                                                        bool composition,
                                                        bool glowing,
                                                        bool disposeFont)
        {
            Debug.Assert(g != null);
            Debug.Assert(text != null);
            Debug.Assert(font != null);

            if (g == null)
            {
                throw new ArgumentNullException(nameof(g));
            }

            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }

            if (font == null)
            {
                throw new ArgumentNullException(nameof(font));
            }

            // An empty string cannot be drawn, so uses the empty memento
            if (text.Length == 0)
            {
                return(AccurateTextMemento.Empty);
            }

            // Create the format object used when measuring and drawing
            StringFormat format = new StringFormat {
                FormatFlags = StringFormatFlags.NoClip
            };

            // Ensure that text reflects reversed RTL setting
            if (rtl == RightToLeft.Yes)
            {
                format.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
            }

            // How do we position text horizontally?
            switch (align)
            {
            case PaletteRelativeAlign.Near:
                format.Alignment = (rtl == RightToLeft.Yes) ? StringAlignment.Far : StringAlignment.Near;
                break;

            case PaletteRelativeAlign.Center:
                format.Alignment = StringAlignment.Center;
                break;

            case PaletteRelativeAlign.Far:
                format.Alignment = (rtl == RightToLeft.Yes) ? StringAlignment.Near : StringAlignment.Far;
                break;

            default:
                // Should never happen!
                Debug.Assert(false);
                break;
            }

            // Do we need to trim text that is too big?
            switch (trim)
            {
            case PaletteTextTrim.Character:
                format.Trimming = StringTrimming.Character;
                break;

            case PaletteTextTrim.EllipsisCharacter:
                format.Trimming = StringTrimming.EllipsisCharacter;
                break;

            case PaletteTextTrim.EllipsisPath:
                format.Trimming = StringTrimming.EllipsisPath;
                break;

            case PaletteTextTrim.EllipsisWord:
                format.Trimming = StringTrimming.EllipsisWord;
                break;

            case PaletteTextTrim.Word:
                format.Trimming = StringTrimming.Word;
                break;

            case PaletteTextTrim.Hide:
                format.Trimming = StringTrimming.None;
                break;

            default:
                // Should never happen!
                Debug.Assert(false);
                break;
            }

            // Setup the correct prefix processing
            switch (prefix)
            {
            case PaletteTextHotkeyPrefix.None:
                format.HotkeyPrefix = HotkeyPrefix.None;
                break;

            case PaletteTextHotkeyPrefix.Hide:
                format.HotkeyPrefix = HotkeyPrefix.Hide;
                break;

            case PaletteTextHotkeyPrefix.Show:
                format.HotkeyPrefix = HotkeyPrefix.Show;
                break;

            default:
                // Should never happen!
                Debug.Assert(false);
                break;
            }

            // Replace tab characters with a fixed four spaces
            text = text.Replace("\t", "    ");

            // Perform actual measure of the text
            using (GraphicsTextHint graphicsHint = new GraphicsTextHint(g, hint))
            {
                SizeF textSize = Size.Empty;

                try
                {
                    textSize = g.MeasureString(text, font, int.MaxValue, format);

                    if (composition && glowing) //Seb
                    {
                        textSize.Width += GLOW_EXTRA_WIDTH;
                    }
                }
                catch
                {
                    // ignored
                }

                // Return a memento with drawing details
                return(new AccurateTextMemento(text, font, textSize, format, hint, disposeFont));
            }
        }
示例#57
0
 /// <summary>
 /// Constructor
 /// </summary>
 public LayoutLegend()
 {
     Name = "Legend";
     _font = new Font("Arial", 10);
     _color = Color.Black;
     _textHint = TextRenderingHint.AntiAliasGridFit;
     _numCol = 1;
     _layers = new List<IMapLayer>();
     ResizeStyle = ResizeStyle.NoScaling;
 }
示例#58
0
 public UseClearTypeGridFit(Graphics graphics)
 {
     g    = graphics;
     _old = g.TextRenderingHint;
     g.TextRenderingHint = TextRenderingHint.SystemDefault;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 public LayoutScaleBar()
 {
     Name = "Scale Bar";
     _font = new Font("Arial", 10);
     _color = Color.Black;
     _unit = ScaleBarUnits.Kilometers;
     _unitText = "km";
     _numBreaks = 4;
     _textHint = TextRenderingHint.AntiAliasGridFit;
     ResizeStyle = ResizeStyle.HandledInternally;
 }
示例#60
0
        public static Image ImageLightEffect(string Str, Font F, Color ColorFore, Color ColorBack, int BlurConsideration, Rectangle rc, StringFormat sf, TextRenderingHint textRender)
        {
            Bitmap image = null;

            using (Graphics.FromHwnd(IntPtr.Zero))
            {
                using (Bitmap bitmap2 = new Bitmap(rc.Width, rc.Height))
                {
                    using (Graphics graphics2 = Graphics.FromImage(bitmap2))
                    {
                        using (SolidBrush brush = new SolidBrush(Color.FromArgb(0x10, ColorBack.R, ColorBack.G, ColorBack.B)))
                        {
                            using (SolidBrush brush2 = new SolidBrush(ColorFore))
                            {
                                graphics2.SmoothingMode     = SmoothingMode.HighQuality;
                                graphics2.TextRenderingHint = textRender;
                                graphics2.DrawString(Str, F, brush, rc, sf);
                                image = new Bitmap(bitmap2.Width, bitmap2.Height);
                                using (Graphics graphics3 = Graphics.FromImage(image))
                                {
                                    if (ColorBack != Color.Transparent)
                                    {
                                        graphics3.SmoothingMode     = SmoothingMode.HighQuality;
                                        graphics3.TextRenderingHint = textRender;
                                        for (int i = 0; i <= BlurConsideration; i++)
                                        {
                                            for (int j = 0; j <= BlurConsideration; j++)
                                            {
                                                graphics3.DrawImageUnscaled(bitmap2, i, j);
                                            }
                                        }
                                    }
                                    graphics3.DrawString(Str, F, brush2, new Rectangle(new Point(Convert.ToInt32((int)(BlurConsideration / 2)) + rc.X, Convert.ToInt32((int)(BlurConsideration / 2)) + rc.Y), rc.Size), sf);
                                }
                                return(image);
                            }
                        }
                    }
                }
            }
        }