]> source.dussan.org Git - poi.git/commitdiff
#65228 - the method getCap() does not work correctly in xslf.usermodel.XSLFTextRun
authorAndreas Beeker <kiwiwings@apache.org>
Thu, 22 Apr 2021 22:09:14 +0000 (22:09 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Thu, 22 Apr 2021 22:09:14 +0000 (22:09 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1889111 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/main/java/org/apache/poi/xslf/model/CharacterPropertyFetcher.java
poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFBugs.java
poi/src/main/java/org/apache/poi/sl/image/ImageHeaderEMF.java
test-data/slideshow/bug65228.pptx [new file with mode: 0644]

index beb8c5a431145371fc3978e25295c24eea9e15b1..0ad4ef8743978bf6539bbf0fea72d9c4b60b27f8 100644 (file)
@@ -65,6 +65,7 @@ public final class CharacterPropertyFetcher<T> extends PropertyFetcher<T> {
 
         if (!(sheet instanceof XSLFSlideMaster)) {
             fetchRunProp();
+            fetchParagraphDefaultRunProp();
             fetchShapeProp(shape);
             fetchThemeProp(shape);
         }
@@ -78,6 +79,15 @@ public final class CharacterPropertyFetcher<T> extends PropertyFetcher<T> {
         fetchProp(run.getRPr(false));
     }
 
+    private void fetchParagraphDefaultRunProp() {
+        if (!isSet()) {
+            CTTextParagraphProperties pr = run.getParagraph().getXmlObject().getPPr();
+            if (pr != null) {
+                fetchProp(pr.getDefRPr());
+            }
+        }
+    }
+
     private void fetchShapeProp(XSLFShape shape) {
         if (!isSet()) {
             shape.fetchShapeProperty(this);
index acbf365046740b7ece4329024e26bb0f297b21bf..08250192acfd6e11c610838737bb99830e260bc9 100644 (file)
@@ -77,25 +77,7 @@ import org.apache.poi.sl.usermodel.TextShape;
 import org.apache.poi.sl.usermodel.VerticalAlignment;
 import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.NullPrintStream;
-import org.apache.poi.xslf.usermodel.XMLSlideShow;
-import org.apache.poi.xslf.usermodel.XSLFAutoShape;
-import org.apache.poi.xslf.usermodel.XSLFGroupShape;
-import org.apache.poi.xslf.usermodel.XSLFHyperlink;
-import org.apache.poi.xslf.usermodel.XSLFNotes;
-import org.apache.poi.xslf.usermodel.XSLFObjectShape;
-import org.apache.poi.xslf.usermodel.XSLFPictureData;
-import org.apache.poi.xslf.usermodel.XSLFPictureShape;
-import org.apache.poi.xslf.usermodel.XSLFRelation;
-import org.apache.poi.xslf.usermodel.XSLFShape;
-import org.apache.poi.xslf.usermodel.XSLFSlide;
-import org.apache.poi.xslf.usermodel.XSLFSlideLayout;
-import org.apache.poi.xslf.usermodel.XSLFSlideMaster;
-import org.apache.poi.xslf.usermodel.XSLFTable;
-import org.apache.poi.xslf.usermodel.XSLFTableCell;
-import org.apache.poi.xslf.usermodel.XSLFTableRow;
-import org.apache.poi.xslf.usermodel.XSLFTextBox;
-import org.apache.poi.xslf.usermodel.XSLFTextParagraph;
-import org.apache.poi.xslf.usermodel.XSLFTextRun;
+import org.apache.poi.xslf.usermodel.*;
 import org.apache.poi.xslf.util.DummyGraphics2d;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Disabled;
@@ -1080,4 +1062,18 @@ class TestXSLFBugs {
         }
     }
 
+    @Test
+    public void bug65228() throws IOException {
+        try (XMLSlideShow ppt = openSampleDocument("bug65228.pptx")) {
+            TextRun.TextCap act = ppt.getSlides().stream()
+                .flatMap(s -> s.getShapes().stream())
+                .filter(s -> "März 2021\u2026".equals(s.getShapeName()))
+                .map(XSLFTextShape.class::cast)
+                .flatMap(s -> s.getTextParagraphs().stream())
+                .flatMap(s -> s.getTextRuns().stream())
+                .map(XSLFTextRun::getTextCap)
+                .findFirst().orElse(null);
+            assertEquals(TextRun.TextCap.ALL, act);
+        }
+    }
 }
index 6dd5faf44056f548c801a2daa8a3bbf9b9b888f7..646c88eb9def336c8962b033139b8c63bcc02be7 100644 (file)
@@ -50,7 +50,7 @@ public class ImageHeaderEMF {
         int top = LittleEndian.getInt(data, offset); offset += 4;
         int right = LittleEndian.getInt(data, offset); offset += 4;
         int bottom = LittleEndian.getInt(data, offset); offset += 4;
-        deviceBounds = new Rectangle(left, top, right-left, bottom-top);
+        deviceBounds = new Rectangle(left, top,  right-left == -1 ? 0 : right-left, bottom-top == -1 ? 0 : bottom-top);
         // ignore frame bounds
         offset += 16;
         String signature = new String(data, offset, EMF_SIGNATURE.length(), LocaleUtil.CHARSET_1252);
diff --git a/test-data/slideshow/bug65228.pptx b/test-data/slideshow/bug65228.pptx
new file mode 100644 (file)
index 0000000..e7de0c0
Binary files /dev/null and b/test-data/slideshow/bug65228.pptx differ