com.aspose.words

Class LayoutEntityType

  • java.lang.Object
    • com.aspose.words.LayoutEntityType
public class LayoutEntityType 
extends java.lang.Object

Utility class containing constants. Types of the layout entities.

Example:

Demonstrates ways of traversing a document's layout entities.
public void layoutEnumerator() throws Exception {
    // Open a document that contains a variety of layout entities
    // Layout entities are pages, cells, rows, lines and other objects included in the LayoutEntityType enum
    // They are defined visually by the rectangular space that they occupy in the document
    Document doc = new Document(getMyDir() + "Document.LayoutEntities.docx");

    // Create an enumerator that can traverse these entities
    LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
    Assert.assertEquals(doc, layoutEnumerator.getDocument());

    // The enumerator points to the first element on the first page and can be traversed like a tree
    layoutEnumerator.moveFirstChild();
    layoutEnumerator.moveFirstChild();
    layoutEnumerator.moveLastChild();
    layoutEnumerator.movePrevious();
    Assert.assertEquals(LayoutEntityType.SPAN, layoutEnumerator.getType());
    Assert.assertEquals("TTT", layoutEnumerator.getText());

    // Only spans can contain text
    layoutEnumerator.moveParent(LayoutEntityType.PAGE);
    Assert.assertEquals(LayoutEntityType.PAGE, layoutEnumerator.getType());

    // We can call this method to make sure that the enumerator points to the very first entity before we go through it forwards
    layoutEnumerator.reset();

    // "Visual order" means when moving through an entity's children that are broken across pages,
    // page layout takes precedence and we avoid elements in other pages and move to others on the same page
    System.out.println("Traversing from first to last, elements between pages separated:");
    traverseLayoutForward(layoutEnumerator, 1);

    // Our enumerator is conveniently at the end of the collection for us to go through the collection backwards
    System.out.println("Traversing from last to first, elements between pages separated:");
    traverseLayoutBackward(layoutEnumerator, 1);

    // "Logical order" means when moving through an entity's children that are broken across pages,
    // node relationships take precedence
    System.out.println("Traversing from first to last, elements between pages mixed:");
    traverseLayoutForwardLogical(layoutEnumerator, 1);

    System.out.println("Traversing from last to first, elements between pages mixed:");
    traverseLayoutBackwardLogical(layoutEnumerator, 1);
}

/// <summary>
/// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Visual" order
/// </summary>
private void traverseLayoutForward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
    do {
        printCurrentEntity(layoutEnumerator, depth);

        if (layoutEnumerator.moveFirstChild()) {
            traverseLayoutForward(layoutEnumerator, depth + 1);
            layoutEnumerator.moveParent();
        }
    } while (layoutEnumerator.moveNext());
}

/// <summary>
/// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Visual" order
/// </summary>
private void traverseLayoutBackward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
    do {
        printCurrentEntity(layoutEnumerator, depth);

        if (layoutEnumerator.moveLastChild()) {
            traverseLayoutBackward(layoutEnumerator, depth + 1);
            layoutEnumerator.moveParent();
        }
    } while (layoutEnumerator.movePrevious());
}

/// <summary>
/// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Logical" order
/// </summary>
private void traverseLayoutForwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
    do {
        printCurrentEntity(layoutEnumerator, depth);

        if (layoutEnumerator.moveFirstChild()) {
            traverseLayoutForwardLogical(layoutEnumerator, depth + 1);
            layoutEnumerator.moveParent();
        }
    } while (layoutEnumerator.moveNextLogical());
}

/// <summary>
/// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Logical" order
/// </summary>
private void traverseLayoutBackwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
    do {
        printCurrentEntity(layoutEnumerator, depth);

        if (layoutEnumerator.moveLastChild()) {
            traverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
            layoutEnumerator.moveParent();
        }
    } while (layoutEnumerator.movePreviousLogical());
}

/// <summary>
/// Print information about layoutEnumerator's current entity to the console, indented by a number of tab characters specified by indent
/// The rectangle that we process at the end represents the area and location thereof that the element takes up in the document
/// </summary>
private void printCurrentEntity(LayoutEnumerator layoutEnumerator, int indent) throws Exception {
    String baseString = "\t";
    String tabs = StringUtils.repeat(baseString, indent);

    if (tabs.equals(layoutEnumerator.getKind())) {
        System.out.println(MessageFormat.format("{0}-> Entity type: {1}", tabs, layoutEnumerator.getType()));
    } else {
        System.out.println(MessageFormat.format("{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator.getType(), layoutEnumerator.getKind()));
    }

    if (layoutEnumerator.getType() == LayoutEntityType.SPAN) {
        System.out.println(MessageFormat.format("{0}   Span contents: \"{1}\"", tabs, layoutEnumerator.getText()));
    }

    Rectangle2D leRect = layoutEnumerator.getRectangle();
    System.out.println(MessageFormat.format("{0}   Rectangle dimensions {1}x{2}, X={3} Y={4}", tabs, leRect.getWidth(), leRect.getHeight(), leRect.getX(), leRect.getY()));
    System.out.println(MessageFormat.format("{0}   Page {1}", tabs, layoutEnumerator.getPageIndex()));
}

Field Summary
static final intNONE = 0
Default value.
static final intPAGE = 1
Represents page of a document. Page may have COLUMN, HEADER_FOOTER and COMMENT child entities.
static final intCOLUMN = 2
Represents a column of text on a page. Column may have the same child entities as CELL, plus FOOTNOTE, ENDNOTE and NOTE_SEPARATOR entities.
static final intROW = 8
Represents a table row. Row may have CELL as child entities.
static final intCELL = 16
Represents a table cell. Cell may have LINE and ROW child entities.
static final intLINE = 32
Represents line of characters of text and inline objects. Line may have SPAN child entities.
static final intSPAN = 64
Represents one or more characters in a line. This include special characters like field start/end markers, bookmarks and comments. Span may not have child entities.
static final intFOOTNOTE = 256
Represents placeholder for footnote content. Footnote may have LINE and ROW child entities.
static final intENDNOTE = 512
Represents placeholder for endnote content. Endnote may have LINE and ROW child entities.
static final intHEADER_FOOTER = 1024
Represents placeholder for header/footer content on a page. HeaderFooter may have LINE and ROW child entities.
static final intTEXT_BOX = 2048
Represents text area inside of a shape. Textbox may have LINE and ROW child entities.
static final intCOMMENT = 4096
Represents placeholder for comment content. Comment may have LINE and ROW child entities.
static final intNOTE_SEPARATOR = 8192
Represents footnote/endnote separator. NoteSeparator may have LINE and ROW child entities.
 

    • Field Detail

      • NONE = 0

        public static final int NONE
        Default value.
      • PAGE = 1

        public static final int PAGE
        Represents page of a document. Page may have COLUMN, HEADER_FOOTER and COMMENT child entities.
      • COLUMN = 2

        public static final int COLUMN
        Represents a column of text on a page. Column may have the same child entities as CELL, plus FOOTNOTE, ENDNOTE and NOTE_SEPARATOR entities.
      • ROW = 8

        public static final int ROW
        Represents a table row. Row may have CELL as child entities.
      • CELL = 16

        public static final int CELL
        Represents a table cell. Cell may have LINE and ROW child entities.
      • LINE = 32

        public static final int LINE
        Represents line of characters of text and inline objects. Line may have SPAN child entities.
      • SPAN = 64

        public static final int SPAN
        Represents one or more characters in a line. This include special characters like field start/end markers, bookmarks and comments. Span may not have child entities.
      • FOOTNOTE = 256

        public static final int FOOTNOTE
        Represents placeholder for footnote content. Footnote may have LINE and ROW child entities.
      • ENDNOTE = 512

        public static final int ENDNOTE
        Represents placeholder for endnote content. Endnote may have LINE and ROW child entities.
      • HEADER_FOOTER = 1024

        public static final int HEADER_FOOTER
        Represents placeholder for header/footer content on a page. HeaderFooter may have LINE and ROW child entities.
      • TEXT_BOX = 2048

        public static final int TEXT_BOX
        Represents text area inside of a shape. Textbox may have LINE and ROW child entities.
      • COMMENT = 4096

        public static final int COMMENT
        Represents placeholder for comment content. Comment may have LINE and ROW child entities.
      • NOTE_SEPARATOR = 8192

        public static final int NOTE_SEPARATOR
        Represents footnote/endnote separator. NoteSeparator may have LINE and ROW child entities.