From fbe58605012a91260528ae703df172e160445a26 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Wed, 12 Apr 2006 18:47:44 +0000 Subject: [PATCH] Add Yegor's documention on the Shapes and Pictures stuff 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 | 1 + .../content/xdocs/hslf/how-to-shapes.xml | 215 ++++++++++++++++++ .../content/xdocs/hslf/hslf_shapes.gif | Bin 0 -> 5855 bytes 3 files changed, 216 insertions(+) create mode 100644 src/documentation/content/xdocs/hslf/how-to-shapes.xml create mode 100644 src/documentation/content/xdocs/hslf/hslf_shapes.gif diff --git a/src/documentation/content/xdocs/hslf/book.xml b/src/documentation/content/xdocs/hslf/book.xml index a0a827b0a7..a8e76d7f79 100644 --- a/src/documentation/content/xdocs/hslf/book.xml +++ b/src/documentation/content/xdocs/hslf/book.xml @@ -13,6 +13,7 @@ + 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 index 0000000000..21cdb00d18 --- /dev/null +++ b/src/documentation/content/xdocs/hslf/how-to-shapes.xml @@ -0,0 +1,215 @@ + + + + + +
+ Busy Developers' Guide to HSLF drawing layer + + + +
+ +
Busy Developers' Guide to HSLF drawing layer +
Index of Features +
    +
  • How to create a new presentation and add new slides to it
  • +
  • How to retrieve or change slide size
  • +
  • How to get shapes contained in a particular slide
  • +
  • Drawing a shape on a slide
  • +
  • How to add/retrieve pictures
  • +
+
+
Features + +
New Presentation + + //create a new empty slide show + SlideShow ppt = new SlideShow(); + + //add first slide + Slide s1 = ppt.createSlide(); + + //add second slide + Slide s2 = ppt.createSlide(); + + //save changes in a file + FileOutputStream out = new FileOutputStream("slideshow.ppt"); + wb.write(out); + out.close(); + +
+ +
How to retrieve or change slide size + + SlideShow ppt = new SlideShow(new HSLFSlideShow("slideshow.ppt")); + //retrieve page size. Coordinates are expressed in points (72 dpi) + java.awt.Dimension pgsize = ppt.getPageSize(); + int pgx = pgsize.width; //slide width + int pgy = pgsize.height; //slide height + + //set new page size + ppt.setPageSize(new java.awt.Dimension(1024, 768)); + //save changes + FileOutputStream out = new FileOutputStream("slideshow.ppt"); + wb.write(out); + out.close(); + +
+ +
How to get shapes contained in a particular slide +

The superclass of all shapes in HSLF is the Shape class - the elemental object that composes a drawing. + The following pictute shows the class tree of HSLF shapes: +

+

+ Class Tree of HSLF Shapes +

+

+ The following fragment demonstrates how to iterate over shapes for each slide. +

+ + SlideShow ppt = new SlideShow(new HSLFSlideShow("slideshow.ppt")); + //get slides + Slide[] slide = ppt.getSlides(); + for (int i = 0; i < slide.length; i++){ + Shape[] sh = slide[i].getShapes(); + for (int j = 0; j < sh.length; j++){ + //name of the shape + String name = sh[j].getShapeName(); + + //shapes's anchor which defines the position of this shape in the slide + java.awt.Rectangle anchor = sh[j].getAnchor(); + + if (sh[j] instanceof Line){ + Line line = (Line)sh[j]; + //work with Line + } else if (sh[j] instanceof AutoShape){ + AutoShape shape = (AutoShape)sh[j]; + //work with AutoShape + } else if (sh[j] instanceof TextBox){ + TextBox shape = (TextBox)sh[j]; + //work with TextBox + } else if (sh[j] instanceof Picture){ + Picture shape = (Picture)sh[j]; + //work with Picture + } + } + } + +
+ +
Drawing a shape on a slide +

+ When you add a shape, you usually specify the dimensions of the shape and the position + of the upper left corner of the bounding box for the shape relative to the upper left + corner of the slide. Distances in the drawing layer are measured in points (72 points = 1 inch). +

+ + SlideShow ppt = new SlideShow); + + Slide slide = ppt.createSlide(); + + //Line shape + Line line = new Line(); + line.setAnchor(new java.awt.Rectangle(50, 50, 100, 20)); + line.setLineColor(new Color(0, 128, 0)); + line.setLineStyle(Line.LineDashDotSys); + slide.addShape(line); + + //TextBox + TextBox txt = new TextBox(); + txt.setText("Hello, World!"); + txt.setAnchor(new java.awt.Rectangle(100, 100, 200, 50)); + txt.setFontSize(32); + txt.setFontName("Arial"); + txt.setBold(true); + slide.addShape(txt); + + //Autoshape + //32-point star + AutoShape sh1 = new AutoShape(ShapeTypes.Star32); + sh1.setAnchor(new java.awt.Rectangle(50, 50, 100, 200)); + sh1.setFillColor(Color.red); + slide.addShape(sh1); + + //Trapezoid + AutoShape sh2 = new AutoShape(ShapeTypes.Trapezoid); + sh2.setAnchor(new java.awt.Rectangle(150, 150, 100, 200)); + sh2.setFillColor(Color.blue); + slide.addShape(sh2); + + FileOutputStream out = new FileOutputStream("slideshow.ppt"); + wb.write(out); + out.close(); + +
+ +
How to add/retrieve pictures +

+ Note, for now only PNG and JPEG formats are supported. +

+ + SlideShow ppt = new SlideShow(new HSLFSlideShow("slideshow.ppt")); + + //extract all pictures contained in the presentation + PictureData[] pdata = ppt.getPictureData(); + for (int i = 0; i < pdata.length; i++){ + PictureData pict = pdata[i]; + + //raw picture data + byte[] data = pict.getData(); + + int type = pict.getType(); + if (type == Picture.JPEG){ + FileOutputStream out = new FileOutputStream("pict"+i+".jpg"); + out.write(data); + out.close(); + } else if (type == Picture.PNG){ + FileOutputStream out = new FileOutputStream("pict"+i+".png"); + out.write(data); + out.close(); + } + } + + // add a new picture to this slideshow and insert it in a new slide + int idx = ppt.addPicture(new File("clock.jpg"), Picture.JPEG); + + Picture pict = new Picture(idx); + + //set image position in the slide + pict.setAnchor(new java.awt.Rectangle(100, 100, 300, 200)); + + Slide slide = ppt.createSlide(); + slide.addShape(pict); + + //now retrieve pictures containes in the first slide and save them on disk + slide = ppt.getSlides()[0]; + Shape[] sh = slide.getShapes(); + for (int i = 0; i < sh.length; i++){ + if (sh[i] instanceof Picture){ + Picture pict = (Picture)sh[i]; + PictureData data = pict.getPictureData(); + byte[] data = pict.getData(); + int type = pict.getType(); + if (type == Picture.JPEG){ + FileOutputStream out = new FileOutputStream("slide0_"+i+".jpg"); + out.write(data); + out.close(); + } else if (type == Picture.PNG){ + FileOutputStream out = new FileOutputStream("slide0_"+i+".png"); + out.write(data); + out.close(); + } + } + } + + FileOutputStream out = new FileOutputStream("slideshow.ppt"); + wb.write(out); + out.close(); + + +
+
+
+ +
diff --git a/src/documentation/content/xdocs/hslf/hslf_shapes.gif b/src/documentation/content/xdocs/hslf/hslf_shapes.gif new file mode 100644 index 0000000000000000000000000000000000000000..9a078b45ac1c7fe1ad30d1bb55b5d05b15988204 GIT binary patch literal 5855 zcmb_egY(f~_<77zm(1K0pGfCUs2hyxLQz>qK)4hAC-=L6aT z9uf&d;$TPuaa@1}5X2#2I2;T|0Hy~>0l6>&5=Owm2*7xN9so_C8ju5+A0Pot2(Sjg z0MYB!MU-Fdxts@NhUJjsWNij0>;;f=B`mNdR;N zlm-L+bkaO&3OcZX3hh}(XwE9i}+6VNw}$}jAX zWresdeylGVjAPJ_;nX|gZF(naQehh%Y(11A^9Ylz=L^GSDf#X$>U|nd&ASyw#iief z{#>N{mh@IvL-|BFC|N&8ziF2dWZckW__V2VrY5K{hRfh(ah~Z@uX_%tW=Xv&&qqD+ z1{sel>R#Mg9vx}%8fyp=s-ZE=TwUy;xh}xm{z|rYAVI(&2;?u<(@jIq>GBM@7IKB2 z=@qvq``XZGj)r!)>TBM;>AEHJbo5#9$TjqkV~}e9^@Ulrvfv2IbBAvW<)0EHJ?TP> zH$Ed_-W;={fptZxXIenSJIPlESFbYSIbnK z#u6{bORoR9N-uA+$P9i%cBZ-Pcv^m(7;wG#3pXgAONPvo1$;G6Q>(Rc&46xRg#X^I zTBCy($vkW|aB^|$VeFM|(PV^x`o^j@g}9%irACuWejMqLKM3^6D0MwRQQ>MqaH^dP zU##Y9rR=y#kS?!F4+-UFx>SveMWB2{fJrp%9MIjSkd{_xf(gl7?drao5G@h%9D-&XKvndIhYf$pa&!QwfJav%e9>p zZpRxxD0s_H3c_BUPt%s$G)b%BCb;6g@`O!Av~^H-U9;fFZ1xczj_kbtE*p}%q?*Ob#1S)J)*9@Nw~$j zcNWGj8!?MP6;#X|57#uaRk*LUiORYEoZiCQZiQQV#__z}4`iN7OtiM#uCo0gFEHCt zs>|Cg`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