use of org.apache.pdfbox.pdmodel.graphics.PDExtendedGraphicsState 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");
}
Aggregations