1 8 package com.nightlabs.editor2d.j2d; 9 10 import java.awt.Font ; 11 import java.awt.Graphics2D ; 12 import java.awt.Point ; 13 import java.awt.Rectangle ; 14 import java.awt.font.FontRenderContext ; 15 import java.awt.font.GlyphVector ; 16 import java.awt.geom.Rectangle2D ; 17 18 import com.nightlabs.editor2d.util.EditorModelUtil; 19 20 21 public class RenderUtil { 22 23 public RenderUtil() { 24 super(); 25 } 26 27 public static GlyphVector createGlyphVector(String s, Font f, FontRenderContext frc) 28 { 29 return f.createGlyphVector(frc, s); 30 } 31 32 public static void paintCenterGlyphVector(String s, Graphics2D g2d, Font f, Rectangle bounds) 33 { 34 GlyphVector glyphVector = createGlyphVector(s, f, g2d.getFontRenderContext()); 35 Rectangle2D glyphBounds = glyphVector.getVisualBounds(); 36 Point glyphLocation = EditorModelUtil.getLeftTopCenterLocation(glyphBounds.getBounds(), bounds); 37 g2d.drawGlyphVector(glyphVector, glyphLocation.x, glyphLocation.y); 38 } 39 40 } 41 | Popular Tags |