Search in sources :

Example 6 with TexturePaint

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

the class XSLFShape method selectPaint.

protected static PaintStyle selectPaint(final CTBlipFillProperties blipFill, final PackagePart parentPart) {
    final CTBlip blip = blipFill.getBlip();
    return new TexturePaint() {

        private PackagePart getPart() {
            try {
                String blipId = blip.getEmbed();
                PackageRelationship rel = parentPart.getRelationship(blipId);
                return parentPart.getRelatedPart(rel);
            } catch (InvalidFormatException e) {
                throw new RuntimeException(e);
            }
        }

        public InputStream getImageData() {
            try {
                return getPart().getInputStream();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public String getContentType() {
            /* TOOD: map content-type */
            return getPart().getContentType();
        }

        public int getAlpha() {
            return (blip.sizeOfAlphaModFixArray() > 0) ? blip.getAlphaModFixArray(0).getAmt() : 100000;
        }
    };
}
Also used : PackageRelationship(org.apache.poi.openxml4j.opc.PackageRelationship) TexturePaint(org.apache.poi.sl.usermodel.PaintStyle.TexturePaint) CTBlip(org.openxmlformats.schemas.drawingml.x2006.main.CTBlip) IOException(java.io.IOException) InvalidFormatException(org.apache.poi.openxml4j.exceptions.InvalidFormatException)

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