Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » Painter Text Underline/Strikeout not working
Painter Text Underline/Strikeout not working [message #47233] |
Fri, 30 December 2016 10:18 |
Tom1
Messages: 1242 Registered: March 2007
|
Senior Contributor |
|
|
Hi Mirek,
Underline and Strikeout font features do not work with Painter::Text(). I found that Painter::DrawTextOp() adds these features after calling Text() to support these.
While I need the path of the text, I can't use DrawTextOp.
Is there any reason to not move the Underline/Strikeout code from DrawTextOp() to Text() to fully support the selected font features?
Best regards,
Tom
|
|
|
Re: Painter Text Underline/Strikeout not working [message #47234 is a reply to message #47233] |
Fri, 30 December 2016 11:05 |
Tom1
Messages: 1242 Registered: March 2007
|
Senior Contributor |
|
|
Hi,
In fact, as far as I can see, it only requires this addition in Painter.cpp in the end of Painter::TextOp():
if(fnt.IsUnderline()||fnt.IsStrikeout()) {
int a = fnt.GetAscent();
int cy = max(a / 16, 1);
if(fnt.IsUnderline()) Rectangle(0, a + cy, x, cy);
if(fnt.IsStrikeout()) Rectangle(0, 2 * a / 3, x, cy);
}
And removal of this in DrawOp.cpp from Painter::DrawTextOp():
/* if(font.IsUnderline()) {
if(IsNull(cx))
cx = GetTextSize(text, font).cx;
int a = font.GetAscent();
int cy = max(a / 16, 1);
Rectangle(0, a + cy, cx, cy);
Fill(ink);
}
if(font.IsStrikeout()) {
if(IsNull(cx))
cx = GetTextSize(text, font).cx;
int a = font.GetAscent();
int cy = max(a / 16, 1);
Rectangle(0, 2 * a / 3, cx, cy);
Fill(ink);
}
*/
Can you merge this change?
Best regards,
Tom
|
|
|
|
Re: Painter Text Underline/Strikeout not working [message #47263 is a reply to message #47253] |
Mon, 02 January 2017 09:28 |
Tom1
Messages: 1242 Registered: March 2007
|
Senior Contributor |
|
|
Hi Mirek,
In fact I do need it: When rendering maps, I use underlining for marking text objects selected for editing or processing. Additionally, I plan to use strikeout for marking text objects that are selected for deletion.
Logically, I think while underline/strikeout are not part of Character(), they still are part of Text(). After all, these are valid Font properties and the most logical and efficient location for rendering them is right there in Text(). They should not hurt anybody not using them at the cost of one if statement. Strikeout/Underline are disabled by default and only voluntarily enabled in a Font.
If this cannot be included, I can of course use external code for the purpose (similar to what is found in DrawTextOp()), which is a bit slower since it needs to calculate the width of the string redundantly.
You choose
Thanks and best regards,
Tom
|
|
|
|
|
Re: Painter Text Underline/Strikeout not working [message #47285 is a reply to message #47265] |
Tue, 03 January 2017 09:12 |
Tom1
Messages: 1242 Registered: March 2007
|
Senior Contributor |
|
|
Hi Mirek,
One more thing. I noticed that "int cx = Null;" and all references to cx can now be removed from the Painter/DrawOp.cpp Painter::DrawTextOp() to further optimize the code. Sorry for waking up late on this.
Thanks and best regards,
Tom
|
|
|
Re: Painter Text Underline/Strikeout not working [message #47435 is a reply to message #47285] |
Mon, 16 January 2017 10:38 |
Tom1
Messages: 1242 Registered: March 2007
|
Senior Contributor |
|
|
Hi,
Here's one more fix for the Painter::TextOp() in Painter.cpp:
void Painter::TextOp(const Pointf& p, const wchar *text, Font fnt, int n, const double *dx)
{
if(n == 0) {
Move(0, 0);
return;
}
FontInfo fi = fnt.Info();
double x = p.x;
while(n) {
int ch = *text++;
Character(x, p.y, ch, fnt);
Div();
if(dx)
x += *dx++;
else
x += fi[ch];
n--;
}
if(fnt.IsUnderline() || fnt.IsStrikeout()) {
int a = fnt.GetAscent();
int cy = max(a / 16, 1);
if(fnt.IsUnderline())
Rectangle(p.x, p.y + a + cy, x, cy);
if(fnt.IsStrikeout())
Rectangle(p.x, p.y + 2 * a / 3, x, cy);
}
}
The underline and strikeout did not follow the Pointf &p parameter, which they obviously should have. This is fixed now above. Please commit.
Best regards,
Tom
|
|
|
|
Re: Painter Text Underline/Strikeout not working [message #47442 is a reply to message #47436] |
Tue, 17 January 2017 09:20 |
Tom1
Messages: 1242 Registered: March 2007
|
Senior Contributor |
|
|
Hi Mirek,
Sorry to waste your time with stupid mistakes I make. I sincerely hope this is my final update for Painter.cpp Painter::TextOp() :
...
if(fnt.IsUnderline() || fnt.IsStrikeout()) {
int a = fnt.GetAscent();
int cy = max(a / 16, 1);
int cx = x - p.x;
if(fnt.IsUnderline())
Rectangle(p.x, p.y + a + cy, cx, cy);
if(fnt.IsStrikeout())
Rectangle(p.x, p.y + 2 * a / 3, cx, cy);
}
Thanks and best regards,
Tom
|
|
|
Re: Painter Text Underline/Strikeout not working [message #47445 is a reply to message #47442] |
Tue, 17 January 2017 09:38 |
|
mirek
Messages: 14039 Registered: November 2005
|
Ultimate Member |
|
|
Missed that one. However, looking at the code (and compiler warnings), should not these 'int's be really 'double's?
if(fnt.IsUnderline() || fnt.IsStrikeout()) {
double a = fnt.GetAscent();
double cy = max(a / 16, 1.0);
double cx = x - p.x;
if(fnt.IsUnderline())
Rectangle(p.x, p.y + a + cy, cx, cy);
if(fnt.IsStrikeout())
Rectangle(p.x, p.y + 2 * a / 3, cx, cy);
}
Maybe even that 'max' is not really needed...
(Commiting with doubles, for now)
|
|
|
Re: Painter Text Underline/Strikeout not working [message #47446 is a reply to message #47445] |
Tue, 17 January 2017 10:55 |
Tom1
Messages: 1242 Registered: March 2007
|
Senior Contributor |
|
|
I agree, double is better than int. Also, cy looks just fine at a/16 without max(). However, if MODE_NOAA is used, using max() would seem reasonable to guarantee visibility of underline/strikeout for small font sizes. Otherwise, they may just disappear at e.g. 10 pts font size.
Best regards,
Tom
|
|
|
|
Goto Forum:
Current Time: Fri Sep 20 19:25:13 CEST 2024
Total time taken to generate the page: 0.03438 seconds
|