Search in sources :

Example 21 with EscherSimpleProperty

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

the class HSLFSimpleShape method getShadowDistance.

public double getShadowDistance() {
    AbstractEscherOptRecord opt = getEscherOptRecord();
    EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.SHADOWSTYLE__OFFSETX);
    int offX = (prop == null) ? 0 : prop.getPropertyValue();
    prop = getEscherProperty(opt, EscherProperties.SHADOWSTYLE__OFFSETY);
    int offY = (prop == null) ? 0 : prop.getPropertyValue();
    return Units.toPoints((long) Math.hypot(offX, offY));
}
Also used : EscherSimpleProperty(org.apache.poi.ddf.EscherSimpleProperty) AbstractEscherOptRecord(org.apache.poi.ddf.AbstractEscherOptRecord) DrawPaint(org.apache.poi.sl.draw.DrawPaint) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)

Example 22 with EscherSimpleProperty

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

the class InternalWorkbook method cloneDrawings.

/**
     * Check if the cloned sheet has drawings. If yes, then allocate a new drawing group ID and
     * re-generate shape IDs
     *
     * @param sheet the cloned sheet
     */
public void cloneDrawings(InternalSheet sheet) {
    findDrawingGroup();
    if (drawingManager == null) {
        //this workbook does not have drawings
        return;
    }
    //check if the cloned sheet has drawings
    int aggLoc = sheet.aggregateDrawingRecords(drawingManager, false);
    if (aggLoc == -1) {
        return;
    }
    EscherAggregate agg = (EscherAggregate) sheet.findFirstRecordBySid(EscherAggregate.sid);
    EscherContainerRecord escherContainer = agg.getEscherContainer();
    if (escherContainer == null) {
        return;
    }
    EscherDggRecord dgg = drawingManager.getDgg();
    //register a new drawing group for the cloned sheet
    int dgId = drawingManager.findNewDrawingGroupId();
    dgg.addCluster(dgId, 0);
    dgg.setDrawingsSaved(dgg.getDrawingsSaved() + 1);
    EscherDgRecord dg = null;
    for (EscherRecord er : escherContainer) {
        if (er instanceof EscherDgRecord) {
            dg = (EscherDgRecord) er;
            //update id of the drawing in the cloned sheet
            dg.setOptions((short) (dgId << 4));
        } else if (er instanceof EscherContainerRecord) {
            // iterate over shapes and re-generate shapeId
            for (EscherRecord er2 : (EscherContainerRecord) er) {
                for (EscherRecord shapeChildRecord : (EscherContainerRecord) er2) {
                    int recordId = shapeChildRecord.getRecordId();
                    if (recordId == EscherSpRecord.RECORD_ID) {
                        if (dg == null) {
                            throw new RecordFormatException("EscherDgRecord wasn't set/processed before.");
                        }
                        EscherSpRecord sp = (EscherSpRecord) shapeChildRecord;
                        int shapeId = drawingManager.allocateShapeId((short) dgId, dg);
                        //allocateShapeId increments the number of shapes. roll back to the previous value
                        dg.setNumShapes(dg.getNumShapes() - 1);
                        sp.setShapeId(shapeId);
                    } else if (recordId == EscherOptRecord.RECORD_ID) {
                        EscherOptRecord opt = (EscherOptRecord) shapeChildRecord;
                        EscherSimpleProperty prop = (EscherSimpleProperty) opt.lookup(EscherProperties.BLIP__BLIPTODISPLAY);
                        if (prop != null) {
                            int pictureIndex = prop.getPropertyValue();
                            // increment reference count for pictures
                            EscherBSERecord bse = getBSERecord(pictureIndex);
                            bse.setRef(bse.getRef() + 1);
                        }
                    }
                }
            }
        }
    }
}
Also used : EscherAggregate(org.apache.poi.hssf.record.EscherAggregate) RecordFormatException(org.apache.poi.util.RecordFormatException) EscherSimpleProperty(org.apache.poi.ddf.EscherSimpleProperty) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherDggRecord(org.apache.poi.ddf.EscherDggRecord) EscherDgRecord(org.apache.poi.ddf.EscherDgRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) EscherOptRecord(org.apache.poi.ddf.EscherOptRecord) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord)

Example 23 with EscherSimpleProperty

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

the class HSLFFill method afterInsert.

/**
     */
protected void afterInsert(HSLFSheet sh) {
    AbstractEscherOptRecord opt = shape.getEscherOptRecord();
    EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__PATTERNTEXTURE);
    if (p != null) {
        int idx = p.getPropertyValue();
        EscherBSERecord bse = getEscherBSERecord(idx);
        if (bse != null) {
            bse.setRef(bse.getRef() + 1);
        }
    }
}
Also used : EscherSimpleProperty(org.apache.poi.ddf.EscherSimpleProperty) 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) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord)

Example 24 with EscherSimpleProperty

use of org.apache.poi.ddf.EscherSimpleProperty 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)

Example 25 with EscherSimpleProperty

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

the class HSLFFreeformShape method setPath.

@Override
public int setPath(Path2D.Double path) {
    Rectangle2D bounds = path.getBounds2D();
    PathIterator it = path.getPathIterator(new AffineTransform());
    List<byte[]> segInfo = new ArrayList<byte[]>();
    List<Point2D.Double> pntInfo = new ArrayList<Point2D.Double>();
    boolean isClosed = false;
    int numPoints = 0;
    while (!it.isDone()) {
        double[] vals = new double[6];
        int type = it.currentSegment(vals);
        switch(type) {
            case PathIterator.SEG_MOVETO:
                pntInfo.add(new Point2D.Double(vals[0], vals[1]));
                segInfo.add(SEGMENTINFO_MOVETO);
                numPoints++;
                break;
            case PathIterator.SEG_LINETO:
                pntInfo.add(new Point2D.Double(vals[0], vals[1]));
                segInfo.add(SEGMENTINFO_LINETO);
                segInfo.add(SEGMENTINFO_ESCAPE);
                numPoints++;
                break;
            case PathIterator.SEG_CUBICTO:
                pntInfo.add(new Point2D.Double(vals[0], vals[1]));
                pntInfo.add(new Point2D.Double(vals[2], vals[3]));
                pntInfo.add(new Point2D.Double(vals[4], vals[5]));
                segInfo.add(SEGMENTINFO_CUBICTO);
                segInfo.add(SEGMENTINFO_ESCAPE2);
                numPoints++;
                break;
            case PathIterator.SEG_QUADTO:
                //TODO: figure out how to convert SEG_QUADTO into SEG_CUBICTO
                LOG.log(POILogger.WARN, "SEG_QUADTO is not supported");
                break;
            case PathIterator.SEG_CLOSE:
                pntInfo.add(pntInfo.get(0));
                segInfo.add(SEGMENTINFO_LINETO);
                segInfo.add(SEGMENTINFO_ESCAPE);
                segInfo.add(SEGMENTINFO_LINETO);
                segInfo.add(SEGMENTINFO_CLOSE);
                isClosed = true;
                numPoints++;
                break;
            default:
                LOG.log(POILogger.WARN, "Ignoring invalid segment type " + type);
                break;
        }
        it.next();
    }
    if (!isClosed) {
        segInfo.add(SEGMENTINFO_LINETO);
    }
    segInfo.add(SEGMENTINFO_END);
    AbstractEscherOptRecord opt = getEscherOptRecord();
    opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__SHAPEPATH, 0x4));
    EscherArrayProperty verticesProp = new EscherArrayProperty((short) (EscherProperties.GEOMETRY__VERTICES + 0x4000), false, null);
    verticesProp.setNumberOfElementsInArray(pntInfo.size());
    verticesProp.setNumberOfElementsInMemory(pntInfo.size());
    verticesProp.setSizeOfElements(8);
    for (int i = 0; i < pntInfo.size(); i++) {
        Point2D.Double pnt = pntInfo.get(i);
        byte[] data = new byte[8];
        LittleEndian.putInt(data, 0, Units.pointsToMaster(pnt.getX() - bounds.getX()));
        LittleEndian.putInt(data, 4, Units.pointsToMaster(pnt.getY() - bounds.getY()));
        verticesProp.setElement(i, data);
    }
    opt.addEscherProperty(verticesProp);
    EscherArrayProperty segmentsProp = new EscherArrayProperty((short) (EscherProperties.GEOMETRY__SEGMENTINFO + 0x4000), false, null);
    segmentsProp.setNumberOfElementsInArray(segInfo.size());
    segmentsProp.setNumberOfElementsInMemory(segInfo.size());
    segmentsProp.setSizeOfElements(0x2);
    for (int i = 0; i < segInfo.size(); i++) {
        byte[] seg = segInfo.get(i);
        segmentsProp.setElement(i, seg);
    }
    opt.addEscherProperty(segmentsProp);
    opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__RIGHT, Units.pointsToMaster(bounds.getWidth())));
    opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__BOTTOM, Units.pointsToMaster(bounds.getHeight())));
    opt.sortProperties();
    setAnchor(bounds);
    return numPoints;
}
Also used : PathIterator(java.awt.geom.PathIterator) EscherArrayProperty(org.apache.poi.ddf.EscherArrayProperty) Rectangle2D(java.awt.geom.Rectangle2D) ArrayList(java.util.ArrayList) AbstractEscherOptRecord(org.apache.poi.ddf.AbstractEscherOptRecord) Point2D(java.awt.geom.Point2D) EscherSimpleProperty(org.apache.poi.ddf.EscherSimpleProperty) AffineTransform(java.awt.geom.AffineTransform)

Aggregations

EscherSimpleProperty (org.apache.poi.ddf.EscherSimpleProperty)48 AbstractEscherOptRecord (org.apache.poi.ddf.AbstractEscherOptRecord)36 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)8 DrawPaint (org.apache.poi.sl.draw.DrawPaint)8 EscherBSERecord (org.apache.poi.ddf.EscherBSERecord)6 GradientPaint (org.apache.poi.sl.usermodel.PaintStyle.GradientPaint)6 TexturePaint (org.apache.poi.sl.usermodel.PaintStyle.TexturePaint)6 Color (java.awt.Color)5 EscherOptRecord (org.apache.poi.ddf.EscherOptRecord)5 EscherRecord (org.apache.poi.ddf.EscherRecord)4 EscherArrayProperty (org.apache.poi.ddf.EscherArrayProperty)3 EscherSpRecord (org.apache.poi.ddf.EscherSpRecord)3 AffineTransform (java.awt.geom.AffineTransform)2 Rectangle2D (java.awt.geom.Rectangle2D)2 EscherBoolProperty (org.apache.poi.ddf.EscherBoolProperty)2 EscherColorRef (org.apache.poi.ddf.EscherColorRef)2 EscherDgRecord (org.apache.poi.ddf.EscherDgRecord)2 EscherProperty (org.apache.poi.ddf.EscherProperty)2 EscherRGBProperty (org.apache.poi.ddf.EscherRGBProperty)2 Document (org.apache.poi.hslf.record.Document)2