Search in sources :

Example 1 with TexturePaint

use of org.apache.poi.sl.usermodel.PaintStyle.TexturePaint in project poi by apache.

the class TestXSLFBugs method bug55714.

@Test
public void bug55714() throws IOException {
    XMLSlideShow srcPptx = XSLFTestDataSamples.openSampleDocument("pptx2svg.pptx");
    XMLSlideShow newPptx = new XMLSlideShow();
    XSLFSlide srcSlide = srcPptx.getSlides().get(0);
    XSLFSlide newSlide = newPptx.createSlide();
    XSLFSlideLayout srcSlideLayout = srcSlide.getSlideLayout();
    XSLFSlideLayout newSlideLayout = newSlide.getSlideLayout();
    newSlideLayout.importContent(srcSlideLayout);
    XSLFSlideMaster srcSlideMaster = srcSlide.getSlideMaster();
    XSLFSlideMaster newSlideMaster = newSlide.getSlideMaster();
    newSlideMaster.importContent(srcSlideMaster);
    newSlide.importContent(srcSlide);
    XMLSlideShow rwPptx = XSLFTestDataSamples.writeOutAndReadBack(newPptx);
    PaintStyle ps = rwPptx.getSlides().get(0).getBackground().getFillStyle().getPaint();
    assertTrue(ps instanceof TexturePaint);
    rwPptx.close();
    newPptx.close();
    srcPptx.close();
}
Also used : TexturePaint(org.apache.poi.sl.usermodel.PaintStyle.TexturePaint) PaintStyle(org.apache.poi.sl.usermodel.PaintStyle) Test(org.junit.Test)

Example 2 with TexturePaint

use of org.apache.poi.sl.usermodel.PaintStyle.TexturePaint in project poi by apache.

the class DrawPaint method getTexturePaint.

protected Paint getTexturePaint(TexturePaint fill, Graphics2D graphics) {
    InputStream is = fill.getImageData();
    if (is == null) {
        return null;
    }
    assert (graphics != null);
    ImageRenderer renderer = DrawPictureShape.getImageRenderer(graphics, fill.getContentType());
    try {
        try {
            renderer.loadImage(is, fill.getContentType());
        } finally {
            is.close();
        }
    } catch (IOException e) {
        LOG.log(POILogger.ERROR, "Can't load image data - using transparent color", e);
        return null;
    }
    int alpha = fill.getAlpha();
    if (0 <= alpha && alpha < 100000) {
        renderer.setAlpha(alpha / 100000.f);
    }
    Rectangle2D textAnchor = shape.getAnchor();
    BufferedImage image;
    if ("image/x-wmf".equals(fill.getContentType())) {
        // don't rely on wmf dimensions, use dimension of anchor
        // TODO: check pixels vs. points for image dimension
        image = renderer.getImage(new Dimension((int) textAnchor.getWidth(), (int) textAnchor.getHeight()));
    } else {
        image = renderer.getImage();
    }
    if (image == null) {
        LOG.log(POILogger.ERROR, "Can't load image data");
        return null;
    }
    Paint paint = new java.awt.TexturePaint(image, textAnchor);
    return paint;
}
Also used : TexturePaint(org.apache.poi.sl.usermodel.PaintStyle.TexturePaint) InputStream(java.io.InputStream) Rectangle2D(java.awt.geom.Rectangle2D) IOException(java.io.IOException) Dimension(java.awt.Dimension) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint) GradientPaint(org.apache.poi.sl.usermodel.PaintStyle.GradientPaint) TexturePaint(org.apache.poi.sl.usermodel.PaintStyle.TexturePaint) LinearGradientPaint(java.awt.LinearGradientPaint) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint) GradientPaint(org.apache.poi.sl.usermodel.PaintStyle.GradientPaint) TexturePaint(org.apache.poi.sl.usermodel.PaintStyle.TexturePaint) LinearGradientPaint(java.awt.LinearGradientPaint) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) BufferedImage(java.awt.image.BufferedImage)

Example 3 with TexturePaint

use of org.apache.poi.sl.usermodel.PaintStyle.TexturePaint in project poi by apache.

the class TestXSLFTheme method slide5.

void slide5(XSLFSlide slide) {
    PaintStyle fs = slide.getBackground().getFillStyle().getPaint();
    assertTrue(fs instanceof TexturePaint);
    XSLFTextShape sh2 = (XSLFTextShape) getShape(slide, "Title 1");
    XSLFTextRun run2 = sh2.getTextParagraphs().get(0).getTextRuns().get(0);
    assertTrue(sameColor(new Color(148, 198, 0), run2.getFontColor()));
    // no fill
    assertNull(sh2.getFillColor());
    // font size is 40pt and scale factor is 90%
    assertEquals(36.0, run2.getFontSize(), 0);
    assertTrue(slide.getSlideLayout().getFollowMasterGraphics());
}
Also used : TexturePaint(org.apache.poi.sl.usermodel.PaintStyle.TexturePaint) PaintStyle(org.apache.poi.sl.usermodel.PaintStyle) Color(java.awt.Color) TestCommonSL.sameColor(org.apache.poi.sl.TestCommonSL.sameColor)

Example 4 with TexturePaint

use of org.apache.poi.sl.usermodel.PaintStyle.TexturePaint in project poi by apache.

the class TestXSLFTheme method slide9.

void slide9(XSLFSlide slide) {
    PaintStyle fs = slide.getBackground().getFillStyle().getPaint();
    assertTrue(fs instanceof TexturePaint);
}
Also used : TexturePaint(org.apache.poi.sl.usermodel.PaintStyle.TexturePaint) PaintStyle(org.apache.poi.sl.usermodel.PaintStyle)

Example 5 with TexturePaint

use of org.apache.poi.sl.usermodel.PaintStyle.TexturePaint in project poi by apache.

the class TestXSLFTheme method slide8.

void slide8(XSLFSlide slide) {
    PaintStyle fs = slide.getBackground().getFillStyle().getPaint();
    assertTrue(fs instanceof TexturePaint);
}
Also used : TexturePaint(org.apache.poi.sl.usermodel.PaintStyle.TexturePaint) PaintStyle(org.apache.poi.sl.usermodel.PaintStyle)

Aggregations

TexturePaint (org.apache.poi.sl.usermodel.PaintStyle.TexturePaint)6 PaintStyle (org.apache.poi.sl.usermodel.PaintStyle)4 IOException (java.io.IOException)2 Color (java.awt.Color)1 Dimension (java.awt.Dimension)1 LinearGradientPaint (java.awt.LinearGradientPaint)1 Paint (java.awt.Paint)1 RadialGradientPaint (java.awt.RadialGradientPaint)1 Rectangle2D (java.awt.geom.Rectangle2D)1 BufferedImage (java.awt.image.BufferedImage)1 InputStream (java.io.InputStream)1 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)1 PackageRelationship (org.apache.poi.openxml4j.opc.PackageRelationship)1 TestCommonSL.sameColor (org.apache.poi.sl.TestCommonSL.sameColor)1 GradientPaint (org.apache.poi.sl.usermodel.PaintStyle.GradientPaint)1 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)1 Test (org.junit.Test)1 CTBlip (org.openxmlformats.schemas.drawingml.x2006.main.CTBlip)1