Search in sources :

Example 1 with EscherArrayProperty

use of org.apache.poi.ddf.EscherArrayProperty in project poi by apache.

the class HSLFTable method setRowHeight.

@Override
public void setRowHeight(int row, final double height) {
    if (row < 0 || row >= cells.length) {
        throw new IllegalArgumentException("Row index '" + row + "' is not within range [0-" + (cells.length - 1) + "]");
    }
    // update row height in the table properties
    AbstractEscherOptRecord opt = getEscherChild(RecordTypes.EscherUserDefined.typeID);
    EscherArrayProperty p = opt.lookup(EscherProperties.GROUPSHAPE__TABLEROWPROPERTIES);
    byte[] masterBytes = p.getElement(row);
    double currentHeight = Units.masterToPoints(LittleEndian.getInt(masterBytes, 0));
    LittleEndian.putInt(masterBytes, 0, Units.pointsToMaster(height));
    p.setElement(row, masterBytes);
    // move the cells
    double dy = height - currentHeight;
    for (int i = row; i < cells.length; i++) {
        for (HSLFTableCell c : cells[i]) {
            if (c == null) {
                continue;
            }
            Rectangle2D anchor = c.getAnchor();
            if (i == row) {
                anchor.setRect(anchor.getX(), anchor.getY(), anchor.getWidth(), height);
            } else {
                anchor.setRect(anchor.getX(), anchor.getY() + dy, anchor.getWidth(), anchor.getHeight());
            }
            c.setAnchor(anchor);
        }
    }
    Rectangle2D tblanchor = getAnchor();
    tblanchor.setRect(tblanchor.getX(), tblanchor.getY(), tblanchor.getWidth(), tblanchor.getHeight() + dy);
    setExteriorAnchor(tblanchor);
}
Also used : EscherArrayProperty(org.apache.poi.ddf.EscherArrayProperty) Rectangle2D(java.awt.geom.Rectangle2D) AbstractEscherOptRecord(org.apache.poi.ddf.AbstractEscherOptRecord)

Example 2 with EscherArrayProperty

use of org.apache.poi.ddf.EscherArrayProperty in project poi by apache.

the class HSLFTable method updateRowHeightsProperty.

private void updateRowHeightsProperty() {
    AbstractEscherOptRecord opt = getEscherChild(RecordTypes.EscherUserDefined.typeID);
    EscherArrayProperty p = opt.lookup(EscherProperties.GROUPSHAPE__TABLEROWPROPERTIES);
    byte[] val = new byte[4];
    for (int rowIdx = 0; rowIdx < cells.length; rowIdx++) {
        int rowHeight = Units.pointsToMaster(cells[rowIdx][0].getAnchor().getHeight());
        LittleEndian.putInt(val, 0, rowHeight);
        p.setElement(rowIdx, val);
    }
}
Also used : EscherArrayProperty(org.apache.poi.ddf.EscherArrayProperty) AbstractEscherOptRecord(org.apache.poi.ddf.AbstractEscherOptRecord)

Example 3 with EscherArrayProperty

use of org.apache.poi.ddf.EscherArrayProperty in project poi by apache.

the class HSLFFill method getGradientPaint.

private GradientPaint getGradientPaint(final GradientType gradientType) {
    AbstractEscherOptRecord opt = shape.getEscherOptRecord();
    final EscherArrayProperty ep = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__SHADECOLORS);
    final int colorCnt = (ep == null) ? 0 : ep.getNumberOfElementsInArray();
    // NOFILLHITTEST can be in the normal escher opt record but also in the tertiary record
    // the extended bit fields seem to be in the second
    opt = (AbstractEscherOptRecord) shape.getEscherChild(RecordTypes.EscherUserDefined);
    EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST);
    int propVal = (p == null) ? 0 : p.getPropertyValue();
    final boolean rotateWithShape = FILL_USE_USE_SHAPE_ANCHOR.isSet(propVal) && FILL_USE_SHAPE_ANCHOR.isSet(propVal);
    return new GradientPaint() {

        @Override
        public double getGradientAngle() {
            // A value of type FixedPoint, as specified in [MS-OSHARED] section 2.2.1.6,
            // that specifies the angle of the gradient fill. Zero degrees represents a vertical vector from
            // bottom to top. The default value for this property is 0x00000000.
            int rot = shape.getEscherProperty(EscherProperties.FILL__ANGLE);
            return 90 - Units.fixedPointToDouble(rot);
        }

        @Override
        public ColorStyle[] getGradientColors() {
            ColorStyle[] cs;
            if (colorCnt == 0) {
                cs = new ColorStyle[2];
                cs[0] = wrapColor(getBackgroundColor());
                cs[1] = wrapColor(getForegroundColor());
            } else {
                cs = new ColorStyle[colorCnt];
                int idx = 0;
                // TODO: handle palette colors and alpha(?) value 
                for (byte[] data : ep) {
                    EscherColorRef ecr = new EscherColorRef(data, 0, 4);
                    cs[idx++] = wrapColor(shape.getColor(ecr));
                }
            }
            return cs;
        }

        private ColorStyle wrapColor(Color col) {
            return (col == null) ? null : DrawPaint.createSolidPaint(col).getSolidColor();
        }

        @Override
        public float[] getGradientFractions() {
            float[] frc;
            if (colorCnt == 0) {
                frc = new float[] { 0, 1 };
            } else {
                frc = new float[colorCnt];
                int idx = 0;
                for (byte[] data : ep) {
                    double pos = Units.fixedPointToDouble(LittleEndian.getInt(data, 4));
                    frc[idx++] = (float) pos;
                }
            }
            return frc;
        }

        @Override
        public boolean isRotatedWithShape() {
            return rotateWithShape;
        }

        @Override
        public GradientType getGradientType() {
            return gradientType;
        }
    };
}
Also used : EscherColorRef(org.apache.poi.ddf.EscherColorRef) ColorStyle(org.apache.poi.sl.usermodel.ColorStyle) EscherArrayProperty(org.apache.poi.ddf.EscherArrayProperty) Color(java.awt.Color) GradientPaint(org.apache.poi.sl.usermodel.PaintStyle.GradientPaint) AbstractEscherOptRecord(org.apache.poi.ddf.AbstractEscherOptRecord) DrawPaint(org.apache.poi.sl.draw.DrawPaint) GradientPaint(org.apache.poi.sl.usermodel.PaintStyle.GradientPaint) TexturePaint(org.apache.poi.sl.usermodel.PaintStyle.TexturePaint) EscherSimpleProperty(org.apache.poi.ddf.EscherSimpleProperty)

Example 4 with EscherArrayProperty

use of org.apache.poi.ddf.EscherArrayProperty in project poi by apache.

the class TestBugs method bug46441.

@Test
public void bug46441() throws IOException {
    HSLFSlideShow ppt = open("bug46441.ppt");
    HSLFAutoShape as = (HSLFAutoShape) ppt.getSlides().get(0).getShapes().get(0);
    AbstractEscherOptRecord opt = as.getEscherOptRecord();
    EscherArrayProperty ep = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__SHADECOLORS);
    double[][] exp = { // r, g, b, position
    { 94, 158, 255, 0 }, { 133, 194, 255, 0.399994 }, { 196, 214, 235, 0.699997 }, { 255, 235, 250, 1 } };
    int i = 0;
    for (byte[] data : ep) {
        EscherColorRef ecr = new EscherColorRef(data, 0, 4);
        int[] rgb = ecr.getRGB();
        double pos = Units.fixedPointToDouble(LittleEndian.getInt(data, 4));
        assertEquals((int) exp[i][0], rgb[0]);
        assertEquals((int) exp[i][1], rgb[1]);
        assertEquals((int) exp[i][2], rgb[2]);
        assertEquals(exp[i][3], pos, 0.01);
        i++;
    }
    ppt.close();
}
Also used : EscherColorRef(org.apache.poi.ddf.EscherColorRef) EscherArrayProperty(org.apache.poi.ddf.EscherArrayProperty) AbstractEscherOptRecord(org.apache.poi.ddf.AbstractEscherOptRecord) DrawPaint(org.apache.poi.sl.draw.DrawPaint) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint) Test(org.junit.Test)

Example 5 with EscherArrayProperty

use of org.apache.poi.ddf.EscherArrayProperty in project poi by apache.

the class HSLFFreeformShape method getPath.

@Override
public Path2D.Double getPath() {
    AbstractEscherOptRecord opt = getEscherOptRecord();
    EscherArrayProperty verticesProp = getShapeProp(opt, EscherProperties.GEOMETRY__VERTICES);
    EscherArrayProperty segmentsProp = getShapeProp(opt, EscherProperties.GEOMETRY__SEGMENTINFO);
    // return empty path if either GEOMETRY__VERTICES or GEOMETRY__SEGMENTINFO is missing, see Bugzilla 54188
    Path2D.Double path = new Path2D.Double();
    //sanity check
    if (verticesProp == null) {
        LOG.log(POILogger.WARN, "Freeform is missing GEOMETRY__VERTICES ");
        return path;
    }
    if (segmentsProp == null) {
        LOG.log(POILogger.WARN, "Freeform is missing GEOMETRY__SEGMENTINFO ");
        return path;
    }
    Iterator<byte[]> vertIter = verticesProp.iterator();
    Iterator<byte[]> segIter = segmentsProp.iterator();
    double[] xyPoints = new double[2];
    while (vertIter.hasNext() && segIter.hasNext()) {
        byte[] segElem = segIter.next();
        PathInfo pi = getPathInfo(segElem);
        switch(pi) {
            case escape:
                {
                    // handleEscapeInfo(path, segElem, vertIter);
                    break;
                }
            case moveTo:
                {
                    fillPoint(vertIter.next(), xyPoints);
                    double x = xyPoints[0];
                    double y = xyPoints[1];
                    path.moveTo(x, y);
                    break;
                }
            case curveTo:
                {
                    fillPoint(vertIter.next(), xyPoints);
                    double x1 = xyPoints[0];
                    double y1 = xyPoints[1];
                    fillPoint(vertIter.next(), xyPoints);
                    double x2 = xyPoints[0];
                    double y2 = xyPoints[1];
                    fillPoint(vertIter.next(), xyPoints);
                    double x3 = xyPoints[0];
                    double y3 = xyPoints[1];
                    path.curveTo(x1, y1, x2, y2, x3, y3);
                    break;
                }
            case lineTo:
                if (vertIter.hasNext()) {
                    fillPoint(vertIter.next(), xyPoints);
                    double x = xyPoints[0];
                    double y = xyPoints[1];
                    path.lineTo(x, y);
                }
                break;
            case close:
                path.closePath();
                break;
            default:
                break;
        }
    }
    EscherSimpleProperty shapePath = getShapeProp(opt, EscherProperties.GEOMETRY__SHAPEPATH);
    ShapePath sp = ShapePath.valueOf(shapePath == null ? 1 : shapePath.getPropertyValue());
    if (sp == ShapePath.LINES_CLOSED || sp == ShapePath.CURVES_CLOSED) {
        path.closePath();
    }
    Rectangle2D anchor = getAnchor();
    Rectangle2D bounds = path.getBounds2D();
    AffineTransform at = new AffineTransform();
    at.translate(anchor.getX(), anchor.getY());
    at.scale(anchor.getWidth() / bounds.getWidth(), anchor.getHeight() / bounds.getHeight());
    return new Path2D.Double(at.createTransformedShape(path));
}
Also used : EscherArrayProperty(org.apache.poi.ddf.EscherArrayProperty) Path2D(java.awt.geom.Path2D) Rectangle2D(java.awt.geom.Rectangle2D) AbstractEscherOptRecord(org.apache.poi.ddf.AbstractEscherOptRecord) EscherSimpleProperty(org.apache.poi.ddf.EscherSimpleProperty) AffineTransform(java.awt.geom.AffineTransform)

Aggregations

EscherArrayProperty (org.apache.poi.ddf.EscherArrayProperty)7 AbstractEscherOptRecord (org.apache.poi.ddf.AbstractEscherOptRecord)6 Rectangle2D (java.awt.geom.Rectangle2D)3 EscherSimpleProperty (org.apache.poi.ddf.EscherSimpleProperty)3 AffineTransform (java.awt.geom.AffineTransform)2 EscherColorRef (org.apache.poi.ddf.EscherColorRef)2 DrawPaint (org.apache.poi.sl.draw.DrawPaint)2 Test (org.junit.Test)2 Color (java.awt.Color)1 Path2D (java.awt.geom.Path2D)1 PathIterator (java.awt.geom.PathIterator)1 Point2D (java.awt.geom.Point2D)1 ArrayList (java.util.ArrayList)1 ColorStyle (org.apache.poi.sl.usermodel.ColorStyle)1 GradientPaint (org.apache.poi.sl.usermodel.PaintStyle.GradientPaint)1 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)1 TexturePaint (org.apache.poi.sl.usermodel.PaintStyle.TexturePaint)1