List of usage examples for com.itextpdf.text.pdf PdfContentByte setLineWidth
public void setLineWidth(final double w)
From source file:org.gephi.preview.plugin.renderers.EdgeRenderer.java
License:Open Source License
public void renderSelfLoop(Item nodeItem, float thickness, Color color, PreviewProperties properties, RenderTarget renderTarget) {/*from w w w . j a v a 2 s . c om*/ Float x = nodeItem.getData(NodeItem.X); Float y = nodeItem.getData(NodeItem.Y); Float size = nodeItem.getData(NodeItem.SIZE); Node node = (Node) nodeItem.getSource(); PVector v1 = new PVector(x, y); v1.add(size, -size, 0); PVector v2 = new PVector(x, y); v2.add(size, size, 0); if (renderTarget instanceof ProcessingTarget) { PGraphics graphics = ((ProcessingTarget) renderTarget).getGraphics(); graphics.strokeWeight(thickness); graphics.stroke(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()); graphics.noFill(); graphics.bezier(x, y, v1.x, v1.y, v1.x, v2.y, x, y); } else if (renderTarget instanceof SVGTarget) { SVGTarget svgTarget = (SVGTarget) renderTarget; Element selfLoopElem = svgTarget.createElement("path"); selfLoopElem.setAttribute("d", String.format(Locale.ENGLISH, "M %f,%f C %f,%f %f,%f %f,%f", x, y, v1.x, v1.y, v2.x, v2.y, x, y)); selfLoopElem.setAttribute("class", node.getNodeData().getId()); selfLoopElem.setAttribute("stroke", svgTarget.toHexString(color)); selfLoopElem.setAttribute("stroke-opacity", (color.getAlpha() / 255f) + ""); selfLoopElem.setAttribute("stroke-width", Float.toString(thickness * svgTarget.getScaleRatio())); selfLoopElem.setAttribute("fill", "none"); svgTarget.getTopElement(SVGTarget.TOP_EDGES).appendChild(selfLoopElem); } else if (renderTarget instanceof PDFTarget) { PDFTarget pdfTarget = (PDFTarget) renderTarget; PdfContentByte cb = pdfTarget.getContentByte(); cb.moveTo(x, -y); cb.curveTo(v1.x, -v1.y, v2.x, -v2.y, x, -y); cb.setRGBColorStroke(color.getRed(), color.getGreen(), color.getBlue()); cb.setLineWidth(thickness); if (color.getAlpha() < 255) { cb.saveState(); float alpha = color.getAlpha() / 255f; PdfGState gState = new PdfGState(); gState.setStrokeOpacity(alpha); cb.setGState(gState); } cb.stroke(); if (color.getAlpha() < 255) { cb.restoreState(); } } }
From source file:org.gephi.preview.plugin.renderers.EdgeRenderer.java
License:Open Source License
public void renderCurvedEdge(Item edgeItem, Item sourceItem, Item targetItem, float thickness, Color color, PreviewProperties properties, RenderTarget renderTarget) { Edge edge = (Edge) edgeItem.getSource(); Float x1 = sourceItem.getData(NodeItem.X); Float x2 = targetItem.getData(NodeItem.X); Float y1 = sourceItem.getData(NodeItem.Y); Float y2 = targetItem.getData(NodeItem.Y); //Curved edgs PVector direction = new PVector(x2, y2); direction.sub(new PVector(x1, y1)); float length = direction.mag(); direction.normalize();/* w ww. j a v a2 s . c o m*/ float factor = properties.getFloatValue(BEZIER_CURVENESS) * length; // normal vector to the edge PVector n = new PVector(direction.y, -direction.x); n.mult(factor); // first control point PVector v1 = new PVector(direction.x, direction.y); v1.mult(factor); v1.add(new PVector(x1, y1)); v1.add(n); // second control point PVector v2 = new PVector(direction.x, direction.y); v2.mult(-factor); v2.add(new PVector(x2, y2)); v2.add(n); if (renderTarget instanceof ProcessingTarget) { PGraphics graphics = ((ProcessingTarget) renderTarget).getGraphics(); graphics.strokeWeight(thickness); graphics.stroke(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()); graphics.noFill(); graphics.bezier(x1, y1, v1.x, v1.y, v2.x, v2.y, x2, y2); } else if (renderTarget instanceof SVGTarget) { SVGTarget svgTarget = (SVGTarget) renderTarget; Element edgeElem = svgTarget.createElement("path"); edgeElem.setAttribute("class", edge.getSource().getNodeData().getId() + " " + edge.getTarget().getNodeData().getId()); edgeElem.setAttribute("d", String.format(Locale.ENGLISH, "M %f,%f C %f,%f %f,%f %f,%f", x1, y1, v1.x, v1.y, v2.x, v2.y, x2, y2)); edgeElem.setAttribute("stroke", svgTarget.toHexString(color)); edgeElem.setAttribute("stroke-width", Float.toString(thickness * svgTarget.getScaleRatio())); edgeElem.setAttribute("stroke-opacity", (color.getAlpha() / 255f) + ""); edgeElem.setAttribute("fill", "none"); svgTarget.getTopElement(SVGTarget.TOP_EDGES).appendChild(edgeElem); } else if (renderTarget instanceof PDFTarget) { PDFTarget pdfTarget = (PDFTarget) renderTarget; PdfContentByte cb = pdfTarget.getContentByte(); cb.moveTo(x1, -y1); cb.curveTo(v1.x, -v1.y, v2.x, -v2.y, x2, -y2); cb.setRGBColorStroke(color.getRed(), color.getGreen(), color.getBlue()); cb.setLineWidth(thickness); if (color.getAlpha() < 255) { cb.saveState(); float alpha = color.getAlpha() / 255f; PdfGState gState = new PdfGState(); gState.setStrokeOpacity(alpha); cb.setGState(gState); } cb.stroke(); if (color.getAlpha() < 255) { cb.restoreState(); } } }
From source file:org.gephi.preview.plugin.renderers.EdgeRenderer.java
License:Open Source License
public void renderStraightEdge(Item edgeItem, Item sourceItem, Item targetItem, float thickness, Color color, PreviewProperties properties, RenderTarget renderTarget) { Edge edge = (Edge) edgeItem.getSource(); Float x1 = sourceItem.getData(NodeItem.X); Float x2 = targetItem.getData(NodeItem.X); Float y1 = sourceItem.getData(NodeItem.Y); Float y2 = targetItem.getData(NodeItem.Y); //Target radius - to start at the base of the arrow Float targetRadius = edgeItem.getData(TARGET_RADIUS); //Avoid edge from passing the node's center: if (targetRadius != null && targetRadius < 0) { PVector direction = new PVector(x2, y2); direction.sub(new PVector(x1, y1)); direction.normalize();//from w w w.j av a2 s.co m direction = new PVector(direction.x, direction.y); direction.mult(targetRadius); direction.add(new PVector(x2, y2)); x2 = direction.x; y2 = direction.y; } //Source radius Float sourceRadius = edgeItem.getData(SOURCE_RADIUS); //Avoid edge from passing the node's center: if (sourceRadius != null && sourceRadius < 0) { PVector direction = new PVector(x1, y1); direction.sub(new PVector(x2, y2)); direction.normalize(); direction = new PVector(direction.x, direction.y); direction.mult(sourceRadius); direction.add(new PVector(x1, y1)); x1 = direction.x; y1 = direction.y; } if (renderTarget instanceof ProcessingTarget) { PGraphics graphics = ((ProcessingTarget) renderTarget).getGraphics(); graphics.strokeWeight(thickness); graphics.strokeCap(PGraphics.SQUARE); graphics.stroke(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()); graphics.noFill(); graphics.line(x1, y1, x2, y2); } else if (renderTarget instanceof SVGTarget) { SVGTarget svgTarget = (SVGTarget) renderTarget; Element edgeElem = svgTarget.createElement("path"); edgeElem.setAttribute("class", edge.getSource().getNodeData().getId() + " " + edge.getTarget().getNodeData().getId()); edgeElem.setAttribute("d", String.format(Locale.ENGLISH, "M %f,%f L %f,%f", x1, y1, x2, y2)); edgeElem.setAttribute("stroke", svgTarget.toHexString(color)); DecimalFormat df = new DecimalFormat("#.########"); edgeElem.setAttribute("stroke-width", df.format(thickness * svgTarget.getScaleRatio())); edgeElem.setAttribute("stroke-opacity", (color.getAlpha() / 255f) + ""); edgeElem.setAttribute("fill", "none"); svgTarget.getTopElement(SVGTarget.TOP_EDGES).appendChild(edgeElem); } else if (renderTarget instanceof PDFTarget) { PDFTarget pdfTarget = (PDFTarget) renderTarget; PdfContentByte cb = pdfTarget.getContentByte(); cb.moveTo(x1, -y1); cb.lineTo(x2, -y2); cb.setRGBColorStroke(color.getRed(), color.getGreen(), color.getBlue()); cb.setLineWidth(thickness); if (color.getAlpha() < 255) { cb.saveState(); float alpha = color.getAlpha() / 255f; PdfGState gState = new PdfGState(); gState.setStrokeOpacity(alpha); cb.setGState(gState); } cb.stroke(); if (color.getAlpha() < 255) { cb.restoreState(); } } }
From source file:org.gephi.preview.plugin.renderers.NodeLabelRenderer.java
License:Open Source License
public void renderPDF(PDFTarget target, Node node, String label, float x, float y, int fontSize, Color color, float outlineSize, Color outlineColor, boolean showBox, Color boxColor) { Font font = fontCache.get(fontSize); PdfContentByte cb = target.getContentByte(); BaseFont bf = target.getBaseFont(font); //Box//from w w w .ja v a2 s. c om if (showBox) { cb.setRGBColorFill(boxColor.getRed(), boxColor.getGreen(), boxColor.getBlue()); if (boxColor.getAlpha() < 255) { cb.saveState(); float alpha = boxColor.getAlpha() / 255f; PdfGState gState = new PdfGState(); gState.setFillOpacity(alpha); cb.setGState(gState); } float textWidth = getTextWidth(bf, fontSize, label); float textHeight = getTextHeight(bf, fontSize, label); //A height of just textHeight seems to be half the text height sometimes //BaseFont getAscentPoint and getDescentPoint may be not very precise cb.rectangle(x - textWidth / 2f - outlineSize / 2f, -y - outlineSize / 2f - textHeight, textWidth + outlineSize, textHeight * 2f + outlineSize); cb.fill(); if (boxColor.getAlpha() < 255) { cb.restoreState(); } } cb.setRGBColorFill(color.getRed(), color.getGreen(), color.getBlue()); float textHeight = getTextHeight(bf, fontSize, label); if (outlineSize > 0) { cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_STROKE); cb.setRGBColorStroke(outlineColor.getRed(), outlineColor.getGreen(), outlineColor.getBlue()); cb.setLineWidth(outlineSize); cb.setLineJoin(PdfContentByte.LINE_JOIN_ROUND); cb.setLineCap(PdfContentByte.LINE_CAP_ROUND); if (outlineColor.getAlpha() < 255) { cb.saveState(); float alpha = outlineColor.getAlpha() / 255f; PdfGState gState = new PdfGState(); gState.setStrokeOpacity(alpha); cb.setGState(gState); } cb.beginText(); cb.setFontAndSize(bf, font.getSize()); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, label, x, -y - (textHeight / 2f), 0f); cb.endText(); if (outlineColor.getAlpha() < 255) { cb.restoreState(); } } cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL); cb.beginText(); cb.setFontAndSize(bf, font.getSize()); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, label, x, -y - (textHeight / 2f), 0f); cb.endText(); }
From source file:org.gephi.preview.plugin.renderers.NodeRenderer.java
License:Open Source License
public void renderPDF(Item item, PDFTarget target, PreviewProperties properties) { Float x = item.getData(NodeItem.X); Float y = item.getData(NodeItem.Y); Float size = item.getData(NodeItem.SIZE); size /= 2f;/* ww w. j a va2 s . c om*/ Color color = item.getData(NodeItem.COLOR); Color borderColor = ((DependantColor) properties.getValue(PreviewProperty.NODE_BORDER_COLOR)) .getColor(color); float borderSize = properties.getFloatValue(PreviewProperty.NODE_BORDER_WIDTH); float alpha = properties.getFloatValue(PreviewProperty.NODE_OPACITY) / 100f; PdfContentByte cb = target.getContentByte(); cb.setRGBColorStroke(borderColor.getRed(), borderColor.getGreen(), borderColor.getBlue()); cb.setLineWidth(borderSize); cb.setRGBColorFill(color.getRed(), color.getGreen(), color.getBlue()); if (alpha < 1f) { cb.saveState(); PdfGState gState = new PdfGState(); gState.setFillOpacity(alpha); gState.setStrokeOpacity(alpha); cb.setGState(gState); } cb.circle(x, -y, size); if (borderSize > 0) { cb.fillStroke(); } else { cb.fill(); } if (alpha < 1f) { cb.restoreState(); } }
From source file:org.javad.pdf.PageTitle.java
License:Apache License
@Override public OutputBounds generate(PdfContentByte content) { int maxWidth = 0; content.setColorStroke(BaseColor.BLACK); Font f = FontRegistry.getInstance().getFont(PdfFontDefinition.Title); content.setFontAndSize(f.getBaseFont(), f.getSize()); float top = getY(); content.setHorizontalScaling(110.0f); if (getTitle() != null && !getTitle().isEmpty()) { maxWidth = (int) f.getBaseFont().getWidthPoint(getTitle().toUpperCase(), f.getSize()); PdfUtil.renderConstrainedText(content, getTitle().toUpperCase(), f, getX(), top, (int) (maxWidth * 1.1)); }//from w w w . ja va 2 s. c o m if (getSubTitle() != null && !getSubTitle().isEmpty()) { Font subFont = FontRegistry.getInstance().getFont(PdfFontDefinition.Subtitle); top -= subFont.getCalculatedSize() + PdfUtil.convertFromMillimeters(3.0f); content.setFontAndSize(subFont.getBaseFont(), subFont.getSize()); maxWidth = Math.max(maxWidth, (int) subFont.getBaseFont().getWidthPoint(getSubTitle().toUpperCase(), subFont.getSize())); PdfUtil.renderConstrainedText(content, getSubTitle().toUpperCase(), subFont, getX(), top, (int) (maxWidth * 1.10)); } content.setHorizontalScaling(100.0f); if (getClassifier() != null && !getClassifier().isEmpty()) { Font classFont = FontRegistry.getInstance().getFont(PdfFontDefinition.Classifier); content.setFontAndSize(classFont.getBaseFont(), classFont.getSize()); top -= classFont.getCalculatedSize() + PdfUtil.convertFromMillimeters(3.0f); float width = classFont.getBaseFont().getWidthPoint(getClassifier(), classFont.getCalculatedSize()) + 4; maxWidth = Math.max(maxWidth, (int) width + (2 * DASH_LENGTH)); content.setLineWidth(0.8f); float lineTop = top + ((int) classFont.getSize() / 2 - 1); content.moveTo(getX() - (width / 2) - DASH_LENGTH, lineTop); content.lineTo(getX() - (width / 2), lineTop); content.moveTo(getX() + (width / 2), lineTop); content.lineTo(getX() + (width / 2) + DASH_LENGTH, lineTop); content.stroke(); PdfUtil.renderConstrainedText(content, getClassifier(), classFont, getX(), top, (int) (maxWidth * 1.10)); } OutputBounds rect = new OutputBounds(getX() - maxWidth / 2, getY(), maxWidth, getY() - top); return rect; }
From source file:org.javad.stamp.pdf.SetTenant.java
License:Apache License
protected void drawSeparator(PdfContentByte content, float x, float y, float width, float height) { float sx = (getOrientation() == Orientation.HORIZONTAL) ? x : x + PdfUtil.convertFromMillimeters(getPadding() + 2); float dx = (getOrientation() == Orientation.HORIZONTAL) ? x : x + width - PdfUtil.convertFromMillimeters(getPadding() + 2); float sy = (getOrientation() == Orientation.HORIZONTAL) ? y + PdfUtil.convertFromMillimeters(getVerticalPadding() + 2) : y;/*w w w. j a v a2s . co m*/ float dy = (getOrientation() == Orientation.HORIZONTAL) ? y + height - PdfUtil.convertFromMillimeters(getVerticalPadding() + 2) : y; content.setLineWidth(0.5f); content.setColorStroke(BaseColor.GRAY); content.moveTo(sx, sy); content.setLineDash(5.0f, 2.0f, 0.0f); content.lineTo(dx, dy); content.stroke(); content.setLineDash(1.0f, 0.0f, 0.0f); }
From source file:org.javad.stamp.pdf.SetTenant.java
License:Apache License
void drawBorder(PdfContentByte content, OutputBounds rect) { content.setColorStroke(BaseColor.BLACK); content.setLineWidth(0.8f); content.rectangle(rect.x, rect.y, rect.width, rect.height); content.stroke();//ww w .j a v a2s . co m }
From source file:org.javad.stamp.pdf.StampBox.java
License:Apache License
/** * Will draw a black frame shape for a given stamp box. The current * supported shapes include/*from w w w . j a v a2s . c o m*/ * <ul><li>rectangle</li> * <li>triangle</li> * <li>diamond</li> * </ul> * * @param content * @param rect */ void drawShape(PdfContentByte content, OutputBounds rect) { content.setColorFill(BaseColor.WHITE); drawPath(content, rect); content.fill(); if (isBorder()) { content.setColorStroke(BaseColor.BLACK); content.setLineWidth(0.8f); drawPath(content, rect); content.stroke(); } content.setColorFill(BaseColor.BLACK); }
From source file:org.javad.stamp.pdf.StampBox.java
License:Apache License
/** * Will draw the bisect lines within the content are of the output * rectangle.//ww w. j ava 2 s . com * * @param content * @param rect */ @SuppressWarnings("incomplete-switch") void drawBisect(PdfContentByte content, OutputBounds rect) { content.setLineWidth(0.5f); content.setColorStroke(BaseColor.GRAY); float dx1 = 0.0f; float dx2 = 0.0f; float dy1 = 0.0f; float dy2 = 0.0f; float xp = (int) PdfUtil.convertFromMillimeters(getPadding() + 2); float yp = (int) PdfUtil.convertFromMillimeters(getVerticalPadding() + 2); switch (bisect) { case top_left: dx1 = xp; dy1 = rect.height - yp; dx2 = rect.width - xp; dy2 = yp; break; case top_right: dx1 = xp; dy1 = yp; dx2 = rect.width - xp; dy2 = rect.height - yp; break; case vertical: dx1 = rect.width / 2; dy1 = yp; dx2 = dx1; dy2 = rect.height - yp; } content.moveTo(rect.x + dx1, rect.y + dy1); content.setLineDash(5.0f, 2.0f, 0.0f); content.lineTo(rect.x + dx2, rect.y + dy2); content.stroke(); content.setLineDash(1.0f, 0.0f, 0.0f); }