List of usage examples for java.awt BasicStroke getMiterLimit
public float getMiterLimit()
From source file:org.apache.pdfbox.util.operator.pagedrawer.StrokePath.java
/** * S stroke the path.// www. j a va 2 s. c o m * @param operator The operator that is being executed. * @param arguments List * * @throws IOException If an error occurs while processing the font. */ public void process(PDFOperator operator, List<COSBase> arguments) throws IOException { ///dwilson 3/19/07 refactor try { PageDrawer drawer = (PageDrawer) context; float lineWidth = (float) context.getGraphicsState().getLineWidth(); Matrix ctm = context.getGraphicsState().getCurrentTransformationMatrix(); if (ctm != null && ctm.getXScale() > 0) { lineWidth = lineWidth * ctm.getXScale(); } BasicStroke stroke = (BasicStroke) drawer.getStroke(); if (stroke == null) { drawer.setStroke(new BasicStroke(lineWidth)); } else { drawer.setStroke(new BasicStroke(lineWidth, stroke.getEndCap(), stroke.getLineJoin(), stroke.getMiterLimit(), stroke.getDashArray(), stroke.getDashPhase())); } drawer.strokePath(); } catch (Exception exception) { log.warn(exception, exception); } }
From source file:org.eclipse.birt.chart.device.svg.SVGGraphics2D.java
/** * Adds stroke color and style information to the element passed in. * //from w ww. j ava2 s . co m * @param currentElement * the element to add style information to. * @param isClipped * boolean that determines whether to defer the clipping of the * element */ protected void setStrokeStyle(Element currentElement, boolean deferClipped) { Element element = currentElement; if (deferStrokColor != null) { // Need to get the parent element. element = deferStrokColor; } String style = element.getAttribute("style"); //$NON-NLS-1$ if (style == null) style = ""; //$NON-NLS-1$ if (color != null) { style += "stroke:" + serializeToString(color) + ";"; //$NON-NLS-1$ //$NON-NLS-2$ } if ((stroke != null) && (stroke instanceof BasicStroke)) { BasicStroke bs = (BasicStroke) stroke; if (bs.getLineWidth() > 0) style += "stroke-width:" + bs.getLineWidth() + ";"; //$NON-NLS-1$ //$NON-NLS-2$ if (bs.getDashArray() != null) { StringBuffer dashArrayStr = new StringBuffer(); for (int x = 0; x < bs.getDashArray().length; x++) { dashArrayStr.append(" ").append(bs.getDashArray()[x]); //$NON-NLS-1$ } if (!(dashArrayStr.toString().equals(""))) //$NON-NLS-1$ style += "stroke-dasharray:" + dashArrayStr + ";"; //$NON-NLS-1$ //$NON-NLS-2$ } style += "stroke-miterlimit:" + bs.getMiterLimit() + ";"; //$NON-NLS-1$ //$NON-NLS-2$ switch (bs.getLineJoin()) { case BasicStroke.JOIN_BEVEL: style += "stroke-linejoin:bevel;"; //$NON-NLS-1$ break; case BasicStroke.JOIN_ROUND: style += "stroke-linejoin:round;"; //$NON-NLS-1$ break; } switch (bs.getEndCap()) { case BasicStroke.CAP_ROUND: style += "stroke-linecap:round;"; //$NON-NLS-1$ break; case BasicStroke.CAP_SQUARE: style += "stroke-linecap:square;"; //$NON-NLS-1$ break; } } element.setAttribute("style", style); //$NON-NLS-1$ if (styleClass != null) element.setAttribute("class", styleClass); //$NON-NLS-1$ if (id != null) element.setAttribute("id", id); //$NON-NLS-1$ if ((clip != null) && (!deferClipped)) element.setAttribute("clip-path", "url(#clip" + clip.hashCode() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java
private Stroke transformStroke(final Stroke stroke) { if (!(stroke instanceof BasicStroke)) { return stroke; }/*from w ww . jav a2 s.c o m*/ final BasicStroke st = (BasicStroke) stroke; final float scale = (float) Math.sqrt(Math.abs(transform.getDeterminant())); final float[] dash = st.getDashArray(); if (dash != null) { final int dashLength = dash.length; for (int k = 0; k < dashLength; ++k) { dash[k] *= scale; } } return new BasicStroke(st.getLineWidth() * scale, st.getEndCap(), st.getLineJoin(), st.getMiterLimit(), dash, st.getDashPhase() * scale); }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java
private void setStrokeDiff(final Stroke newStroke, final Stroke oldStroke) { if (newStroke == oldStroke) { return;//from w w w .j a v a 2s. co m } if (!(newStroke instanceof BasicStroke)) { return; } final BasicStroke nStroke = (BasicStroke) newStroke; final boolean oldOk = (oldStroke instanceof BasicStroke); BasicStroke oStroke = null; if (oldOk) { oStroke = (BasicStroke) oldStroke; } if (!oldOk || nStroke.getLineWidth() != oStroke.getLineWidth()) { cb.setLineWidth(nStroke.getLineWidth()); } if (!oldOk || nStroke.getEndCap() != oStroke.getEndCap()) { switch (nStroke.getEndCap()) { case BasicStroke.CAP_BUTT: cb.setLineCap(0); break; case BasicStroke.CAP_SQUARE: cb.setLineCap(2); break; default: cb.setLineCap(1); } } if (!oldOk || nStroke.getLineJoin() != oStroke.getLineJoin()) { switch (nStroke.getLineJoin()) { case BasicStroke.JOIN_MITER: cb.setLineJoin(0); break; case BasicStroke.JOIN_BEVEL: cb.setLineJoin(2); break; default: cb.setLineJoin(1); } } if (!oldOk || nStroke.getMiterLimit() != oStroke.getMiterLimit()) { cb.setMiterLimit(nStroke.getMiterLimit()); } final boolean makeDash; if (oldOk) { if (nStroke.getDashArray() != null) { if (nStroke.getDashPhase() != oStroke.getDashPhase()) { makeDash = true; } else if (!Arrays.equals(nStroke.getDashArray(), oStroke.getDashArray())) { makeDash = true; } else { makeDash = false; } } else if (oStroke.getDashArray() != null) { makeDash = true; } else { makeDash = false; } } else { makeDash = true; } if (makeDash) { final float[] dash = nStroke.getDashArray(); if (dash == null) { cb.setLiteral("[]0 d\n"); } else { cb.setLiteral('['); final int lim = dash.length; for (int k = 0; k < lim; ++k) { cb.setLiteral(dash[k]); cb.setLiteral(' '); } cb.setLiteral(']'); cb.setLiteral(nStroke.getDashPhase()); cb.setLiteral(" d\n"); } } }