I want to draw different font, specifically Times New Roman (which is available on the iMac I use)
I set the font right & draw the strings, the FontMetrics
- which I use - measures the font right - but it doesn't draw the correct font! Instead I think it's Arial that gets drawn.
Underneath I use a Graphics2D object, but it doesn't work with a normal Graphics object either.
// FONTS
Font fBank = new Font("Times New Roman", Font.PLAIN, 9);
Font fPrice = new Font("Times New Roman", Font.PLAIN, 17);
Font fnormalText = new Font("Times New Roman", Font.PLAIN, 13);
Font fHeadlineText = new Font("Times New Roman", Font.PLAIN, 27);
Font fPayAndDiagnose = new Font("Times New Roman", Font.PLAIN, 12);
Font fHeadlineNumber = new Font("Times New Roman", Font.PLAIN, 17);
// FONTMETRIC
FontMetrics fMetric = _parent.getFontMetrics(fnormalText);
// LOGO
int imgPosX = (int) pageFormat.getImageableX() + 30;
int imgPosY = (int) pageFormat.getImageableY() + 30;
Image logo = new ImageIcon(getClass().getResource("/at/corgler/images/Print_Header_Plain.jpg")).getImage();
g.drawImage(logo, imgPosX, imgPosY, 184, 117, null);
// BILLDATE
String dateText = "XX, " + new SimpleDateFormat("dd. MMMM yyyy").format(_billDate);
int datePosY = imgPosY + 105;
int datePosX = (int) pageFormat.getImageableWidth() - fMetric.stringWidth(dateText);
g.setFont(fnormalText);
g.drawString(dateText, datePosX, datePosY);
// HEADLINE WITH NUMBER
String headlineText = "Honorarnote";
String numberText = "Nr. " + _payNumber + "/" + new SimpleDateFormat("yy").format(new Date());
fMetric = _parent.getFontMetrics(fHeadlineText);
int headlineWidth = fMetric.stringWidth(headlineText);
fMetric = _parent.getFontMetrics(fHeadlineNumber);
int numberWidth = fMetric.stringWidth(numberText);
int headlinePosY = datePosY + 65;
int headlineTextPosX = (int) ((pageFormat.getImageableWidth() / 2) - ((headlineWidth + numberWidth) / 2));
int headlineNumberPosX = headlineTextPosX + headlineWidth + 3;
g.setFont(fHeadlineText);
g.drawString(headlineText, headlineTextPosX, headlinePosY);
g.setFont(fHeadlineNumber);
g.drawString(numberText, headlineNumberPosX, headlinePosY);
g.drawLine(headlineTextPosX - 1, headlinePosY + 2, headlineTextPosX + headlineWidth, headlinePosY + 2);
g.setStroke(new BasicStroke(0.5f));
g.dispose();