Class StyleTree

java.lang.Object
org.docx4j.model.styles.StyleTree

public class StyleTree extends Object
Represent a style hierarchy as a tree. TODO - need a way to update/refresh. This is useful for creating certain representations (eg CSS).
  • Field Details

  • Constructor Details

    • StyleTree

      private StyleTree()
    • StyleTree

      public StyleTree(Set<String> stylesInUse, Map<String,Style> allStyles, DocDefaults docDefaults, Style normal)
      Build a StyleTree for stylesInUse.
      Parameters:
      stylesInUse - styles actually in use in the main document part, headers/footers, footnotes/endnotes
      allStyles - styles defined in the style definitions part
    • StyleTree

      public StyleTree(Set<String> stylesInUse, Map<String,Style> allStyles, DocDefaults docDefaults, Style normal, Style defaultCharStyle, Style defaultTableStyle)
      Build a StyleTree for stylesInUse.
      Parameters:
      stylesInUse - styles actually in use in the main document part, headers/footers, footnotes/endnotes
      allStyles - styles defined in the style definitions part
      Since:
      11.1.3
  • Method Details

    • getTableStylesTree

      public Tree<StyleTree.AugmentedStyle> getTableStylesTree()
    • getParagraphStylesTree

      public Tree<StyleTree.AugmentedStyle> getParagraphStylesTree()
    • getCharacterStylesTree

      public Tree<StyleTree.AugmentedStyle> getCharacterStylesTree()
    • init

      public void init(Set<String> stylesInUse, Map<String,Style> allStyles, DocDefaults docDefaults, Style normal, Style defaultCharStyle, Style defaultTableStyle)
      Build a StyleTree for stylesInUse.
      Parameters:
      stylesInUse - styles actually in use in the main document part, headers/footers, footnotes/endnotes
      allStyles - styles defined in the style definitions part
    • addNode

      private Node<StyleTree.AugmentedStyle> addNode(String styleId, Map<String,Style> allStyles, Tree<StyleTree.AugmentedStyle> tree)
    • getHtmlClassAttributeValue

      public static String getHtmlClassAttributeValue(Tree<StyleTree.AugmentedStyle> tree, Node<StyleTree.AugmentedStyle> n)
    • createVirtualStylesForDocDefaults

      private void createVirtualStylesForDocDefaults(DocDefaults docDefaults, Style normal) throws Docx4JException
      Manufacture a paragraph style from the following, so it can be used as the root of our paragraph style tree. <w:docDefaults> <w:rPrDefault> <w:rPr> <w:rFonts w:asciiTheme="minorHAnsi" w:eastAsiaTheme="minorHAnsi" w:hAnsiTheme="minorHAnsi" w:cstheme="minorBidi" /> <w:sz w:val="22" /> <w:szCs w:val="22" /> <w:lang w:val="en-US" w:eastAsia="en-US" w:bidi="ar-SA" /> </w:rPr> </w:rPrDefault> <w:pPrDefault> <w:pPr> <w:spacing w:after="200" w:line="276" w:lineRule="auto" /> </w:pPr> </w:pPrDefault> </w:docDefaults> BEWARE: in a table, paragraph style ppr generally trumps table style ppr (but see below). The effect of including w:docDefaults in the style hierarchy is that they trump table style ppr, but they should not! There is no need for a doc defaults character style. The reason for this is that Word seems to ignore Default Paragraph Style! So the run formatting comes from paragraph style + explicit character style (if any), plus direct formatting. ------------------ w:compatSetting[w:name="overrideTableStyleFontSizeAndJustification"] is defined in [MS-DOCX] If this value is true, then the style hierarchy of the document is evaluated as specified in [ISO/IEC29500-1:2011] section 17.7.2. If this value is false, which is the default, then the following additional rules apply: If the default paragraph style (as specified in [ISO/IEC29500-1:2011] section 17.7.4.17) specifies a font size of 11pt or 12pt, then that setting will not override the font size specified by the table style for paragraphs in tables. If the default paragraph style (as specified in [ISO/IEC29500-1:2011] section 17.7.4.17) specifies a justification of left, then that setting will not override the justification specified by the table style for paragraphs in tables. Note org.docx4j.convert.out.common.preprocess.ParagraphStylesInTableFix
      Throws:
      Docx4JException