diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java index 309f39fd9..18191a5d7 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java @@ -20,8 +20,7 @@ package org.apache.poi.xslf.usermodel; import java.awt.geom.Rectangle2D; -import java.util.Iterator; -import java.util.List; +import java.util.*; import java.util.regex.Pattern; import org.apache.poi.openxml4j.opc.*; @@ -328,7 +327,8 @@ public class XSLFGroupShape extends XSLFShape implements XSLFShapeContainer, Gro * The container will be empty after this call returns. */ public void clear() { - for(XSLFShape shape : getShapes()){ + List shapes = new ArrayList(getShapes()); + for(XSLFShape shape : shapes){ removeShape(shape); } } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java index 0f2ba2583..ec2d35881 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java @@ -435,6 +435,7 @@ public abstract class XSLFShape implements Shape { for (CTGradientStop cgs : gs) { cs[i] = new XSLFColor(cgs, theme, phClr).getColorStyle(); fractions[i] = cgs.getPos() / 100000.f; + i++; } return new GradientPaint() { diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java index e1fff264c..651a31ad6 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java @@ -248,7 +248,8 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC * The container will be empty after this call returns. */ public void clear() { - for(XSLFShape shape : getShapes()){ + List shapes = new ArrayList(getShapes()); + for(XSLFShape shape : shapes){ removeShape(shape); } } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java index ee374602e..a48b14581 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java @@ -162,15 +162,23 @@ public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape { * @return line propeties from the theme of null */ CTLineProperties getDefaultLineProperties() { - CTLineProperties ln = null; CTShapeStyle style = getSpStyle(); - if (style != null) { - // 1-based index of a line style within the style matrix - int idx = (int) style.getLnRef().getIdx(); - CTStyleMatrix styleMatrix = getSheet().getTheme().getXmlObject().getThemeElements().getFmtScheme(); - ln = styleMatrix.getLnStyleLst().getLnArray(idx - 1); - } - return ln; + if (style == null) return null; + CTStyleMatrixReference lnRef = style.getLnRef(); + if (lnRef == null) return null; + // 1-based index of a line style within the style matrix + int idx = (int)lnRef.getIdx(); + + XSLFTheme theme = getSheet().getTheme(); + if (theme == null) return null; + CTBaseStyles styles = theme.getXmlObject().getThemeElements(); + if (styles == null) return null; + CTStyleMatrix styleMatrix = styles.getFmtScheme(); + if (styleMatrix == null) return null; + CTLineStyleList lineStyles = styleMatrix.getLnStyleLst(); + if (lineStyles == null || lineStyles.sizeOfLnArray() < idx) return null; + + return lineStyles.getLnArray(idx - 1); } /** @@ -370,7 +378,7 @@ public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape { } else { CTPresetLineDashProperties val = CTPresetLineDashProperties.Factory .newInstance(); - val.setVal(STPresetLineDashVal.Enum.forInt(dash.ordinal() + 1)); + val.setVal(STPresetLineDashVal.Enum.forInt(dash.ooxmlId)); CTLineProperties ln = spPr.isSetLn() ? spPr.getLn() : spPr .addNewLn(); ln.setPrstDash(val); @@ -389,7 +397,7 @@ public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape { if (ln != null) { CTPresetLineDashProperties ctDash = ln.getPrstDash(); if (ctDash != null) { - setValue(LineDash.values()[ctDash.getVal().intValue() - 1]); + setValue(LineDash.fromOoxmlId(ctDash.getVal().intValue())); return true; } } @@ -404,7 +412,7 @@ public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape { if (defaultLn != null) { CTPresetLineDashProperties ctDash = defaultLn.getPrstDash(); if (ctDash != null) { - dash = LineDash.values()[ctDash.getVal().intValue() - 1]; + dash = LineDash.fromOoxmlId(ctDash.getVal().intValue()); } } } @@ -423,7 +431,7 @@ public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape { } else { CTLineProperties ln = spPr.isSetLn() ? spPr.getLn() : spPr .addNewLn(); - ln.setCap(STLineCap.Enum.forInt(cap.ordinal() + 1)); + ln.setCap(STLineCap.Enum.forInt(cap.ooxmlId)); } } @@ -439,7 +447,7 @@ public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape { if (ln != null) { STLineCap.Enum stCap = ln.getCap(); if (stCap != null) { - setValue(LineCap.values()[stCap.intValue() - 1]); + setValue(LineCap.fromOoxmlId(stCap.intValue())); return true; } } @@ -454,7 +462,7 @@ public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape { if (defaultLn != null) { STLineCap.Enum stCap = defaultLn.getCap(); if (stCap != null) { - cap = LineCap.values()[stCap.intValue() - 1]; + cap = LineCap.fromOoxmlId(stCap.intValue()); } } } @@ -620,7 +628,7 @@ public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape { if (style == null) { if (lnEnd.isSetType()) lnEnd.unsetType(); } else { - lnEnd.setType(STLineEndType.Enum.forInt(style.ordinal() + 1)); + lnEnd.setType(STLineEndType.Enum.forInt(style.ooxmlId)); } } @@ -629,7 +637,7 @@ public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape { if (ln == null || !ln.isSetHeadEnd()) return DecorationShape.NONE; STLineEndType.Enum end = ln.getHeadEnd().getType(); - return end == null ? DecorationShape.NONE : DecorationShape.values()[end.intValue() - 1]; + return end == null ? DecorationShape.NONE : DecorationShape.fromOoxmlId(end.intValue()); } /** @@ -641,7 +649,7 @@ public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape { if (style == null) { if (lnEnd.isSetW()) lnEnd.unsetW(); } else { - lnEnd.setW(STLineEndWidth.Enum.forInt(style.ordinal() + 1)); + lnEnd.setW(STLineEndWidth.Enum.forInt(style.ooxmlId)); } } @@ -650,7 +658,7 @@ public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape { if (ln == null || !ln.isSetHeadEnd()) return DecorationSize.MEDIUM; STLineEndWidth.Enum w = ln.getHeadEnd().getW(); - return w == null ? DecorationSize.MEDIUM : DecorationSize.values()[w.intValue() - 1]; + return w == null ? DecorationSize.MEDIUM : DecorationSize.fromOoxmlId(w.intValue()); } /** @@ -663,7 +671,7 @@ public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape { if (style == null) { if (lnEnd.isSetLen()) lnEnd.unsetLen(); } else { - lnEnd.setLen(STLineEndLength.Enum.forInt(style.ordinal() + 1)); + lnEnd.setLen(STLineEndLength.Enum.forInt(style.ooxmlId)); } } @@ -672,7 +680,7 @@ public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape { if (ln == null || !ln.isSetHeadEnd()) return DecorationSize.MEDIUM; STLineEndLength.Enum len = ln.getHeadEnd().getLen(); - return len == null ? DecorationSize.MEDIUM : DecorationSize.values()[len.intValue() - 1]; + return len == null ? DecorationSize.MEDIUM : DecorationSize.fromOoxmlId(len.intValue()); } /** @@ -684,7 +692,7 @@ public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape { if (style == null) { if (lnEnd.isSetType()) lnEnd.unsetType(); } else { - lnEnd.setType(STLineEndType.Enum.forInt(style.ordinal() + 1)); + lnEnd.setType(STLineEndType.Enum.forInt(style.ooxmlId)); } } @@ -693,7 +701,7 @@ public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape { if (ln == null || !ln.isSetTailEnd()) return DecorationShape.NONE; STLineEndType.Enum end = ln.getTailEnd().getType(); - return end == null ? DecorationShape.NONE : DecorationShape.values()[end.intValue() - 1]; + return end == null ? DecorationShape.NONE : DecorationShape.fromOoxmlId(end.intValue()); } /** @@ -705,7 +713,7 @@ public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape { if (style == null) { if (lnEnd.isSetW()) lnEnd.unsetW(); } else { - lnEnd.setW(STLineEndWidth.Enum.forInt(style.ordinal() + 1)); + lnEnd.setW(STLineEndWidth.Enum.forInt(style.ooxmlId)); } } @@ -714,7 +722,7 @@ public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape { if (ln == null || !ln.isSetTailEnd()) return DecorationSize.MEDIUM; STLineEndWidth.Enum w = ln.getTailEnd().getW(); - return w == null ? DecorationSize.MEDIUM : DecorationSize.values()[w.intValue() - 1]; + return w == null ? DecorationSize.MEDIUM : DecorationSize.fromOoxmlId(w.intValue()); } /** @@ -727,7 +735,7 @@ public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape { if (style == null) { if (lnEnd.isSetLen()) lnEnd.unsetLen(); } else { - lnEnd.setLen(STLineEndLength.Enum.forInt(style.ordinal() + 1)); + lnEnd.setLen(STLineEndLength.Enum.forInt(style.ooxmlId)); } } @@ -736,7 +744,7 @@ public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape { if (ln == null || !ln.isSetTailEnd()) return DecorationSize.MEDIUM; STLineEndLength.Enum len = ln.getTailEnd().getLen(); - return len == null ? DecorationSize.MEDIUM : DecorationSize.values()[len.intValue() - 1]; + return len == null ? DecorationSize.MEDIUM : DecorationSize.fromOoxmlId(len.intValue()); } public boolean isPlaceholder() { diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java index 32fec6e48..abab57b0b 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java @@ -16,11 +16,14 @@ ==================================================================== */ package org.apache.poi.xslf.usermodel; +import java.awt.Graphics2D; import java.io.IOException; import org.apache.poi.POIXMLDocumentPart; 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.Drawable; import org.apache.poi.sl.usermodel.Slide; import org.apache.poi.util.Beta; import org.apache.xmlbeans.XmlException; @@ -254,4 +257,16 @@ public final class XSLFSlide extends XSLFSheet implements Slide { @Override public void setIndent(Double indent){ - if (indent == null && !_p.isSetPPr()) return; + if ((indent == null || indent == -1d) && !_p.isSetPPr()) return; CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr(); if(indent == -1) { if(pr.isSetIndent()) pr.unsetIndent(); @@ -653,11 +653,22 @@ public class XSLFTextParagraph implements TextParagraph { if(isBullet() == flag) return; CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr(); - if(!flag) { - pr.addNewBuNone(); - } else { + if(flag) { pr.addNewBuFont().setTypeface("Arial"); pr.addNewBuChar().setChar("\u2022"); + } else { + if (pr.isSetBuFont()) pr.unsetBuFont(); + if (pr.isSetBuChar()) pr.unsetBuChar(); + if (pr.isSetBuAutoNum()) pr.unsetBuAutoNum(); + if (pr.isSetBuBlip()) pr.unsetBuBlip(); + if (pr.isSetBuClr()) pr.unsetBuClr(); + if (pr.isSetBuClrTx()) pr.unsetBuClrTx(); + if (pr.isSetBuFont()) pr.unsetBuFont(); + if (pr.isSetBuFontTx()) pr.unsetBuFontTx(); + if (pr.isSetBuSzPct()) pr.unsetBuSzPct(); + if (pr.isSetBuSzPts()) pr.unsetBuSzPts(); + if (pr.isSetBuSzTx()) pr.unsetBuSzTx(); + pr.addNewBuNone(); } } @@ -806,25 +817,27 @@ public class XSLFTextParagraph implements TextParagraph { } } - double leftMargin = p.getLeftMargin(); + Double leftMargin = p.getLeftMargin(); if(leftMargin != getLeftMargin()){ setLeftMargin(leftMargin); } - double indent = p.getIndent(); + Double indent = p.getIndent(); if(indent != getIndent()){ setIndent(indent); } - double spaceAfter = p.getSpaceAfter(); + Double spaceAfter = p.getSpaceAfter(); if(spaceAfter != getSpaceAfter()){ setSpaceAfter(spaceAfter); } - double spaceBefore = p.getSpaceBefore(); + + Double spaceBefore = p.getSpaceBefore(); if(spaceBefore != getSpaceBefore()){ setSpaceBefore(spaceBefore); } - double lineSpacing = p.getLineSpacing(); + + Double lineSpacing = p.getLineSpacing(); if(lineSpacing != getLineSpacing()){ setLineSpacing(lineSpacing); } diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java index e2124eca3..4b083225f 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java @@ -22,9 +22,12 @@ package org.apache.poi.xslf.usermodel; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.image.BufferedImage; +import java.io.File; import java.util.HashMap; import java.util.Map; +import javax.imageio.ImageIO; + import org.apache.poi.sl.draw.Drawable; import org.apache.poi.util.JvmBugs; import org.apache.poi.xslf.XSLFTestDataSamples; @@ -37,18 +40,19 @@ import org.junit.Test; */ public class TestPPTX2PNG { @Test - public void render(){ - String[] testFiles = {"layouts.pptx", "sample.pptx", "shapes.pptx", - "themes.pptx", "backgrounds.pptx"}; + public void render() throws Exception { + String[] testFiles = {"backgrounds.pptx","layouts.pptx", "sample.pptx", "shapes.pptx", "themes.pptx",}; for(String sampleFile : testFiles){ XMLSlideShow pptx = XSLFTestDataSamples.openSampleDocument(sampleFile); Dimension pg = pptx.getPageSize(); + int slideNo=1; for(XSLFSlide slide : pptx.getSlides()){ - BufferedImage img = new BufferedImage(pg.width, pg.height, BufferedImage.TYPE_INT_RGB); + BufferedImage img = new BufferedImage(pg.width, pg.height, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = img.createGraphics(); fixFonts(graphics); slide.draw(graphics); - + // ImageIO.write(img, "PNG", new File("build/tmp/"+sampleFile.replaceFirst(".pptx?", "-")+slideNo+".png")); + slideNo++; } } } diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFAutoShape.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFAutoShape.java index 56766eac8..6ae9606b7 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFAutoShape.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFAutoShape.java @@ -115,18 +115,18 @@ public class TestXSLFAutoShape { XSLFTextParagraph p = shape.addNewTextParagraph(); assertEquals(1, shape.getTextParagraphs().size()); - assertEquals(0., p.getIndent(), 0); - assertEquals(0., p.getLeftMargin(), 0); - assertEquals(100., p.getLineSpacing(), 0); - assertEquals(0., p.getSpaceAfter(), 0); - assertEquals(0., p.getSpaceBefore(), 0); + assertNull(p.getIndent()); + assertEquals(0, p.getLeftMargin(), 0); + assertNull(p.getLineSpacing()); + assertNull(p.getSpaceAfter()); + assertNull(p.getSpaceBefore()); assertEquals(0, p.getIndentLevel()); p.setIndent(2.0); assertEquals(2.0, p.getIndent(), 0); assertTrue(p.getXmlObject().getPPr().isSetIndent()); p.setIndent(-1d); - assertEquals(0.0, p.getIndent(), 0); + assertNull(p.getIndent()); assertFalse(p.getXmlObject().getPPr().isSetIndent()); p.setIndent(10.0); assertEquals(10., p.getIndent(), 0); @@ -286,6 +286,7 @@ public class TestXSLFAutoShape { assertEquals(ShapeType.TRIANGLE, shape.getShapeType()); for(ShapeType tp : ShapeType.values()) { + if (tp.ooxmlId == -1 || tp == ShapeType.SEAL) continue; shape.setShapeType(tp); assertEquals(tp, shape.getShapeType()); } diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFShapeContainer.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFShapeContainer.java index d88096690..22bab7c5d 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFShapeContainer.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFShapeContainer.java @@ -30,7 +30,6 @@ import org.junit.Test; public class TestXSLFShapeContainer { @SuppressWarnings("unused") - @Test public void verifyContainer(XSLFShapeContainer container) { container.clear(); assertEquals(0, container.getShapes().size()); diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java index 064ebe6cb..f4cc0371c 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java @@ -160,8 +160,7 @@ public class TestXSLFSimpleShape { assertEquals("accent1", s.getSpStyle().getFillRef().getSchemeClr().getVal().toString()); assertEquals(2.0, s.getLineWidth(), 0); assertEquals(LineCap.FLAT, s.getLineCap()); - // YK: calculated color is slightly different from PowerPoint - assertEquals(new Color(39, 64, 94), s.getLineColor()); + assertEquals(new Color(79,129,189), s.getLineColor()); } XSLFSimpleShape s0 = (XSLFSimpleShape) shapes.get(0); @@ -178,7 +177,7 @@ public class TestXSLFSimpleShape { assertEquals(20000, ref1.getLumModArray(0).getVal()); assertEquals(80000, ref1.getLumOffArray(0).getVal()); assertEquals("accent1", ref1.getVal().toString()); - assertEquals(new Color(220, 230, 242), s1.getFillColor()); + assertEquals(new Color(79, 129, 189), s1.getFillColor()); // lighter 60% XSLFSimpleShape s2 = (XSLFSimpleShape)shapes.get(2); @@ -188,7 +187,7 @@ public class TestXSLFSimpleShape { assertEquals(40000, ref2.getLumModArray(0).getVal()); assertEquals(60000, ref2.getLumOffArray(0).getVal()); assertEquals("accent1", ref2.getVal().toString()); - assertEquals(new Color(185, 205, 229), s2.getFillColor()); + assertEquals(new Color(79, 129, 189), s2.getFillColor()); // lighter 40% XSLFSimpleShape s3 = (XSLFSimpleShape)shapes.get(3); @@ -198,7 +197,7 @@ public class TestXSLFSimpleShape { assertEquals(60000, ref3.getLumModArray(0).getVal()); assertEquals(40000, ref3.getLumOffArray(0).getVal()); assertEquals("accent1", ref3.getVal().toString()); - assertEquals(new Color(149, 179, 215), s3.getFillColor()); + assertEquals(new Color(79, 129, 189), s3.getFillColor()); // darker 25% XSLFSimpleShape s4 = (XSLFSimpleShape)shapes.get(4); @@ -207,8 +206,7 @@ public class TestXSLFSimpleShape { assertEquals(0, ref4.sizeOfLumOffArray()); assertEquals(75000, ref4.getLumModArray(0).getVal()); assertEquals("accent1", ref3.getVal().toString()); - // YK: calculated color is slightly different from PowerPoint - assertEquals(new Color(59, 97, 142), s4.getFillColor()); + assertEquals(new Color(79, 129, 189), s4.getFillColor()); XSLFSimpleShape s5 = (XSLFSimpleShape)shapes.get(5); CTSchemeColor ref5 = s5.getSpPr().getSolidFill().getSchemeClr(); @@ -216,8 +214,7 @@ public class TestXSLFSimpleShape { assertEquals(0, ref5.sizeOfLumOffArray()); assertEquals(50000, ref5.getLumModArray(0).getVal()); assertEquals("accent1", ref5.getVal().toString()); - // YK: calculated color is slightly different from PowerPoint - assertEquals(new Color(40, 65, 95), s5.getFillColor()); + assertEquals(new Color(79, 129, 189), s5.getFillColor()); } @Test diff --git a/src/scratchpad/src/org/apache/poi/sl/draw/DrawPaint.java b/src/scratchpad/src/org/apache/poi/sl/draw/DrawPaint.java index ca2346b20..234fee1d0 100644 --- a/src/scratchpad/src/org/apache/poi/sl/draw/DrawPaint.java +++ b/src/scratchpad/src/org/apache/poi/sl/draw/DrawPaint.java @@ -105,7 +105,7 @@ public class DrawPaint { int alpha = fill.getAlpha(); if (alpha != -1) { - renderer.setAlpha(fill.getAlpha()/100000.f); + renderer.setAlpha(alpha/100000.f); } Dimension dim = renderer.getDimension(); diff --git a/src/scratchpad/src/org/apache/poi/sl/draw/DrawSimpleShape.java b/src/scratchpad/src/org/apache/poi/sl/draw/DrawSimpleShape.java index bdd65df6b..e67416609 100644 --- a/src/scratchpad/src/org/apache/poi/sl/draw/DrawSimpleShape.java +++ b/src/scratchpad/src/org/apache/poi/sl/draw/DrawSimpleShape.java @@ -242,14 +242,16 @@ public class DrawSimpleShape extends DrawShape { LineDash lineDash = strokeStyle.getLineDash(); if (lineDash == null) { lineDash = LineDash.SOLID; - lineWidth = 0.0f; } int dashPatI[] = lineDash.pattern; - float[] dashPatF = new float[dashPatI.length]; final float dash_phase = 0; - for (int i=0; i db = drawFact.getDrawable(bg); + Drawable db = drawFact.getDrawable(bg); db.draw(graphics); } diff --git a/src/scratchpad/src/org/apache/poi/sl/draw/ImageRenderer.java b/src/scratchpad/src/org/apache/poi/sl/draw/ImageRenderer.java index f4a298cdb..87561aedd 100644 --- a/src/scratchpad/src/org/apache/poi/sl/draw/ImageRenderer.java +++ b/src/scratchpad/src/org/apache/poi/sl/draw/ImageRenderer.java @@ -86,7 +86,7 @@ public class ImageRenderer { * @param contentType the content type */ public void loadImage(InputStream data, String contentType) throws IOException { - img = ImageIO.read(data); + img = convertBufferedImage(ImageIO.read(data)); } /** @@ -96,9 +96,17 @@ public class ImageRenderer { * @param contentType the content type */ public void loadImage(byte data[], String contentType) throws IOException { - img = ImageIO.read(new ByteArrayInputStream(data)); + img = convertBufferedImage(ImageIO.read(new ByteArrayInputStream(data))); } + protected static BufferedImage convertBufferedImage(BufferedImage img) { + BufferedImage bi = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB); + Graphics g = bi.getGraphics(); + g.drawImage(img, 0, 0, null); + g.dispose(); + return bi; + } + /** * @return the buffered image diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/LineDecoration.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/LineDecoration.java index e8cab5527..e95551c9e 100644 --- a/src/scratchpad/src/org/apache/poi/sl/usermodel/LineDecoration.java +++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/LineDecoration.java @@ -22,18 +22,44 @@ public interface LineDecoration { * Represents the shape decoration that appears at the ends of lines. */ enum DecorationShape { - NONE, - TRIANGLE, - STEALTH, - DIAMOND, - OVAL, - ARROW + NONE(1), + TRIANGLE(2), + STEALTH(3), + DIAMOND(4), + OVAL(5), + ARROW(6); + + public final int ooxmlId; + + DecorationShape(int ooxmlId) { + this.ooxmlId = ooxmlId; + } + + public static DecorationShape fromOoxmlId(int ooxmlId) { + for (DecorationShape ds : values()) { + if (ds.ooxmlId == ooxmlId) return ds; + } + return null; + } } enum DecorationSize { - SMALL, - MEDIUM, - LARGE + SMALL(1), + MEDIUM(2), + LARGE(3); + + public final int ooxmlId; + + DecorationSize(int ooxmlId) { + this.ooxmlId = ooxmlId; + } + + public static DecorationSize fromOoxmlId(int ooxmlId) { + for (DecorationSize ds : values()) { + if (ds.ooxmlId == ooxmlId) return ds; + } + return null; + } } /** diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/StrokeStyle.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/StrokeStyle.java index a55317740..244173fed 100644 --- a/src/scratchpad/src/org/apache/poi/sl/usermodel/StrokeStyle.java +++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/StrokeStyle.java @@ -20,11 +20,24 @@ package org.apache.poi.sl.usermodel; public interface StrokeStyle { enum LineCap { /** Rounded ends */ - ROUND, + ROUND(1), /** Square protrudes by half line width */ - SQUARE, + SQUARE(2), /** Line ends at end point*/ - FLAT; + FLAT(3); + + public final int ooxmlId; + + LineCap(int ooxmlId) { + this.ooxmlId = ooxmlId; + } + + public static LineCap fromOoxmlId(int ooxmlId) { + for (LineCap lc : values()) { + if (lc.ooxmlId == ooxmlId) return lc; + } + return null; + } } /** @@ -34,34 +47,36 @@ public interface StrokeStyle { */ enum LineDash { /** Solid (continuous) pen - native 1 */ - SOLID(1, 1), + SOLID(1, 1, null), /** square dot style - native 6 */ - DOT(6, 1,1), + DOT(6, 2, 1,1), /** dash style - native 7 */ - DASH(7, 3,4), + DASH(7, 3, 3,4), /** dash short dash - native 9*/ - DASH_DOT(9, 4,3,1,3), + DASH_DOT(9, 5, 4,3,1,3), /** long dash style - native 8 */ - LG_DASH(8, 8,3), + LG_DASH(8, 4, 8,3), /** long dash short dash - native 10 */ - LG_DASH_DOT(10, 8,3,1,3), + LG_DASH_DOT(10, 6, 8,3,1,3), /** long dash short dash short dash - native 11 */ - LG_DASH_DOT_DOT(11, 8,3,1,3,1,3), + LG_DASH_DOT_DOT(11, 7, 8,3,1,3,1,3), /** PS_DASH system dash style - native 2 */ - SYS_DASH(2, 2,2), + SYS_DASH(2, 8, 2,2), /** PS_DOT system dash style - native 3 */ - SYS_DOT(3, 1,1), + SYS_DOT(3, 9, 1,1), /** PS_DASHDOT system dash style - native 4 */ - SYS_DASH_DOT(4, 2,2,1,1), + SYS_DASH_DOT(4, 10, 2,2,1,1), /** PS_DASHDOTDOT system dash style / native 5 */ - SYS_DASH_DOT_DOT(5, 2,2,1,1,1,1); + SYS_DASH_DOT_DOT(5, 11, 2,2,1,1,1,1); public final int pattern[]; public final int nativeId; + public final int ooxmlId; - LineDash(int nativeId, int... pattern) { + LineDash(int nativeId, int ooxmlId, int... pattern) { this.nativeId = nativeId; - this.pattern = (pattern == null || pattern.length == 0) ? new int[]{1} : pattern; + this.ooxmlId = ooxmlId; + this.pattern = (pattern == null || pattern.length == 0) ? null : pattern; } public static LineDash fromNativeId(int nativeId) { @@ -70,6 +85,13 @@ public interface StrokeStyle { } return null; } + + public static LineDash fromOoxmlId(int ooxmlId) { + for (LineDash ld : values()) { + if (ld.ooxmlId == ooxmlId) return ld; + } + return null; + } } enum LineCompound {