ParagraphStyleHandler 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 = getParagraphDefaultStyle(); 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; } ParagraphStyleHandler(Paragraph aParagraph); 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); void setHorizontalAlignment(HorizontalAlignmentType alignType); HorizontalAlignmentType getHorizontalAlignment();  }
@Test public void testGetFont() { try { TextDocument doc = TextDocument.newTextDocument(); Paragraph paragraph = doc.addParagraph("paragraphTest"); ParagraphStyleHandler paragraphHandler = paragraph.getStyleHandler(); Font fontBase = new Font("Arial", FontStyle.ITALIC, 10, Color.BLACK, TextLinePosition.THROUGH); paragraphHandler.setFont(fontBase); Font font = paragraphHandler.getFont(Document.ScriptType.WESTERN); Assert.assertEquals(fontBase, font); paragraphHandler.setFont(fontBase, Locale.CHINESE); Font font1 = paragraphHandler.getFont(Document.ScriptType.WESTERN); Assert.assertEquals(fontBase, font1); } catch (Exception e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); Assert.fail(e.getMessage()); } }