List of usage examples for java.awt.geom GeneralPath GeneralPath
public GeneralPath()
From source file:org.apache.pdfbox.rendering.CIDType0Glyph2D.java
@Override public GeneralPath getPathForCharacterCode(int code) { if (cache.containsKey(code)) { return cache.get(code); }/*from ww w. j ava 2s . c o m*/ try { if (!font.hasGlyph(code)) { int cid = font.getParent().codeToCID(code); String cidHex = String.format("%04x", cid); LOG.warn("No glyph for " + code + " (CID " + cidHex + ") in font " + fontName); } GeneralPath path = font.getPath(code); cache.put(code, path); return path; } catch (IOException e) { // todo: escalate this error? LOG.error("Glyph rendering failed", e); return new GeneralPath(); } }
From source file:org.apache.pdfbox.rendering.GlyphCache.java
public GeneralPath getPathForCharacterCode(int code) { GeneralPath path = cache.get(code); if (path != null) { return path; }// www. j ava 2 s . co m try { if (!font.hasGlyph(code)) { String fontName = ((PDFont) font).getName(); if (font instanceof PDType0Font) { int cid = ((PDType0Font) font).codeToCID(code); String cidHex = String.format("%04x", cid); LOG.warn("No glyph for " + code + " (CID " + cidHex + ") in font " + fontName); } else { LOG.warn("No glyph for " + code + " in font " + fontName); } } path = font.getNormalizedPath(code); cache.put(code, path); return path; } catch (IOException e) { // todo: escalate this error? LOG.error("Glyph rendering failed", e); return new GeneralPath(); } }
From source file:org.apache.pdfbox.rendering.PageDrawer.java
/** * Draws the pattern stream to the requested context. * * @param g The graphics context to draw onto. * @param pattern The tiling pattern to be used. * @param colorSpace color space for this tiling. * @param color color for this tiling.//from ww w . jav a2 s. c om * @param patternMatrix the pattern matrix * @throws IOException If there is an IO error while drawing the page. */ void drawTilingPattern(Graphics2D g, PDTilingPattern pattern, PDColorSpace colorSpace, PDColor color, Matrix patternMatrix) throws IOException { Graphics2D oldGraphics = graphics; graphics = g; GeneralPath oldLinePath = linePath; linePath = new GeneralPath(); Area oldLastClip = lastClip; lastClip = null; setRenderingHints(); processTilingPattern(pattern, color, colorSpace, patternMatrix); graphics = oldGraphics; linePath = oldLinePath; lastClip = oldLastClip; }
From source file:org.apache.pdfbox.rendering.TTFGlyph2D.java
/** * Returns the path describing the glyph for the given glyphId. * * @param gid the GID//from w ww . j a va 2 s . c o m * @param code the character code * * @return the GeneralPath for the given glyphId */ public GeneralPath getPathForGID(int gid, int code) throws IOException { GeneralPath glyphPath; if (glyphs.containsKey(gid)) { glyphPath = glyphs.get(gid); } else { if (gid == 0 || gid >= ttf.getMaximumProfile().getNumGlyphs()) { if (isCIDFont) { int cid = ((PDType0Font) font).codeToCID(code); String cidHex = String.format("%04x", cid); LOG.warn("No glyph for " + code + " (CID " + cidHex + ") in font " + font.getName()); } else { LOG.warn("No glyph for " + code + " in font " + font.getName()); } } GeneralPath glyph = vectorFont.getPath(code); // Acrobat only draws GID 0 for embedded or "Standard 14" fonts, see PDFBOX-2372 if (gid == 0 && !font.isEmbedded() && !font.isStandard14()) { glyph = null; } if (glyph == null) { // empty glyph (e.g. space, newline) glyphPath = new GeneralPath(); glyphs.put(gid, glyphPath); } else { glyphPath = glyph; if (hasScaling) { AffineTransform atScale = AffineTransform.getScaleInstance(scale, scale); glyphPath.transform(atScale); } glyphs.put(gid, glyphPath); } } return glyphPath != null ? (GeneralPath) glyphPath.clone() : null; // todo: expensive }
From source file:org.apache.pdfbox.rendering.Type1Glyph2D.java
@Override public GeneralPath getPathForCharacterCode(int code) { // cache//w w w. ja va 2 s . c o m if (cache.containsKey(code)) { return cache.get(code); } // fetch try { String name = font.getEncoding().getName(code); if (!font.hasGlyph(name)) { LOG.warn("No glyph for " + code + " (" + name + ") in font " + font.getName()); } // todo: can this happen? should it be encapsulated? GeneralPath path = font.getPath(name); if (path == null) { path = font.getPath(".notdef"); } cache.put(code, path); return path; } catch (IOException e) { // todo: escalate this error? LOG.error("Glyph rendering failed", e); return new GeneralPath(); } }
From source file:org.broad.igv.renderer.SpliceJunctionRenderer.java
/** * Draw a filled arc representing a single feature. The thickness and height of the arc are proportional to the * depth of coverage. Some of this gets a bit arcane -- the result of lots of visual tweaking. * * @param pixelFeatureStart the starting position of the feature, whether on-screen or not * @param pixelFeatureEnd the ending position of the feature, whether on-screen or not * @param pixelJunctionStart the starting position of the junction, whether on-screen or not * @param pixelJunctionEnd the ending position of the junction, whether on-screen or not * @param depth coverage depth * @param trackRectangle//w ww. jav a2s .co m * @param context * @param strand * @param junctionFeature * @param shouldHighlight * @param featureColor the color specified for this feature. May be null. */ protected void drawFeature(int pixelFeatureStart, int pixelFeatureEnd, int pixelJunctionStart, int pixelJunctionEnd, float depth, Rectangle trackRectangle, RenderContext context, Strand strand, SpliceJunctionFeature junctionFeature, boolean shouldHighlight, Color featureColor, boolean shouldShowFlankingRegions) { boolean isPositiveStrand = true; // Get the feature's direction, color appropriately if (strand != null && strand.equals(Strand.NEGATIVE)) isPositiveStrand = false; //If the feature color is specified, use it, except that we set our own alpha depending on whether //the feature is highlighted. Otherwise default based on strand and highlight. Color color; if (featureColor != null) { int r = featureColor.getRed(); int g = featureColor.getGreen(); int b = featureColor.getBlue(); int alpha = shouldHighlight ? 255 : 140; color = new Color(r, g, b, alpha); } else { if (isPositiveStrand) color = shouldHighlight ? ARC_COLOR_HIGHLIGHT_POS : ARC_COLOR_POS; else color = shouldHighlight ? ARC_COLOR_HIGHLIGHT_NEG : ARC_COLOR_NEG; } Graphics2D g2D = context.getGraphic2DForColor(color); if (PreferenceManager.getInstance().getAsBoolean(PreferenceManager.ENABLE_ANTIALISING)) { g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } //Height of top of an arc of maximum depth int maxPossibleArcHeight = (trackRectangle.height - 1) / 2; if (shouldShowFlankingRegions) { if (junctionFeature.hasFlankingRegionDepthArrays()) { //draw a wigglegram of the splice junction flanking region depth of coverage int startFlankingRegionPixelLength = pixelJunctionStart - pixelFeatureStart; int endFlankingRegionPixelLength = pixelFeatureEnd - pixelJunctionEnd; drawFlankingRegion(g2D, pixelFeatureStart, startFlankingRegionPixelLength, junctionFeature.getStartFlankingRegionDepthArray(), maxPossibleArcHeight, trackRectangle, isPositiveStrand); drawFlankingRegion(g2D, pixelJunctionEnd + 1, endFlankingRegionPixelLength, junctionFeature.getEndFlankingRegionDepthArray(), maxPossibleArcHeight, trackRectangle, isPositiveStrand); } else { //Draw rectangles indicating the overlap on each side of the junction int overlapRectHeight = 3; int overlapRectTopX = (int) trackRectangle.getCenterY() + (isPositiveStrand ? -2 : 0); if (pixelFeatureStart < pixelJunctionStart) { g2D.fillRect(pixelFeatureStart, overlapRectTopX, pixelJunctionStart - pixelFeatureStart, overlapRectHeight); } if (pixelJunctionEnd < pixelFeatureEnd) { g2D.fillRect(pixelJunctionEnd, overlapRectTopX, pixelFeatureEnd - pixelJunctionEnd, overlapRectHeight); } } } //Create a path describing the arc, using Bezier curves. The Bezier control points for the top and //bottom arcs are based on the boundary points of the rectangles containing the arcs //proportion of the maximum arc height used by a minimum-height arc double minArcHeightProportion = 0.33; int innerArcHeight = (int) (maxPossibleArcHeight * minArcHeightProportion); float depthProportionOfMax = Math.min(1, depth / maxDepth); int arcWidth = Math.max(1, (int) ((1 - minArcHeightProportion) * maxPossibleArcHeight * depthProportionOfMax)); int outerArcHeight = innerArcHeight + arcWidth; //Height of bottom of the arc int arcBeginY = (int) trackRectangle.getCenterY() + (isPositiveStrand ? -1 : 1); int outerArcPeakY = isPositiveStrand ? arcBeginY - outerArcHeight : arcBeginY + outerArcHeight; int innerArcPeakY = isPositiveStrand ? arcBeginY - innerArcHeight : arcBeginY + innerArcHeight; //dhmay: I don't really understand Bezier curves. For some reason I have to put the Bezier control //points farther up or down than I want the arcs to extend. This multiplier seems about right int outerBezierY = arcBeginY + (int) (1.3 * (outerArcPeakY - arcBeginY)); int innerBezierY = arcBeginY + (int) (1.3 * (innerArcPeakY - arcBeginY)); //Putting the Bezier control points slightly off to the sides of the arc int bezierXPad = Math.max(1, (pixelJunctionEnd - pixelJunctionStart) / 30); GeneralPath arcPath = new GeneralPath(); arcPath.moveTo(pixelJunctionStart, arcBeginY); arcPath.curveTo(pixelJunctionStart - bezierXPad, outerBezierY, //Bezier 1 pixelJunctionEnd + bezierXPad, outerBezierY, //Bezier 2 pixelJunctionEnd, arcBeginY); //Arc end arcPath.curveTo(pixelJunctionEnd + bezierXPad, innerBezierY, //Bezier 1 pixelJunctionStart - bezierXPad, innerBezierY, //Bezier 2 pixelJunctionStart, arcBeginY); //Arc end //Draw the arc, to ensure outline is drawn completely (fill won't do it, necessarily). This will also //give the arc a darker outline g2D.draw(arcPath); //Fill the arc g2D.fill(arcPath); g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT); g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT); }
From source file:org.eclipse.birt.chart.device.g2d.G2dRendererBase.java
@Override public void drawArc(ArcRenderEvent are) throws ChartException { if (iv != null) { iv.modifyEvent(are);//from ww w .j av a2 s . c o m } // CHECK IF THE LINE ATTRIBUTES ARE CORRECTLY DEFINED final LineAttributes lia = are.getOutline(); if (!validateLineAttributes(are.getSource(), lia)) { return; } // SETUP THE FOREGROUND COLOR (DARKER BACKGROUND IF DEFINED AS NULL) final Color cFG = (Color) validateEdgeColor(lia.getColor(), are.getBackground(), _ids); if (cFG == null || cFG.getAlpha() == 0) { return; } // DRAW THE ARC Stroke sPrevious = null; Stroke sCurrent = getCachedStroke(lia); if (sCurrent != null) // SOME STROKE DEFINED? { sPrevious = _g2d.getStroke(); _g2d.setStroke(sCurrent); } _g2d.setColor(cFG); if ((are.getInnerRadius() >= 0 && are.getOuterRadius() > 0 && are.getInnerRadius() < are.getOuterRadius()) || (are.getInnerRadius() > 0 && are.getOuterRadius() <= 0)) { Bounds rctOuter = getOuterRectangle(are); Bounds rctInner = getInnerRectangle(are); Shape outerArc = new Arc2D.Double(rctOuter.getLeft(), rctOuter.getTop(), rctOuter.getWidth(), rctOuter.getHeight(), are.getStartAngle(), are.getAngleExtent(), Arc2D.OPEN); Shape innerArc = new Arc2D.Double(rctInner.getLeft(), rctInner.getTop(), rctInner.getWidth(), rctInner.getHeight(), are.getStartAngle() + are.getAngleExtent(), -are.getAngleExtent(), Arc2D.OPEN); double startAngle = Math.toRadians(-are.getStartAngle()); double stopAngle = Math.toRadians(-are.getStartAngle() - are.getAngleExtent()); double xsOuter = (rctOuter.getLeft() + (Math.cos(startAngle) * 0.5 + 0.5) * rctOuter.getWidth()); double ysOuter = (rctOuter.getTop() + (Math.sin(startAngle) * 0.5 + 0.5) * rctOuter.getHeight()); double xeInner = (rctInner.getLeft() + (Math.cos(stopAngle) * 0.5 + 0.5) * rctInner.getWidth()); double yeInner = (rctInner.getTop() + (Math.sin(stopAngle) * 0.5 + 0.5) * rctInner.getHeight()); GeneralPath gp = new GeneralPath(); gp.append(outerArc, false); gp.lineTo((float) xeInner, (float) yeInner); gp.append(innerArc, false); gp.lineTo((float) xsOuter, (float) ysOuter); Area area = new Area(gp); Shape prevClip = _g2d.getClip(); Area ar2 = new Area(area); if (prevClip != null) { Area ar1 = new Area(prevClip); ar2.intersect(ar1); } _g2d.setClip(ar2); _g2d.draw(area); _g2d.setClip(prevClip); } else { _g2d.draw(new Arc2D.Double(are.getTopLeft().getX(), are.getTopLeft().getY(), are.getWidth(), are.getHeight(), are.getStartAngle(), are.getAngleExtent(), toG2dArcType(are.getStyle()))); } if (sPrevious != null) // RESTORE PREVIOUS STROKE { _g2d.setStroke(sPrevious); } }
From source file:org.eclipse.birt.chart.device.g2d.G2dRendererBase.java
@Override public void drawArea(AreaRenderEvent are) throws ChartException { if (iv != null) { iv.modifyEvent(are);//from www. j ava 2 s .c o m } // CHECK IF THE LINE ATTRIBUTES ARE CORRECTLY DEFINED final LineAttributes lia = are.getOutline(); if (!validateLineAttributes(are.getSource(), lia)) { return; } // SETUP THE FOREGROUND COLOR (DARKER BACKGROUND IF DEFINED AS NULL) final Color cFG = (Color) validateEdgeColor(lia.getColor(), are.getBackground(), _ids); // IF UNDEFINED OR TOTALLY TRANSPARENT, EXIT if (cFG == null || cFG.getAlpha() == 0) { return; } // BUILD THE GENERAL PATH STRUCTURE final GeneralPath gp = new GeneralPath(); PrimitiveRenderEvent pre; for (int i = 0; i < are.getElementCount(); i++) { pre = are.getElement(i); if (pre instanceof ArcRenderEvent) { final ArcRenderEvent acre = (ArcRenderEvent) pre; final Arc2D.Double a2d = new Arc2D.Double(acre.getTopLeft().getX(), acre.getTopLeft().getY(), acre.getWidth(), acre.getHeight(), acre.getStartAngle(), acre.getAngleExtent(), toG2dArcType(acre.getStyle())); gp.append(a2d, true); } else if (pre instanceof LineRenderEvent) { final LineRenderEvent lre = (LineRenderEvent) pre; final Line2D.Double l2d = new Line2D.Double(lre.getStart().getX(), lre.getStart().getY(), lre.getEnd().getX(), lre.getEnd().getY()); gp.append(l2d, true); } } // DRAW THE GENERAL PATH Stroke sPrevious = null; Stroke sCurrent = getCachedStroke(lia); if (sCurrent != null) // SOME STROKE DEFINED? { sPrevious = _g2d.getStroke(); _g2d.setStroke(sCurrent); } _g2d.setColor(cFG); _g2d.draw(gp); if (sPrevious != null) // RESTORE PREVIOUS STROKE { _g2d.setStroke(sPrevious); } }
From source file:org.eclipse.birt.chart.device.g2d.G2dRendererBase.java
@Override public void fillArea(AreaRenderEvent are) throws ChartException { if (iv != null) { iv.modifyEvent(are);/*from w w w . j a v a 2 s. c o m*/ } final Fill flBackground = validateMultipleFill(are.getBackground()); if (isFullTransparent(flBackground)) { return; } // SETUP SWING DATA STRUCTURES final GeneralPath gp = new GeneralPath(); PrimitiveRenderEvent pre; for (int i = 0; i < are.getElementCount(); i++) { pre = are.getElement(i); if (pre instanceof ArcRenderEvent) { final ArcRenderEvent acre = (ArcRenderEvent) pre; final Arc2D.Double a2d = new Arc2D.Double(acre.getTopLeft().getX(), acre.getTopLeft().getY(), acre.getWidth(), acre.getHeight(), acre.getStartAngle(), acre.getAngleExtent(), toG2dArcType(acre.getStyle())); gp.append(a2d, true); } else if (pre instanceof LineRenderEvent) { final LineRenderEvent lre = (LineRenderEvent) pre; final Line2D.Double l2d = new Line2D.Double(lre.getStart().getX(), lre.getStart().getY(), lre.getEnd().getX(), lre.getEnd().getY()); gp.append(l2d, true); } } // BEGIN FILLING if (flBackground instanceof ColorDefinition) { _g2d.setColor((Color) _ids.getColor((ColorDefinition) flBackground)); } else if (flBackground instanceof Gradient) { final Gradient g = (Gradient) flBackground; final ColorDefinition cdStart = g.getStartColor(); final ColorDefinition cdEnd = g.getEndColor(); // boolean bCyclic = g.isCyclic(); double dAngleInDegrees = g.getDirection(); final double dAngleInRadians = ((-dAngleInDegrees * Math.PI) / 180.0); // int iAlpha = g.getTransparency(); Bounds bo = are.getBounds(); /* * if (bCyclic) { } */ if (dAngleInDegrees < -90 || dAngleInDegrees > 90) { throw new ChartException(ChartDeviceExtensionPlugin.ID, ChartException.RENDERING, "SwingRendererImpl.exception.gradient.angle", //$NON-NLS-1$ new Object[] { new Double(dAngleInDegrees) }, Messages.getResourceBundle(getULocale())); } Point2D.Double p2dStart, p2dEnd; if (dAngleInDegrees == 90) { p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop() + bo.getHeight()); p2dEnd = new Point2D.Double(bo.getLeft(), bo.getTop()); } else if (dAngleInDegrees == -90) { p2dEnd = new Point2D.Double(bo.getLeft(), bo.getTop() + bo.getHeight()); p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop()); } else if (dAngleInDegrees > 0) { p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop() + bo.getHeight()); p2dEnd = new Point2D.Double(bo.getLeft() + bo.getWidth(), bo.getTop() + bo.getHeight() - bo.getWidth() * Math.abs(Math.tan(dAngleInRadians))); } else if (dAngleInDegrees < 0) { p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop()); p2dEnd = new Point2D.Double(bo.getLeft() + bo.getWidth(), bo.getTop() + bo.getWidth() * Math.abs(Math.tan(dAngleInRadians))); } else { p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop()); p2dEnd = new Point2D.Double(bo.getLeft() + bo.getWidth(), bo.getTop()); } _g2d.setPaint(new GradientPaint(p2dStart, (Color) _ids.getColor(cdStart), p2dEnd, (Color) _ids.getColor(cdEnd))); } else if (flBackground instanceof org.eclipse.birt.chart.model.attribute.Image) { // TODO TBD } _g2d.fill(gp); }
From source file:org.squidy.designer.util.ImageUtils.java
public static Shape getShapeOfImage(BufferedImage image) { // Get the data Raster data = image.getData(); ///* ww w . j a v a 2s . co m*/ // System.out.println("num of bands = " + data.getNumBands()); // The colour of the pixel looking at // Shoulld have length of 4 (RGBA) int[] lookAt = null; // The map of all the points Point2D[][] pointMap = new Point2D[data.getWidth()][data.getHeight()]; // The from point Point2D from = null; // The general path GeneralPath path = new GeneralPath(); // Go round height for (int y = 0; y < data.getHeight(); y++) { // Go round width for (int x = 0; x < data.getWidth(); x++) { // Get the colour lookAt = data.getPixel(x, y, lookAt); // The alpha int a = lookAt[3]; // If > then 0 if (a > 0) { // Output 1 //System.out.print(1); // Save point pointMap[x][y] = new Point2D.Double(x, y); if (from == null) { from = pointMap[x][y]; } } // 0 else { // Output 0 //System.out.print(0); // Nothing her pointMap[x][y] = null; } } // New line //System.out.println(); } // Move it to the from if (from != null) { path.moveTo(from.getX(), from.getY()); /* * Make the shape */ // Go round height for (int y = 0; y < data.getHeight(); y++) { // Go round width for (int x = 0; x < data.getWidth(); x++) { // If the point is not null if (pointMap[x][y] != null) { // Draw a line to path.append(new Rectangle2D.Double(pointMap[x][y].getX(), pointMap[x][y].getY(), 1, 1), true); // path.lineTo(pointMap[x][y].getX(), pointMap[x][y].getY()); } } } path.closePath(); // TODO: Put in the middle return path; } return null; }