Return-Path: Delivered-To: apmail-poi-dev-archive@www.apache.org Received: (qmail 67444 invoked from network); 4 Sep 2008 09:09:40 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Sep 2008 09:09:40 -0000 Received: (qmail 64170 invoked by uid 500); 4 Sep 2008 09:09:37 -0000 Delivered-To: apmail-poi-dev-archive@poi.apache.org Received: (qmail 64143 invoked by uid 500); 4 Sep 2008 09:09:37 -0000 Mailing-List: contact dev-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "POI Developers List" Delivered-To: mailing list dev@poi.apache.org Received: (qmail 64132 invoked by uid 99); 4 Sep 2008 09:09:37 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Sep 2008 02:09:37 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Sep 2008 09:08:47 +0000 Received: by brutus.apache.org (Postfix, from userid 33) id 54040234C1CB; Thu, 4 Sep 2008 02:08:47 -0700 (PDT) From: bugzilla@apache.org To: dev@poi.apache.org Subject: DO NOT REPLY [Bug 45738] New: [PATCH] New code for reading Office Art shapes X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: newchanged X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: POI X-Bugzilla-Component: HWPF X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: domenico.napoletano@exprivia.it X-Bugzilla-Status: NEW X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: dev@poi.apache.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Thu, 4 Sep 2008 02:08:47 -0700 (PDT) X-Virus-Checked: Checked by ClamAV on apache.org https://issues.apache.org/bugzilla/show_bug.cgi?id=45738 Summary: [PATCH] New code for reading Office Art shapes Product: POI Version: 3.0-dev Platform: PC OS/Version: Linux Status: NEW Severity: enhancement Priority: P2 Component: HWPF AssignedTo: dev@poi.apache.org ReportedBy: domenico.napoletano@exprivia.it CC: domenico.napoletano@exprivia.it Created an attachment (id=22524) --> (https://issues.apache.org/bugzilla/attachment.cgi?id=22524) Document with 2 shapes (the second is a group) Office Art shapes (rectangles, circles, arrows, shape groups, etc.) are coded into Word documents in a PlexOfCps that starts at fib.getFcPlcspaMom(), ends at fib.getLcbPlcspaMom() and is made of structures 26 bytes wide. I've written some patch code to access these data by: 1) adding to "usermodel" package the class package org.apache.poi.hwpf.usermodel; import org.apache.poi.hwpf.model.GenericPropertyNode; import org.apache.poi.util.LittleEndian; public class Shape { int _id, _left, _right, _top, _bottom; boolean _inDoc; //true if the Shape bounds are within document (for example, it's false if the image left corner is outside the doc, like for embedded documents) public Shape(GenericPropertyNode nodo) { byte [] contenuto = nodo.getBytes(); _id = LittleEndian.getInt(contenuto); _left = LittleEndian.getInt(contenuto, 4); _top = LittleEndian.getInt(contenuto, 8); _right = LittleEndian.getInt(contenuto, 12); _bottom = LittleEndian.getInt(contenuto, 16); _inDoc = (_left >= 0 && _right >= 0 && _top >= 0 && _bottom >= 0); } public int getId() { return _id; } public int getLeft() { return _left; } public int getRight() { return _right; } public int getTop() { return _top; } public int getBottom() { return _bottom; } public int getWidth() { return _right - _left + 1; } public int getHeight() { return _bottom - _top + 1; } public boolean isWithinDocument() { return _inDoc; } } 2) adding to "model" package the class package org.apache.poi.hwpf.model; import java.util.ArrayList; import java.util.List; import org.apache.poi.hwpf.usermodel.Shape; public class ShapesTable { private List _shapes; private List _shapesVisibili; //holds visible shapes public ShapesTable(byte [] tblStream, FileInformationBlock fib) { PlexOfCps binTable = new PlexOfCps(tblStream, fib.getFcPlcspaMom(), fib.getLcbPlcspaMom(), 26); _shapes = new ArrayList(); _shapesVisibili = new ArrayList(); for(int i = 0; i < binTable.length(); i++) { GenericPropertyNode nodo = binTable.getProperty(i); Shape sh = new Shape(nodo); _shapes.add(sh); if(sh.isWithinDocument()) _shapesVisibili.add(sh); } } public List getAllShapes() { return _shapes; } public List getVisibleShapes() { return _shapesVisibili; } } 3) editing the HWPFDocument class, adding in the constructor public HWPFDocument(DirectoryNode directory, POIFSFileSystem pfilesystem) throws IOException the declaration /** Holds Office Art objects */ protected ShapesTable _officeArts; and the line (for example after the _pictures stream reading line) _officeArts = new ShapesTable(_tableStream, _fib); which reads shapes data from doc table stream 4) I've also written a simple main method to test this public static void main(String[] args) { try { JFileChooser jfc = new JFileChooser(); int esito = jfc.showOpenDialog(null); if(esito != JFileChooser.APPROVE_OPTION) { JOptionPane.showMessageDialog(null, "No file selected"); } else { String path = jfc.getSelectedFile().getAbsolutePath(); HWPFDocument doc = new HWPFDocument(new FileInputStream(path)); Range r = doc.getRange(); List shapes = doc.getShapesTable().getAllShapes(); for(Shape shp: shapes) System.out.println("SHAPE " + shp.getWidth() + "x" + shp.getHeight() + ", WITHIN DOC=" + shp.isWithinDocument()); } } catch(Exception er) { er.printStackTrace(); } } that can be tried with the attached doc 5) Perhaps the MS Open Specification Promise initiative can be helpful? They have published all Office doc specs... Hope this helps :D -- Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org For additional commands, e-mail: dev-help@poi.apache.org