Example #1
0
 /** 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);
 }
Example #2
0
 private Font cloneFont(CellStyle cellstyle) {
   Font newFont = spreadsheet.getWorkbook().createFont();
   Font originalFont = spreadsheet.getWorkbook().getFontAt(cellstyle.getFontIndex());
   if (originalFont != null) {
     newFont.setBold(originalFont.getBold());
     newFont.setItalic(originalFont.getItalic());
     newFont.setFontHeight(originalFont.getFontHeight());
     newFont.setUnderline(originalFont.getUnderline());
     newFont.setStrikeout(originalFont.getStrikeout());
     // This cast an only be done when using .xlsx files
     XSSFFont originalXFont = (XSSFFont) originalFont;
     XSSFFont newXFont = (XSSFFont) newFont;
     newXFont.setColor(originalXFont.getXSSFColor());
   }
   return newFont;
 }