You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ye...@apache.org on 2011/12/19 09:17:47 UTC

svn commit: r1220642 - in /poi/trunk/src: documentation/content/xdocs/status.xml ooxml/java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java

Author: yegor
Date: Mon Dec 19 08:17:46 2011
New Revision: 1220642

URL: http://svn.apache.org/viewvc?rev=1220642&view=rev
Log:
Bugzilla 52219: fixed XSSFSimpleShape to set rich text attributes from XSSFRichTextString

Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1220642&r1=1220641&r2=1220642&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Mon Dec 19 08:17:46 2011
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta6" date="2012-??-??">
+           <action dev="poi-developers" type="fix">52219 - fixed XSSFSimpleShape to set rich text attributes from XSSFRichtextString</action>
            <action dev="poi-developers" type="fix">52314 - enhanced SheetUtil.getColumnWidth</action>
         </release>
         <release version="3.8-beta5" date="2011-12-17">

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java?rev=1220642&r1=1220641&r2=1220642&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java Mon Dec 19 08:17:46 2011
@@ -17,32 +17,15 @@
 
 package org.apache.poi.xssf.usermodel;
 
-import org.openxmlformats.schemas.drawingml.x2006.main.CTFontReference;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBodyProperties;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextFont;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D;
-import org.openxmlformats.schemas.drawingml.x2006.main.STFontCollectionIndex;
-import org.openxmlformats.schemas.drawingml.x2006.main.STSchemeColorVal;
-import org.openxmlformats.schemas.drawingml.x2006.main.STShapeType;
-import org.openxmlformats.schemas.drawingml.x2006.main.STTextAlignType;
-import org.openxmlformats.schemas.drawingml.x2006.main.STTextAnchoringType;
+import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.ss.usermodel.IndexedColors;
+import org.openxmlformats.schemas.drawingml.x2006.main.*;
 import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape;
 import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShapeNonVisual;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRElt;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt;
 import org.apache.poi.util.Internal;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STUnderlineValues;
 
 /**
  * Represents a shape with a predefined geometry in a SpreadsheetML drawing.
@@ -190,15 +173,43 @@ public class XSSFSimpleShape extends XSS
 
     /**
      *
-     * CTRPrElt --> CTFont adapter
+     * org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt to
+     * org.openxmlformats.schemas.drawingml.x2006.main.CTFont adapter
      */
     private static void applyAttributes(CTRPrElt pr, CTTextCharacterProperties rPr){
 
         if(pr.sizeOfBArray() > 0) rPr.setB(pr.getBArray(0).getVal());
-        //if(pr.sizeOfUArray() > 0) rPr.setU(pr.getUArray(0).getVal());
+        if(pr.sizeOfUArray() > 0) {
+            STUnderlineValues.Enum u1 = pr.getUArray(0).getVal();
+            if(u1 == STUnderlineValues.SINGLE) rPr.setU(STTextUnderlineType.SNG);
+            else if(u1 == STUnderlineValues.DOUBLE) rPr.setU(STTextUnderlineType.DBL);
+            else if(u1 == STUnderlineValues.NONE) rPr.setU(STTextUnderlineType.NONE);
+        }
         if(pr.sizeOfIArray() > 0) rPr.setI(pr.getIArray(0).getVal());
 
-        CTTextFont rFont = rPr.addNewLatin();
-        rFont.setTypeface(pr.sizeOfRFontArray() > 0 ? pr.getRFontArray(0).getVal() : "Arial");
+        if(pr.sizeOfFamilyArray() > 0) {
+            CTTextFont rFont = rPr.addNewLatin();
+            rFont.setTypeface(pr.getRFontArray(0).getVal());
+        }
+        
+        if(pr.sizeOfColorArray() > 0) {
+            CTSolidColorFillProperties fill = rPr.isSetSolidFill() ? rPr.getSolidFill() : rPr.addNewSolidFill();
+            org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor xlsColor = pr.getColorArray(0);
+            if(xlsColor.isSetRgb()) {
+                CTSRgbColor clr = fill.isSetSrgbClr() ? fill.getSrgbClr() : fill.addNewSrgbClr();
+                clr.setVal(xlsColor.getRgb());
+            }
+            else if(xlsColor.isSetIndexed()) {
+                HSSFColor indexed = HSSFColor.getIndexHash().get((int) xlsColor.getIndexed());
+                if (indexed != null) {
+                    byte[] rgb = new byte[3];
+                    rgb[0] = (byte) indexed.getTriplet()[0];
+                    rgb[1] = (byte) indexed.getTriplet()[1];
+                    rgb[2] = (byte) indexed.getTriplet()[2];
+                    CTSRgbColor clr = fill.isSetSrgbClr() ? fill.getSrgbClr() : fill.addNewSrgbClr();
+                    clr.setVal(rgb);
+                }
+            }
+        }
     }
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java?rev=1220642&r1=1220641&r2=1220642&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java Mon Dec 19 08:17:46 2011
@@ -16,15 +16,24 @@
 ==================================================================== */
 package org.apache.poi.xssf.usermodel;
 
+import java.awt.*;
+import java.util.Arrays;
 import java.util.List;
 
 import junit.framework.TestCase;
 
 import org.apache.poi.POIXMLDocumentPart;
 import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.ss.usermodel.FontUnderline;
+import org.apache.poi.ss.usermodel.IndexedColors;
 import org.apache.poi.xssf.XSSFTestDataSamples;
 import org.apache.poi.xssf.dev.XSSFDump;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph;
+import org.openxmlformats.schemas.drawingml.x2006.main.STTextUnderlineType;
 import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing;
+import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape;
 
 /**
  * @author Yegor Kozlov
@@ -171,4 +180,40 @@ public class TestXSSFDrawing extends Tes
             assertEquals(sh1.getShapeProperties().toString(), sh2.getShapeProperties().toString());
         }
     }
+
+    /**
+     * ensure that rich text attributes defined in a XSSFRichTextString
+     * are passed to XSSFSimpleShape.
+     *
+     * See Bugzilla 52219.
+     */
+    public void testRichText(){
+        XSSFWorkbook wb = new XSSFWorkbook();
+        XSSFSheet sheet = wb.createSheet();
+        XSSFDrawing drawing = sheet.createDrawingPatriarch();
+
+        XSSFTextBox shape = drawing.createTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4));
+        XSSFRichTextString rt = new XSSFRichTextString("Test String");
+
+        XSSFFont font = wb.createFont();
+        font.setColor(new XSSFColor(new Color(0, 128, 128)));
+        font.setItalic(true);
+        font.setBold(true);
+        font.setUnderline(FontUnderline.SINGLE);
+        rt.applyFont(font);
+
+        shape.setText(rt);
+
+        CTTextParagraph pr = shape.getCTShape().getTxBody().getPArray(0);
+        assertEquals(1, pr.sizeOfRArray());
+
+        CTTextCharacterProperties rPr = pr.getRArray(0).getRPr();
+        assertEquals(true, rPr.getB());
+        assertEquals(true, rPr.getI());
+        assertEquals(STTextUnderlineType.SNG, rPr.getU());
+        assertTrue(Arrays.equals(
+                new byte[]{0, (byte)128, (byte)128} ,
+                rPr.getSolidFill().getSrgbClr().getVal()));
+
+    }
 }



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