/** Copy text attributes from the supplied Font to Java2D AttributedString */ private static void copyAttributes(Font font, AttributedString str, int startIdx, int endIdx) { str.addAttribute(TextAttribute.FAMILY, font.getFontName(), startIdx, endIdx); str.addAttribute(TextAttribute.SIZE, (float) font.getFontHeightInPoints()); if (font.getBoldweight() == Font.BOLDWEIGHT_BOLD) str.addAttribute(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD, startIdx, endIdx); if (font.getItalic()) str.addAttribute(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE, startIdx, endIdx); if (font.getUnderline() == Font.U_SINGLE) str.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, startIdx, endIdx); }
private void fontStyle(Font font) { if (font.getBoldweight() >= Font.BOLDWEIGHT_BOLD) out.format(" font-weight: bold;%n"); if (font.getItalic()) out.format(" font-style: italic;%n"); out.format(" font-family: %s;%n", font.getFontName()); int fontheight = font.getFontHeightInPoints(); if (fontheight == 9) { fontheight = 10; } out.format(" font-size: %dpt;%n", fontheight); helper.styleColor(out, "color", getColor(font)); }