Selaa lähdekoodia

[github-150] XWPFPicture: easy access to width and depth. Thanks to Thibaut Cuvelier. This closes #150

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1863434 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_4_1_1
PJ Fanning 4 vuotta sitten
vanhempi
commit
4fbad5c3f7

+ 15
- 0
src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFPicture.java Näytä tiedosto

@@ -18,6 +18,7 @@ package org.apache.poi.xwpf.usermodel;

import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.util.Units;
import org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties;
import org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture;

@@ -77,6 +78,20 @@ public class XWPFPicture {
}
return null;
}
/**
* Returns the width of the picture (in points).
*/
public double getWidth() {
return Units.toPoints(ctPic.getSpPr().getXfrm().getExt().getCx());
}
/**
* Returns the depth of the picture (in points).
*/
public double getDepth() {
return Units.toPoints(ctPic.getSpPr().getXfrm().getExt().getCy());
}

public String getDescription() {
return description;

+ 22
- 1
src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java Näytä tiedosto

@@ -520,7 +520,7 @@ public class TestXWPFRun {
XWPFPicture pic = r.getEmbeddedPictures().get(0);
CTPicture ctPic = pic.getCTPicture();
CTBlipFillProperties ctBlipFill = ctPic.getBlipFill();
assertNotNull(ctBlipFill);
CTBlip ctBlip = ctBlipFill.getBlip();
@@ -788,4 +788,25 @@ public class TestXWPFRun {
document.close();
}

@Test
public void testGetDepthWidth() throws IOException, InvalidFormatException {
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("TestDocument.docx");
XWPFHeader hdr = doc.createHeader(HeaderFooterType.DEFAULT);
XWPFParagraph p = hdr.createParagraph();
XWPFRun r = p.createRun();

assertEquals(0, hdr.getAllPictures().size());
assertEquals(0, r.getEmbeddedPictures().size());

r.addPicture(new ByteArrayInputStream(new byte[0]), Document.PICTURE_TYPE_JPEG, "test.jpg", 21, 32);

assertEquals(1, hdr.getAllPictures().size());
assertEquals(1, r.getEmbeddedPictures().size());

XWPFPicture pic = r.getEmbeddedPictures().get(0);

assertEquals(pic.getWidth(), Units.toPoints(21), 0.0);
assertEquals(pic.getDepth(), Units.toPoints(32), 0.0);
}

}

Loading…
Peruuta
Tallenna