Search in sources :

Example 41 with EscherSimpleProperty

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

the class HSLFTextShape method getInset.

/**
     * Returns the distance (in points) between the edge of the text frame
     * and the edge of the inscribed rectangle of the shape that contains the text.
     * Default value is 1/20 inch.
     *
     * @param propId the id of the inset edge
     * @return the inset in points
     */
private double getInset(short propId, double defaultInch) {
    AbstractEscherOptRecord opt = getEscherOptRecord();
    EscherSimpleProperty prop = getEscherProperty(opt, propId);
    int val = prop == null ? (int) (Units.toEMU(Units.POINT_DPI) * defaultInch) : prop.getPropertyValue();
    return Units.toPoints(val);
}
Also used : EscherSimpleProperty(org.apache.poi.ddf.EscherSimpleProperty) AbstractEscherOptRecord(org.apache.poi.ddf.AbstractEscherOptRecord)

Example 42 with EscherSimpleProperty

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

the class HSLFTextShape method getTextId.

/**
     * @return id for the text.
     */
public int getTextId() {
    AbstractEscherOptRecord opt = getEscherOptRecord();
    EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__TEXTID);
    return prop == null ? 0 : prop.getPropertyValue();
}
Also used : EscherSimpleProperty(org.apache.poi.ddf.EscherSimpleProperty) AbstractEscherOptRecord(org.apache.poi.ddf.AbstractEscherOptRecord)

Example 43 with EscherSimpleProperty

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

the class HSLFTextShape method getAlignment.

/**
     * Returns the type of vertical alignment for the text.
     * One of the <code>Anchor*</code> constants defined in this class.
     *
     * @return the type of alignment
     */
/* package */
HSLFTextAnchor getAlignment() {
    AbstractEscherOptRecord opt = getEscherOptRecord();
    EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__ANCHORTEXT);
    HSLFTextAnchor align = HSLFTextAnchor.TOP;
    if (prop == null) {
        /**
             * If vertical alignment was not found in the shape properties then try to
             * fetch the master shape and search for the align property there.
             */
        int type = getRunType();
        HSLFSheet sh = getSheet();
        HSLFMasterSheet master = (sh != null) ? sh.getMasterSheet() : null;
        HSLFTextShape masterShape = (master != null) ? master.getPlaceholderByTextType(type) : null;
        if (masterShape != null && type != TextHeaderAtom.OTHER_TYPE) {
            align = masterShape.getAlignment();
        } else {
            //not found in the master sheet. Use the hardcoded defaults.
            switch(type) {
                case TextHeaderAtom.TITLE_TYPE:
                case TextHeaderAtom.CENTER_TITLE_TYPE:
                    align = HSLFTextAnchor.MIDDLE;
                    break;
                default:
                    align = HSLFTextAnchor.TOP;
                    break;
            }
        }
    } else {
        align = HSLFTextAnchor.fromNativeId(prop.getPropertyValue());
    }
    if (align == null) {
        align = HSLFTextAnchor.TOP;
    }
    return align;
}
Also used : EscherSimpleProperty(org.apache.poi.ddf.EscherSimpleProperty) AbstractEscherOptRecord(org.apache.poi.ddf.AbstractEscherOptRecord)

Example 44 with EscherSimpleProperty

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

the class HSSFSimpleShape method setString.

/**
     * @param string Sets the rich text string used by this object.
     */
public void setString(RichTextString string) {
    //TODO add other shape types which can not contain text
    if (getShapeType() == 0 || getShapeType() == OBJECT_TYPE_LINE) {
        throw new IllegalStateException("Cannot set text for shape type: " + getShapeType());
    }
    HSSFRichTextString rtr = (HSSFRichTextString) string;
    // If font is not set we must set the default one
    if (rtr.numFormattingRuns() == 0)
        rtr.applyFont((short) 0);
    TextObjectRecord txo = getOrCreateTextObjRecord();
    txo.setStr(rtr);
    if (string.getString() != null) {
        setPropertyValue(new EscherSimpleProperty(EscherProperties.TEXT__TEXTID, string.getString().hashCode()));
    }
}
Also used : TextObjectRecord(org.apache.poi.hssf.record.TextObjectRecord) EscherSimpleProperty(org.apache.poi.ddf.EscherSimpleProperty)

Example 45 with EscherSimpleProperty

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

the class HSSFSimpleShape method createSpContainer.

@Override
protected EscherContainerRecord createSpContainer() {
    EscherContainerRecord spContainer = new EscherContainerRecord();
    spContainer.setRecordId(EscherContainerRecord.SP_CONTAINER);
    spContainer.setOptions((short) 0x000F);
    EscherSpRecord sp = new EscherSpRecord();
    sp.setRecordId(EscherSpRecord.RECORD_ID);
    sp.setFlags(EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE);
    sp.setVersion((short) 0x2);
    EscherClientDataRecord clientData = new EscherClientDataRecord();
    clientData.setRecordId(EscherClientDataRecord.RECORD_ID);
    clientData.setOptions((short) (0x0000));
    EscherOptRecord optRecord = new EscherOptRecord();
    optRecord.setEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEDASHING, LINESTYLE_SOLID));
    optRecord.setEscherProperty(new EscherBoolProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080008));
    //        optRecord.setEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEWIDTH, LINEWIDTH_DEFAULT));
    optRecord.setEscherProperty(new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, FILL__FILLCOLOR_DEFAULT));
    optRecord.setEscherProperty(new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, LINESTYLE__COLOR_DEFAULT));
    optRecord.setEscherProperty(new EscherBoolProperty(EscherProperties.FILL__NOFILLHITTEST, NO_FILLHITTEST_FALSE));
    optRecord.setEscherProperty(new EscherBoolProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080008));
    optRecord.setEscherProperty(new EscherShapePathProperty(EscherProperties.GEOMETRY__SHAPEPATH, EscherShapePathProperty.COMPLEX));
    optRecord.setEscherProperty(new EscherBoolProperty(EscherProperties.GROUPSHAPE__PRINT, 0x080000));
    optRecord.setRecordId(EscherOptRecord.RECORD_ID);
    EscherTextboxRecord escherTextbox = new EscherTextboxRecord();
    escherTextbox.setRecordId(EscherTextboxRecord.RECORD_ID);
    escherTextbox.setOptions((short) 0x0000);
    spContainer.addChildRecord(sp);
    spContainer.addChildRecord(optRecord);
    spContainer.addChildRecord(getAnchor().getEscherAnchor());
    spContainer.addChildRecord(clientData);
    spContainer.addChildRecord(escherTextbox);
    return spContainer;
}
Also used : EscherBoolProperty(org.apache.poi.ddf.EscherBoolProperty) EscherSimpleProperty(org.apache.poi.ddf.EscherSimpleProperty) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) EscherTextboxRecord(org.apache.poi.ddf.EscherTextboxRecord) EscherClientDataRecord(org.apache.poi.ddf.EscherClientDataRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherShapePathProperty(org.apache.poi.ddf.EscherShapePathProperty) EscherOptRecord(org.apache.poi.ddf.EscherOptRecord) EscherRGBProperty(org.apache.poi.ddf.EscherRGBProperty)

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