Bug in Graphics.DrawString ?

  • Thread starter Alexander Smirnov
  • Start date
A

Alexander Smirnov

If you draw a string that consists of repeating lower case characters
'i' or 'l' or 'j' then starting from 20th character the space between
characters is more than that before 20th character. I got this with a
font "Microsoft Sans Serif" size 8.25
 
J

Jani Jarvinen [MVP]

Hello Alexander,
If you draw a string that consists of repeating lower case characters
'i' or 'l' or 'j' then starting from 20th character the space between
characters is more than that before 20th character. I got this with a
font "Microsoft Sans Serif" size 8.25

Although a bug is possible, I wouldn't expect one in this case. To
investigate further, could you send us a complete code example that shows
the error, and also state which Visual Studio/.NET Framework version you are
using, what is your application type, and your operating system?

This way we are better able to verify if its a bug or not.

Thanks!

--
Regards,

Mr. Jani Jarvinen
C# MVP
Helsinki, Finland
(e-mail address removed)
http://www.saunalahti.fi/janij/
 
A

Alexander Smirnov

I use Visual Studio 2005 Standard edition SP1.
NET Framework 2.0
Windows XP Professional SP2

Code example:
// form paint event handler
private void Form1_Paint(object sender, PaintEventArgs e) {

e.Graphics.DrawString("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",this.Font,Brushes.Black,
10,10);
TextRenderer.DrawText(e.Graphics,
"iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",this.Font,new Point(10,30),
Color.Black);
}
//----------


See the difference between the output of DrawString and DrawText.
Same effect for DrawString() in VS2003 Net 1.1 where TextRenderer
isn't available
 
B

Ben Schwehn

See the difference between the output of DrawString and DrawText.
Same effect for DrawString() in VS2003 Net 1.1 where TextRenderer


I assume this is, because the stem width of the letter is a fractional
pixel value so DrawString tries to apply some kerning to make up for
this with less then ideal results.

You can actually influence this behaviour by setting
System.Drawing.Text.TextRenderingHint to e.g. SingleBitPerPixel or
AntiAlias like this:

e.Graphics.TextRenderingHint =
System.Drawing.Text.TextRenderingHint.AntiAlias

But in my opinion the result is even worse.

Anyways, normally this shouldn't really be a problem (normally you don't
want to display a long string of just i or j).


In 1.1 you can P/Invoke to DrawTextEx in user32 (see
http://pinvoke.net/default.aspx/user32/DrawTextEx.html). This is what
the TextRenderer uses.


hth
Ben
 
H

Hilton

I definitely see this with some code I wrote - looks pretty bad. In my
case, the characters get closer together.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top