1 16 17 package org.apache.poi.hssf.usermodel; 18 19 import junit.framework.TestCase; 20 21 import java.awt.*; 22 import java.io.FileOutputStream ; 23 24 29 public class TestEscherGraphics2d extends TestCase 30 { 31 private HSSFShapeGroup escherGroup; 32 private EscherGraphics2d graphics; 33 34 protected void setUp() throws Exception 35 { 36 super.setUp(); 37 38 HSSFWorkbook workbook = new HSSFWorkbook(); 39 HSSFSheet sheet = workbook.createSheet("test"); 40 escherGroup = sheet.createDrawingPatriarch().createGroup(new HSSFClientAnchor(0,0,1023,255,(short)0,0,(short) 0,0)); 41 escherGroup = new HSSFShapeGroup(null, new HSSFChildAnchor()); 42 EscherGraphics g = new EscherGraphics(this.escherGroup, workbook, Color.black, 1.0f); 43 graphics = new EscherGraphics2d(g); 44 45 } 46 47 public void testDrawString() throws Exception 48 { 49 graphics.drawString("This is a test", 10, 10); 50 HSSFTextbox t = (HSSFTextbox) escherGroup.getChildren().get(0); 51 assertEquals("This is a test", t.getString().toString()); 52 } 53 54 public void testFillRect() throws Exception 55 { 56 graphics.fillRect( 10, 10, 20, 20 ); 57 HSSFSimpleShape s = (HSSFSimpleShape) escherGroup.getChildren().get(0); 58 assertEquals(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE, s.getShapeType()); 59 assertEquals(10, s.getAnchor().getDx1()); 60 assertEquals(10, s.getAnchor().getDy1()); 61 assertEquals(30, s.getAnchor().getDy2()); 62 assertEquals(30, s.getAnchor().getDx2()); 63 } 64 65 public void testGetFontMetrics() throws Exception 66 { 67 FontMetrics fontMetrics = graphics.getFontMetrics(graphics.getFont()); 68 if (graphics.getFont().toString().indexOf("dialog") != -1) return; 70 assertEquals(7, fontMetrics.charWidth('X')); 71 assertEquals("java.awt.Font[family=Arial,name=Arial,style=plain,size=10]", fontMetrics.getFont().toString()); 72 } 73 74 public void testSetFont() throws Exception 75 { 76 Font f = new Font("Helvetica", 0, 12); 77 graphics.setFont(f); 78 assertEquals(f, graphics.getFont()); 79 } 80 81 public void testSetColor() throws Exception 82 { 83 graphics.setColor(Color.red); 84 assertEquals(Color.red, graphics.getColor()); 85 } 86 87 public void testGetFont() throws Exception 88 { 89 Font f = graphics.getFont(); 90 if (graphics.getFont().toString().indexOf("dialog") != -1) return; 92 93 assertEquals("java.awt.Font[family=Arial,name=Arial,style=plain,size=10]", f.toString()); 94 } 95 } 96 | Popular Tags |