Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » Painter small text quality
Painter small text quality [message #39752] |
Tue, 23 April 2013 12:37 |
|
koldo
Messages: 3398 Registered: August 2008
|
Senior Veteran |
|
|
Hello all
I would like to improve text quality using Painter for small texts.
In the image it is the same screen with Draw and Painter. The small texts in the X axis (Jan, Feb, Mar, ...) look better with Draw.
This is the code for both:
void DrawText(Draw &w, double x, double y, int angle, const String &text, Font font, Color color) {
w.DrawText(fround(x), fround(y), angle, text, font, color);
}
void DrawText(Painter &w, double x, double y, int angle, const String &text, Font font, Color color) {
w.Begin();
w.Translate(x, y).Rotate(-angle*M_PI/1800.);
w.Text(0, 0, text, font).Fill(color);
w.End();
}
Do you know how to improve the quality?
-
Attachment: Painter.png
(Size: 142.96KB, Downloaded 659 times)
Best regards
Iñaki
|
|
|
Re: Painter small text quality [message #39756 is a reply to message #39752] |
Tue, 23 April 2013 19:01 |
|
Hi Koldo,
Small fonts always look ugly when they're anti-aliased. I'd suggest to round the values for the painter variant as well, it can make a huge difference:
This preview was generated using this code:void TextTest(Painter& sw) {
sw.DrawText(10,100, "Hello world! // DrawText()", Roman(12), Black());
for(int i=0; i<=5; ++i)
sw.Text(10+0.2*i, 120+i*20, Format("Hello world! // Text() shifted %2vf pixel left",i*0.2), Roman(12))
.Fill(Black());
for(int i=0; i<=5; ++i)
sw.Text(300, 120+i*20.2, Format("Hello world! // Text() shifted %2vf pixel down",i*0.2), Roman(12))
.Fill(Black());
}
Also, you're pictures seem like there are errors in the letter spacing. Not sure where that comes from, I couldn't reproduce it on my system... I think you can safely use DrawText() everywhere, or do some compromise, e.g.void DrawText(Painter &w, double x, double y, int angle, const String &text, Font font, Color color) {
if(font.GetHeight()>15) {
w.Begin();
w.Translate(x, y).Rotate(-angle*M_PI/1800.);
w.Text(0, 0, text, font).Fill(color);
w.End();
} else
w.DrawText(fround(x), fround(y), angle, text, font, color);
}
Best regards,
Honza
EDIT: Corrected image and code
-
Attachment: text.png
(Size: 24.82KB, Downloaded 634 times)
[Updated on: Tue, 23 April 2013 20:18] Report message to a moderator
|
|
|
|
|
|
Goto Forum:
Current Time: Thu Oct 31 23:56:07 CET 2024
Total time taken to generate the page: 0.00630 seconds
|