List of usage examples for com.itextpdf.text.pdf PdfContentByte stroke
public void stroke()
From source file:org.gephi.edgelayout.api.SubdividedEdgeRenderer.java
License:Open Source License
private void renderBigPDFItem(SubdividedEdgeBigItem item, RenderTarget target, PreviewProperties properties) { for (SortedEdgeWrapper edgeWrapper : item.edges) { Edge edge = edgeWrapper.edge;/*from w ww . ja v a 2 s. co m*/ EdgeLayoutData data = (EdgeLayoutData) edge.getEdgeData().getLayoutData(); Point2D.Double[] points = data.getSubdivisonPoints(); if (data.getEdgeColor() == null || points == null) { continue; } Color color = new Color(data.getEdgeColor().getRed(), data.getEdgeColor().getGreen(), data.getEdgeColor().getBlue(), (int) (255 * alpha)); PDFTarget pdfTarget = (PDFTarget) target; PdfContentByte cb = pdfTarget.getContentByte(); for (int i = 0; i < points.length - 1; i++) { cb.moveTo((float) points[i].x, (float) points[i].y); cb.lineTo((float) points[i + 1].x, (float) points[i + 1].y); } cb.setRGBColorStroke(color.getRed(), color.getGreen(), color.getBlue()); cb.setLineWidth(thickness); float usedAlpha = (forceAlpha ? intAlpha : color.getAlpha()); if (usedAlpha < 255) { cb.saveState(); float alpha = usedAlpha / 255f; PdfGState gState = new PdfGState(); gState.setStrokeOpacity(alpha); cb.setGState(gState); } cb.stroke(); if (usedAlpha < 255) { cb.restoreState(); } } }
From source file:org.gephi.edgelayout.api.SubdividedEdgeRenderer.java
License:Open Source License
private void renderBigAndComplexPDFItem(SubdividedEdgeBigItem item, RenderTarget target, PreviewProperties properties) {// ww w . j av a 2 s . c o m for (SortedEdgeWrapper edgeWrapper : item.edges) { Edge edge = edgeWrapper.edge; EdgeLayoutData data = (EdgeLayoutData) edge.getEdgeData().getLayoutData(); Point2D.Double[] points = data.getSubdivisonPoints(); if (data.getSubdivisionEdgeColor() == null || data.getSubdivisionEdgeColor()[edgeWrapper.id] == null || points == null) { continue; } Color color = data.getSubdivisionEdgeColor()[edgeWrapper.id]; PDFTarget pdfTarget = (PDFTarget) target; PdfContentByte cb = pdfTarget.getContentByte(); int i = edgeWrapper.id; if (i == points.length - 1) { continue; } cb.moveTo((float) points[i].x, (float) points[i].y); cb.lineTo((float) points[i + 1].x, (float) points[i + 1].y); cb.setRGBColorStroke(color.getRed(), color.getGreen(), color.getBlue()); cb.setLineWidth(thickness); float usedAlpha = (forceAlpha ? intAlpha : color.getAlpha()); if (usedAlpha < 255) { cb.saveState(); float alpha = usedAlpha / 255f; PdfGState gState = new PdfGState(); gState.setStrokeOpacity(alpha); cb.setGState(gState); } cb.stroke(); if (usedAlpha < 255) { cb.restoreState(); } } }
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 ava2s .c o m*/ 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 .ja v a 2 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();// w w w . j av a2 s .c o 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.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 ww w. j a va2 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.PdfGenerator.java
License:Apache License
protected void generatePage(GenerateBean bean, PdfWriter writer, float center, Element elm, int currentPage) { EventBus.publish(new StatusEvent(StatusType.Progress, currentPage)); EventBus.publish(new StatusEvent(StatusType.Message, MessageFormat.format(Resources.getString("message.generatingPage"), (currentPage)))); Object p = factory.getParser(elm.getTagName()).parse(elm, config); if (p != null) { if (p instanceof Page) { Page page = (Page) p;/* w w w . j a v a2s. c o m*/ ISetContent[] content = new ISetContent[page.getContent().size()]; content = page.getContent().toArray(content); createPage(writer, center, page.getTitle(), content); } else if (p instanceof TitlePage) { TitlePage page = (TitlePage) p; createTitlePage(writer, center, page.getTitlePageContent()); } if (bean.isDrawBorder() || debug || (elm.hasAttribute("border") && Boolean.parseBoolean(elm.getAttribute("border")))) { PdfContentByte handler = writer.getDirectContent(); float width = PdfUtil.convertFromMillimeters( config.getWidth() - config.getMarginLeft() - config.getMarginRight()); float height = PdfUtil.convertFromMillimeters( config.getHeight() - config.getMarginTop() - config.getMarginBottom()); handler.rectangle(PdfUtil.convertFromMillimeters(config.getMarginLeft()), PdfUtil.convertFromMillimeters(config.getMarginBottom()), width, height); handler.stroke(); } } }
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 . ja va 2s . c om 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);/*from w w w.j a v a2 s .c o m*/ content.rectangle(rect.x, rect.y, rect.width, rect.height); content.stroke(); }
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 ava 2 s . 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); }