Java 8 GlyphVector - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 GlyphVector class.

This code example shows how to use the following methods:getGlyphTransform
	public float getBearingX(char c) {
		return glyphMetrics[indexOf(c)].getLSB();
	} 
 
	public float getBearingY(char c) {
		AffineTransform ts = vec.getGlyphTransform(asciiset.indexOf(c));
		if (ts == null) {
			return 0; 
		} 
		return (float) ts.getTranslateY();
	} 
 
	@Override 
	public float getAdvance(char c) {
		return glyphMetrics[indexOf(c)].getAdvanceX();
	} 
 
	@Override 
	public boolean isValidChar(char c) {
		return indexOf(c) < glyphBounds.length;
5
CodeRank
This code example shows how to use the following methods:getOutline, getPixelBounds, getVisualBounds
            /// Using that number, adjust the position of the character drawn 
            if ( textToUse == ALL_GLYPHS )
              gv = testFont.createGlyphVector( frc, oneGlyph );
            else 
              gv = testFont.createGlyphVector( frc, charArray );
            Rectangle2D r2d2 = gv.getPixelBounds(frc, 0, 0);
            int shiftedX = baseX;
            // getPixelBounds returns a result in device space. 
            // we need to convert back to user space to be able to 
            // calculate the shift as baseX is in user space. 
            try { 
                 double pt[] = new double[4];
                 pt[0] = r2d2.getX();
                 pt[1] = r2d2.getY();
                 pt[2] = r2d2.getX()+r2d2.getWidth();
                 pt[3] = r2d2.getY()+r2d2.getHeight();
                 oldTX.inverseTransform(pt,0,pt,0,2);
                 shiftedX = baseX - (int) ( pt[2] / 2 + pt[0] );
            } catch (NoninvertibleTransformException e) {
            } 

5
CodeRank
This code example shows how to use the following methods:getOutline
 
        // write the name of the font to the graphic. Use the same rendering method used by the 
        // WMS (more convoluted, but the only one that can be actually centered within a halo) 
        GlyphVector gv = font.createGlyphVector(graphics2D.getFontRenderContext(), PREVIEW_TEXT.toCharArray());
        final AffineTransform at = AffineTransform.getTranslateInstance(2, PREVIEW_IMAGE_HEIGHT / 2 + stringHeight / 4);
        Shape sample = at.createTransformedShape(gv.getOutline());
        graphics2D.fill(sample);
 
        // create the image 
        BufferedDynamicImageResource generatedImage = new BufferedDynamicImageResource("png");
        generatedImage.setImage(bi);
        generatedImage.setCacheable(true);
 
        return generatedImage;
    } 
 
    /** 
     * Returns the font name 
     *  
     * @return 
5
CodeRank
This code example shows how to use the following methods:getVisualBounds
	 
	private static void drawVersionNumber(Graphics2D g2) {
		String text = "Version " + BuildProperties.getVersion();
		GlyphVector gv = VERSION_FONT.createGlyphVector(g2.getFontRenderContext(), text);
		 
		Rectangle2D rect = gv.getVisualBounds();
		double width = rect.getWidth();
		 
		g2.setColor(VERSION_COLOR);
		g2.drawGlyphVector(gv, (float) (VERSION_POSITION_X - width), VERSION_POSITION_Y);
		 
	} 
	 
	 
	/** 
	 * Return the current splash screen or <code>null</code> if not available or already closed. 
	 * This method catches the possible exceptions and returns null if they occur. 
	 *  
	 * @return	the current (visible) splash screen, or <code>null</code>. 
	 */ 
5
CodeRank
This code example shows how to use the following methods:getVisualBounds
	 
	 
 
	private void drawMarker(Graphics2D g2, float x, float y, String str) {
		GlyphVector gv = markerFont.createGlyphVector(g2.getFontRenderContext(), str);
		Rectangle2D rect = gv.getVisualBounds();
		 
		x -= rect.getWidth() / 2;
		y += rect.getHeight() / 2;
		 
		g2.drawGlyphVector(gv, x, y);
		 
	} 
	 
	 
 
 
 
	public double getScaler() { 
		return scaler;
4
CodeRank
This code example shows how to use the following methods:getPixelBounds
This code example shows how to use the following methods:getGlyphMetrics, getGlyphOutline
            // unicode to char 
            String.valueOf((char) c));
 
        // create and store the SVG Glyph 
        return new SVGGlyph( 
            glyphVector.getGlyphOutline(0),
            c,
            glyphVector.getGlyphMetrics(0));
    } 
 
    /** 
     * creates the glyph for the string 
     * 
     * @param string 
     * @param font 
     */ 
    protected void addGlyphs(String string, Font font) {
        font = untransform(font);
 
        // add characters 
4
CodeRank
This code example shows how to use the following methods:getGlyphMetrics, getGlyphOutline
        AWTGlyphGeometryCache glyphCache =
            (AWTGlyphGeometryCache)fontCache.get(font.awtFont);
 
        AWTGlyphGeometryCache.Value v = glyphCache.get(c);
        if (v == null) {
            Shape outline = gv.getGlyphOutline(glyphIndex);
            GlyphMetrics metrics = gv.getGlyphMetrics(glyphIndex);
            Rectangle2D gmB = metrics.getBounds2D();
            if (AWTGVTGlyphVector.outlinesPositioned()) { 
                AffineTransform tr = AffineTransform.getTranslateInstance
                    (-glyphPos.getX(), -glyphPos.getY());
                outline = tr.createTransformedShape(outline);
            } 
            v = new AWTGlyphGeometryCache.Value(outline, gmB);
            //System.out.println("put "+font.awtFont+" "+c); 
            glyphCache.put(c, v);
        } 
        return v;
    } 
 
4
CodeRank
This code example shows how to use the following methods:getPixelBounds
This code example shows how to use the following methods:getPixelBounds
	public Rectangle2D getBounds(String str, Font font, FontRenderContext frc) {
		return getBounds(font.createGlyphVector(frc, str), frc);
	} 
 
	public Rectangle2D getBounds(GlyphVector gv, FontRenderContext frc) {
		Rectangle2D stringBounds = gv.getPixelBounds(frc, 0, 0);
		return new Rectangle2D.Double(stringBounds.getX(), stringBounds.getY(), stringBounds.getWidth(), stringBounds.getHeight());
	} 
 
	public void drawGlyphVector(Graphics2D graphics, GlyphVector str, int x,
			int y) {
		graphics.setColor(Color.WHITE);
		graphics.setPaint(/*new GradientPaint(x, y, color, x, y + gradientSize
				/ 2, color2, true)*/color);
		graphics.drawGlyphVector(str, x, y);
	} 
 
	public void draw(Graphics2D graphics, String str, int x, int y) {
		graphics.setColor(Color.WHITE);
		graphics.setPaint(/*new GradientPaint(x, y, color1, x, y + gradientSize
4
CodeRank
See Code Examples for Java 8 GlyphVector Methods: