Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Shrink text on overflow - Feature request? (Read 1601 times)
jf2020
Junior Member
**
Offline


I love FlowChart!

Posts: 63
Joined: Feb 23rd, 2006
Shrink text on overflow - Feature request?
Jul 1st, 2012 at 8:17am
Print Post  
Hi,

I'm trying to implement the PowerPoint shrink text on overflow feature, so that if the text is too long to fit in a node, the font size is reduced untill it fits. I'm somehow fighting with string.measureText, but I'm not getting there. What would be the best way to implement that? Also I think that it would be nice if you could consider adding such a feature in the next version.

Jean-Francois
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Shrink text on overflow - Feature request?
Reply #1 - Jul 2nd, 2012 at 12:40pm
Print Post  
Hi,

You could measure text using the ResizeToFitText method of a temporary node; this will accommodate for the node's shape and text margins, which are not taken into account by Diagram.MeasureString:

Code
Select All
private void diagram_NodeModified(object sender, NodeEventArgs e)
{
	if (e.Node is ShapeNode)
		ShrinkTextToFit(e.Node as ShapeNode);
}

private void ShrinkTextToFit(ShapeNode node)
{
	ShapeNode temp = new ShapeNode(node);
	temp.ResizeToFitText(FitSize.KeepWidth);
	if (temp.Bounds.Height <= node.Bounds.Height)
		return;	// text already fits

	float originalHeight = node.Bounds.Height;
	do
	{
		// assuming original font size in points
		temp.Font = new Font(temp.Font.FontFamily,
			temp.Font.Size - 1, GraphicsUnit.Point);
		temp.ResizeToFitText(FitSize.KeepWidth);
	}
	while (temp.Bounds.Height > originalHeight);

	node.Font = temp.Font;
}
 



You might want to add some code to enforce a minimum font size, so that the text remains legible.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint