List of usage examples for com.itextpdf.text.pdf PdfContentByte moveTo
public void moveTo(final double x, final double y)
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;/* w ww . ja v a 2 s .c o 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) {//from w w 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.ArrowRenderer.java
License:Open Source License
public void renderStraight(RenderTarget target, Item item, float x1, float y1, float x2, float y2, float radius, float size, Color color) { Edge edge = (Edge) item.getSource(); PVector direction = new PVector(x2, y2); direction.sub(new PVector(x1, y1)); direction.normalize();/*from w ww. j ava 2 s .c o m*/ PVector p1 = new PVector(direction.x, direction.y); p1.mult(radius); p1.add(new PVector(x2, y2)); PVector p1r = new PVector(direction.x, direction.y); p1r.mult(radius - size); p1r.add(new PVector(x2, y2)); PVector p2 = new PVector(-direction.y, direction.x); p2.mult(size * BASE_RATIO); p2.add(p1r); PVector p3 = new PVector(direction.y, -direction.x); p3.mult(size * BASE_RATIO); p3.add(p1r); if (target instanceof ProcessingTarget) { PGraphics graphics = ((ProcessingTarget) target).getGraphics(); graphics.noStroke(); graphics.fill(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()); graphics.triangle(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y); } else if (target instanceof SVGTarget) { SVGTarget svgTarget = (SVGTarget) target; Element arrowElem = svgTarget.createElement("polyline"); arrowElem.setAttribute("points", String.format(Locale.ENGLISH, "%f,%f %f,%f %f,%f", p1.x, p1.y, p2.x, p2.y, p3.x, p3.y)); arrowElem.setAttribute("class", edge.getSource().getNodeData().getId() + " " + edge.getTarget().getNodeData().getId()); arrowElem.setAttribute("fill", svgTarget.toHexString(color)); arrowElem.setAttribute("fill-opacity", (color.getAlpha() / 255f) + ""); arrowElem.setAttribute("stroke", "none"); svgTarget.getTopElement(SVGTarget.TOP_ARROWS).appendChild(arrowElem); } else if (target instanceof PDFTarget) { PDFTarget pdfTarget = (PDFTarget) target; PdfContentByte cb = pdfTarget.getContentByte(); cb.moveTo(p1.x, -p1.y); cb.lineTo(p2.x, -p2.y); cb.lineTo(p3.x, -p3.y); cb.closePath(); cb.setRGBColorFill(color.getRed(), color.getGreen(), color.getBlue()); if (color.getAlpha() < 255) { cb.saveState(); float alpha = color.getAlpha() / 255f; PdfGState gState = new PdfGState(); gState.setFillOpacity(alpha); cb.setGState(gState); } cb.fill(); if (color.getAlpha() < 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 a va 2 s . co 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();/*from w w w.j ava 2 s . c om*/ 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 a va 2 s. c om*/ 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 w ww . j a v a2 s.c om 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;//from www.jav a2 s.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.StampBox.java
License:Apache License
private void drawPath(PdfContentByte content, OutputBounds rect) { switch (shape) { case rectangle: content.rectangle(rect.x, rect.y, rect.width, rect.height); break;/*from w w w. j a v a 2 s . c om*/ case triangle: // calculation of delta x based on triangle and cosine dimensions //float delta_x = (getPadding() / 2.0f) * (rect.width / 2.0f) / (float) Math.sqrt(Math.pow(rect.height, 2.0) + Math.pow(rect.width / 2.0, 2.0)); content.moveTo(rect.x, rect.y); content.lineTo(rect.x + rect.width, rect.y); content.lineTo(rect.x + rect.width / 2.0f, rect.y + rect.height); content.lineTo(rect.x, rect.y); break; case triangleInverted: content.moveTo(rect.x + rect.width / 2.0f, rect.y); content.lineTo(rect.x + rect.width, rect.y + rect.height); content.lineTo(rect.x, rect.y + rect.height); content.lineTo(rect.x + rect.width / 2.0f, rect.y); break; case diamond: content.moveTo(rect.x, rect.y + rect.height / 2.0f); content.lineTo(rect.x + rect.width / 2.0f, rect.y); content.lineTo(rect.x + rect.width, rect.y + rect.height / 2.0f); content.lineTo(rect.x + rect.width / 2.0f, rect.y + rect.height); content.lineTo(rect.x, rect.y + rect.height / 2.0f); break; } }
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./*from w w w . j av a 2 s . c o m*/ * * @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); }