Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to next message
Tom1
Messages: 659
Registered: March 2007
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 Go to previous messageGo to next message
Tom1
Messages: 659
Registered: March 2007
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 #47253 is a reply to message #47234] Sun, 01 January 2017 21:33 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12105
Registered: November 2005
Ultimate Member
The reason is that I wanted Text to render the vector shape that is in the font. Strikeout / Underline are not there...

Do you really need that for something?

Mirek
Re: Painter Text Underline/Strikeout not working [message #47263 is a reply to message #47253] Mon, 02 January 2017 09:28 Go to previous messageGo to next message
Tom1
Messages: 659
Registered: March 2007
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 Smile

Thanks and best regards,

Tom
Re: Painter Text Underline/Strikeout not working [message #47264 is a reply to message #47263] Mon, 02 January 2017 09:56 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12105
Registered: November 2005
Ultimate Member
OK, patch applied.

Mirek
Re: Painter Text Underline/Strikeout not working [message #47265 is a reply to message #47264] Mon, 02 January 2017 10:09 Go to previous messageGo to next message
Tom1
Messages: 659
Registered: March 2007
Contributor
Thanks Mirek!

// Tom
Re: Painter Text Underline/Strikeout not working [message #47285 is a reply to message #47265] Tue, 03 January 2017 09:12 Go to previous messageGo to next message
Tom1
Messages: 659
Registered: March 2007
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 Go to previous messageGo to next message
Tom1
Messages: 659
Registered: March 2007
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 #47436 is a reply to message #47435] Mon, 16 January 2017 11:19 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12105
Registered: November 2005
Ultimate Member
Thanks, applied
Re: Painter Text Underline/Strikeout not working [message #47442 is a reply to message #47436] Tue, 17 January 2017 09:20 Go to previous messageGo to next message
Tom1
Messages: 659
Registered: March 2007
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 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12105
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 Go to previous messageGo to next message
Tom1
Messages: 659
Registered: March 2007
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
Re: Painter Text Underline/Strikeout not working [message #47448 is a reply to message #47446] Tue, 17 January 2017 16:09 Go to previous message
mirek is currently offline  mirek
Messages: 12105
Registered: November 2005
Ultimate Member
Tom1 wrote on Tue, 17 January 2017 10:55
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


OK, max it is then...

Mirek
Previous Topic: Assertion fails in BufferPainter::TransformOp() with rotated text
Next Topic: Painter Fill with Image MSC14x64 performance issue
Goto Forum:
  


Current Time: Sun Nov 17 11:49:21 CET 2019

Total time taken to generate the page: 0.01470 seconds