poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmarkmur...@apache.org
Subject svn commit: r1773729 - in /poi: site/src/documentation/content/xdocs/status.xml trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java
Date Mon, 12 Dec 2016 02:43:46 GMT
Author: jmarkmurphy
Date: Mon Dec 12 02:43:45 2016
New Revision: 1773729

URL: http://svn.apache.org/viewvc?rev=1773729&view=rev
Log:
58237: Unable to add image to a word document header using XWPF 

Task-Url: https://bz.apache.org/bugzilla/show_bug.cgi?id=58237

Modified:
    poi/site/src/documentation/content/xdocs/status.xml
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java

Modified: poi/site/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/status.xml?rev=1773729&r1=1773728&r2=1773729&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/status.xml (original)
+++ poi/site/src/documentation/content/xdocs/status.xml Mon Dec 12 02:43:45 2016
@@ -61,6 +61,7 @@
         <summary-item>The third-party jar for commons-collections4 is now required
for handling of OLE2 properties</summary-item>
       </summary>
       <actions>
+        <action dev="PD" type="fix" fixes-bug="58237" module="XWPF">Unable to add image
to Word document header</action>
         <action dev="PD" type="update" fixes-bug="55902" module="SL Common">Mixed fonts
issue with Chinese characters (unable to form images from ppt)</action>
         <action dev="PD" type="remove" fixes-bug="60331" breaks-compatibility="true" module="OOXML">Remove
deprecated classes - remove constructors with PackageRelationship argument</action>
       	<action dev="PD" type="fix" fixes-bug="60329" module="XWPF">Added try/catch
block to swallow NPE</action>

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java?rev=1773729&r1=1773728&r2=1773729&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java Mon Dec 12 02:43:45
2016
@@ -1003,7 +1003,7 @@ public class XWPFRun implements ISDTCont
 
             CTBlipFillProperties blipFill = pic.addNewBlipFill();
             CTBlip blip = blipFill.addNewBlip();
-            blip.setEmbed(parent.getDocument().getRelationId(picData));
+            blip.setEmbed(parent.getPart().getRelationId(picData));
             blipFill.addNewStretch().addNewFillRect();
 
             CTShapeProperties spPr = pic.addNewSpPr();

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java?rev=1773729&r1=1773728&r2=1773729&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java Mon Dec 12
02:43:45 2016
@@ -16,14 +16,8 @@
 ==================================================================== */
 package org.apache.poi.xwpf.usermodel;
 
-import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
-import org.apache.poi.util.Units;
-import org.apache.poi.xwpf.XWPFTestDataSamples;
-import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
@@ -31,8 +25,26 @@ import java.math.BigInteger;
 import java.util.Iterator;
 import java.util.List;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.util.Units;
+import org.apache.poi.wp.usermodel.HeaderFooterType;
+import org.apache.poi.xwpf.XWPFTestDataSamples;
+import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTBlip;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties;
+import org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBrClear;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHighlightColor;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STUnderline;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalAlignRun;
 
 /**
  * Tests for XWPF Run
@@ -472,6 +484,46 @@ public class TestXWPFRun {
         assertEquals(1, docBack.getAllPictures().size());
         assertEquals(1, rBack.getEmbeddedPictures().size());
     }
+    
+    /**
+     * Bugzilla #58237 - Unable to add image to word document header
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testAddPictureInHeader() throws Exception {
+        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);
+        CTPicture ctPic = pic.getCTPicture();
+        CTBlipFillProperties ctBlipFill = ctPic.getBlipFill();
+        
+        assertNotNull(ctBlipFill);
+        
+        CTBlip ctBlip = ctBlipFill.getBlip();
+        
+        assertNotNull(ctBlip);
+        assertEquals("rId1", ctBlip.getEmbed());
+        
+        XWPFDocument docBack = XWPFTestDataSamples.writeOutAndReadBack(doc);
+        XWPFHeader hdrBack = docBack.getHeaderArray(0);
+        XWPFParagraph pBack = hdrBack.getParagraphArray(0);
+        XWPFRun rBack = pBack.getRuns().get(0);
+        
+        assertEquals(1, hdrBack.getAllPictures().size());
+        assertEquals(1, rBack.getEmbeddedPictures().size());
+    }
 
     /**
      * Bugzilla #52288 - setting the font family on the



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message