float angle = (float) FastMath.atan2(dy, dx); while (currentChar < length && distance >= next) { Shape glyph = glyphVector.getGlyphOutline(currentChar); Point2D p = glyphVector.getGlyphPosition(currentChar); float px = (float) p.getX();
public boolean process(GlyphVector glyphVector, int g, AffineTransform tx, char c) { if (Character.isWhitespace(c)) return false; painter.graphics.draw( tx.createTransformedShape(glyphVector.getGlyphOutline(g)).getBounds2D()); return true; } }
+ unicodeFont.getPaddingRight()); shape = vector.getGlyphOutline(index, -bounds.x + unicodeFont.getPaddingLeft(), -bounds.y + unicodeFont.getPaddingTop());
+ unicodeFont.getPaddingRight()); shape = vector.getGlyphOutline(index, -bounds.x + unicodeFont.getPaddingLeft(), -bounds.y + unicodeFont.getPaddingTop());
public boolean process(GlyphVector glyphVector, int g, AffineTransform tx, char c) { if (Character.isWhitespace(c)) return false; Rectangle2D labelEnvelope = tx.createTransformedShape(glyphVector.getGlyphOutline(g)).getBounds2D(); index.addLabel(labelItem, labelEnvelope); return true; } }
/** * Draw a String centered in the middle of a Rectangle. * * @param g The Graphics instance. * @param text The String to draw. * @param rect The Rectangle to center the text in. * @param font */ public void drawCenteredStringWOutline(Graphics2D g, String text, Rectangle rect, Font font) { // Get the FontMetrics FontMetrics metrics = g.getFontMetrics(font); // Determine the X coordinate for the text int x = rect.x + (rect.width - metrics.stringWidth(text)) / 2; // Determine the Y coordinate for the text (note we add the ascent, as in java 2d 0 is top of the screen) int y = rect.y + ((rect.height - metrics.getHeight()) / 2) + metrics.getAscent(); // Set the font g.setFont(font); GlyphVector gv = font.createGlyphVector(g.getFontRenderContext(), text); g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); g.drawGlyphVector(gv, x, y); g.translate(x - 1, y - 1); for (int i = 0; i < text.length(); i++) { g.setColor(Color.BLACK); g.draw(gv.getGlyphOutline(i)); } g.translate(-x + 1, -y + 1); }
AffineTransform at = AffineTransform.getTranslateInstance(p.getX(), p.getY()); at.rotate(theta); Shape glyph = gv.getGlyphOutline(i); Shape transformedGlyph = at.createTransformedShape(glyph); g2.fill(transformedGlyph);
/** * Converts text rendered in the given {@link Font} to a {@link Geometry} * * @param text the text to render * @param font the font to render with * @param flatness the flatness to use * @param geomFact the geometryFactory to use to create the result * @return a polygonal geometry representing the rendered text */ public static Geometry read(String text, Font font, double flatness, GeometryFactory geomFact) { char[] chs = text.toCharArray(); FontRenderContext fontContext = new FontRenderContext(null, false, true); GlyphVector gv = font.createGlyphVector(fontContext, chs); List polys = new ArrayList(); for (int i = 0; i < gv.getNumGlyphs(); i++) { Geometry geom = ShapeReader.read(gv.getGlyphOutline(i), flatness, geomFact); for (int j = 0; j < geom.getNumGeometries(); j++) { polys.add(geom.getGeometryN(j)); } } return geomFact.buildGeometry(polys); }
@Override public Shape next() { return glyphs.getGlyphOutline( i++, xOff, yOff ); } };
@Override public Shape getGlyphOutline(int arg0) { return this.vec.getGlyphOutline(arg0); }
Number tracking = (Number) font.getAttributes().get(TextAttribute.TRACKING); for (int i = 0; i < numGlyphs; i++) { outlines[i] = glyphVector.getGlyphOutline(i); Point2D p = glyphVector.getGlyphPosition(i); float advance = nextAdvance;
Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); String s = "dasdasdasd1"; Font font = new Font("Courier", Font.PLAIN, 12); g2d.translate(20, 20); FontRenderContext frc = g2d.getFontRenderContext(); GlyphVector gv = font.createGlyphVector(frc, s); int length = gv.getNumGlyphs(); Rectangle2D barra=new Rectangle2D.Double(0, 0, 700, 500); g2d.draw(barra); for (int i = 0; i < length; i++) { Point2D p = gv.getGlyphPosition(i); AffineTransform at = AffineTransform.getTranslateInstance(p.getX(), p.getY()); at.rotate((double) i / (double) (length - 1) * Math.PI / 3); Shape glyph = gv.getGlyphOutline(i); Shape transformedGlyph = at.createTransformedShape(glyph); g2d.fill(transformedGlyph); }
@Override public Shape getGlyphOutline(int i) { java.awt.Shape ret = impl.getGlyphOutline(i); if (ret instanceof java.awt.geom.GeneralPath) { return new GeneralPathD((java.awt.geom.GeneralPath) ret); } FactoryProvider.getInstance() .debug("unhandled Shape " + ret.getClass()); return null; }
/** * Determines the transformed centre of a specified glyph. * * @param index glyph index * @return center point */ private Point2D getGlyphCenter(final int index) { if (text.length() == 1) return getCenter(); final Shape glyph = glyphs.getGlyphOutline(index); final Rectangle2D glyphBounds = transformedBounds(glyph); return new Point2D.Double(glyphBounds.getCenterX(), glyphBounds.getCenterY()); }
/** * @param c * @param font * @return GlyphVector using a default rendering context */ private SVGGlyph createGlyph(int c, Font font) { GlyphVector glyphVector = font.createGlyphVector( // flipping is done by SVGGlyph new FontRenderContext(null, true, true), // unicode to char String.valueOf((char) c)); // create and store the SVG Glyph return new SVGGlyph( glyphVector.getGlyphOutline(0), c, glyphVector.getGlyphMetrics(0)); }
static Shape[] getGlyphShapes(Font font, String strGlyphs, AffineTransform transform) { FontRenderContext frc = new FontRenderContext(null, true, true); GlyphVector glyphs = font.createGlyphVector(frc, strGlyphs); int count = glyphs.getNumGlyphs(); Shape[] shapes = new Shape[count]; for (int i = 0; i < count; i ++) { // get transformed glyph shape GeneralPath path = (GeneralPath) glyphs.getGlyphOutline(i); shapes[i] = path.createTransformedShape(transform); } return shapes; }
protected Shape getGlyph(int i) { // This one-line implementation produces different results under JDK 1.3 // and 1.4 // return glyphs.getGlyphOutline(i); // The substitute code attempts to work around this by using defensive // programming // See code marked FONTHACK elsewhere in this file // Create a GlyphVector for this single character. FontRenderContext orig = getContext(); FontRenderContext frc = new FontRenderContext(null, orig .isAntiAliased(), orig.usesFractionalMetrics()); Shape shape = font.createGlyphVector(frc, new char[] { getUnicode(i) }) .getGlyphOutline(0); return orig.getTransform().createTransformedShape(shape); }
protected Shape getGlyph(int i) { // This one-line implementation produces different results under JDK 1.3 // and 1.4 // return glyphs.getGlyphOutline(i); // The substitute code attempts to work around this by using defensive // programming // See code marked FONTHACK elsewhere in this file // Create a GlyphVector for this single character. FontRenderContext orig = getContext(); FontRenderContext frc = new FontRenderContext(null, orig .isAntiAliased(), orig.usesFractionalMetrics()); Shape shape = font.createGlyphVector(frc, new char[] { getUnicode(i) }) .getGlyphOutline(0); return orig.getTransform().createTransformedShape(shape); }
protected Triangles getTesselatedGlyph(char c) { GlyphVector glyphVect = getFont().createGlyphVector(getFontRenderContext(), new char[] { c }); Shape s = glyphVect.getGlyphOutline(0); CollectingTesselator tess = new CollectingTesselator(); visitShape(s, tess); Triangles triangles = tess.getTesselated(); return triangles; } }
protected Triangles getTesselatedGlyph(char c) { GlyphVector glyphVect = getFont().createGlyphVector(getFontRenderContext(), new char[] { c }); Shape s = glyphVect.getGlyphOutline(0); CollectingTesselator tess = new CollectingTesselator(); visitShape(s, tess); Triangles triangles = tess.getTesselated(); return triangles; } }