poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r677029 - in /poi/trunk/src: java/org/apache/poi/hssf/model/Workbook.java testcases/org/apache/poi/hssf/model/TestWorkbook.java
Date Tue, 15 Jul 2008 20:24:54 GMT
Author: nick
Date: Tue Jul 15 13:24:53 2008
New Revision: 677029

URL: http://svn.apache.org/viewvc?rev=677029&view=rev
Log:
Support for removing low level font records

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/model/Workbook.java
    poi/trunk/src/testcases/org/apache/poi/hssf/model/TestWorkbook.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/model/Workbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/model/Workbook.java?rev=677029&r1=677028&r2=677029&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/model/Workbook.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/model/Workbook.java Tue Jul 15 13:24:53 2008
@@ -443,6 +443,17 @@
         numfonts++;
         return rec;
     }
+    
+    /**
+     * Removes the given font record from the
+     *  file's list. This will make all 
+     *  subsequent font indicies drop by one,
+     *  so you'll need to update those yourself!
+     */
+    public void removeFontRecord(FontRecord rec) {
+    	records.remove(rec); // this updates FontPos for us
+        numfonts--;
+    }
 
     /**
      * gets the number of font records

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/model/TestWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/model/TestWorkbook.java?rev=677029&r1=677028&r2=677029&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/model/TestWorkbook.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/model/TestWorkbook.java Tue Jul 15 13:24:53
2008
@@ -32,6 +32,7 @@
 		Workbook wb = (new HW()).getWorkbook();
 		
 		assertEquals(4, wb.getNumberOfFontRecords());
+		assertEquals(68, wb.getRecords().size());
 		
 		FontRecord f1 = wb.getFontRecordAt(0);
 		FontRecord f4 = wb.getFontRecordAt(3);
@@ -45,9 +46,41 @@
 		// There is no 4! new ones go in at 5
 		
 		FontRecord n = wb.createNewFont();
+		assertEquals(69, wb.getRecords().size());
 		assertEquals(5, wb.getNumberOfFontRecords());
 		assertEquals(5, wb.getFontIndex(n));
 		assertEquals(n, wb.getFontRecordAt(5));
+		
+		// And another
+		FontRecord n6 = wb.createNewFont();
+		assertEquals(70, wb.getRecords().size());
+		assertEquals(6, wb.getNumberOfFontRecords());
+		assertEquals(6, wb.getFontIndex(n6));
+		assertEquals(n6, wb.getFontRecordAt(6));
+		
+		
+		// Now remove the one formerly at 5
+		assertEquals(70, wb.getRecords().size());
+		wb.removeFontRecord(n);
+
+		// Check that 6 has gone to 5
+		assertEquals(69, wb.getRecords().size());
+		assertEquals(5, wb.getNumberOfFontRecords());
+		assertEquals(5, wb.getFontIndex(n6));
+		assertEquals(n6, wb.getFontRecordAt(5));
+		
+		// Check that the earlier ones are unchanged
+		assertEquals(0, wb.getFontIndex(f1));
+		assertEquals(3, wb.getFontIndex(f4));
+		assertEquals(f1, wb.getFontRecordAt(0));
+		assertEquals(f4, wb.getFontRecordAt(3));
+		
+		// Finally, add another one
+		FontRecord n7 = wb.createNewFont();
+		assertEquals(70, wb.getRecords().size());
+		assertEquals(6, wb.getNumberOfFontRecords());
+		assertEquals(6, wb.getFontIndex(n7));
+		assertEquals(n7, wb.getFontRecordAt(6));
 	}
 	
 	private class HW extends HSSFWorkbook {



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


Mime
View raw message