ASF Bugzilla – Attachment 33601 Details for
Bug 59056
[Patch] Render individual slideshow shapes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Patch for drawing single shapes
draw-single-shape.diff (text/x-diff), 9.27 KB, created by
Andreas Beeker
on 2016-02-26 21:43:22 UTC
(
hide
)
Description:
Patch for drawing single shapes
Filename:
MIME Type:
Creator:
Andreas Beeker
Created:
2016-02-26 21:43:22 UTC
Size:
9.27 KB
patch
obsolete
>Index: src/java/org/apache/poi/sl/draw/DrawFactory.java >=================================================================== >--- src/java/org/apache/poi/sl/draw/DrawFactory.java (revision 1732236) >+++ src/java/org/apache/poi/sl/draw/DrawFactory.java (working copy) >@@ -19,6 +19,8 @@ > > import java.awt.Graphics2D; > import java.awt.font.TextLayout; >+import java.awt.geom.AffineTransform; >+import java.awt.geom.Rectangle2D; > import java.text.AttributedString; > import java.util.HashMap; > import java.util.Map; >@@ -168,7 +170,41 @@ > return new DrawPaint(shape); > } > >+ /** >+ * Convenience method for drawing single shapes. >+ * For drawing whole slides, use {@link Slide#draw(Graphics2D)} >+ * >+ * @param graphics the graphics context to draw to >+ * @param shape the shape >+ * @param bounds the bounds within the graphics context to draw to >+ */ >+ public void drawShape(Graphics2D graphics, Shape<?,?> shape, Rectangle2D bounds) { >+ Rectangle2D shapeBounds = shape.getAnchor(); >+ if (shapeBounds.isEmpty() || (bounds != null && bounds.isEmpty())) { >+ return; >+ } > >+ AffineTransform txg = (AffineTransform)graphics.getRenderingHint(Drawable.GROUP_TRANSFORM); >+ AffineTransform tx = new AffineTransform(); >+ try { >+ if (bounds != null) { >+ double scaleX = bounds.getWidth()/shapeBounds.getWidth(); >+ double scaleY = bounds.getHeight()/shapeBounds.getHeight(); >+ tx.translate(bounds.getCenterX(), bounds.getCenterY()); >+ tx.scale(scaleX, scaleY); >+ tx.translate(-shapeBounds.getCenterX(), -shapeBounds.getCenterY()); >+ } >+ graphics.setRenderingHint(Drawable.GROUP_TRANSFORM, tx); >+ >+ Drawable d = getDrawable(shape); >+ d.applyTransform(graphics); >+ d.draw(graphics); >+ } finally { >+ graphics.setRenderingHint(Drawable.GROUP_TRANSFORM, txg); >+ } >+ } >+ >+ > /** > * Replace font families for Windows JVM 6, which contains a font rendering error. > * This is likely to be removed, when POI upgrades to JDK 7 >Index: src/java/org/apache/poi/sl/usermodel/Shape.java >=================================================================== >--- src/java/org/apache/poi/sl/usermodel/Shape.java (revision 1732236) >+++ src/java/org/apache/poi/sl/usermodel/Shape.java (working copy) >@@ -17,6 +17,7 @@ > > package org.apache.poi.sl.usermodel; > >+import java.awt.Graphics2D; > import java.awt.geom.Rectangle2D; > > public interface Shape< >@@ -24,17 +25,26 @@ > P extends TextParagraph<S,P,?> > > { > ShapeContainer<S,P> getParent(); >- >+ > /** > * @return the sheet this shape belongs to > */ > Sheet<S,P> getSheet(); >- >+ > /** > * Returns the anchor (the bounding box rectangle) of this shape. > * All coordinates are expressed in points (72 dpi). > * > * @return the anchor of this shape > */ >- Rectangle2D getAnchor(); >+ Rectangle2D getAnchor(); >+ >+ /** >+ * Convenience method to draw a single shape >+ * >+ * @param graphics the graphics context >+ * @param bounds the rectangle to fit the shape to. >+ * if null, the bounds of the shape are used. >+ */ >+ void draw(Graphics2D graphics, Rectangle2D bounds); > } >Index: src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java >=================================================================== >--- src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java (revision 1727211) >+++ src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java (working copy) >@@ -19,6 +19,8 @@ > > package org.apache.poi.xslf.usermodel; > >+import java.awt.Graphics2D; >+import java.awt.geom.Rectangle2D; > import java.io.IOException; > import java.io.InputStream; > import java.util.Arrays; >@@ -27,6 +29,7 @@ > import org.apache.poi.openxml4j.exceptions.InvalidFormatException; > import org.apache.poi.openxml4j.opc.PackagePart; > import org.apache.poi.openxml4j.opc.PackageRelationship; >+import org.apache.poi.sl.draw.DrawFactory; > import org.apache.poi.sl.draw.DrawPaint; > import org.apache.poi.sl.usermodel.ColorStyle; > import org.apache.poi.sl.usermodel.PaintStyle; >@@ -537,4 +540,9 @@ > } > return (fillProps == null) ? null : selectPaint(fillProps, phClr, theme.getPackagePart()); > } >+ >+ @Override >+ public void draw(Graphics2D graphics, Rectangle2D bounds) { >+ DrawFactory.getInstance(graphics).drawShape(graphics, this, bounds); >+ } > } >\ No newline at end of file >Index: src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java >=================================================================== >--- src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java (revision 1732236) >+++ src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java (working copy) >@@ -38,6 +38,7 @@ > import org.apache.poi.hslf.record.HSLFEscherClientDataRecord; > import org.apache.poi.hslf.record.Record; > import org.apache.poi.hslf.record.RecordTypes; >+import org.apache.poi.sl.draw.DrawFactory; > import org.apache.poi.sl.usermodel.FillStyle; > import org.apache.poi.sl.usermodel.Shape; > import org.apache.poi.sl.usermodel.ShapeContainer; >@@ -447,8 +448,9 @@ > return getFill().getFillStyle(); > } > >- public void draw(Graphics2D graphics){ >- logger.log(POILogger.INFO, "Rendering " + getShapeName()); >+ @Override >+ public void draw(Graphics2D graphics, Rectangle2D bounds){ >+ DrawFactory.getInstance(graphics).drawShape(graphics, this, bounds); > } > > public AbstractEscherOptRecord getEscherOptRecord() { >Index: src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java >=================================================================== >--- src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java (revision 1727211) >+++ src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java (working copy) >@@ -24,6 +24,9 @@ > import static org.junit.Assert.assertTrue; > > import java.awt.Color; >+import java.awt.Graphics2D; >+import java.awt.geom.Rectangle2D; >+import java.awt.image.BufferedImage; > import java.io.File; > import java.io.IOException; > import java.io.OutputStream; >@@ -38,6 +41,8 @@ > import java.util.Map; > import java.util.Set; > >+import javax.imageio.ImageIO; >+ > import org.apache.poi.ddf.AbstractEscherOptRecord; > import org.apache.poi.ddf.EscherArrayProperty; > import org.apache.poi.ddf.EscherColorRef; >@@ -52,6 +57,7 @@ > import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet; > import org.apache.poi.hslf.record.TextHeaderAtom; > import org.apache.poi.hssf.usermodel.DummyGraphics2d; >+import org.apache.poi.sl.draw.DrawFactory; > import org.apache.poi.sl.draw.DrawPaint; > import org.apache.poi.sl.draw.DrawTextParagraph; > import org.apache.poi.sl.usermodel.PaintStyle; >@@ -68,6 +74,7 @@ > import org.apache.poi.util.LittleEndian; > import org.apache.poi.util.StringUtil; > import org.apache.poi.util.Units; >+import org.junit.Ignore; > import org.junit.Test; > > /** >@@ -879,6 +886,27 @@ > > ppt.close(); > } >+ >+ @Test >+ @Ignore("this is just a visual test") >+ public void bug59056() throws IOException { >+ HSLFSlideShow ppt = open("54541_cropped_bitmap.ppt"); >+ >+ for (HSLFShape shape : ppt.getSlides().get(0).getShapes()) { >+ BufferedImage img = new BufferedImage(500, 300, BufferedImage.TYPE_INT_ARGB); >+ Graphics2D graphics = img.createGraphics(); >+ Rectangle2D box = new Rectangle2D.Double(50,50,300,100); >+ graphics.setPaint(Color.red); >+ graphics.fill(box); >+ box = new Rectangle2D.Double(box.getX()+1,box.getY()+1,box.getWidth()-2,box.getHeight()-2); >+ DrawFactory.getInstance(graphics).drawShape(graphics, shape, box); >+ graphics.dispose(); >+ ImageIO.write(img, "png", new File("bla"+shape.getShapeId()+".png")); >+ } >+ >+ ppt.close(); >+ >+ } > > private static HSLFSlideShow open(String fileName) throws IOException { > File sample = HSLFTestDataSamples.getSampleFile(fileName); >Index: src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPicture.java >=================================================================== >--- src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPicture.java (revision 1732236) >+++ src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPicture.java (working copy) >@@ -27,6 +27,8 @@ > import java.awt.Dimension; > import java.awt.Graphics2D; > import java.awt.Rectangle; >+import java.awt.geom.Rectangle2D; >+import java.awt.geom.Rectangle2D.Double; > import java.awt.image.BufferedImage; > import java.io.ByteArrayInputStream; > import java.io.File; >@@ -106,13 +108,14 @@ > HSLFPictureData pd = HSLFPictureData.create(PictureType.PNG); > > HSLFPictureShape pict = new HSLFPictureShape(pd); //index to non-existing picture data >+ pict.setAnchor(new Rectangle2D.Double(50,50,100,100)); > pict.setSheet(slide); > HSLFPictureData data = pict.getPictureData(); > assertNull(data); > > BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); > Graphics2D graphics = img.createGraphics(); >- pict.draw(graphics); >+ pict.draw(graphics, null); > > ppt.close(); > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 59056
: 33601