From ef049ea258d029ea6730dfcea032993bdfe8aa65 Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Sat, 19 Nov 2011 12:28:33 +0000 Subject: [PATCH] Bugzilla 52209: fixed inserting multiple pictures to a group or slide in XSLF git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1203969 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 1 + .../apache/poi/xslf/usermodel/XMLSlideShow.java | 2 +- .../apache/poi/xslf/usermodel/XSLFGroupShape.java | 8 ++++++-- .../org/apache/poi/xslf/usermodel/XSLFSheet.java | 8 ++++++-- .../poi/xslf/usermodel/XSLFTextParagraph.java | 14 +++++++++----- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index ace9d11642..4741a2e341 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 52209 - fixed inserting multiple pictures in XSLF 51803 - fixed HSLF TextExtractor to extract content from master slide 52190 - null check on XWPF setFontFamily 52062 - ensure that temporary files in SXSSF are deleted diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java index efec667a93..9de0c7493a 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java @@ -338,7 +338,7 @@ public class XMLSlideShow extends POIXMLDocument { public int addPicture(byte[] pictureData, int format) { getAllPictures(); - int imageNumber = getPackage().getPartsByName(Pattern.compile("/ppt/media/.*?")).size() + 1; + int imageNumber = _pictures.size() + 1; XSLFPictureData img = (XSLFPictureData) createRelationship( XSLFPictureData.RELATIONS[format], XSLFFactory.getInstance(), imageNumber, true); _pictures.add(img); diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java index 85b426ef92..7993f11dda 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java @@ -227,9 +227,13 @@ public class XSLFGroupShape extends XSLFShape { public XSLFPictureShape createPicture(int pictureIndex){ List pics = _sheet.getPackagePart().getPackage() - .getPartsByName(Pattern.compile("/ppt/media/.*?")); + .getPartsByName(Pattern.compile("/ppt/media/image" + (pictureIndex + 1) + ".*?")); - PackagePart pic = pics.get(pictureIndex); + if(pics.size() == 0) { + throw new IllegalArgumentException("Picture with index=" + pictureIndex + " was not found"); + } + + PackagePart pic = pics.get(0); PackageRelationship rel = _sheet.getPackagePart().addRelationship( pic.getPartName(), TargetMode.INTERNAL, XSLFRelation.IMAGES.getRelation()); diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java index a5baed5312..8a74e2d0f6 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java @@ -172,9 +172,13 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements Iterable pics = getPackagePart().getPackage() - .getPartsByName(Pattern.compile("/ppt/media/.*?")); + .getPartsByName(Pattern.compile("/ppt/media/image" + (pictureIndex + 1) + ".*?")); - PackagePart pic = pics.get(pictureIndex); + if(pics.size() == 0) { + throw new IllegalArgumentException("Picture with index=" + pictureIndex + " was not found"); + } + + PackagePart pic = pics.get(0); PackageRelationship rel = getPackagePart().addRelationship( pic.getPartName(), TargetMode.INTERNAL, XSLFRelation.IMAGES.getRelation()); diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java index a0a5c73fda..dcca92fbf9 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java @@ -841,18 +841,22 @@ public class XSLFTextParagraph implements Iterable{ layout = measurer.nextLayout((float)wrappingWidth, nextBreak, false); } + if(layout == null) { + // exit if can't break any more + break; + } + int endIndex = measurer.getPosition(); + // skip over new line breaks (we paint 'clear' text runs not starting or ending with \n) + if(endIndex < it.getEndIndex() && text.charAt(endIndex) == '\n'){ + measurer.setPosition(endIndex + 1); + } TextAlign hAlign = getTextAlign(); if(hAlign == TextAlign.JUSTIFY || hAlign == TextAlign.JUSTIFY_LOW) { layout = layout.getJustifiedLayout((float)wrappingWidth); } - // skip over new line breaks (we paint 'clear' text runs not starting or ending with \n) - if(endIndex < it.getEndIndex() && text.charAt(endIndex) == '\n'){ - measurer.setPosition(endIndex + 1); - } - AttributedString str = new AttributedString(it, startIndex, endIndex); TextFragment line = new TextFragment( layout, // we will not paint empty paragraphs