Bug 45140 - TextShape.resizeToFitText() Not Properly Sizing TextShape
Summary: TextShape.resizeToFitText() Not Properly Sizing TextShape
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSLF (show other bugs)
Version: unspecified
Hardware: PC Windows Vista
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on: 61169
Blocks:
  Show dependency tree
 
Reported: 2008-06-05 07:42 UTC by Nathan Mische
Modified: 2017-06-24 08:52 UTC (History)
0 users



Attachments
Patch for resizeToFitText (2.08 KB, patch)
2008-06-05 07:42 UTC, Nathan Mische
Details | Diff
Text overflowing its textbox (4.54 KB, image/png)
2017-06-08 14:52 UTC, François Beaune
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nathan Mische 2008-06-05 07:42:59 UTC
Created attachment 22081 [details]
Patch for resizeToFitText

TextShape.resizeToFitText() does not appear to properly size the TextShape. Take for example the following code:

SlideShow ppt = new SlideShow();
Slide slide = ppt.createSlide();
TextBox title = slide.addTitle();
title.setText("Title Line One\nTitle Line Two");
title.resizeToFitText();
	    
//save changes 
FileOutputStream out = new FileOutputStream("test.ppt");
ppt.write(out);
out.close();

The title TextBox created by this example is much wider than the text and is only the height of a single line, although the title has multiple lines of text. 

From my investigation there appear to be two issues with the size calculation. 

First, the text doesn't seem to properly split into lines. The existing code attempts to split on \r but I've found it needs to split on \n.

Second, the TextShape height is set to the highest line, not the cumulative height of all of the lines.

I've attached a patch which in my testing seems to do a better job at sizing the TextShape.
Comment 1 Yegor Kozlov 2008-06-05 09:16:08 UTC
Thanks for the patch. It will be included in 3.1-final.

Regards,
Yegor
Comment 2 Yegor Kozlov 2008-06-08 05:32:56 UTC
Patch applied in r664492. Thanks.

Yegor
Comment 3 François Beaune 2017-06-08 14:52:14 UTC
Created attachment 35038 [details]
Text overflowing its textbox
Comment 4 François Beaune 2017-06-08 14:52:56 UTC
It looks like this no longer works properly.

The following code results in the text overflowing the textbox:

XSLFTextBox textBox = slide.createTextBox();
XSLFTextParagraph paragraph = textBox.getTextParagraphs().get(0);
XSLFTextRun textRun = paragraph.addNewTextRun();
textRun.setText("TRENDALERT | Summer trends for men.\n T-shirts and shirts with tropical prints. Bomberjacks are still a musthave.");
textBox.setAnchor(new Rectangle(left, top, width, 10000));
textBox.resizeToFitText();

I've attached a screenshot of the text overflowing the textbox in PowerPoint 2016: https://bz.apache.org/bugzilla/attachment.cgi?id=35038
Comment 5 François Beaune 2017-06-08 15:42:43 UTC
Ah, it appears that the bug was initially fixed in the HSLF API and not in the XSLF API, which we are using...