Search in sources :

Example 1 with LineDash

use of org.apache.poi.sl.usermodel.StrokeStyle.LineDash in project poi by apache.

the class XSLFSimpleShape method getLineDash.

/**
     * @return  a preset line dashing scheme to stroke the shape outline
     */
public LineDash getLineDash() {
    PropertyFetcher<LineDash> fetcher = new PropertyFetcher<LineDash>() {

        @Override
        public boolean fetch(XSLFShape shape) {
            CTLineProperties ln = getLn(shape, false);
            if (ln == null || !ln.isSetPrstDash()) {
                return false;
            }
            setValue(LineDash.fromOoxmlId(ln.getPrstDash().getVal().intValue()));
            return true;
        }
    };
    fetchShapeProperty(fetcher);
    LineDash dash = fetcher.getValue();
    if (dash == null) {
        CTLineProperties defaultLn = getDefaultLineProperties();
        if (defaultLn != null && defaultLn.isSetPrstDash()) {
            dash = LineDash.fromOoxmlId(defaultLn.getPrstDash().getVal().intValue());
        }
    }
    return dash;
}
Also used : CTLineProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties) PropertyFetcher(org.apache.poi.xslf.model.PropertyFetcher) LineDash(org.apache.poi.sl.usermodel.StrokeStyle.LineDash)

Example 2 with LineDash

use of org.apache.poi.sl.usermodel.StrokeStyle.LineDash in project poi by apache.

the class HSLFTableCell method setBorderStyle.

@Override
public void setBorderStyle(BorderEdge edge, StrokeStyle style) {
    if (style == null) {
        throw new IllegalArgumentException("StrokeStyle needs to be specified.");
    }
    // setting the line cap is not implemented, as the border lines aren't connected
    LineCompound compound = style.getLineCompound();
    if (compound != null) {
        setBorderCompound(edge, compound);
    }
    LineDash dash = style.getLineDash();
    if (dash != null) {
        setBorderDash(edge, dash);
    }
    double width = style.getLineWidth();
    setBorderWidth(edge, width);
}
Also used : LineCompound(org.apache.poi.sl.usermodel.StrokeStyle.LineCompound) LineDash(org.apache.poi.sl.usermodel.StrokeStyle.LineDash)

Example 3 with LineDash

use of org.apache.poi.sl.usermodel.StrokeStyle.LineDash in project poi by apache.

the class XSLFSimpleShape method copy.

@Override
void copy(XSLFShape sh) {
    super.copy(sh);
    XSLFSimpleShape s = (XSLFSimpleShape) sh;
    Color srsSolidFill = s.getFillColor();
    Color tgtSoliFill = getFillColor();
    if (srsSolidFill != null && !srsSolidFill.equals(tgtSoliFill)) {
        setFillColor(srsSolidFill);
    }
    XSLFFillProperties fp = XSLFPropertiesDelegate.getFillDelegate(getShapeProperties());
    if (fp != null && fp.isSetBlipFill()) {
        CTBlip blip = fp.getBlipFill().getBlip();
        String blipId = blip.getEmbed();
        String relId = getSheet().importBlip(blipId, s.getSheet().getPackagePart());
        blip.setEmbed(relId);
    }
    Color srcLineColor = s.getLineColor();
    Color tgtLineColor = getLineColor();
    if (srcLineColor != null && !srcLineColor.equals(tgtLineColor)) {
        setLineColor(srcLineColor);
    }
    double srcLineWidth = s.getLineWidth();
    double tgtLineWidth = getLineWidth();
    if (srcLineWidth != tgtLineWidth) {
        setLineWidth(srcLineWidth);
    }
    LineDash srcLineDash = s.getLineDash();
    LineDash tgtLineDash = getLineDash();
    if (srcLineDash != null && srcLineDash != tgtLineDash) {
        setLineDash(srcLineDash);
    }
    LineCap srcLineCap = s.getLineCap();
    LineCap tgtLineCap = getLineCap();
    if (srcLineCap != null && srcLineCap != tgtLineCap) {
        setLineCap(srcLineCap);
    }
}
Also used : CTBlip(org.openxmlformats.schemas.drawingml.x2006.main.CTBlip) Color(java.awt.Color) CTSchemeColor(org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor) LineDash(org.apache.poi.sl.usermodel.StrokeStyle.LineDash) LineCap(org.apache.poi.sl.usermodel.StrokeStyle.LineCap) STLineCap(org.openxmlformats.schemas.drawingml.x2006.main.STLineCap) XSLFFillProperties(org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties)

Example 4 with LineDash

use of org.apache.poi.sl.usermodel.StrokeStyle.LineDash in project poi by apache.

the class XSLFTableCell method setBorderStyle.

@Override
public void setBorderStyle(BorderEdge edge, StrokeStyle style) {
    if (style == null) {
        throw new IllegalArgumentException("StrokeStyle needs to be specified.");
    }
    LineCap cap = style.getLineCap();
    if (cap != null) {
        setBorderCap(edge, cap);
    }
    LineCompound compound = style.getLineCompound();
    if (compound != null) {
        setBorderCompound(edge, compound);
    }
    LineDash dash = style.getLineDash();
    if (dash != null) {
        setBorderDash(edge, dash);
    }
    double width = style.getLineWidth();
    setBorderWidth(edge, width);
}
Also used : LineCompound(org.apache.poi.sl.usermodel.StrokeStyle.LineCompound) LineDash(org.apache.poi.sl.usermodel.StrokeStyle.LineDash) LineCap(org.apache.poi.sl.usermodel.StrokeStyle.LineCap) STLineCap(org.openxmlformats.schemas.drawingml.x2006.main.STLineCap)

Example 5 with LineDash

use of org.apache.poi.sl.usermodel.StrokeStyle.LineDash in project poi by apache.

the class DrawShape method getStroke.

protected static BasicStroke getStroke(StrokeStyle strokeStyle) {
    float lineWidth = (float) strokeStyle.getLineWidth();
    if (lineWidth == 0.0f) {
        // Both PowerPoint and OOo draw zero-length lines as 0.25pt
        lineWidth = 0.25f;
    }
    LineDash lineDash = strokeStyle.getLineDash();
    if (lineDash == null) {
        lineDash = LineDash.SOLID;
    }
    int[] dashPatI = lineDash.pattern;
    final float dash_phase = 0;
    float[] dashPatF = null;
    if (dashPatI != null) {
        dashPatF = new float[dashPatI.length];
        for (int i = 0; i < dashPatI.length; i++) {
            dashPatF[i] = dashPatI[i] * Math.max(1, lineWidth);
        }
    }
    LineCap lineCapE = strokeStyle.getLineCap();
    if (lineCapE == null) {
        lineCapE = LineCap.FLAT;
    }
    int lineCap;
    switch(lineCapE) {
        case ROUND:
            lineCap = BasicStroke.CAP_ROUND;
            break;
        case SQUARE:
            lineCap = BasicStroke.CAP_SQUARE;
            break;
        default:
        case FLAT:
            lineCap = BasicStroke.CAP_BUTT;
            break;
    }
    int lineJoin = BasicStroke.JOIN_ROUND;
    return new BasicStroke(lineWidth, lineCap, lineJoin, lineWidth, dashPatF, dash_phase);
}
Also used : BasicStroke(java.awt.BasicStroke) LineDash(org.apache.poi.sl.usermodel.StrokeStyle.LineDash) LineCap(org.apache.poi.sl.usermodel.StrokeStyle.LineCap)

Aggregations

LineDash (org.apache.poi.sl.usermodel.StrokeStyle.LineDash)5 LineCap (org.apache.poi.sl.usermodel.StrokeStyle.LineCap)3 LineCompound (org.apache.poi.sl.usermodel.StrokeStyle.LineCompound)2 STLineCap (org.openxmlformats.schemas.drawingml.x2006.main.STLineCap)2 BasicStroke (java.awt.BasicStroke)1 Color (java.awt.Color)1 PropertyFetcher (org.apache.poi.xslf.model.PropertyFetcher)1 XSLFFillProperties (org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties)1 CTBlip (org.openxmlformats.schemas.drawingml.x2006.main.CTBlip)1 CTLineProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties)1 CTSchemeColor (org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor)1