poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1678179 - in /poi/trunk/src/ooxml: java/org/apache/poi/xwpf/usermodel/XWPFStyles.java testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java
Date Thu, 07 May 2015 12:37:43 GMT
Author: nick
Date: Thu May  7 12:37:43 2015
New Revision: 1678179

URL: http://svn.apache.org/r1678179
Log:
Begin on test for going from xwpf text to style

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java?rev=1678179&r1=1678178&r2=1678179&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java Thu May  7 12:37:43
2015
@@ -43,8 +43,10 @@ import org.openxmlformats.schemas.wordpr
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocDefaults;
 /**
- * @author Philipp Epp
- *
+ * Holds details of built-in, default and user styles, which
+ *  apply to tables / paragraphs / lists etc.
+ * Text within one of those with custom stylings has the style
+ *  information stored in the {@link XWPFRun}
  */
 public class XWPFStyles extends POIXMLDocumentPart{
     
@@ -83,8 +85,6 @@ public class XWPFStyles extends POIXMLDo
       } catch (XmlException e) {
          throw new POIXMLException("Unable to read styles", e);
       }
-      
-      
    }
 	
    @Override
@@ -154,6 +154,9 @@ public class XWPFStyles extends POIXMLDo
 		}
 		return null;
 	}
+	public int getNumberOfStyles() {
+	    return listStyle.size();
+	}
 
 	/**
 	 * get the styles which are related to the parameter style and their relatives

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java?rev=1678179&r1=1678178&r2=1678179&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java Thu May
 7 12:37:43 2015
@@ -138,4 +138,52 @@ public class TestXWPFStyles extends Test
         styles = docIn.getStyles();
         assertTrue(styles.styleExist(strStyleId));
     }
+    
+    public void testEasyAccessToStyles() throws IOException {
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx");
+        XWPFStyles styles = doc.getStyles();
+        assertNotNull(styles);
+        
+        // Has 3 paragraphs on page one, a break, and 3 on page 2
+        assertEquals(7, doc.getParagraphs().size());
+        
+        // Check the first three have no run styles, just default paragraph style
+        for (int i=0; i<3; i++) {
+            XWPFParagraph p = doc.getParagraphs().get(i);
+            assertEquals(null, p.getStyle());
+            assertEquals(null, p.getStyleID());
+            assertEquals(1, p.getRuns().size());
+            
+            XWPFRun r = p.getRuns().get(0);
+            assertEquals(null, r.getColor());
+            assertEquals(null, r.getFontFamily());
+            assertEquals(null, r.getFontName());
+            assertEquals(-1, r.getFontSize());
+        }
+        
+        // On page two, has explicit styles, but on runs not on
+        //  the paragraph itself
+        for (int i=4; i<7; i++) {
+            XWPFParagraph p = doc.getParagraphs().get(i);
+            assertEquals(null, p.getStyle());
+            assertEquals(null, p.getStyleID());
+            assertEquals(1, p.getRuns().size());
+            
+            XWPFRun r = p.getRuns().get(0);
+            assertEquals("Arial Black", r.getFontFamily());
+            assertEquals("Arial Black", r.getFontName());
+            assertEquals(16, r.getFontSize());
+            assertEquals("548DD4", r.getColor());
+        }
+        
+        // Check the document styles
+        // Should have a style defined for each type
+        assertEquals(4, styles.getNumberOfStyles());
+        assertNotNull(styles.getStyle("Normal"));
+        assertNotNull(styles.getStyle("DefaultParagraphFont"));
+        assertNotNull(styles.getStyle("TableNormal"));
+        assertNotNull(styles.getStyle("NoList"));
+        
+        // TODO Check latent and default
+    }
 }



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


Mime
View raw message