Summary: | TextShape.resizeToFitText() Not Properly Sizing TextShape | ||
---|---|---|---|
Product: | POI | Reporter: | Nathan Mische <nmische> |
Component: | HSLF | Assignee: | POI Developers List <dev> |
Status: | RESOLVED FIXED | ||
Severity: | normal | ||
Priority: | P2 | ||
Version: | unspecified | ||
Target Milestone: | --- | ||
Hardware: | PC | ||
OS: | Windows Vista | ||
Bug Depends on: | 61169 | ||
Bug Blocks: | |||
Attachments: |
Patch for resizeToFitText
Text overflowing its textbox |
Thanks for the patch. It will be included in 3.1-final. Regards, Yegor Created attachment 35038 [details]
Text overflowing its textbox
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 Ah, it appears that the bug was initially fixed in the HSLF API and not in the XSLF API, which we are using... |
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.