Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to determine text fitment value (Read 1470 times)
Bala
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 156
Joined: Apr 21st, 2009
How to determine text fitment value
Jul 18th, 2011 at 1:48pm
Print Post  
Hi,

We create some nodes with fonsize 12 and with a particular shape and textarea - our objective is to try to fit large node text in area by decreasing fontsize 1 at a time till the fontsize reaches 9 for this we have written some code and which is working fine,

however, in the code we have arrived to one condition where we check height of string with a constant (which is 15 in our case) - we could get to this constant value using trial and error - and we saw that this varies as node fontsize changes but we do not know the exact relation.

We are also sharing the corresponding sample - which have two nodes - one is having large text and which gets fit using method FitTextInTextArea() - please see the comments in this function.

Please help us in eliminating this constant hardcoded value (15 in this case) and suggest on how we can calculate this.

Thanks in advance,
Bala
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: How to determine text fitment value
Reply #1 - Jul 19th, 2011 at 6:24am
Print Post  
In your sample TEXTWIDTH specifies a value relative (expressed as percentage) to the current width of the node. Therefore you cannot use it directly for measurement. Here is the code that works without the need of hardcoded values:

Code
Select All
double textAreaWidth = node.Bounds.Width * TEXTWIDTH / 100;
double textAreaHeight = node.Bounds.Height * TEXTHEIGHT / 100;
Size size = diagram.MeasureString(node.Text, node, (int)textAreaWidth);
if (size.Height > textAreaHeight)
{
      node.FontSize -= 1;
      node.Repaint(false);
}
else
{
      isGotFit = true;
} 


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