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 » RichText,QTF,RTF... » Text wrapping in QTF Table
Text wrapping in QTF Table [message #56492] Fri, 19 March 2021 06:23 Go to next message
Pradip is currently offline  Pradip
Messages: 109
Registered: February 2019
Location: India
Experienced Member
Hi guys,

I'm trying to make a QTF table, and it's needed to have all rows with exactly same row height, without wrapping Strings in the cells but truncating and probably adding an ellipsis character. I found DrawTextEllipsis() routine but not sure how could I use it in QTF.

Any ideas?


Regards,
Pradip

[Updated on: Fri, 19 March 2021 06:23]

Report message to a moderator

Re: Text wrapping in QTF Table [message #56514 is a reply to message #56492] Sat, 20 March 2021 12:59 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Pradip wrote on Fri, 19 March 2021 06:23
Hi guys,

I'm trying to make a QTF table, and it's needed to have all rows with exactly same row height, without wrapping Strings in the cells but truncating and probably adding an ellipsis character. I found DrawTextEllipsis() routine but not sure how could I use it in QTF.

Any ideas?


You cannot use DrawTextEllipsis there.

This is though one. If I really needed this, I would probably:

- create temporary RichText just for testing with the cell of correct width and with intended font
- measure the height of text (with GetHeight)
- put the inteded text into this cell
- keep shortening the text until the height matches (you can use binary search to make this log(len(text)))
- use this shortened text in the real table.

Not very elegant, but not that hard to implement and should work...

Mirek
Re: Text wrapping in QTF Table [message #56529 is a reply to message #56514] Mon, 22 March 2021 06:38 Go to previous messageGo to next message
Pradip is currently offline  Pradip
Messages: 109
Registered: February 2019
Location: India
Experienced Member
Yesss, I had started working in that line! Thanks a lot Mirek!

I think you meant to measure the width, not height, with GetWidth(), I've seen this works! I'm planning to measure the width of the intended ellipsis character as well and shorten the text and add the ellipsis to fit in the cell width. It will suffice as long as it works, needn't be too elegant Very Happy

But how to implement the binary search with log(len(text)) (which I think will save few iterations)?


Regards,
Pradip
Re: Text wrapping in QTF Table [message #56530 is a reply to message #56529] Mon, 22 March 2021 07:58 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Pradip wrote on Mon, 22 March 2021 06:38
Yesss, I had started working in that line! Thanks a lot Mirek!

I think you meant to measure the width, not height, with GetWidth(), I've seen this works! I'm planning to measure the width of the intended ellipsis character as well and shorten the text and add the ellipsis to fit in the cell width. It will suffice as long as it works, needn't be too elegant Very Happy


I really meant Height. I guess width will work too, but maybe less reliably and more complicated.

Quote:

But how to implement the binary search with log(len(text)) (which I think will save few iterations)?


Think of it as function - the parameter is the number of characters you have to remove. This goes from 0 to len(text).

To maximize it, you start at len/2. If it fits, the correct number is in len/2, len range. If not, in 0 to len/2. Rinse and repeat...
Re: Text wrapping in QTF Table [message #56537 is a reply to message #56530] Tue, 23 March 2021 08:13 Go to previous messageGo to next message
Pradip is currently offline  Pradip
Messages: 109
Registered: February 2019
Location: India
Experienced Member
Yes, got your idea of checking the height. And the binary search would be very cool! For time being this code does the job for me:

void TrimQTFTextEllipsis(String& qtf, int width, const String& ellipsis) {
	String str = qtf;
	while(ParseQTF(qtf).GetWidth() > width) {
		str.TrimLast();
		qtf = str + ellipsis;
	}
}


It's not really elegant, will trim ending ']' from QTF if it's there, so that should be added after trimming. However with the width given correctly it works pretty good. Uploading image of output.

index.php?t=getfile&id=6395&private=0

Will try to implement the way you suggested when I can do some optimisation.


Regards,
Pradip
Re: Text wrapping in QTF Table [message #56538 is a reply to message #56537] Tue, 23 March 2021 08:53 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Pradip wrote on Tue, 23 March 2021 08:13
Yes, got your idea of checking the height. And the binary search would be very cool! For time being this code does the job for me:

void TrimQTFTextEllipsis(String& qtf, int width, const String& ellipsis) {
	String str = qtf;
	while(ParseQTF(qtf).GetWidth() > width) {
		str.TrimLast();
		qtf = str + ellipsis;
	}
}


It's not really elegant, will trim ending ']' from QTF if it's there, so that should be added after trimming. However with the width given correctly it works pretty good. Uploading image of output.

index.php?t=getfile&id=6395&private=0

Will try to implement the way you suggested when I can do some optimisation.


With GetHeight, you would not need to specify width...

Mirek
Re: Text wrapping in QTF Table [message #56544 is a reply to message #56538] Wed, 24 March 2021 05:39 Go to previous messageGo to next message
Pradip is currently offline  Pradip
Messages: 109
Registered: February 2019
Location: India
Experienced Member
Quote:
With GetHeight, you would not need to specify width...


Oh, sorry I don't know how to handle RichCell and RichText properly Embarassed
To create that test cell we would still need to know the correct width right?


Regards,
Pradip
Re: Text wrapping in QTF Table [message #56599 is a reply to message #56544] Sat, 27 March 2021 10:44 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Pradip wrote on Wed, 24 March 2021 05:39
Quote:
With GetHeight, you would not need to specify width...


Oh, sorry I don't know how to handle RichCell and RichText properly Embarassed
To create that test cell we would still need to know the correct width right?


If you put nothing into it, just empty paragraph with proper font set, it will give you the height you need.

(Although, this might not be guaranteed in the future. Today, single line / single font cell height only depends on the font set. It is possible that with advanced unicode support, we will need to adjust that for characters with multiple marking that will extend the height of individual characters...)
Previous Topic: search in Report
Next Topic: Bugfix: Report header/footer looks good in dark mode, not dark
Goto Forum:
  


Current Time: Thu Apr 25 01:20:11 CEST 2024

Total time taken to generate the page: 0.02979 seconds