From b6ea214cc1e42332b7198954c63a783935b4bdf4 Mon Sep 17 00:00:00 2001
From: Glen Stampoultzis
Date: Fri, 9 Apr 2004 11:45:38 +0000
Subject: [PATCH] Ported the drawing stuff from the rel_2_branch. Given the
effort this took I'm really really wanting to move to subversion.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353542 13f79535-47bb-0310-9956-ffa450edef68
---
build.xml | 25 +-
.../contrib/metrics/FontMetricsDumper.java | 65 ++
.../content/xdocs/hssf/quick-guide.xml | 209 ++++
.../usermodel/examples/OfficeDrawing.java | 255 +++++
.../examples/OfficeDrawingWithGraphics.java | 87 ++
.../poi/ddf/DefaultEscherRecordFactory.java | 114 ++
.../apache/poi/ddf/EscherArrayProperty.java | 162 +++
.../org/apache/poi/ddf/EscherBSERecord.java | 383 +++++++
.../org/apache/poi/ddf/EscherBlipRecord.java | 417 ++++++++
.../apache/poi/ddf/EscherBoolProperty.java | 50 +
.../poi/ddf/EscherChildAnchorRecord.java | 176 ++++
.../poi/ddf/EscherClientAnchorRecord.java | 317 ++++++
.../poi/ddf/EscherClientDataRecord.java | 130 +++
.../apache/poi/ddf/EscherComplexProperty.java | 152 +++
.../apache/poi/ddf/EscherContainerRecord.java | 168 +++
.../org/apache/poi/ddf/EscherDgRecord.java | 163 +++
.../org/apache/poi/ddf/EscherDggRecord.java | 241 +++++
src/java/org/apache/poi/ddf/EscherDump.java | 990 ++++++++++++++++++
.../org/apache/poi/ddf/EscherOptRecord.java | 174 +++
.../org/apache/poi/ddf/EscherProperties.java | 607 +++++++++++
.../org/apache/poi/ddf/EscherProperty.java | 78 ++
.../apache/poi/ddf/EscherPropertyFactory.java | 91 ++
.../poi/ddf/EscherPropertyMetaData.java | 51 +
.../org/apache/poi/ddf/EscherRGBProperty.java | 37 +
src/java/org/apache/poi/ddf/EscherRecord.java | 273 +++++
.../apache/poi/ddf/EscherRecordFactory.java | 16 +
.../poi/ddf/EscherSerializationListener.java | 27 +
.../poi/ddf/EscherShapePathProperty.java | 25 +
.../apache/poi/ddf/EscherSimpleProperty.java | 103 ++
.../org/apache/poi/ddf/EscherSpRecord.java | 201 ++++
.../org/apache/poi/ddf/EscherSpgrRecord.java | 192 ++++
.../poi/ddf/EscherSplitMenuColorsRecord.java | 171 +++
.../apache/poi/ddf/EscherTextboxRecord.java | 215 ++++
.../ddf/NullEscherSerializationListener.java | 20 +
.../apache/poi/ddf/TestEscherBSERecord.java | 87 ++
.../apache/poi/ddf/TestEscherBlipRecord.java | 110 ++
.../poi/ddf/TestEscherBoolProperty.java | 13 +
.../poi/ddf/TestEscherChildAnchorRecord.java | 73 ++
.../poi/ddf/TestEscherClientAnchorRecord.java | 91 ++
.../poi/ddf/TestEscherClientDataRecord.java | 57 +
.../poi/ddf/TestEscherContainerRecord.java | 98 ++
.../apache/poi/ddf/TestEscherDgRecord.java | 62 ++
.../apache/poi/ddf/TestEscherDggRecord.java | 89 ++
.../apache/poi/ddf/TestEscherOptRecord.java | 140 +++
.../poi/ddf/TestEscherPropertyFactory.java | 42 +
.../apache/poi/ddf/TestEscherSpRecord.java | 62 ++
.../apache/poi/ddf/TestEscherSpgrRecord.java | 73 ++
.../ddf/TestEscherSplitMenuColorsRecord.java | 73 ++
.../poi/ddf/TestUnknownEscherRecord.java | 106 ++
.../apache/poi/ddf/UnknownEscherRecord.java | 234 +++++
src/java/org/apache/poi/ddf/package.html | 11 +
.../org/apache/poi/dev/RecordGenerator.java | 9 -
.../org/apache/poi/hssf/dev/BiffViewer.java | 163 +--
.../apache/poi/hssf/model/AbstractShape.java | 126 +++
.../apache/poi/hssf/model/ConvertAnchor.java | 50 +
.../apache/poi/hssf/model/DrawingManager.java | 136 +++
.../org/apache/poi/hssf/model/LineShape.java | 105 ++
.../apache/poi/hssf/model/PolygonShape.java | 143 +++
src/java/org/apache/poi/hssf/model/Sheet.java | 232 +++-
.../poi/hssf/model/SimpleFilledShape.java | 111 ++
.../poi/hssf/model/TestDrawingManager.java | 81 ++
.../apache/poi/hssf/model/TextboxShape.java | 151 +++
.../org/apache/poi/hssf/model/Workbook.java | 52 +
.../record/AbstractEscherHolderRecord.java | 266 +++++
.../record/CommonObjectDataSubRecord.java | 498 +++++++++
.../poi/hssf/record/DrawingGroupRecord.java | 30 +
.../apache/poi/hssf/record/DrawingRecord.java | 97 ++
.../record/DrawingRecordForBiffViewer.java | 35 +
.../hssf/record/DrawingSelectionRecord.java | 30 +
.../apache/poi/hssf/record/EndSubRecord.java | 176 ++++
.../poi/hssf/record/EscherAggregate.java | 696 ++++++++++++
.../poi/hssf/record/GroupMarkerSubRecord.java | 176 ++++
.../record/HorizontalPageBreakRecord.java | 107 ++
.../org/apache/poi/hssf/record/ObjRecord.java | 227 ++++
.../poi/hssf/record/PageBreakRecord.java | 304 ++++++
.../apache/poi/hssf/record/RecordFactory.java | 10 +-
.../org/apache/poi/hssf/record/SubRecord.java | 98 ++
.../record/TestCommonObjectDataSubRecord.java | 127 +++
.../hssf/record/TestDrawingGroupRecord.java | 36 +
.../poi/hssf/record/TestEndSubRecord.java | 102 ++
.../poi/hssf/record/TestEscherAggregate.java | 124 +++
.../hssf/record/TestTextObjectBaseRecord.java | 137 +++
.../poi/hssf/record/TextObjectBaseRecord.java | 519 +++++++++
.../poi/hssf/record/TextObjectRecord.java | 216 ++++
.../apache/poi/hssf/record/UnknownRecord.java | 7 +
.../hssf/record/VerticalPageBreakRecord.java | 107 ++
.../poi/hssf/usermodel/DummyGraphics2d.java | 773 ++++++++++++++
.../poi/hssf/usermodel/EscherGraphics.java | 450 ++++++++
.../poi/hssf/usermodel/EscherGraphics2d.java | 567 ++++++++++
.../poi/hssf/usermodel/FontDetails.java | 143 +++
.../apache/poi/hssf/usermodel/HSSFAnchor.java | 40 +
.../poi/hssf/usermodel/HSSFChildAnchor.java | 37 +
.../poi/hssf/usermodel/HSSFClientAnchor.java | 207 ++++
.../apache/poi/hssf/usermodel/HSSFFont.java | 8 +
.../poi/hssf/usermodel/HSSFPalette.java | 55 +-
.../poi/hssf/usermodel/HSSFPatriarch.java | 159 +++
.../poi/hssf/usermodel/HSSFPolygon.java | 66 ++
.../hssf/usermodel/HSSFRichTextString.java | 179 ++++
.../apache/poi/hssf/usermodel/HSSFShape.java | 195 ++++
.../hssf/usermodel/HSSFShapeContainer.java | 17 +
.../poi/hssf/usermodel/HSSFShapeGroup.java | 148 +++
.../apache/poi/hssf/usermodel/HSSFSheet.java | 161 ++-
.../poi/hssf/usermodel/HSSFSimpleShape.java | 64 ++
.../poi/hssf/usermodel/HSSFTextbox.java | 107 ++
.../poi/hssf/usermodel/HSSFWorkbook.java | 34 +
.../poi/hssf/usermodel/StaticFontMetrics.java | 81 ++
.../hssf/usermodel/TestEscherGraphics.java | 71 ++
.../hssf/usermodel/TestEscherGraphics2d.java | 74 ++
.../poi/hssf/usermodel/TestFontDetails.java | 45 +
.../hssf/usermodel/TestHSSFClientAnchor.java | 44 +
.../usermodel/TestHSSFRichTextString.java | 50 +
src/java/org/apache/poi/util/DrawingDump.java | 24 +
.../definitions/common_object_data_record.xml | 52 +
src/records/definitions/ftend_record.xml | 9 +
src/records/definitions/subrecord.xsl | 326 ++++++
src/records/definitions/subrecord_test.xsl | 155 +++
src/records/definitions/textobject_record.xml | 41 +
.../fontmetrics/font_metrics.properties | 912 ++++++++++++++++
.../org/apache/poi/hssf/model/SheetTest.java | 132 ++-
.../poi/hssf/usermodel/TestCloneSheet.java | 21 +-
.../poi/hssf/usermodel/TestHSSFPalette.java | 16 +-
.../poi/hssf/usermodel/TestHSSFSheet.java | 48 +
.../hssf/usermodel/TestSheetShiftRows.java | 17 +
123 files changed, 18707 insertions(+), 111 deletions(-)
create mode 100644 src/contrib/src/org/apache/poi/contrib/metrics/FontMetricsDumper.java
create mode 100644 src/examples/src/org/apache/poi/hssf/usermodel/examples/OfficeDrawing.java
create mode 100644 src/examples/src/org/apache/poi/hssf/usermodel/examples/OfficeDrawingWithGraphics.java
create mode 100644 src/java/org/apache/poi/ddf/DefaultEscherRecordFactory.java
create mode 100644 src/java/org/apache/poi/ddf/EscherArrayProperty.java
create mode 100644 src/java/org/apache/poi/ddf/EscherBSERecord.java
create mode 100644 src/java/org/apache/poi/ddf/EscherBlipRecord.java
create mode 100644 src/java/org/apache/poi/ddf/EscherBoolProperty.java
create mode 100644 src/java/org/apache/poi/ddf/EscherChildAnchorRecord.java
create mode 100644 src/java/org/apache/poi/ddf/EscherClientAnchorRecord.java
create mode 100644 src/java/org/apache/poi/ddf/EscherClientDataRecord.java
create mode 100644 src/java/org/apache/poi/ddf/EscherComplexProperty.java
create mode 100644 src/java/org/apache/poi/ddf/EscherContainerRecord.java
create mode 100644 src/java/org/apache/poi/ddf/EscherDgRecord.java
create mode 100644 src/java/org/apache/poi/ddf/EscherDggRecord.java
create mode 100644 src/java/org/apache/poi/ddf/EscherDump.java
create mode 100644 src/java/org/apache/poi/ddf/EscherOptRecord.java
create mode 100644 src/java/org/apache/poi/ddf/EscherProperties.java
create mode 100644 src/java/org/apache/poi/ddf/EscherProperty.java
create mode 100644 src/java/org/apache/poi/ddf/EscherPropertyFactory.java
create mode 100644 src/java/org/apache/poi/ddf/EscherPropertyMetaData.java
create mode 100644 src/java/org/apache/poi/ddf/EscherRGBProperty.java
create mode 100644 src/java/org/apache/poi/ddf/EscherRecord.java
create mode 100644 src/java/org/apache/poi/ddf/EscherRecordFactory.java
create mode 100644 src/java/org/apache/poi/ddf/EscherSerializationListener.java
create mode 100644 src/java/org/apache/poi/ddf/EscherShapePathProperty.java
create mode 100644 src/java/org/apache/poi/ddf/EscherSimpleProperty.java
create mode 100644 src/java/org/apache/poi/ddf/EscherSpRecord.java
create mode 100644 src/java/org/apache/poi/ddf/EscherSpgrRecord.java
create mode 100644 src/java/org/apache/poi/ddf/EscherSplitMenuColorsRecord.java
create mode 100644 src/java/org/apache/poi/ddf/EscherTextboxRecord.java
create mode 100644 src/java/org/apache/poi/ddf/NullEscherSerializationListener.java
create mode 100644 src/java/org/apache/poi/ddf/TestEscherBSERecord.java
create mode 100644 src/java/org/apache/poi/ddf/TestEscherBlipRecord.java
create mode 100644 src/java/org/apache/poi/ddf/TestEscherBoolProperty.java
create mode 100644 src/java/org/apache/poi/ddf/TestEscherChildAnchorRecord.java
create mode 100644 src/java/org/apache/poi/ddf/TestEscherClientAnchorRecord.java
create mode 100644 src/java/org/apache/poi/ddf/TestEscherClientDataRecord.java
create mode 100644 src/java/org/apache/poi/ddf/TestEscherContainerRecord.java
create mode 100644 src/java/org/apache/poi/ddf/TestEscherDgRecord.java
create mode 100644 src/java/org/apache/poi/ddf/TestEscherDggRecord.java
create mode 100644 src/java/org/apache/poi/ddf/TestEscherOptRecord.java
create mode 100644 src/java/org/apache/poi/ddf/TestEscherPropertyFactory.java
create mode 100644 src/java/org/apache/poi/ddf/TestEscherSpRecord.java
create mode 100644 src/java/org/apache/poi/ddf/TestEscherSpgrRecord.java
create mode 100644 src/java/org/apache/poi/ddf/TestEscherSplitMenuColorsRecord.java
create mode 100644 src/java/org/apache/poi/ddf/TestUnknownEscherRecord.java
create mode 100644 src/java/org/apache/poi/ddf/UnknownEscherRecord.java
create mode 100644 src/java/org/apache/poi/ddf/package.html
create mode 100644 src/java/org/apache/poi/hssf/model/AbstractShape.java
create mode 100644 src/java/org/apache/poi/hssf/model/ConvertAnchor.java
create mode 100644 src/java/org/apache/poi/hssf/model/DrawingManager.java
create mode 100644 src/java/org/apache/poi/hssf/model/LineShape.java
create mode 100644 src/java/org/apache/poi/hssf/model/PolygonShape.java
create mode 100644 src/java/org/apache/poi/hssf/model/SimpleFilledShape.java
create mode 100644 src/java/org/apache/poi/hssf/model/TestDrawingManager.java
create mode 100644 src/java/org/apache/poi/hssf/model/TextboxShape.java
create mode 100644 src/java/org/apache/poi/hssf/record/AbstractEscherHolderRecord.java
create mode 100644 src/java/org/apache/poi/hssf/record/CommonObjectDataSubRecord.java
create mode 100644 src/java/org/apache/poi/hssf/record/DrawingGroupRecord.java
create mode 100644 src/java/org/apache/poi/hssf/record/DrawingRecord.java
create mode 100644 src/java/org/apache/poi/hssf/record/DrawingRecordForBiffViewer.java
create mode 100644 src/java/org/apache/poi/hssf/record/DrawingSelectionRecord.java
create mode 100644 src/java/org/apache/poi/hssf/record/EndSubRecord.java
create mode 100644 src/java/org/apache/poi/hssf/record/EscherAggregate.java
create mode 100644 src/java/org/apache/poi/hssf/record/GroupMarkerSubRecord.java
create mode 100644 src/java/org/apache/poi/hssf/record/HorizontalPageBreakRecord.java
create mode 100644 src/java/org/apache/poi/hssf/record/ObjRecord.java
create mode 100644 src/java/org/apache/poi/hssf/record/PageBreakRecord.java
create mode 100644 src/java/org/apache/poi/hssf/record/SubRecord.java
create mode 100644 src/java/org/apache/poi/hssf/record/TestCommonObjectDataSubRecord.java
create mode 100644 src/java/org/apache/poi/hssf/record/TestDrawingGroupRecord.java
create mode 100644 src/java/org/apache/poi/hssf/record/TestEndSubRecord.java
create mode 100644 src/java/org/apache/poi/hssf/record/TestEscherAggregate.java
create mode 100644 src/java/org/apache/poi/hssf/record/TestTextObjectBaseRecord.java
create mode 100644 src/java/org/apache/poi/hssf/record/TextObjectBaseRecord.java
create mode 100644 src/java/org/apache/poi/hssf/record/TextObjectRecord.java
create mode 100644 src/java/org/apache/poi/hssf/record/VerticalPageBreakRecord.java
create mode 100644 src/java/org/apache/poi/hssf/usermodel/DummyGraphics2d.java
create mode 100644 src/java/org/apache/poi/hssf/usermodel/EscherGraphics.java
create mode 100644 src/java/org/apache/poi/hssf/usermodel/EscherGraphics2d.java
create mode 100644 src/java/org/apache/poi/hssf/usermodel/FontDetails.java
create mode 100644 src/java/org/apache/poi/hssf/usermodel/HSSFAnchor.java
create mode 100644 src/java/org/apache/poi/hssf/usermodel/HSSFChildAnchor.java
create mode 100644 src/java/org/apache/poi/hssf/usermodel/HSSFClientAnchor.java
create mode 100644 src/java/org/apache/poi/hssf/usermodel/HSSFPatriarch.java
create mode 100644 src/java/org/apache/poi/hssf/usermodel/HSSFPolygon.java
create mode 100644 src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java
create mode 100644 src/java/org/apache/poi/hssf/usermodel/HSSFShape.java
create mode 100644 src/java/org/apache/poi/hssf/usermodel/HSSFShapeContainer.java
create mode 100644 src/java/org/apache/poi/hssf/usermodel/HSSFShapeGroup.java
create mode 100644 src/java/org/apache/poi/hssf/usermodel/HSSFSimpleShape.java
create mode 100644 src/java/org/apache/poi/hssf/usermodel/HSSFTextbox.java
create mode 100644 src/java/org/apache/poi/hssf/usermodel/StaticFontMetrics.java
create mode 100644 src/java/org/apache/poi/hssf/usermodel/TestEscherGraphics.java
create mode 100644 src/java/org/apache/poi/hssf/usermodel/TestEscherGraphics2d.java
create mode 100644 src/java/org/apache/poi/hssf/usermodel/TestFontDetails.java
create mode 100644 src/java/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java
create mode 100644 src/java/org/apache/poi/hssf/usermodel/TestHSSFRichTextString.java
create mode 100644 src/java/org/apache/poi/util/DrawingDump.java
create mode 100644 src/records/definitions/common_object_data_record.xml
create mode 100644 src/records/definitions/ftend_record.xml
create mode 100644 src/records/definitions/subrecord.xsl
create mode 100644 src/records/definitions/subrecord_test.xsl
create mode 100644 src/records/definitions/textobject_record.xml
create mode 100644 src/resources/fontmetrics/font_metrics.properties
diff --git a/build.xml b/build.xml
index 1561122467..9e2148fb21 100644
--- a/build.xml
+++ b/build.xml
@@ -135,10 +135,27 @@ Main targets:
+
+
+
+
+
+
+ Generating clover report
+
+
+
+
+
+
+
+
+
+
@@ -253,7 +270,7 @@ Main targets:
-
@@ -312,7 +329,7 @@ Main targets:
-
+
@@ -521,6 +538,7 @@ FORREST_HOME environment variable!
+
@@ -560,6 +578,9 @@ FORREST_HOME environment variable!
+
+
+
diff --git a/src/contrib/src/org/apache/poi/contrib/metrics/FontMetricsDumper.java b/src/contrib/src/org/apache/poi/contrib/metrics/FontMetricsDumper.java
new file mode 100644
index 0000000000..2a02ae9fbf
--- /dev/null
+++ b/src/contrib/src/org/apache/poi/contrib/metrics/FontMetricsDumper.java
@@ -0,0 +1,65 @@
+package org.apache.poi.contrib.metrics;
+
+import java.awt.*;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+public class FontMetricsDumper
+{
+ public static void main( String[] args ) throws IOException
+ {
+
+ Properties props = new Properties();
+
+ Font[] allFonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
+ for ( int i = 0; i < allFonts.length; i++ )
+ {
+ String fontName = allFonts[i].getFontName();
+
+ Font font = new Font(fontName, Font.BOLD, 10);
+ FontMetrics fontMetrics = Toolkit.getDefaultToolkit().getFontMetrics(font);
+ int fontHeight = fontMetrics.getHeight();
+
+ props.setProperty("font." + fontName + ".height", fontHeight+"");
+ StringBuffer characters = new StringBuffer();
+ for (char c = 'a'; c <= 'z'; c++)
+ {
+ characters.append( c + ", " );
+ }
+ for (char c = 'A'; c <= 'Z'; c++)
+ {
+ characters.append( c + ", " );
+ }
+ for (char c = '0'; c <= '9'; c++)
+ {
+ characters.append( c + ", " );
+ }
+ StringBuffer widths = new StringBuffer();
+ for (char c = 'a'; c <= 'z'; c++)
+ {
+ widths.append( fontMetrics.getWidths()[c] + ", " );
+ }
+ for (char c = 'A'; c <= 'Z'; c++)
+ {
+ widths.append( fontMetrics.getWidths()[c] + ", " );
+ }
+ for (char c = '0'; c <= '9'; c++)
+ {
+ widths.append( fontMetrics.getWidths()[c] + ", " );
+ }
+ props.setProperty("font." + fontName + ".characters", characters.toString());
+ props.setProperty("font." + fontName + ".widths", widths.toString());
+ }
+
+ FileOutputStream fileOut = new FileOutputStream("font_metrics.properties");
+ try
+ {
+ props.store(fileOut, "Font Metrics");
+ }
+ finally
+ {
+ fileOut.close();
+ }
+ }
+}
diff --git a/src/documentation/content/xdocs/hssf/quick-guide.xml b/src/documentation/content/xdocs/hssf/quick-guide.xml
index 8940bc5fe1..0ef0ccb629 100644
--- a/src/documentation/content/xdocs/hssf/quick-guide.xml
+++ b/src/documentation/content/xdocs/hssf/quick-guide.xml
@@ -40,6 +40,9 @@
Create split and freeze panes.
Repeating rows and columns.
Headers and Footers.
+ Drawing Shapes.
+ Styling Shapes.
+ Shapes and Graphics2d.
Features
@@ -692,6 +695,212 @@
fileOut.close();
+
+
+ Drawing Shapes
+
+ POI supports drawing shapes using the Microsoft Office
+ drawing tools. Shapes on a sheet are organized in a
+ hiearchy of groups and and shapes. The top-most shape
+ is the patriarch. This is not visisble on the sheet
+ at all. To start drawing you need to call createPatriarch
+ on the HSSFSheet
class. This has the
+ effect erasing any other shape information stored
+ in that sheet. By default POI will leave shape
+ records alone in the sheet unless you make a call to
+ this method.
+
+
+ To create a shape you have to go through the following
+ steps:
+
+
+ Create the patriarch.
+ Create an anchor to position the shape on the sheet.
+ Ask the patriarch to create the shape.
+ Set the shape type (line, oval, rectangle etc...)
+ Set any other style details converning the shape. (eg:
+ line thickness, etc...)
+
+
+ HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
+ a = new HSSFClientAnchor( 0, 0, 1023, 255, (short) 1, 0, (short) 1, 0 );
+ HSSFSimpleShape shape1 = patriarch.createSimpleShape(a1);
+ shape1.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE);
+
+
+ Text boxes are created using a different call:
+
+
+ HSSFTextbox textbox1 = patriarch.createTextbox(
+ new HSSFClientAnchor(0,0,0,0,(short)1,1,(short)2,2));
+ textbox1.setString(new HSSFRichTextString("This is a test") );
+
+
+ It's possible to use different fonts to style parts of
+ the text in the textbox. Here's how:
+
+
+ HSSFFont font = wb.createFont();
+ font.setItalic(true);
+ font.setUnderline(HSSFFont.U_DOUBLE);
+ HSSFRichTextString string = new HSSFRichTextString("Woo!!!");
+ string.applyFont(2,5,font);
+ textbox.setString(string );
+
+
+ Just as can be done manually using Excel, it is possible
+ to group shapes together. This is done by calling
+ createGroup()
and then creating the shapes
+ using those groups.
+
+
+ It's also possible to create groups within groups.
+
+ Any group you create should contain at least two
+ other shapes or subgroups.
+
+ Here's how to create a shape group:
+
+
+ // Create a shape group.
+ HSSFShapeGroup group = patriarch.createGroup(
+ new HSSFClientAnchor(0,0,900,200,(short)2,2,(short)2,2));
+
+ // Create a couple of lines in the group.
+ HSSFSimpleShape shape1 = group.createShape(new HSSFChildAnchor(3,3,500,500));
+ shape1.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE);
+ ( (HSSFChildAnchor) shape1.getAnchor() ).setAnchor((short)3,3,500,500);
+ HSSFSimpleShape shape2 = group.createShape(new HSSFChildAnchor((short)1,200,400,600));
+ shape2.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE);
+
+
+ If you're being observant you'll noticed that the shapes
+ that are added to the group use a new type of anchor:
+ the HSSFChildAnchor
. What happens is that
+ the created group has it's own coordinate space for
+ shapes that are placed into it. POI defaults this to
+ (0,0,1023,255) but you are able to change it as desired.
+ Here's how:
+
+
+ myGroup.setCoordinates(10,10,20,20); // top-left, bottom-right
+
+
+ If you create a group within a group it's also going
+ to have it's own coordinate space.
+
+
+
+
+ Styling Shapes
+
+ By default shapes can look a little plain. It's possible
+ to apply different styles to the shapes however. The
+ sorts of things that can currently be done are:
+
+
+ Change the fill color.
+ Make a shape with no fill color.
+ Change the thickness of the lines.
+ Change the style of the lines. Eg: dashed, dotted.
+ Change the line color.
+
+
+ Here's an examples of how this is done:
+
+
+ HSSFSimpleShape s = patriarch.createSimpleShape(a);
+ s.setShapeType(HSSFSimpleShape.OBJECT_TYPE_OVAL);
+ s.setLineStyleColor(10,10,10);
+ s.setFillColor(90,10,200);
+ s.setLineWidth(HSSFShape.LINEWIDTH_ONE_PT * 3);
+ s.setLineStyle(HSSFShape.LINESTYLE_DOTSYS);
+
+
+
+ Shapes and Graphics2d
+
+ While the native POI shape drawing commands are the
+ recommended way to draw shapes in a shape it's sometimes
+ desirable to use a standard API for compatibility with
+ external libraries. With this in mind we created some
+ wrappers for Graphics
and Graphics2d
.
+
+
+ It's important to not however before continuing that
+ Graphics2d
is a poor match to the capabilities
+ of the Microsoft Office drawing commands. The older
+ Graphics
class offers a closer match but is
+ still a square peg in a round hole.
+
+
+ All Graphics commands are issued into an HSSFShapeGroup
.
+ Here's how it's done:
+
+
+ a = new HSSFClientAnchor( 0, 0, 1023, 255, (short) 1, 0, (short) 1, 0 );
+ group = patriarch.createGroup( a );
+ group.setCoordinates( 0, 0, 80 * 4 , 12 * 23 );
+ float verticalPointsPerPixel = a.getAnchorHeightInPoints(sheet) / (float)Math.abs(group.getY2() - group.getY1());
+ g = new EscherGraphics( group, wb, Color.black, verticalPointsPerPixel );
+ g2d = new EscherGraphics2d( g );
+ drawChemicalStructure( g2d );
+
+
+ The first thing we do is create the group and set it's coordinates
+ to match what we plan to draw. Next we calculate a reasonable
+ fontSizeMultipler then create the EscherGraphics object.
+ Since what we really want is a Graphics2d
+ object we create an EscherGraphics2d object and pass in
+ the graphics object we created. Finally we call a routine
+ that draws into the EscherGraphics2d object.
+
+
+ The vertical points per pixel deserves some more explanation.
+ One of the difficulties in converting Graphics calls
+ into escher drawing calls is that Excel does not have
+ the concept of absolute pixel positions. It measures
+ it's cell widths in 'characters' and the cell heights in points.
+ Unfortunately it's not defined exactly what type of character it's
+ measuring. Presumably this is due to the fact that the Excel will be
+ using different fonts on different platforms or even within the same
+ platform.
+
+
+ Because of this constraint we've had to implement the concept of a
+ verticalPointsPerPixel. This the amount the font should be scaled by when
+ you issue commands such as drawString(). To calculate this value
+ use the follow formula:
+
+
+ multipler = groupHeightInPoints / heightOfGroup
+
+
+ The height of the group is calculated fairly simply by calculating the
+ difference between the y coordinates of the bounding box of the shape. The
+ height of the group can be calculated by using a convenience called
+ HSSFClientAnchor.getAnchorHeightInPoints()
.
+
+
+ Many of the functions supported by the graphics classes
+ are not complete. Here's some of the functions that are known
+ to work.
+
+
+ fillRect()
+ fillOval()
+ drawString()
+ drawOval()
+ drawLine()
+ clearRect()
+
+
+ Functions that are not supported will return and log a message
+ using the POI logging infrastructure (disabled by default).
+
+
+
+
+ This package contains classes for decoding the Microsoft Office
+ Drawing format otherwise known as escher henceforth known in POI
+ as the Dreadful Drawing Format.
+
+
+
+