public XDDFTextBody(TextContainer parent) {
this(parent, CTTextBody.Factory.newInstance());
- initialize();
}
@Internal
bp.setRightToLeft(false);
XDDFTextParagraph p = addNewParagraph();
p.setTextAlignment(TextAlignment.LEFT);
+ p.appendRegularRun("");
XDDFRunProperties end = p.addAfterLastRunProperties();
end.setLanguage(Locale.US);
end.setFontSize(11.0);
CTTextBody txBody = shape.getTxBody();
if (txBody == null && create) {
XDDFTextBody body = new XDDFTextBody(this);
- initTextBody(body);
shape.setTxBody(body.getXmlObject());
txBody = shape.getTxBody();
- getTextParagraphs().add(newTextParagraph(txBody.getPArray(0)));
}
return txBody;
}
import org.apache.poi.sl.usermodel.TableShape;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Units;
+import org.apache.poi.xddf.usermodel.text.XDDFTextBody;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.impl.values.XmlAnyTypeImpl;
col.setW(width);
for(XSLFTableRow row : _rows) {
XSLFTableCell cell = row.addCell();
- cell.getTextBody(true);
+ new XDDFTextBody(cell, cell.getTextBody(true)).initialize();
}
updateRowColIndexes();
}
col.setW(width);
for(XSLFTableRow row : _rows) {
XSLFTableCell cell = row.insertCell(colIdx);
- cell.getTextBody(true);
+ new XDDFTextBody(cell, cell.getTextBody(true)).initialize();
}
updateRowColIndexes();
}
CTTextBody txBody = cell.getTxBody();
if (txBody == null && create) {
XDDFTextBody body = new XDDFTextBody(this);
- initTextBody(body);
cell.setTxBody(body.getXmlObject());
txBody = cell.getTxBody();
- getTextParagraphs().add(newTextParagraph(txBody.getPArray(0)));
}
return txBody;
}
prst.setPrst(STShapeType.RECT);
prst.addNewAvLst();
XDDFTextBody body = new XDDFTextBody(null);
- initTextBody(body);
+ body.initialize();
ct.setTxBody(body.getXmlObject());
return ct;
import org.apache.poi.sl.draw.DrawPaint;
import org.apache.poi.sl.usermodel.PaintStyle;
import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;
-import org.apache.poi.sl.usermodel.TextParagraph;
import org.apache.poi.sl.usermodel.TextRun;
import org.apache.poi.util.Beta;
+import org.apache.poi.util.Internal;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
import org.apache.poi.xslf.model.CharacterPropertyFetcher;
*
* @return the xmlbeans object
*/
+ @Internal
public XmlObject getXmlObject(){
return _r;
}
Double srcFontSize = r.getFontSize();
if (srcFontSize == null) {
- if (getFontSize() != null) setFontSize(null);
+ if (getFontSize() != null) {
+ setFontSize(null);
+ }
} else if(!srcFontSize.equals(getFontSize())) {
setFontSize(srcFontSize);
}
}
return;
}
-
+
CTTextCharacterProperties props = getRPr(false);
if (props == null) {
return;
font = coll.getLatin();
}
// SYMBOL is missing
-
+
if (font == null || !font.isSetTypeface() || "".equals(font.getTypeface())) {
font = coll.getLatin();
}
import org.apache.poi.util.Units;
import org.apache.poi.xddf.usermodel.text.TextContainer;
import org.apache.poi.xddf.usermodel.text.XDDFTextBody;
-import org.apache.poi.xddf.usermodel.text.XDDFTextParagraph;
import org.apache.poi.xslf.model.PropertyFetcher;
import org.apache.poi.xslf.model.TextBodyPropertyFetcher;
import org.apache.xmlbeans.XmlObject;
}
}
- protected static void initTextBody(XDDFTextBody body) {
- XDDFTextParagraph p = body.getParagraph(0);
- p.appendRegularRun("");
- }
-
@Beta
public XDDFTextBody getTextBody() {
CTTextBody txBody = getTextBody(false);
CTTextParagraph p;
if (txBody == null) {
txBody = getTextBody(true);
+ new XDDFTextBody(this, txBody).initialize();
p = txBody.getPArray(0);
p.removeR(0);
} else {
XSLFTextShape otherTS = (XSLFTextShape) other;
CTTextBody otherTB = otherTS.getTextBody(false);
- CTTextBody thisTB = getTextBody(true);
if (otherTB == null) {
return;
}
+ CTTextBody thisTB = getTextBody(true);
thisTB.setBodyPr((CTTextBodyProperties) otherTB.getBodyPr().copy());
if (thisTB.isSetLstStyle()) {
xslfOnly = true;
}
}
-
+
/** a generic way to open a sample slideshow document **/
public static SlideShow<?,?> openSampleDocument(String sampleName) throws IOException {
InputStream is = ssSamples.openResourceAsStream(sampleName);
assumeFalse(xslfOnly);
testResize("pictures.ppt");
}
-
+
@Test
public void testResizeXSLF() throws IOException {
testResize("shapes.pptx");
}
-
-
+
+
public void testResize(String file) throws IOException {
SlideShow<?,?> ss = openSampleDocument(file);
-
+
Slide<?,?> slide = ss.getSlides().get(0);
PictureShape<?,?> picShape = null;
for (Shape<?,?> shape : slide.getShapes()) {
(int)picShape.getAnchor().getHeight()
);
assertEquals(dimPd, dimShape);
-
+
double newWidth = (dimPd.getWidth()*(100d/dimPd.getHeight()));
// ... -1 is a rounding error
Rectangle2D expRect = new Rectangle2D.Double(rbf(50+300-newWidth, picShape), 50, rbf(newWidth, picShape), 100);
assertEquals(expRect.getHeight(), actRect.getHeight(), .0001);
ss.close();
}
-
+
// round back and forth - points -> master -> points
static double rbf(double val, PictureShape<?,?> picShape) {
if (picShape.getClass().getName().contains("HSLF")) {
@Test
public void testProperties() throws IOException {
- XDDFBodyProperties body = new XDDFTextBody(null).getBodyProperties();
+ XDDFTextBody text = new XDDFTextBody(null);
+ text.initialize();
+ XDDFBodyProperties body = text.getBodyProperties();
CTTextBodyProperties props = body.getXmlObject();
body.setBottomInset(null);
sh.addNewTextParagraph();
XDDFTextBody body = sh.getTextBody();
+ body.initialize();
XDDFTextParagraph para = body.getParagraph(0);
XDDFTextRun r = para.appendRegularRun("text");
assertEquals(LocaleUtil.getUserLocale().toLanguageTag(), r.getLanguage().toLanguageTag());
import org.openxmlformats.schemas.drawingml.x2006.main.CTOuterShadowEffect;
import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
-
public class TestXSLFBugs {
private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
is.close();
PackagePartName ppn = PackagingURIHelper.createPartName("/ppt/media/image1.png");
-
+
XMLSlideShow ppt1 = new XMLSlideShow(new ByteArrayInputStream(buf));
XSLFSlide slide1 = ppt1.getSlides().get(0);
-
+
Optional<XSLFShape> shapeToDelete1 =
slide1.getShapes().stream().filter(s -> s instanceof XSLFPictureShape).findFirst();
-
+
assertTrue(shapeToDelete1.isPresent());
slide1.removeShape(shapeToDelete1.get());
assertTrue(slide1.getRelationParts().stream()
.allMatch(rp -> "rId1,rId3".contains(rp.getRelationship().getId()) ));
-
+
assertNotNull(ppt1.getPackage().getPart(ppn));
ppt1.close();
assertNull(ppt3.getPackage().getPart(ppn));
ppt3.close();
}
-
+
@Test
public void bug51187() throws Exception {
XMLSlideShow ss1 = XSLFTestDataSamples.openSampleDocument("51187.pptx");
import org.junit.runners.Parameterized.Parameters;
/**
- * Test class for testing PPTX2PNG utility which renderes .ppt and .pptx slideshows
+ * Test class for testing PPTX2PNG utility which renders .ppt and .pptx slideshows
*/
@RunWith(Parameterized.class)
public class TestPPTX2PNG {
"backgrounds.pptx, layouts.pptx, sample.pptx, shapes.pptx, 54880_chinese.ppt, keyframes.pptx," +
"customGeo.pptx, customGeo.ppt, wrench.emf, santa.wmf";
-
-
+
+
@BeforeClass
public static void checkHslf() {
try {
xslfOnly = true;
}
}
-
+
// use filename instead of File object to omit full pathname in test name
@Parameter(value = 0)
public String pptFile;
-
+
@SuppressWarnings("ConstantConditions")
@Parameters(name="{0}")
public static Collection<String> data() {
public class TestXMLSlideShow extends BaseTestSlideShow<XSLFShape,XSLFTextParagraph> {
private OPCPackage pack;
-
+
@Override
public XMLSlideShow createSlideShow() {
return new XMLSlideShow();
public void setUp() throws Exception {
pack = OPCPackage.open(slTests.openResourceAsStream("sample.pptx"));
}
-
+
@After
public void tearDown() {
pack.revert();
// Check it has some slides
assertFalse(xml.getSlides().isEmpty());
assertFalse(xml.getSlideMasters().isEmpty());
-
+
xml.close();
}
assertNotNull(notesMaster);
assertNotNull(xml.getNotesMaster());
-
+
xml.close();
}
-
+
@Test
public void testMetadataBasics() throws IOException {
XMLSlideShow xml = new XMLSlideShow(pack);
assertNull(xml.getProperties().getCoreProperties().getTitle());
assertFalse(xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().isPresent());
-
+
xml.close();
}
-
+
@Test
public void testComments() throws Exception {
// Default sample file has none
XMLSlideShow xml = new XMLSlideShow(pack);
assertNull(xml.getCommentAuthors());
-
+
for (XSLFSlide slide : xml.getSlides()) {
assertTrue(slide.getComments().isEmpty());
}
-
+
// Try another with comments
XMLSlideShow xmlComments = new XMLSlideShow(slTests.openResourceAsStream("45545_Comment.pptx"));
-
+
// Has one author
assertNotNull(xmlComments.getCommentAuthors());
assertEquals(1, xmlComments.getCommentAuthors().getCTCommentAuthorsList().sizeOfCmAuthorArray());
assertEquals("XPVMWARE01", xmlComments.getCommentAuthors().getAuthorById(0).getName());
-
+
// First two slides have comments
int i = -1;
for (XSLFSlide slide : xmlComments.getSlides()) {
i++;
-
+
if(i == 0) {
assertNotNull(slide.getCommentsPart());
assertEquals(1, slide.getCommentsPart().getNumberOfComments());
assertTrue(slide.getComments().isEmpty());
}
}
-
+
xmlComments.close();
xml.close();
}
-
+
@Override
public XMLSlideShow reopen(SlideShow<XSLFShape,XSLFTextParagraph> show) {
try {
assertEquals(TextDirection.VERTICAL, shape.getTextDirection());
shape.setTextDirection(null);
assertEquals(TextDirection.HORIZONTAL, shape.getTextDirection());
-
+
ppt.close();
}
p.setTextAlign(null);
assertEquals(TextAlign.LEFT, p.getTextAlign());
assertFalse(p.getXmlObject().getPPr().isSetAlgn());
-
+
ppt.close();
}
assertEquals(1, p.getTextRuns().size());
assertSame(r, p.getTextRuns().get(0));
-
+
assertEquals(18.0, r.getFontSize(), 0); // default font size for text boxes
assertFalse(rPr.isSetSz());
r.setFontSize(10.0);
assertEquals("POI", r.getRawText());
r.setText(null);
assertNull(r.getRawText());
-
+
ppt.close();
}
assertEquals(ShapeType.TRIANGLE, shape.getShapeType());
for(ShapeType tp : ShapeType.values()) {
- if (tp.ooxmlId == -1 || tp == ShapeType.SEAL) continue;
+ if (tp.ooxmlId == -1 || tp == ShapeType.SEAL) {
+ continue;
+ }
shape.setShapeType(tp);
assertEquals(tp, shape.getShapeType());
}
-
+
ppt.close();
}
}
\ No newline at end of file
==================================================================== */
package org.apache.poi.xslf.usermodel;
-import static org.apache.poi.POIDataSamples.TEST_PROPERTY;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
InputStream is = _slTests.openResourceAsStream("shapes.pptx");
XMLSlideShow ppt = new XMLSlideShow(is);
is.close();
-
+
XSLFSlide slide = ppt.getSlides().get(0);
XSLFPictureShape ps = (XSLFPictureShape)slide.getShapes().get(3);
slide.removeShape(ps);
-
+
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ppt.write(bos);
ppt.close();
-
+
XMLSlideShow ppt2 = new XMLSlideShow(new ByteArrayInputStream(bos.toByteArray()));
assertTrue(ppt2.getPictureData().isEmpty());
ppt2.close();
}
-
+
@Test
public void testTiffImageBug59742() throws Exception {
XMLSlideShow slideShow = new XMLSlideShow();
final InputStream tiffStream = _slTests.openResourceAsStream("testtiff.tif");
final byte[] pictureData = IOUtils.toByteArray(tiffStream);
IOUtils.closeQuietly(tiffStream);
-
+
XSLFPictureData pic = slideShow.addPicture(pictureData, PictureType.TIFF);
assertEquals("image/tiff", pic.getContentType());
assertEquals("image1.tiff", pic.getFileName());
-
+
slideShow.close();
}