mirror of https://github.com/apache/poi.git
Bug 63290: retrieve default run properties from paragraph
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1878147 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6126c3d24c
commit
8cbc3703c3
|
@ -612,7 +612,8 @@ public class XDDFTextRun {
|
||||||
} else if (isRegularRun() && _rtr.isSetRPr()) {
|
} else if (isRegularRun() && _rtr.isSetRPr()) {
|
||||||
return _rtr.getRPr();
|
return _rtr.getRPr();
|
||||||
}
|
}
|
||||||
return null;
|
XDDFRunProperties defaultProperties = _parent.getDefaultRunProperties();
|
||||||
|
return (defaultProperties == null) ? null : defaultProperties.getXmlObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
private XDDFRunProperties getOrCreateProperties() {
|
private XDDFRunProperties getOrCreateProperties() {
|
||||||
|
|
|
@ -492,6 +492,9 @@ public class XSLFTextRun implements TextRun {
|
||||||
return tr.addNewRPr();
|
return tr.addNewRPr();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (_p.getXmlObject().isSetPPr() && _p.getXmlObject().getPPr().isSetDefRPr()) {
|
||||||
|
return _p.getXmlObject().getPPr().getDefRPr();
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,16 +18,22 @@ package org.apache.poi.xddf.usermodel.text;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.util.LocaleUtil;
|
import org.apache.poi.util.LocaleUtil;
|
||||||
import org.apache.poi.xslf.usermodel.XMLSlideShow;
|
import org.apache.poi.xslf.usermodel.XMLSlideShow;
|
||||||
|
import org.apache.poi.xslf.usermodel.XSLFShape;
|
||||||
import org.apache.poi.xslf.usermodel.XSLFSlide;
|
import org.apache.poi.xslf.usermodel.XSLFSlide;
|
||||||
|
import org.apache.poi.xslf.usermodel.XSLFTextParagraph;
|
||||||
|
import org.apache.poi.xslf.usermodel.XSLFTextRun;
|
||||||
import org.apache.poi.xslf.usermodel.XSLFTextShape;
|
import org.apache.poi.xslf.usermodel.XSLFTextShape;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
|
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFDrawing;
|
import org.apache.poi.xssf.usermodel.XSSFDrawing;
|
||||||
|
@ -133,4 +139,29 @@ public class TestXDDFTextRun {
|
||||||
assertNotNull(run.getText());
|
assertNotNull(run.getText());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDefaultRunProperties() throws IOException {
|
||||||
|
// bug #63290
|
||||||
|
POIDataSamples pds = POIDataSamples.getSlideShowInstance();
|
||||||
|
try (InputStream is = pds.openResourceAsStream("bug63290.pptx");
|
||||||
|
XMLSlideShow ppt = new XMLSlideShow(is)) {
|
||||||
|
XSLFSlide slide = ppt.getSlides().get(0);
|
||||||
|
for (XSLFShape shape : slide.getShapes()) {
|
||||||
|
if (shape instanceof XSLFTextShape) {
|
||||||
|
XSLFTextShape text = (XSLFTextShape) shape;
|
||||||
|
XDDFTextParagraph paragraph = text.getTextBody().getParagraph(0);
|
||||||
|
XDDFTextRun defaultRun = paragraph.getTextRuns().get(0);
|
||||||
|
assertEquals("DefaultRunProperties", defaultRun.getText().trim());
|
||||||
|
XDDFTextRun explicitRun = paragraph.getTextRuns().get(1);
|
||||||
|
assertEquals("ExplicitRunProperties", explicitRun.getText().trim());
|
||||||
|
assertEquals(defaultRun.getDirty(), explicitRun.getDirty());
|
||||||
|
assertEquals(defaultRun.getFontSize(), explicitRun.getFontSize());
|
||||||
|
assertEquals(defaultRun.getLanguage(), explicitRun.getLanguage());
|
||||||
|
assertEquals(defaultRun.getSpellError(), explicitRun.getSpellError());
|
||||||
|
assertNotEquals(defaultRun.getFontColor(), explicitRun.getFontColor());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,11 +21,15 @@ package org.apache.poi.xslf.usermodel;
|
||||||
import static org.apache.poi.sl.TestCommonSL.getColor;
|
import static org.apache.poi.sl.TestCommonSL.getColor;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import org.apache.poi.POIDataSamples;
|
||||||
|
import org.apache.poi.ooxml.POIXMLDocumentPart;
|
||||||
import org.apache.poi.sl.draw.DrawTextParagraph;
|
import org.apache.poi.sl.draw.DrawTextParagraph;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextLineBreak;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextLineBreak;
|
||||||
|
@ -118,4 +122,27 @@ public class TestXSLFTextRun {
|
||||||
|
|
||||||
r.copy(s);
|
r.copy(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDefaultRunProperties() throws IOException {
|
||||||
|
// bug #63290
|
||||||
|
POIDataSamples pds = POIDataSamples.getSlideShowInstance();
|
||||||
|
try (InputStream is = pds.openResourceAsStream("bug63290.pptx");
|
||||||
|
XMLSlideShow ppt = new XMLSlideShow(is)) {
|
||||||
|
XSLFSlide slide = ppt.getSlides().get(0);
|
||||||
|
for (XSLFShape shape : slide.getShapes()) {
|
||||||
|
if (shape instanceof XSLFTextShape) {
|
||||||
|
XSLFTextShape text = (XSLFTextShape) shape;
|
||||||
|
XSLFTextParagraph paragraph = text.getTextParagraphs().get(0);
|
||||||
|
XSLFTextRun defaultRun = paragraph.getTextRuns().get(0);
|
||||||
|
assertEquals("DefaultRunProperties", defaultRun.getRawText().trim());
|
||||||
|
XSLFTextRun explicitRun = paragraph.getTextRuns().get(1);
|
||||||
|
assertEquals("ExplicitRunProperties", explicitRun.getRawText().trim());
|
||||||
|
assertEquals(defaultRun.getFontSize(), explicitRun.getFontSize());
|
||||||
|
assertNotEquals(defaultRun.getFontColor(), explicitRun.getFontColor());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue