Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Text that goes over the shape boundaries (Read 6065 times)
Patrick Guerin
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 21
Joined: Dec 11th, 2014
Text that goes over the shape boundaries
Mar 3rd, 2015 at 8:09pm
Print Post  
Could it be possible to have shapes which have text so long that it goes over the shape boundaries ?

Second question for text, is there a way to wrap the text inside a shape at "spaces" instead of cutting words in half.

Thanks
  

Text_outside_shape.PNG ( 54 KB | 191 Downloads )
Text_outside_shape.PNG
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Text that goes over the shape boundaries
Reply #1 - Mar 4th, 2015 at 8:41am
Print Post  
This looks as in the 'want' image:

Code
Select All
Shape decision = Shape.fromId("Decision");
decision.setTextArea(Shape.fromId("Rectangle").getOutline());

shapeNode.setShape(decision);
shapeNode.setText("Could it be possible to have shapes which have text so long that it goes over the shape boundaries ?");
shapeNode.setTextFormat(new TextFormat(Align.Center, Align.Center));
shapeNode.getTextFormat().setWrapAtCharacter(false); 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Patrick Guerin
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 21
Joined: Dec 11th, 2014
Re: Text that goes over the shape boundaries
Reply #2 - Mar 4th, 2015 at 2:37pm
Print Post  
Yes, it's work perfectly.   Smiley

One more question, is there a way to change the textArea size ?  (We want to know if it's possible to get a greater rectangle). 

And in case of very very long text, is there a kind of function like "ShapeNode.resizeTextToFitShape()" ?
Actually, the only function available is ShapeNode.resizeToFitText(fit).  But we don't want to resize the shape of the node to the matched text lenght, but the size of the text inside the TextArea (Fixed size of the TextArea.

Thanks for your great help !
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Text that goes over the shape boundaries
Reply #3 - Mar 4th, 2015 at 5:04pm
Print Post  
Shape geometry coordinates are specified as percentage of node size, so this will make the text area twice larger that the node:

Code
Select All
Shape decision = Shape.fromId("Decision");
decision.setTextArea(new ElementTemplate[] {
	new LineTemplate(-50, -50, 150, -50),
	new LineTemplate(150, -50, 150, 150),
	new LineTemplate(150, 150, -50, 150),
	new LineTemplate(-50, 150, -50, -50)
}); 



Quote:
is there a kind of function like "ShapeNode.resizeTextToFitShape()" ?


Do you mean changing the font size so that text fits inside current shape?
  
Back to top
 
IP Logged
 
Patrick Guerin
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 21
Joined: Dec 11th, 2014
Re: Text that goes over the shape boundaries
Reply #4 - Mar 4th, 2015 at 5:12pm
Print Post  
Yes, exactly, but, we don't want to use try/error value until we get the right font size to fit the text into the TextArea location.  We want to get the "proportional" font size to be able to fit all text into the TextArea location.

Thanks for your help.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Text that goes over the shape boundaries
Reply #5 - Mar 5th, 2015 at 11:09am
Print Post  
I don't think there is linear proportionality between the font size and text layout size, mostly because of how line breaks would change positions, but possibly including other minor peculiarities of font rendering such as kerning.

You might try measuring with proportional font size only as a starting point, but then would still need to do a few tries to make sure text fits. E.g. try something like this:

Code
Select All
// assuming rectangular shape
void fitText(ShapeNode node)
{
	Rectangle2D.Float nodeRect = node.getBounds();
	double nodeArea = nodeRect.width * nodeRect.height;
	Font font = node.getEffectiveFont();

	float paddingWidth = 2, paddingHeight = 2;
	Thickness padding = node.getTextPadding();
	if (padding != null)
	{
		paddingWidth = padding.getLeft() + padding.getRight();
		paddingHeight = padding.getTop() + padding.getBottom();
	}

	Dimension2D textSize = TextRenderer.measureText(
		node.getText(), nodeRect.width - paddingWidth, font);
	double textArea = textSize.getWidth() * (textSize.getHeight() + paddingHeight);
	while (textArea > nodeArea)
	{
		// due to changing line break positions, text area might not be strictly decreasing function?
		// make sure font size always decreases to avoid infinite loop
		double newSize = font.getSize2D() / Math.sqrt(textArea / nodeArea);
		newSize = Math.min(newSize, font.getSize2D() - 1);

		font = font.deriveFont((float)newSize);
		node.setFont(font);

		textSize = TextRenderer.measureText(
			node.getText(), nodeRect.width - paddingWidth, font);
		textArea = textSize.getWidth() * (textSize.getHeight() + paddingHeight);
	}
} 



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