Search in sources :

Example 1 with PDLineDashPattern

use of org.apache.pdfbox.pdmodel.graphics.PDLineDashPattern in project pdfbox by apache.

the class PDBoxStyle method getLineDashPattern.

/**
 * Get the line dash pattern for this box style.  This is guaranteed to not
 * return null.  The default is [3],0.
 *
 * @return The line dash pattern.
 */
public PDLineDashPattern getLineDashPattern() {
    PDLineDashPattern pattern;
    COSArray d = (COSArray) dictionary.getDictionaryObject(COSName.D);
    if (d == null) {
        d = new COSArray();
        d.add(COSInteger.THREE);
        dictionary.setItem(COSName.D, d);
    }
    COSArray lineArray = new COSArray();
    lineArray.add(d);
    // dash phase is not specified and assumed to be zero.
    pattern = new PDLineDashPattern(lineArray, 0);
    return pattern;
}
Also used : COSArray(org.apache.pdfbox.cos.COSArray) PDLineDashPattern(org.apache.pdfbox.pdmodel.graphics.PDLineDashPattern)

Example 2 with PDLineDashPattern

use of org.apache.pdfbox.pdmodel.graphics.PDLineDashPattern in project pdfbox by apache.

the class PDExtendedGraphicsState method getLineDashPattern.

/**
 * This will get the dash pattern.
 *
 * @return null or the D value in the dictionary.
 */
public PDLineDashPattern getLineDashPattern() {
    PDLineDashPattern retval = null;
    COSBase dp = dict.getDictionaryObject(COSName.D);
    if (dp instanceof COSArray && ((COSArray) dp).size() == 2) {
        COSBase dashArray = ((COSArray) dp).getObject(0);
        COSBase phase = ((COSArray) dp).getObject(1);
        if (dashArray instanceof COSArray && phase instanceof COSNumber) {
            retval = new PDLineDashPattern((COSArray) dashArray, ((COSNumber) phase).intValue());
        }
    }
    return retval;
}
Also used : COSArray(org.apache.pdfbox.cos.COSArray) COSNumber(org.apache.pdfbox.cos.COSNumber) PDLineDashPattern(org.apache.pdfbox.pdmodel.graphics.PDLineDashPattern) COSBase(org.apache.pdfbox.cos.COSBase)

Example 3 with PDLineDashPattern

use of org.apache.pdfbox.pdmodel.graphics.PDLineDashPattern in project pdfbox by apache.

the class PDBorderStyleDictionary method getDashStyle.

/**
 * This will retrieve the dash style used for drawing the border.
 *
 * @return the dash style of the border
 */
public PDLineDashPattern getDashStyle() {
    COSArray d = (COSArray) getCOSObject().getDictionaryObject("D");
    if (d == null) {
        d = new COSArray();
        d.add(COSInteger.THREE);
        getCOSObject().setItem("D", d);
    }
    return new PDLineDashPattern(d, 0);
}
Also used : COSArray(org.apache.pdfbox.cos.COSArray) PDLineDashPattern(org.apache.pdfbox.pdmodel.graphics.PDLineDashPattern)

Example 4 with PDLineDashPattern

use of org.apache.pdfbox.pdmodel.graphics.PDLineDashPattern in project pdfbox by apache.

the class PDFStreamEngine method setLineDashPattern.

/**
 * @param array dash array
 * @param phase dash phase
 */
public void setLineDashPattern(COSArray array, int phase) {
    if (phase < 0) {
        LOG.warn("Dash phase has negative value " + phase + ", set to 0");
        phase = 0;
    }
    PDLineDashPattern lineDash = new PDLineDashPattern(array, phase);
    getGraphicsState().setLineDashPattern(lineDash);
}
Also used : PDLineDashPattern(org.apache.pdfbox.pdmodel.graphics.PDLineDashPattern)

Example 5 with PDLineDashPattern

use of org.apache.pdfbox.pdmodel.graphics.PDLineDashPattern in project com.revolsys.open by revolsys.

the class PdfViewport method setGeometryStyle.

private void setGeometryStyle(final GeometryStyle style) throws IOException {
    String styleName = this.styleNames.get(style);
    if (styleName == null) {
        styleName = "rgStyle" + this.styleId++;
        final PDExtendedGraphicsState graphicsState = new PDExtendedGraphicsState();
        final int lineOpacity = style.getLineOpacity();
        if (lineOpacity != 255) {
            graphicsState.setStrokingAlphaConstant(lineOpacity / 255f);
        }
        final Quantity<Length> lineWidth = style.getLineWidth();
        final Unit<Length> unit = lineWidth.getUnit();
        graphicsState.setLineWidth((float) toDisplayValue(lineWidth));
        final List<Double> lineDashArray = style.getLineDashArray();
        if (lineDashArray != null && !lineDashArray.isEmpty()) {
            int size = lineDashArray.size();
            if (size == 1) {
                size++;
            }
            final float[] dashArray = new float[size];
            for (int i = 0; i < dashArray.length; i++) {
                if (i < lineDashArray.size()) {
                    final Double dashDouble = lineDashArray.get(i);
                    final Quantity<Length> dashMeasure = Quantities.getQuantity(dashDouble, unit);
                    final float dashFloat = (float) toDisplayValue(dashMeasure);
                    dashArray[i] = dashFloat;
                } else {
                    dashArray[i] = dashArray[i - 1];
                }
            }
            final int offset = (int) toDisplayValue(Quantities.getQuantity(style.getLineDashOffset(), unit));
            final COSArray dashCosArray = new COSArray();
            dashCosArray.setFloatArray(dashArray);
            final PDLineDashPattern pattern = new PDLineDashPattern(dashCosArray, offset);
            graphicsState.setLineDashPattern(pattern);
        }
        switch(style.getLineCap()) {
            case BUTT:
                graphicsState.setLineCapStyle(0);
                break;
            case ROUND:
                graphicsState.setLineCapStyle(1);
                break;
            case SQUARE:
                graphicsState.setLineCapStyle(2);
                break;
        }
        switch(style.getLineJoin()) {
            case MITER:
                graphicsState.setLineJoinStyle(0);
                break;
            case ROUND:
                graphicsState.setLineJoinStyle(1);
                break;
            case BEVEL:
                graphicsState.setLineJoinStyle(2);
                break;
        }
        final int polygonFillOpacity = style.getPolygonFillOpacity();
        if (polygonFillOpacity != 255) {
            graphicsState.setNonStrokingAlphaConstant(polygonFillOpacity / 255f);
        }
        final PDResources resources = this.page.findResources();
        Map<String, PDExtendedGraphicsState> graphicsStateDictionary = resources.getGraphicsStates();
        if (graphicsStateDictionary == null) {
            graphicsStateDictionary = new TreeMap<>();
        }
        graphicsStateDictionary.put(styleName, graphicsState);
        resources.setGraphicsStates(graphicsStateDictionary);
        this.styleNames.put(style, styleName);
    }
    this.contentStream.appendRawCommands("/" + styleName + " gs\n");
}
Also used : PDExtendedGraphicsState(org.apache.pdfbox.pdmodel.graphics.PDExtendedGraphicsState) PDResources(org.apache.pdfbox.pdmodel.PDResources) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) COSArray(org.apache.pdfbox.cos.COSArray) Length(javax.measure.quantity.Length) PDLineDashPattern(org.apache.pdfbox.pdmodel.graphics.PDLineDashPattern)

Aggregations

PDLineDashPattern (org.apache.pdfbox.pdmodel.graphics.PDLineDashPattern)6 COSArray (org.apache.pdfbox.cos.COSArray)4 LineString (com.revolsys.geometry.model.LineString)1 Point (com.revolsys.geometry.model.Point)1 BasicStroke (java.awt.BasicStroke)1 Paint (java.awt.Paint)1 Point (java.awt.Point)1 TexturePaint (java.awt.TexturePaint)1 Length (javax.measure.quantity.Length)1 COSBase (org.apache.pdfbox.cos.COSBase)1 COSNumber (org.apache.pdfbox.cos.COSNumber)1 PDResources (org.apache.pdfbox.pdmodel.PDResources)1 PDExtendedGraphicsState (org.apache.pdfbox.pdmodel.graphics.PDExtendedGraphicsState)1 PDGraphicsState (org.apache.pdfbox.pdmodel.graphics.state.PDGraphicsState)1