Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Best fit font size on zoom level (Read 410 times)
Gaurav Dubey
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 9
Joined: Sep 28th, 2016
Best fit font size on zoom level
Jun 25th, 2021 at 2:26pm
Print Post  
We are using shape nodes to display components. We are showing short and long labels depends on zoom level(below 25 percent short label and above 25 percent long labels).
However in some zoom level shape node gets blank and shows empty box. We have identified the reason and decreasing font size solved the problem.

However this is not generic solution, and if text length shown in shape node varies same problem occurs again.

Is there any algorithm/solution which will ensure that text in shape node will display no matter what the text size? We are using styled text with following settings

         node.getTextFormat().setNoWrap( false);
         node.getTextFormat().setHorizontalAlign( Align.Near);
         node.getTextFormat().setVerticalAlign( Align.Near);

Thanks in advance
  

issue.png ( 19 KB | 7 Downloads )
issue.png
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 2532
Joined: Oct 19th, 2005
Re: Best fit font size on zoom level
Reply #1 - Jun 28th, 2021 at 7:59am
Print Post  
Text does not scale perfectly along with zoom factor due to how OS font renderers work, e.g. switching to a different set of glyphs when font size changes (absolute size that's also multiplied by current scale). You could call TextFormat.setWrapAtCharacter(true) to allow wrapping the long first word from your image to a new line. Otherwise the text renderer stops when only allowed to wrap at word boundaries and it can't fit current word. You could also try calling resizeToFitText on a hidden clone of the node to see if text fits with current font size, and reduce the font size of the original node if necessary until text starts fitting.

Regards,
Slavcho
Mindfusion
« Last Edit: Jun 28th, 2021 at 11:25am by Slavcho »  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 2532
Joined: Oct 19th, 2005
Re: Best fit font size on zoom level
Reply #2 - Jul 1st, 2021 at 10:29am
Print Post  
Our developer's improved text rendering here, in case you prefer not to use the WrapAtCharacter option -
https://mindfusion.eu/_beta/jdiag46.zip

Now if a text line can't fit a single word, it is drawn clipped instead of stopping rendering there. In addition, a new WrapOverflowingSingleWordLines property lets you wrap only such long words, but otherwise keep wrapping lines only at word boundaries.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint