cgray1223
asked on
Matching Fonts Using Java FontMetrics and Graphics2D Generated Text
I'm trying to match my generated text font to that of a design composition (PSD file). In the composition, the font is danteMt, but when I set that below my image text doesn't match. See attached images.
private String writeTextThumbDream(File file, String text, Long userId) throws Exception{
Image image = ImageIO.read(file);
BufferedImage img=bufferImage(image);
Graphics2D g = (Graphics2D) img.getGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
[b]Font fnt=new Font("danteMt",1,20);[/b]
Color fntC = new Color(0, 102, 153);
g.setColor(fntC);
g.setFont(fnt);
Dimension d = new Dimension(200, 113);
drawCenteredString(text, d.width, d.height, g);
}
public static void drawCenteredString(String s, int w, int h, Graphics g) {
FontMetrics fm = g.getFontMetrics();
int x = (w - fm.stringWidth(s)) / 2;
int y = (fm.getAscent() + (h - (fm.getAscent() + fm.getDescent())) / 2);
g.drawString(s, x, y);
}
you'll need to have the font file to achieve that
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Check you are using the right name
use the link i posted above to list all fonts to check names
use the link i posted above to list all fonts to check names
ASKER
some reason my browser cached it.