Last.fm radio!
Since I’m using it so much (and to have music available also where my files aren’t :)) I’ve subscribed to last.fm.
This gives me the radio feature… you can listen to my radio, on the right sidebar.
April 21, 2008 | Filed Under Uncategorized | Comments Off
A little better MeasureString…
System.Drawing.MeasureString is a shit.
You are better work it out with API calls and so on, but if you are on Mono that is out of choice.
Apart from the known problems (not working correctly without Antialiasing enabled, requiring specific StringFormats), it also skips trailing spaces.
At least this should fix that issue up:
int CountTrailingSpaces(string str)
{
int spaces = 0;
int i = 0;
for (i = 0; i < str.Length; i++)
{
if (str[i] == ' ') ++spaces;
else break;
}
for (int j = str.Length - 1; j > i; j--)
{
if (str[j] == ' ') ++spaces;
else break;
}
return spaces;
}
SizeF MeasureString(Graphics gfx, string str, Font font)
{
// these are the times you hate MS..
SizeF size = gfx.MeasureString(str, font,
new PointF(0.0f, 0.0f),
StringFormat.GenericTypographic);
if ((str.EndsWith(" ")||(str.StartsWith(" "))))
{
SizeF spacesize = gfx.MeasureString("! !", font,
new PointF(0.0f, 0.0f),
StringFormat.GenericTypographic);
SizeF spacesizemin = gfx.MeasureString("!!", font,
new PointF(0.0f, 0.0f),
StringFormat.GenericTypographic);
float spacewidth = spacesize.Width - spacesizemin.Width;
int spaces = CountTrailingSpaces(str);
size.Width += (spacewidth*(float)spaces);
}
return size;
}
![]()