CellStyleHandler extends DefaultStyleHandler { public Font getFont(ScriptType type) { Font font = null; TextProperties textProperties = getTextPropertiesForRead(); if (textProperties != null) font = textProperties.getFont(type); else font = new Font(null, null, 0, (StyleTypeDefinitions.TextLinePosition) null); if (font != null && font.getFamilyName() != null && font.getColor() != null && font.getSize() != 0 && font.getFontStyle() != null && font.getTextLinePosition() != null) return font; boolean isDefault = isUseDefaultStyle; OdfStyleBase parentStyle = null; if (!isDefault) parentStyle = getParentStyle((OdfStyle) getCurrentUsedStyle()); while ((!isDefault) && (parentStyle != null)) { TextProperties parentStyleSetting = TextProperties.getTextProperties(parentStyle); Font tempFont = parentStyleSetting.getFont(type); mergeFont(font, tempFont); if (font.getFamilyName() != null && font.getColor() != null && font.getSize() > 0 && font.getFontStyle() != null && font.getTextLinePosition() != null) { return font; } if (parentStyle instanceof OdfDefaultStyle) isDefault = true; else parentStyle = getParentStyle((OdfStyle) parentStyle); } if (!isDefault) { OdfDefaultStyle defaultStyle = getCellDefaultStyle(); if (defaultStyle == null) { defaultStyle = getParagraphDefaultStyle(); } if (defaultStyle != null) { TextProperties defaultStyleSetting = TextProperties.getTextProperties(defaultStyle); Font tempFont = defaultStyleSetting.getFont(type); mergeFont(font, tempFont); } } if (font.getColor() == null) font.setColor(Color.BLACK); if (font.getFontStyle() == null) font.setFontStyle(FontStyle.REGULAR); if (font.getTextLinePosition() == null) font.setTextLinePosition(TextLinePosition.REGULAR); return font; } CellStyleHandler(Cell aCell); @Override String getUsedStyleName(); @Override OdfStyle getStyleElementForWrite(); String getCountry(ScriptType type); Font getFont(ScriptType type); String getLanguage(ScriptType type); void setCountry(String country, ScriptType type); void setFont(Font font); void setFont(Font font, Locale language); void setLanguage(String language, ScriptType type); Color getBackgroundColor(); Border getBorder(CellBordersType type); VerticalAlignmentType getVerticalAlignment(); boolean isTextWrapped(); void setBackgroundColor(Color color); void setBorders(Border border, CellBordersType bordersType); void setVerticalAlignment(VerticalAlignmentType alignType); void setTextWrapped(boolean isWrapped); void setHorizontalAlignment(HorizontalAlignmentType alignType); HorizontalAlignmentType getHorizontalAlignment();  }
@Test public void testGetFont() { try { Document doc = Document.loadDocument(ResourceUtilities.getTestResourceAsStream(TEST_FILE_NAME)); Table table = doc.getTableByName("slideTable"); CellStyleHandler styleHandler = table.getCellByPosition(1, 1).getStyleHandler(); styleHandler.getFont(Document.ScriptType.WESTERN); } catch (Exception e) { Logger.getLogger(CellStyleHandlerTest.class.getName()).log(Level.SEVERE, null, e); Assert.fail(e.getMessage()); } }