Search in sources :

Example 6 with EscherSimpleProperty

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

the class TestShapes method lineWidth.

@Test
public void lineWidth() {
    HSLFSimpleShape sh = new HSLFAutoShape(ShapeType.RT_TRIANGLE);
    AbstractEscherOptRecord opt = sh.getEscherOptRecord();
    EscherSimpleProperty prop = HSLFSimpleShape.getEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH);
    assertNull(prop);
    assertEquals(HSLFSimpleShape.DEFAULT_LINE_WIDTH, sh.getLineWidth(), 0);
    sh.setLineWidth(1.0);
    prop = HSLFSimpleShape.getEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH);
    assertNotNull(prop);
    assertEquals(1.0, sh.getLineWidth(), 0);
}
Also used : EscherSimpleProperty(org.apache.poi.ddf.EscherSimpleProperty) HSLFAutoShape(org.apache.poi.hslf.usermodel.HSLFAutoShape) HSLFSimpleShape(org.apache.poi.hslf.usermodel.HSLFSimpleShape) AbstractEscherOptRecord(org.apache.poi.ddf.AbstractEscherOptRecord) Test(org.junit.Test)

Example 7 with EscherSimpleProperty

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

the class HSLFPictureShape method getFractProp.

/**
     * @return the fractional property or 0 if not defined
     */
private static double getFractProp(AbstractEscherOptRecord opt, short propertyId) {
    EscherSimpleProperty prop = getEscherProperty(opt, propertyId);
    if (prop == null)
        return 0;
    int fixedPoint = prop.getPropertyValue();
    return Units.fixedPointToDouble(fixedPoint);
}
Also used : EscherSimpleProperty(org.apache.poi.ddf.EscherSimpleProperty)

Example 8 with EscherSimpleProperty

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

the class HSLFPictureShape method getPictureIndex.

/**
     * Returns index associated with this picture.
     * Index starts with 1 and points to a EscherBSE record which
     * holds information about this picture.
     *
     * @return the index to this picture (1 based).
     */
public int getPictureIndex() {
    AbstractEscherOptRecord opt = getEscherOptRecord();
    EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.BLIP__BLIPTODISPLAY);
    return prop == null ? 0 : prop.getPropertyValue();
}
Also used : EscherSimpleProperty(org.apache.poi.ddf.EscherSimpleProperty) AbstractEscherOptRecord(org.apache.poi.ddf.AbstractEscherOptRecord)

Example 9 with EscherSimpleProperty

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

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

the class HSLFFill method getFillType.

/**
     * Returns fill type.
     * Must be one of the <code>FILL_*</code> constants defined in this class.
     *
     * @return type of fill
     */
public int getFillType() {
    AbstractEscherOptRecord opt = shape.getEscherOptRecord();
    EscherSimpleProperty prop = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__FILLTYPE);
    return prop == null ? FILL_SOLID : prop.getPropertyValue();
}
Also used : EscherSimpleProperty(org.apache.poi.ddf.EscherSimpleProperty) AbstractEscherOptRecord(org.apache.poi.ddf.AbstractEscherOptRecord)

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