List of usage examples for java.awt BasicStroke getEndCap
public int getEndCap()
From source file:SWTGraphics2D.java
/** * Sets the stroke for this graphics context. For now, this implementation * only recognises the {@link BasicStroke} class. * * @param stroke the stroke (<code>null</code> not permitted). * * @see #getStroke()/*from w ww .j a v a2s . c om*/ */ public void setStroke(Stroke stroke) { if (stroke instanceof BasicStroke) { BasicStroke bs = (BasicStroke) stroke; // linewidth this.gc.setLineWidth((int) bs.getLineWidth()); // line join switch (bs.getLineJoin()) { case BasicStroke.JOIN_BEVEL: this.gc.setLineJoin(SWT.JOIN_BEVEL); break; case BasicStroke.JOIN_MITER: this.gc.setLineJoin(SWT.JOIN_MITER); break; case BasicStroke.JOIN_ROUND: this.gc.setLineJoin(SWT.JOIN_ROUND); break; } // line cap switch (bs.getEndCap()) { case BasicStroke.CAP_BUTT: this.gc.setLineCap(SWT.CAP_FLAT); break; case BasicStroke.CAP_ROUND: this.gc.setLineCap(SWT.CAP_ROUND); break; case BasicStroke.CAP_SQUARE: this.gc.setLineCap(SWT.CAP_SQUARE); break; } // set the line style to solid by default this.gc.setLineStyle(SWT.LINE_SOLID); // apply dash style if any float[] dashes = bs.getDashArray(); if (dashes != null) { int[] swtDashes = new int[dashes.length]; for (int i = 0; i < swtDashes.length; i++) { swtDashes[i] = (int) dashes[i]; } this.gc.setLineDash(swtDashes); } } else { throw new RuntimeException("Can only handle 'Basic Stroke' at present."); } }
From source file:org.apache.pdfbox.util.operator.pagedrawer.StrokePath.java
/** * S stroke the path./* ww w .j ava 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 ww w . ja va2s . 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 www . j a va2s .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;//w w w .ja v a 2 s . c o 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"); } } }