Bug 45391 - Line dimensions are not proper when read from a PPT
Summary: Line dimensions are not proper when read from a PPT
Alias: None
Product: POI
Classification: Unclassified
Component: HSLF (show other bugs)
Version: unspecified
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2008-07-13 22:49 UTC by Vinu Kumar
Modified: 2008-07-21 11:08 UTC (History)
0 users

Sampe ppt for the bug (30.50 KB, application/octet-stream)
2008-07-13 22:49 UTC, Vinu Kumar

Note You need to log in before you can comment on or make changes to this bug.
Description Vinu Kumar 2008-07-13 22:49:37 UTC
Created attachment 22250 [details]
Sampe ppt for the bug

Following code is for reading a line in the ppt and converting to a graphics object.

// Read all shapes

if  (type == ShapeTypes.Line)
  Line l = (Line)s;
  Rectangle a = l.getAnchor();
  int w = a.width;
  int h = a.height;
  double x = a.getX();
  double y = a.getY();
  BufferedImage img = new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);
  Graphics2D g = img.createGraphics();
  // ... Draw the image


The issue is the height and width returned from anchor is smaller that actual size.

If a ppt has a table, the table is drawn half.
Comment 1 Yegor Kozlov 2008-07-21 11:08:32 UTC
Anchor doesn't take into account the line width. 
If you want to draw individual lines you need to set the image dimensions
as max(linewidth, anchor.width) and max(linewidth, anchor.height):

   Rectangle2D a = l.getAnchor2D();
   double w = Math.max(a.getWidth(), l.getLineWidth());
   double h = Math.max(a.getHeight(), l.getLineWidth());

   BufferedImage img = new BufferedImage((int) Math.round(w), (int) Math.round(h), BufferedImage.TYPE_INT_RGB);