]> source.dussan.org Git - poi.git/commitdiff
Add Yegor's documention on the Shapes and Pictures stuff
authorNick Burch <nick@apache.org>
Wed, 12 Apr 2006 18:47:44 +0000 (18:47 +0000)
committerNick Burch <nick@apache.org>
Wed, 12 Apr 2006 18:47:44 +0000 (18:47 +0000)
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@393575 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/hslf/book.xml
src/documentation/content/xdocs/hslf/how-to-shapes.xml [new file with mode: 0644]
src/documentation/content/xdocs/hslf/hslf_shapes.gif [new file with mode: 0644]

index a0a827b0a7b35632011d4571f70aa5699e04f857..a8e76d7f79ce0ac032bb9e3d9f2ccd2d35ce8517 100644 (file)
@@ -13,6 +13,7 @@
     <menu label="HSLF">
         <menu-item label="Overview" href="index.html"/>
         <menu-item label="Quick Guide" href="quick-guide.html"/>
+        <menu-item label="Shapes HowTo" href="how-to-shapes.html"/>
         <menu-item label="PPT File Format" href="ppt-file-format.html"/>
        </menu>
        
diff --git a/src/documentation/content/xdocs/hslf/how-to-shapes.xml b/src/documentation/content/xdocs/hslf/how-to-shapes.xml
new file mode 100644 (file)
index 0000000..21cdb00
--- /dev/null
@@ -0,0 +1,215 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<!-- Copyright (C) 2004 The Apache Software Foundation. All rights reserved. -->\r
+<!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.1//EN" "../dtd/document-v11.dtd">\r
+\r
+<document>\r
+    <header>\r
+        <title>Busy Developers' Guide to HSLF drawing layer</title>\r
+        <authors>\r
+            <person email="yegor@dinom.ru" name="Yegor Kozlov" id="CO"/>\r
+        </authors>\r
+    </header>\r
+    <body>\r
+        <section><title>Busy Developers' Guide to HSLF drawing layer</title>\r
+             <section><title>Index of Features</title>\r
+                <ul>\r
+                    <li><link href="#NewPresentation">How to create a new presentation and add new slides to it</link></li>\r
+                    <li><link href="#PageSize">How to retrieve or change slide size</link></li>\r
+                    <li><link href="#GetShapes">How to get shapes contained in a particular slide</link></li>\r
+                    <li><link href="#Shapes">Drawing a shape on a slide</link></li>\r
+                    <li><link href="#Pictures">How to add/retrieve pictures</link></li>\r
+                </ul>\r
+            </section>\r
+            <section><title>Features</title>\r
+                <anchor id="NewPresentation"/>\r
+                <section><title>New Presentation</title>\r
+                  <source>\r
+    //create a new empty slide show\r
+    SlideShow ppt = new SlideShow();\r
+\r
+    //add first slide\r
+    Slide s1 = ppt.createSlide();\r
+\r
+    //add second slide\r
+    Slide s2 = ppt.createSlide();\r
+    \r
+    //save changes in a file\r
+    FileOutputStream out = new FileOutputStream("slideshow.ppt");\r
+    wb.write(out);\r
+    out.close();\r
+                 </source>\r
+                </section>\r
+                <anchor id="PageSize"/>\r
+                <section><title>How to retrieve or change slide size</title>\r
+                    <source>\r
+    SlideShow ppt = new SlideShow(new HSLFSlideShow("slideshow.ppt"));\r
+    //retrieve page size. Coordinates are expressed in points (72 dpi)\r
+    java.awt.Dimension pgsize = ppt.getPageSize();\r
+    int pgx = pgsize.width; //slide width\r
+    int pgy = pgsize.height; //slide height\r
+\r
+    //set new page size\r
+    ppt.setPageSize(new java.awt.Dimension(1024, 768));\r
+    //save changes \r
+    FileOutputStream out = new FileOutputStream("slideshow.ppt");\r
+    wb.write(out);\r
+    out.close();\r
+                  </source>\r
+                </section>\r
+                <anchor id="GetShapes"/>\r
+                <section><title>How to get shapes contained in a particular slide</title>\r
+                  <p>The superclass of all shapes in HSLF is the Shape class - the elemental object that composes a drawing.\r
+                    The following pictute shows the class tree of HSLF shapes:\r
+                  </p>\r
+                  <p>\r
+                    <img src="hslf_shapes.gif" alt="Class Tree of HSLF Shapes" width="611" height="285"/>\r
+                  </p>\r
+                  <p>\r
+                    The following fragment demonstrates how to iterate over shapes for each slide.\r
+                  </p>\r
+                    <source>\r
+  SlideShow ppt = new SlideShow(new HSLFSlideShow("slideshow.ppt"));\r
+  //get slides \r
+  Slide[] slide = ppt.getSlides();\r
+  for (int i = 0; i &lt; slide.length; i++){\r
+    Shape[] sh = slide[i].getShapes();\r
+    for (int j = 0; j &lt; sh.length; j++){\r
+      //name of the shape\r
+      String name = sh[j].getShapeName();\r
+\r
+      //shapes's anchor which defines the position of this shape in the slide\r
+      java.awt.Rectangle anchor = sh[j].getAnchor();\r
+\r
+      if (sh[j] instanceof Line){\r
+        Line line = (Line)sh[j];\r
+        //work with Line\r
+      } else if (sh[j] instanceof AutoShape){\r
+        AutoShape shape = (AutoShape)sh[j];\r
+        //work with AutoShape\r
+      } else if (sh[j] instanceof TextBox){\r
+        TextBox shape = (TextBox)sh[j];\r
+        //work with TextBox\r
+      } else if (sh[j] instanceof Picture){\r
+        Picture shape = (Picture)sh[j];\r
+        //work with Picture\r
+      }\r
+    }\r
+  }\r
+                  </source>\r
+                </section>\r
+                <anchor id="Shapes"/>\r
+                <section><title>Drawing a shape on a slide</title>\r
+                   <p>\r
+                     When you add a shape, you usually specify the dimensions of the shape and the position\r
+                     of the upper left corner of the bounding box for the shape relative to the upper left\r
+                     corner of the slide. Distances in the drawing layer are measured in points (72 points = 1 inch).\r
+                   </p>\r
+                    <source>\r
+  SlideShow ppt = new SlideShow);\r
+\r
+  Slide slide = ppt.createSlide();\r
+\r
+  //Line shape\r
+  Line line = new Line();\r
+  line.setAnchor(new java.awt.Rectangle(50, 50, 100, 20));\r
+  line.setLineColor(new Color(0, 128, 0));\r
+  line.setLineStyle(Line.LineDashDotSys);\r
+  slide.addShape(line);\r
+\r
+  //TextBox\r
+  TextBox txt = new TextBox();\r
+  txt.setText("Hello, World!");\r
+  txt.setAnchor(new java.awt.Rectangle(100, 100, 200, 50));\r
+  txt.setFontSize(32);\r
+  txt.setFontName("Arial");\r
+  txt.setBold(true);\r
+  slide.addShape(txt);\r
+\r
+  //Autoshape\r
+  //32-point star\r
+  AutoShape sh1 = new AutoShape(ShapeTypes.Star32);\r
+  sh1.setAnchor(new java.awt.Rectangle(50, 50, 100, 200));\r
+  sh1.setFillColor(Color.red);\r
+  slide.addShape(sh1);\r
+\r
+  //Trapezoid\r
+  AutoShape sh2 = new AutoShape(ShapeTypes.Trapezoid);\r
+  sh2.setAnchor(new java.awt.Rectangle(150, 150, 100, 200));\r
+  sh2.setFillColor(Color.blue);\r
+  slide.addShape(sh2);\r
+\r
+  FileOutputStream out = new FileOutputStream("slideshow.ppt");\r
+  wb.write(out);\r
+  out.close();\r
+                  </source>\r
+                </section>\r
+                <anchor id="Pictures"/>\r
+                <section><title>How to add/retrieve pictures</title>\r
+                  <p>\r
+                    Note, for now only PNG and JPEG formats are supported.\r
+                  </p>\r
+                    <source>\r
+  SlideShow ppt = new SlideShow(new HSLFSlideShow("slideshow.ppt"));\r
+\r
+  //extract all pictures contained in the presentation\r
+  PictureData[] pdata = ppt.getPictureData();\r
+  for (int i = 0; i &lt; pdata.length; i++){\r
+    PictureData pict = pdata[i];\r
+\r
+    //raw picture data\r
+    byte[] data = pict.getData();\r
+\r
+    int type = pict.getType();\r
+    if (type == Picture.JPEG){\r
+      FileOutputStream out = new FileOutputStream("pict"+i+".jpg");\r
+      out.write(data);\r
+      out.close();\r
+    } else if (type == Picture.PNG){\r
+      FileOutputStream out = new FileOutputStream("pict"+i+".png");\r
+      out.write(data);\r
+      out.close();\r
+    }\r
+  }\r
+\r
+  // add a new picture to this slideshow and insert it in a  new slide\r
+  int idx = ppt.addPicture(new File("clock.jpg"), Picture.JPEG);\r
+\r
+  Picture pict = new Picture(idx);\r
+\r
+  //set image position in the slide\r
+  pict.setAnchor(new java.awt.Rectangle(100, 100, 300, 200));\r
+\r
+  Slide slide = ppt.createSlide();\r
+  slide.addShape(pict);\r
+\r
+  //now retrieve pictures containes in the first slide and save them on disk\r
+  slide = ppt.getSlides()[0];\r
+  Shape[] sh = slide.getShapes();\r
+  for (int i = 0; i &lt; sh.length; i++){\r
+    if (sh[i] instanceof Picture){\r
+      Picture pict = (Picture)sh[i];\r
+      PictureData data = pict.getPictureData();\r
+      byte[] data = pict.getData();\r
+      int type = pict.getType();\r
+      if (type == Picture.JPEG){\r
+        FileOutputStream out = new FileOutputStream("slide0_"+i+".jpg");\r
+        out.write(data);\r
+        out.close();\r
+      } else if (type == Picture.PNG){\r
+        FileOutputStream out = new FileOutputStream("slide0_"+i+".png");\r
+        out.write(data);\r
+        out.close();\r
+      }\r
+    }\r
+  }\r
+\r
+  FileOutputStream out = new FileOutputStream("slideshow.ppt");\r
+  wb.write(out);\r
+  out.close();\r
+\r
+                    </source>\r
+                </section>\r
+            </section>\r
+        </section>\r
+    </body>\r
+</document>\r
diff --git a/src/documentation/content/xdocs/hslf/hslf_shapes.gif b/src/documentation/content/xdocs/hslf/hslf_shapes.gif
new file mode 100644 (file)
index 0000000..9a078b4
Binary files /dev/null and b/src/documentation/content/xdocs/hslf/hslf_shapes.gif differ