Aspose::Words::Layout::LayoutEnumerator Class Reference

Detailed Description

Enumerates page layout entities of a document. You can use this class to walk over the page layout model. Available properties are type, geometry, text and page index where entity is rendered, as well as overall structure and relationships. Use combination of GetEntity() and Current move to the entity which corresponds to a document node.

Examples

Shows ways of traversing a document's layout entities.

void LayoutEnumerator_()
{
// 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.
// Each layout entity has a rectangular space that it occupies in the document body.
auto doc = MakeObject<Document>(MyDir + u"Layout entities.docx");
// Create an enumerator that can traverse these entities like a tree.
auto layoutEnumerator = MakeObject<LayoutEnumerator>(doc);
ASPOSE_ASSERT_EQ(doc, layoutEnumerator->get_Document());
layoutEnumerator->MoveParent(LayoutEntityType::Page);
ASSERT_EQ(LayoutEntityType::Page, layoutEnumerator->get_Type());
ASSERT_THROW(layoutEnumerator->get_Text(), System::InvalidOperationException);
// We can call this method to make sure that the enumerator will be at the first layout entity.
layoutEnumerator->Reset();
// There are two orders that determine how the layout enumerator continues traversing layout entities
// when it encounters entities that span across multiple pages.
// 1 - In visual order:
// When moving through an entity's children that span multiple pages,
// page layout takes precedence, and we move to other child elements on this page and avoid the ones on the next.
std::cout << "Traversing from first to last, elements between pages separated:" << std::endl;
TraverseLayoutForward(layoutEnumerator, 1);
// Our enumerator is now at the end of the collection. We can traverse the layout entities backwards to go back to the beginning.
std::cout << "Traversing from last to first, elements between pages separated:" << std::endl;
TraverseLayoutBackward(layoutEnumerator, 1);
// 2 - In logical order:
// When moving through an entity's children that span multiple pages,
// the enumerator will move between pages to traverse all the child entities.
std::cout << "Traversing from first to last, elements between pages mixed:" << std::endl;
TraverseLayoutForwardLogical(layoutEnumerator, 1);
std::cout << "Traversing from last to first, elements between pages mixed:" << std::endl;
TraverseLayoutBackwardLogical(layoutEnumerator, 1);
}
static void TraverseLayoutForward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNext());
}
static void TraverseLayoutBackward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePrevious());
}
static void TraverseLayoutForwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNextLogical());
}
static void TraverseLayoutBackwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePreviousLogical());
}
static void PrintCurrentEntity(SharedPtr<LayoutEnumerator> layoutEnumerator, int indent)
{
String tabs(u'\t', indent);
std::cout << (layoutEnumerator->get_Kind() == String::Empty
? String::Format(u"{0}-> Entity type: {1}", tabs, layoutEnumerator->get_Type())
: String::Format(u"{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator->get_Type(), layoutEnumerator->get_Kind()))
<< std::endl;
// Only spans can contain text.
if (layoutEnumerator->get_Type() == LayoutEntityType::Span)
{
std::cout << tabs << " Span contents: \"" << layoutEnumerator->get_Text() << "\"" << std::endl;
}
System::Drawing::RectangleF leRect = layoutEnumerator->get_Rectangle();
std::cout << tabs << " Rectangle dimensions " << leRect.get_Width() << "x" << leRect.get_Height() << ", X=" << leRect.get_X()
<< " Y=" << leRect.get_Y() << std::endl;
std::cout << tabs << " Page " << layoutEnumerator->get_PageIndex() << std::endl;
}

#include <Aspose.Words.Cpp/Layout/LayoutEnumerator.h>

+ Inheritance diagram for Aspose::Words::Layout::LayoutEnumerator:

Public Member Functions

 LayoutEnumerator (const SharedPtr< Document > &document)
 Initializes new instance of this class. More...
 
SharedPtr< Objectget_Current () const
 Gets or sets current position in the page layout model. This property returns an opaque object which corresponds to the current layout entity. More...
 
SharedPtr< Documentget_Document () const
 Gets document this instance enumerates. More...
 
String get_Kind ()
 Gets the kind of the current entity. This can be an empty string but never null. More...
 
int32_t get_PageIndex ()
 Gets the 1-based index of a page which contains the current entity. More...
 
RectangleF get_Rectangle ()
 Returns the bounding rectangle of the current entity relative to the page top left corner (in points). More...
 
String get_Text ()
 Gets text of the current span entity. Throws for other entity types. More...
 
LayoutEntityType get_Type ()
 Gets the type of the current entity. More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
bool MoveFirstChild ()
 Moves to the first child entity. More...
 
bool MoveLastChild ()
 Moves to the last child entity. More...
 
bool MoveNext ()
 Moves to the next sibling entity in visual order. When iterating lines of a paragraph broken across pages this method will not move to the next page but rather move to the next entity on the same page. More...
 
bool MoveNextLogical ()
 Moves to the next sibling entity in a logical order. When iterating lines of a paragraph broken across pages this method will move to the next line even if it resides on another page. More...
 
bool MoveParent ()
 Moves to the parent entity. More...
 
bool MoveParent (LayoutEntityType types)
 Moves to the parent entity of the specified type. More...
 
bool MovePrevious ()
 Moves to the previous sibling entity. More...
 
bool MovePreviousLogical ()
 Moves to the previous sibling entity in a logical order. When iterating lines of a paragraph broken across pages this method will move to the previous line even if it resides on another page. More...
 
void Reset ()
 Moves the enumerator to the first page of the document. More...
 
void set_Current (const SharedPtr< Object > &value)
 Setter for get_Current. More...
 

Static Public Member Functions

static const TypeInfoType ()
 

Constructor & Destructor Documentation

◆ LayoutEnumerator()

Aspose::Words::Layout::LayoutEnumerator::LayoutEnumerator ( const System::SharedPtr< Aspose::Words::Document > &  document)

Initializes new instance of this class.

If page layout model of the document hasn't been built the enumerator calls UpdatePageLayout to build it.

Whenever document is updated and new page layout model is created, a new enumerator must be used to access it.

Parameters
documentA document whose page layout model to enumerate.
Examples

Shows ways of traversing a document's layout entities.

void LayoutEnumerator_()
{
// 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.
// Each layout entity has a rectangular space that it occupies in the document body.
auto doc = MakeObject<Document>(MyDir + u"Layout entities.docx");
// Create an enumerator that can traverse these entities like a tree.
auto layoutEnumerator = MakeObject<LayoutEnumerator>(doc);
ASPOSE_ASSERT_EQ(doc, layoutEnumerator->get_Document());
layoutEnumerator->MoveParent(LayoutEntityType::Page);
ASSERT_EQ(LayoutEntityType::Page, layoutEnumerator->get_Type());
ASSERT_THROW(layoutEnumerator->get_Text(), System::InvalidOperationException);
// We can call this method to make sure that the enumerator will be at the first layout entity.
layoutEnumerator->Reset();
// There are two orders that determine how the layout enumerator continues traversing layout entities
// when it encounters entities that span across multiple pages.
// 1 - In visual order:
// When moving through an entity's children that span multiple pages,
// page layout takes precedence, and we move to other child elements on this page and avoid the ones on the next.
std::cout << "Traversing from first to last, elements between pages separated:" << std::endl;
TraverseLayoutForward(layoutEnumerator, 1);
// Our enumerator is now at the end of the collection. We can traverse the layout entities backwards to go back to the beginning.
std::cout << "Traversing from last to first, elements between pages separated:" << std::endl;
TraverseLayoutBackward(layoutEnumerator, 1);
// 2 - In logical order:
// When moving through an entity's children that span multiple pages,
// the enumerator will move between pages to traverse all the child entities.
std::cout << "Traversing from first to last, elements between pages mixed:" << std::endl;
TraverseLayoutForwardLogical(layoutEnumerator, 1);
std::cout << "Traversing from last to first, elements between pages mixed:" << std::endl;
TraverseLayoutBackwardLogical(layoutEnumerator, 1);
}
static void TraverseLayoutForward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNext());
}
static void TraverseLayoutBackward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePrevious());
}
static void TraverseLayoutForwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNextLogical());
}
static void TraverseLayoutBackwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePreviousLogical());
}
static void PrintCurrentEntity(SharedPtr<LayoutEnumerator> layoutEnumerator, int indent)
{
String tabs(u'\t', indent);
std::cout << (layoutEnumerator->get_Kind() == String::Empty
? String::Format(u"{0}-> Entity type: {1}", tabs, layoutEnumerator->get_Type())
: String::Format(u"{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator->get_Type(), layoutEnumerator->get_Kind()))
<< std::endl;
// Only spans can contain text.
if (layoutEnumerator->get_Type() == LayoutEntityType::Span)
{
std::cout << tabs << " Span contents: \"" << layoutEnumerator->get_Text() << "\"" << std::endl;
}
System::Drawing::RectangleF leRect = layoutEnumerator->get_Rectangle();
std::cout << tabs << " Rectangle dimensions " << leRect.get_Width() << "x" << leRect.get_Height() << ", X=" << leRect.get_X()
<< " Y=" << leRect.get_Y() << std::endl;
std::cout << tabs << " Page " << layoutEnumerator->get_PageIndex() << std::endl;
}

Member Function Documentation

◆ get_Current()

System::SharedPtr<System::Object> Aspose::Words::Layout::LayoutEnumerator::get_Current ( ) const

Gets or sets current position in the page layout model. This property returns an opaque object which corresponds to the current layout entity.

Examples

Shows how to see the the ranges of pages that a node spans.

auto doc = MakeObject<Document>();
auto layoutCollector = MakeObject<LayoutCollector>(doc);
// Call the "GetNumPagesSpanned" method to count how many pages the content of our document spans.
// Since the document is empty, that number of pages is currently zero.
ASPOSE_ASSERT_EQ(doc, layoutCollector->get_Document());
ASSERT_EQ(0, layoutCollector->GetNumPagesSpanned(doc));
// Populate the document with 5 pages of content.
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Write(u"Section 1");
builder->InsertBreak(BreakType::PageBreak);
builder->InsertBreak(BreakType::PageBreak);
builder->InsertBreak(BreakType::SectionBreakEvenPage);
builder->Write(u"Section 2");
builder->InsertBreak(BreakType::PageBreak);
builder->InsertBreak(BreakType::PageBreak);
// Before the layout collector, we need to call the "UpdatePageLayout" method to give us
// an accurate figure for any layout-related metric, such as the page count.
ASSERT_EQ(0, layoutCollector->GetNumPagesSpanned(doc));
layoutCollector->Clear();
doc->UpdatePageLayout();
ASSERT_EQ(5, layoutCollector->GetNumPagesSpanned(doc));
// We can see the numbers of the start and end pages of any node and their overall page spans.
SharedPtr<NodeCollection> nodes = doc->GetChildNodes(NodeType::Any, true);
for (const auto& node : System::IterateOver(nodes))
{
std::cout << String::Format(u"-> NodeType.{0}: ", node->get_NodeType()) << std::endl;
std::cout << (String::Format(u"\tStarts on page {0}, ends on page {1},", layoutCollector->GetStartPageIndex(node),
layoutCollector->GetEndPageIndex(node)) +
String::Format(u" spanning {0} pages.", layoutCollector->GetNumPagesSpanned(node)))
<< std::endl;
}
// We can iterate over the layout entities using a LayoutEnumerator.
auto layoutEnumerator = MakeObject<LayoutEnumerator>(doc);
ASSERT_EQ(LayoutEntityType::Page, layoutEnumerator->get_Type());
// The LayoutEnumerator can traverse the collection of layout entities like a tree.
// We can also apply it to any node's corresponding layout entity.
layoutEnumerator->set_Current(layoutCollector->GetEntity(doc->GetChild(NodeType::Paragraph, 1, true)));
ASSERT_EQ(LayoutEntityType::Span, layoutEnumerator->get_Type());
ASSERT_EQ(u"ΒΆ", layoutEnumerator->get_Text());

◆ get_Document()

System::SharedPtr<Aspose::Words::Document> Aspose::Words::Layout::LayoutEnumerator::get_Document ( ) const

Gets document this instance enumerates.

Examples

Shows ways of traversing a document's layout entities.

void LayoutEnumerator_()
{
// 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.
// Each layout entity has a rectangular space that it occupies in the document body.
auto doc = MakeObject<Document>(MyDir + u"Layout entities.docx");
// Create an enumerator that can traverse these entities like a tree.
auto layoutEnumerator = MakeObject<LayoutEnumerator>(doc);
ASPOSE_ASSERT_EQ(doc, layoutEnumerator->get_Document());
layoutEnumerator->MoveParent(LayoutEntityType::Page);
ASSERT_EQ(LayoutEntityType::Page, layoutEnumerator->get_Type());
ASSERT_THROW(layoutEnumerator->get_Text(), System::InvalidOperationException);
// We can call this method to make sure that the enumerator will be at the first layout entity.
layoutEnumerator->Reset();
// There are two orders that determine how the layout enumerator continues traversing layout entities
// when it encounters entities that span across multiple pages.
// 1 - In visual order:
// When moving through an entity's children that span multiple pages,
// page layout takes precedence, and we move to other child elements on this page and avoid the ones on the next.
std::cout << "Traversing from first to last, elements between pages separated:" << std::endl;
TraverseLayoutForward(layoutEnumerator, 1);
// Our enumerator is now at the end of the collection. We can traverse the layout entities backwards to go back to the beginning.
std::cout << "Traversing from last to first, elements between pages separated:" << std::endl;
TraverseLayoutBackward(layoutEnumerator, 1);
// 2 - In logical order:
// When moving through an entity's children that span multiple pages,
// the enumerator will move between pages to traverse all the child entities.
std::cout << "Traversing from first to last, elements between pages mixed:" << std::endl;
TraverseLayoutForwardLogical(layoutEnumerator, 1);
std::cout << "Traversing from last to first, elements between pages mixed:" << std::endl;
TraverseLayoutBackwardLogical(layoutEnumerator, 1);
}
static void TraverseLayoutForward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNext());
}
static void TraverseLayoutBackward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePrevious());
}
static void TraverseLayoutForwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNextLogical());
}
static void TraverseLayoutBackwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePreviousLogical());
}
static void PrintCurrentEntity(SharedPtr<LayoutEnumerator> layoutEnumerator, int indent)
{
String tabs(u'\t', indent);
std::cout << (layoutEnumerator->get_Kind() == String::Empty
? String::Format(u"{0}-> Entity type: {1}", tabs, layoutEnumerator->get_Type())
: String::Format(u"{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator->get_Type(), layoutEnumerator->get_Kind()))
<< std::endl;
// Only spans can contain text.
if (layoutEnumerator->get_Type() == LayoutEntityType::Span)
{
std::cout << tabs << " Span contents: \"" << layoutEnumerator->get_Text() << "\"" << std::endl;
}
System::Drawing::RectangleF leRect = layoutEnumerator->get_Rectangle();
std::cout << tabs << " Rectangle dimensions " << leRect.get_Width() << "x" << leRect.get_Height() << ", X=" << leRect.get_X()
<< " Y=" << leRect.get_Y() << std::endl;
std::cout << tabs << " Page " << layoutEnumerator->get_PageIndex() << std::endl;
}

◆ get_Kind()

System::String Aspose::Words::Layout::LayoutEnumerator::get_Kind ( )

Gets the kind of the current entity. This can be an empty string but never null.

Examples

Shows ways of traversing a document's layout entities.

void LayoutEnumerator_()
{
// 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.
// Each layout entity has a rectangular space that it occupies in the document body.
auto doc = MakeObject<Document>(MyDir + u"Layout entities.docx");
// Create an enumerator that can traverse these entities like a tree.
auto layoutEnumerator = MakeObject<LayoutEnumerator>(doc);
ASPOSE_ASSERT_EQ(doc, layoutEnumerator->get_Document());
layoutEnumerator->MoveParent(LayoutEntityType::Page);
ASSERT_EQ(LayoutEntityType::Page, layoutEnumerator->get_Type());
ASSERT_THROW(layoutEnumerator->get_Text(), System::InvalidOperationException);
// We can call this method to make sure that the enumerator will be at the first layout entity.
layoutEnumerator->Reset();
// There are two orders that determine how the layout enumerator continues traversing layout entities
// when it encounters entities that span across multiple pages.
// 1 - In visual order:
// When moving through an entity's children that span multiple pages,
// page layout takes precedence, and we move to other child elements on this page and avoid the ones on the next.
std::cout << "Traversing from first to last, elements between pages separated:" << std::endl;
TraverseLayoutForward(layoutEnumerator, 1);
// Our enumerator is now at the end of the collection. We can traverse the layout entities backwards to go back to the beginning.
std::cout << "Traversing from last to first, elements between pages separated:" << std::endl;
TraverseLayoutBackward(layoutEnumerator, 1);
// 2 - In logical order:
// When moving through an entity's children that span multiple pages,
// the enumerator will move between pages to traverse all the child entities.
std::cout << "Traversing from first to last, elements between pages mixed:" << std::endl;
TraverseLayoutForwardLogical(layoutEnumerator, 1);
std::cout << "Traversing from last to first, elements between pages mixed:" << std::endl;
TraverseLayoutBackwardLogical(layoutEnumerator, 1);
}
static void TraverseLayoutForward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNext());
}
static void TraverseLayoutBackward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePrevious());
}
static void TraverseLayoutForwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNextLogical());
}
static void TraverseLayoutBackwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePreviousLogical());
}
static void PrintCurrentEntity(SharedPtr<LayoutEnumerator> layoutEnumerator, int indent)
{
String tabs(u'\t', indent);
std::cout << (layoutEnumerator->get_Kind() == String::Empty
? String::Format(u"{0}-> Entity type: {1}", tabs, layoutEnumerator->get_Type())
: String::Format(u"{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator->get_Type(), layoutEnumerator->get_Kind()))
<< std::endl;
// Only spans can contain text.
if (layoutEnumerator->get_Type() == LayoutEntityType::Span)
{
std::cout << tabs << " Span contents: \"" << layoutEnumerator->get_Text() << "\"" << std::endl;
}
System::Drawing::RectangleF leRect = layoutEnumerator->get_Rectangle();
std::cout << tabs << " Rectangle dimensions " << leRect.get_Width() << "x" << leRect.get_Height() << ", X=" << leRect.get_X()
<< " Y=" << leRect.get_Y() << std::endl;
std::cout << tabs << " Page " << layoutEnumerator->get_PageIndex() << std::endl;
}

◆ get_PageIndex()

int32_t Aspose::Words::Layout::LayoutEnumerator::get_PageIndex ( )

Gets the 1-based index of a page which contains the current entity.

Examples

Shows ways of traversing a document's layout entities.

void LayoutEnumerator_()
{
// 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.
// Each layout entity has a rectangular space that it occupies in the document body.
auto doc = MakeObject<Document>(MyDir + u"Layout entities.docx");
// Create an enumerator that can traverse these entities like a tree.
auto layoutEnumerator = MakeObject<LayoutEnumerator>(doc);
ASPOSE_ASSERT_EQ(doc, layoutEnumerator->get_Document());
layoutEnumerator->MoveParent(LayoutEntityType::Page);
ASSERT_EQ(LayoutEntityType::Page, layoutEnumerator->get_Type());
ASSERT_THROW(layoutEnumerator->get_Text(), System::InvalidOperationException);
// We can call this method to make sure that the enumerator will be at the first layout entity.
layoutEnumerator->Reset();
// There are two orders that determine how the layout enumerator continues traversing layout entities
// when it encounters entities that span across multiple pages.
// 1 - In visual order:
// When moving through an entity's children that span multiple pages,
// page layout takes precedence, and we move to other child elements on this page and avoid the ones on the next.
std::cout << "Traversing from first to last, elements between pages separated:" << std::endl;
TraverseLayoutForward(layoutEnumerator, 1);
// Our enumerator is now at the end of the collection. We can traverse the layout entities backwards to go back to the beginning.
std::cout << "Traversing from last to first, elements between pages separated:" << std::endl;
TraverseLayoutBackward(layoutEnumerator, 1);
// 2 - In logical order:
// When moving through an entity's children that span multiple pages,
// the enumerator will move between pages to traverse all the child entities.
std::cout << "Traversing from first to last, elements between pages mixed:" << std::endl;
TraverseLayoutForwardLogical(layoutEnumerator, 1);
std::cout << "Traversing from last to first, elements between pages mixed:" << std::endl;
TraverseLayoutBackwardLogical(layoutEnumerator, 1);
}
static void TraverseLayoutForward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNext());
}
static void TraverseLayoutBackward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePrevious());
}
static void TraverseLayoutForwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNextLogical());
}
static void TraverseLayoutBackwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePreviousLogical());
}
static void PrintCurrentEntity(SharedPtr<LayoutEnumerator> layoutEnumerator, int indent)
{
String tabs(u'\t', indent);
std::cout << (layoutEnumerator->get_Kind() == String::Empty
? String::Format(u"{0}-> Entity type: {1}", tabs, layoutEnumerator->get_Type())
: String::Format(u"{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator->get_Type(), layoutEnumerator->get_Kind()))
<< std::endl;
// Only spans can contain text.
if (layoutEnumerator->get_Type() == LayoutEntityType::Span)
{
std::cout << tabs << " Span contents: \"" << layoutEnumerator->get_Text() << "\"" << std::endl;
}
System::Drawing::RectangleF leRect = layoutEnumerator->get_Rectangle();
std::cout << tabs << " Rectangle dimensions " << leRect.get_Width() << "x" << leRect.get_Height() << ", X=" << leRect.get_X()
<< " Y=" << leRect.get_Y() << std::endl;
std::cout << tabs << " Page " << layoutEnumerator->get_PageIndex() << std::endl;
}

◆ get_Rectangle()

System::Drawing::RectangleF Aspose::Words::Layout::LayoutEnumerator::get_Rectangle ( )

Returns the bounding rectangle of the current entity relative to the page top left corner (in points).

Examples

Shows ways of traversing a document's layout entities.

void LayoutEnumerator_()
{
// 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.
// Each layout entity has a rectangular space that it occupies in the document body.
auto doc = MakeObject<Document>(MyDir + u"Layout entities.docx");
// Create an enumerator that can traverse these entities like a tree.
auto layoutEnumerator = MakeObject<LayoutEnumerator>(doc);
ASPOSE_ASSERT_EQ(doc, layoutEnumerator->get_Document());
layoutEnumerator->MoveParent(LayoutEntityType::Page);
ASSERT_EQ(LayoutEntityType::Page, layoutEnumerator->get_Type());
ASSERT_THROW(layoutEnumerator->get_Text(), System::InvalidOperationException);
// We can call this method to make sure that the enumerator will be at the first layout entity.
layoutEnumerator->Reset();
// There are two orders that determine how the layout enumerator continues traversing layout entities
// when it encounters entities that span across multiple pages.
// 1 - In visual order:
// When moving through an entity's children that span multiple pages,
// page layout takes precedence, and we move to other child elements on this page and avoid the ones on the next.
std::cout << "Traversing from first to last, elements between pages separated:" << std::endl;
TraverseLayoutForward(layoutEnumerator, 1);
// Our enumerator is now at the end of the collection. We can traverse the layout entities backwards to go back to the beginning.
std::cout << "Traversing from last to first, elements between pages separated:" << std::endl;
TraverseLayoutBackward(layoutEnumerator, 1);
// 2 - In logical order:
// When moving through an entity's children that span multiple pages,
// the enumerator will move between pages to traverse all the child entities.
std::cout << "Traversing from first to last, elements between pages mixed:" << std::endl;
TraverseLayoutForwardLogical(layoutEnumerator, 1);
std::cout << "Traversing from last to first, elements between pages mixed:" << std::endl;
TraverseLayoutBackwardLogical(layoutEnumerator, 1);
}
static void TraverseLayoutForward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNext());
}
static void TraverseLayoutBackward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePrevious());
}
static void TraverseLayoutForwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNextLogical());
}
static void TraverseLayoutBackwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePreviousLogical());
}
static void PrintCurrentEntity(SharedPtr<LayoutEnumerator> layoutEnumerator, int indent)
{
String tabs(u'\t', indent);
std::cout << (layoutEnumerator->get_Kind() == String::Empty
? String::Format(u"{0}-> Entity type: {1}", tabs, layoutEnumerator->get_Type())
: String::Format(u"{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator->get_Type(), layoutEnumerator->get_Kind()))
<< std::endl;
// Only spans can contain text.
if (layoutEnumerator->get_Type() == LayoutEntityType::Span)
{
std::cout << tabs << " Span contents: \"" << layoutEnumerator->get_Text() << "\"" << std::endl;
}
System::Drawing::RectangleF leRect = layoutEnumerator->get_Rectangle();
std::cout << tabs << " Rectangle dimensions " << leRect.get_Width() << "x" << leRect.get_Height() << ", X=" << leRect.get_X()
<< " Y=" << leRect.get_Y() << std::endl;
std::cout << tabs << " Page " << layoutEnumerator->get_PageIndex() << std::endl;
}

◆ get_Text()

System::String Aspose::Words::Layout::LayoutEnumerator::get_Text ( )

Gets text of the current span entity. Throws for other entity types.

Examples

Shows ways of traversing a document's layout entities.

void LayoutEnumerator_()
{
// 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.
// Each layout entity has a rectangular space that it occupies in the document body.
auto doc = MakeObject<Document>(MyDir + u"Layout entities.docx");
// Create an enumerator that can traverse these entities like a tree.
auto layoutEnumerator = MakeObject<LayoutEnumerator>(doc);
ASPOSE_ASSERT_EQ(doc, layoutEnumerator->get_Document());
layoutEnumerator->MoveParent(LayoutEntityType::Page);
ASSERT_EQ(LayoutEntityType::Page, layoutEnumerator->get_Type());
ASSERT_THROW(layoutEnumerator->get_Text(), System::InvalidOperationException);
// We can call this method to make sure that the enumerator will be at the first layout entity.
layoutEnumerator->Reset();
// There are two orders that determine how the layout enumerator continues traversing layout entities
// when it encounters entities that span across multiple pages.
// 1 - In visual order:
// When moving through an entity's children that span multiple pages,
// page layout takes precedence, and we move to other child elements on this page and avoid the ones on the next.
std::cout << "Traversing from first to last, elements between pages separated:" << std::endl;
TraverseLayoutForward(layoutEnumerator, 1);
// Our enumerator is now at the end of the collection. We can traverse the layout entities backwards to go back to the beginning.
std::cout << "Traversing from last to first, elements between pages separated:" << std::endl;
TraverseLayoutBackward(layoutEnumerator, 1);
// 2 - In logical order:
// When moving through an entity's children that span multiple pages,
// the enumerator will move between pages to traverse all the child entities.
std::cout << "Traversing from first to last, elements between pages mixed:" << std::endl;
TraverseLayoutForwardLogical(layoutEnumerator, 1);
std::cout << "Traversing from last to first, elements between pages mixed:" << std::endl;
TraverseLayoutBackwardLogical(layoutEnumerator, 1);
}
static void TraverseLayoutForward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNext());
}
static void TraverseLayoutBackward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePrevious());
}
static void TraverseLayoutForwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNextLogical());
}
static void TraverseLayoutBackwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePreviousLogical());
}
static void PrintCurrentEntity(SharedPtr<LayoutEnumerator> layoutEnumerator, int indent)
{
String tabs(u'\t', indent);
std::cout << (layoutEnumerator->get_Kind() == String::Empty
? String::Format(u"{0}-> Entity type: {1}", tabs, layoutEnumerator->get_Type())
: String::Format(u"{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator->get_Type(), layoutEnumerator->get_Kind()))
<< std::endl;
// Only spans can contain text.
if (layoutEnumerator->get_Type() == LayoutEntityType::Span)
{
std::cout << tabs << " Span contents: \"" << layoutEnumerator->get_Text() << "\"" << std::endl;
}
System::Drawing::RectangleF leRect = layoutEnumerator->get_Rectangle();
std::cout << tabs << " Rectangle dimensions " << leRect.get_Width() << "x" << leRect.get_Height() << ", X=" << leRect.get_X()
<< " Y=" << leRect.get_Y() << std::endl;
std::cout << tabs << " Page " << layoutEnumerator->get_PageIndex() << std::endl;
}

◆ get_Type()

Aspose::Words::Layout::LayoutEntityType Aspose::Words::Layout::LayoutEnumerator::get_Type ( )

Gets the type of the current entity.

Examples

Shows ways of traversing a document's layout entities.

void LayoutEnumerator_()
{
// 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.
// Each layout entity has a rectangular space that it occupies in the document body.
auto doc = MakeObject<Document>(MyDir + u"Layout entities.docx");
// Create an enumerator that can traverse these entities like a tree.
auto layoutEnumerator = MakeObject<LayoutEnumerator>(doc);
ASPOSE_ASSERT_EQ(doc, layoutEnumerator->get_Document());
layoutEnumerator->MoveParent(LayoutEntityType::Page);
ASSERT_EQ(LayoutEntityType::Page, layoutEnumerator->get_Type());
ASSERT_THROW(layoutEnumerator->get_Text(), System::InvalidOperationException);
// We can call this method to make sure that the enumerator will be at the first layout entity.
layoutEnumerator->Reset();
// There are two orders that determine how the layout enumerator continues traversing layout entities
// when it encounters entities that span across multiple pages.
// 1 - In visual order:
// When moving through an entity's children that span multiple pages,
// page layout takes precedence, and we move to other child elements on this page and avoid the ones on the next.
std::cout << "Traversing from first to last, elements between pages separated:" << std::endl;
TraverseLayoutForward(layoutEnumerator, 1);
// Our enumerator is now at the end of the collection. We can traverse the layout entities backwards to go back to the beginning.
std::cout << "Traversing from last to first, elements between pages separated:" << std::endl;
TraverseLayoutBackward(layoutEnumerator, 1);
// 2 - In logical order:
// When moving through an entity's children that span multiple pages,
// the enumerator will move between pages to traverse all the child entities.
std::cout << "Traversing from first to last, elements between pages mixed:" << std::endl;
TraverseLayoutForwardLogical(layoutEnumerator, 1);
std::cout << "Traversing from last to first, elements between pages mixed:" << std::endl;
TraverseLayoutBackwardLogical(layoutEnumerator, 1);
}
static void TraverseLayoutForward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNext());
}
static void TraverseLayoutBackward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePrevious());
}
static void TraverseLayoutForwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNextLogical());
}
static void TraverseLayoutBackwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePreviousLogical());
}
static void PrintCurrentEntity(SharedPtr<LayoutEnumerator> layoutEnumerator, int indent)
{
String tabs(u'\t', indent);
std::cout << (layoutEnumerator->get_Kind() == String::Empty
? String::Format(u"{0}-> Entity type: {1}", tabs, layoutEnumerator->get_Type())
: String::Format(u"{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator->get_Type(), layoutEnumerator->get_Kind()))
<< std::endl;
// Only spans can contain text.
if (layoutEnumerator->get_Type() == LayoutEntityType::Span)
{
std::cout << tabs << " Span contents: \"" << layoutEnumerator->get_Text() << "\"" << std::endl;
}
System::Drawing::RectangleF leRect = layoutEnumerator->get_Rectangle();
std::cout << tabs << " Rectangle dimensions " << leRect.get_Width() << "x" << leRect.get_Height() << ", X=" << leRect.get_X()
<< " Y=" << leRect.get_Y() << std::endl;
std::cout << tabs << " Page " << layoutEnumerator->get_PageIndex() << std::endl;
}

◆ GetType()

virtual const System::TypeInfo& Aspose::Words::Layout::LayoutEnumerator::GetType ( ) const
overridevirtual

Reimplemented from System::Object.

◆ Is()

virtual bool Aspose::Words::Layout::LayoutEnumerator::Is ( const System::TypeInfo target) const
overridevirtual

Reimplemented from System::Object.

◆ MoveFirstChild()

bool Aspose::Words::Layout::LayoutEnumerator::MoveFirstChild ( )

Moves to the first child entity.

Examples

Shows ways of traversing a document's layout entities.

void LayoutEnumerator_()
{
// 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.
// Each layout entity has a rectangular space that it occupies in the document body.
auto doc = MakeObject<Document>(MyDir + u"Layout entities.docx");
// Create an enumerator that can traverse these entities like a tree.
auto layoutEnumerator = MakeObject<LayoutEnumerator>(doc);
ASPOSE_ASSERT_EQ(doc, layoutEnumerator->get_Document());
layoutEnumerator->MoveParent(LayoutEntityType::Page);
ASSERT_EQ(LayoutEntityType::Page, layoutEnumerator->get_Type());
ASSERT_THROW(layoutEnumerator->get_Text(), System::InvalidOperationException);
// We can call this method to make sure that the enumerator will be at the first layout entity.
layoutEnumerator->Reset();
// There are two orders that determine how the layout enumerator continues traversing layout entities
// when it encounters entities that span across multiple pages.
// 1 - In visual order:
// When moving through an entity's children that span multiple pages,
// page layout takes precedence, and we move to other child elements on this page and avoid the ones on the next.
std::cout << "Traversing from first to last, elements between pages separated:" << std::endl;
TraverseLayoutForward(layoutEnumerator, 1);
// Our enumerator is now at the end of the collection. We can traverse the layout entities backwards to go back to the beginning.
std::cout << "Traversing from last to first, elements between pages separated:" << std::endl;
TraverseLayoutBackward(layoutEnumerator, 1);
// 2 - In logical order:
// When moving through an entity's children that span multiple pages,
// the enumerator will move between pages to traverse all the child entities.
std::cout << "Traversing from first to last, elements between pages mixed:" << std::endl;
TraverseLayoutForwardLogical(layoutEnumerator, 1);
std::cout << "Traversing from last to first, elements between pages mixed:" << std::endl;
TraverseLayoutBackwardLogical(layoutEnumerator, 1);
}
static void TraverseLayoutForward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNext());
}
static void TraverseLayoutBackward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePrevious());
}
static void TraverseLayoutForwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNextLogical());
}
static void TraverseLayoutBackwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePreviousLogical());
}
static void PrintCurrentEntity(SharedPtr<LayoutEnumerator> layoutEnumerator, int indent)
{
String tabs(u'\t', indent);
std::cout << (layoutEnumerator->get_Kind() == String::Empty
? String::Format(u"{0}-> Entity type: {1}", tabs, layoutEnumerator->get_Type())
: String::Format(u"{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator->get_Type(), layoutEnumerator->get_Kind()))
<< std::endl;
// Only spans can contain text.
if (layoutEnumerator->get_Type() == LayoutEntityType::Span)
{
std::cout << tabs << " Span contents: \"" << layoutEnumerator->get_Text() << "\"" << std::endl;
}
System::Drawing::RectangleF leRect = layoutEnumerator->get_Rectangle();
std::cout << tabs << " Rectangle dimensions " << leRect.get_Width() << "x" << leRect.get_Height() << ", X=" << leRect.get_X()
<< " Y=" << leRect.get_Y() << std::endl;
std::cout << tabs << " Page " << layoutEnumerator->get_PageIndex() << std::endl;
}

◆ MoveLastChild()

bool Aspose::Words::Layout::LayoutEnumerator::MoveLastChild ( )

Moves to the last child entity.

Examples

Shows ways of traversing a document's layout entities.

void LayoutEnumerator_()
{
// 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.
// Each layout entity has a rectangular space that it occupies in the document body.
auto doc = MakeObject<Document>(MyDir + u"Layout entities.docx");
// Create an enumerator that can traverse these entities like a tree.
auto layoutEnumerator = MakeObject<LayoutEnumerator>(doc);
ASPOSE_ASSERT_EQ(doc, layoutEnumerator->get_Document());
layoutEnumerator->MoveParent(LayoutEntityType::Page);
ASSERT_EQ(LayoutEntityType::Page, layoutEnumerator->get_Type());
ASSERT_THROW(layoutEnumerator->get_Text(), System::InvalidOperationException);
// We can call this method to make sure that the enumerator will be at the first layout entity.
layoutEnumerator->Reset();
// There are two orders that determine how the layout enumerator continues traversing layout entities
// when it encounters entities that span across multiple pages.
// 1 - In visual order:
// When moving through an entity's children that span multiple pages,
// page layout takes precedence, and we move to other child elements on this page and avoid the ones on the next.
std::cout << "Traversing from first to last, elements between pages separated:" << std::endl;
TraverseLayoutForward(layoutEnumerator, 1);
// Our enumerator is now at the end of the collection. We can traverse the layout entities backwards to go back to the beginning.
std::cout << "Traversing from last to first, elements between pages separated:" << std::endl;
TraverseLayoutBackward(layoutEnumerator, 1);
// 2 - In logical order:
// When moving through an entity's children that span multiple pages,
// the enumerator will move between pages to traverse all the child entities.
std::cout << "Traversing from first to last, elements between pages mixed:" << std::endl;
TraverseLayoutForwardLogical(layoutEnumerator, 1);
std::cout << "Traversing from last to first, elements between pages mixed:" << std::endl;
TraverseLayoutBackwardLogical(layoutEnumerator, 1);
}
static void TraverseLayoutForward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNext());
}
static void TraverseLayoutBackward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePrevious());
}
static void TraverseLayoutForwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNextLogical());
}
static void TraverseLayoutBackwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePreviousLogical());
}
static void PrintCurrentEntity(SharedPtr<LayoutEnumerator> layoutEnumerator, int indent)
{
String tabs(u'\t', indent);
std::cout << (layoutEnumerator->get_Kind() == String::Empty
? String::Format(u"{0}-> Entity type: {1}", tabs, layoutEnumerator->get_Type())
: String::Format(u"{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator->get_Type(), layoutEnumerator->get_Kind()))
<< std::endl;
// Only spans can contain text.
if (layoutEnumerator->get_Type() == LayoutEntityType::Span)
{
std::cout << tabs << " Span contents: \"" << layoutEnumerator->get_Text() << "\"" << std::endl;
}
System::Drawing::RectangleF leRect = layoutEnumerator->get_Rectangle();
std::cout << tabs << " Rectangle dimensions " << leRect.get_Width() << "x" << leRect.get_Height() << ", X=" << leRect.get_X()
<< " Y=" << leRect.get_Y() << std::endl;
std::cout << tabs << " Page " << layoutEnumerator->get_PageIndex() << std::endl;
}

◆ MoveNext()

bool Aspose::Words::Layout::LayoutEnumerator::MoveNext ( )

Moves to the next sibling entity in visual order. When iterating lines of a paragraph broken across pages this method will not move to the next page but rather move to the next entity on the same page.

Examples

Shows ways of traversing a document's layout entities.

void LayoutEnumerator_()
{
// 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.
// Each layout entity has a rectangular space that it occupies in the document body.
auto doc = MakeObject<Document>(MyDir + u"Layout entities.docx");
// Create an enumerator that can traverse these entities like a tree.
auto layoutEnumerator = MakeObject<LayoutEnumerator>(doc);
ASPOSE_ASSERT_EQ(doc, layoutEnumerator->get_Document());
layoutEnumerator->MoveParent(LayoutEntityType::Page);
ASSERT_EQ(LayoutEntityType::Page, layoutEnumerator->get_Type());
ASSERT_THROW(layoutEnumerator->get_Text(), System::InvalidOperationException);
// We can call this method to make sure that the enumerator will be at the first layout entity.
layoutEnumerator->Reset();
// There are two orders that determine how the layout enumerator continues traversing layout entities
// when it encounters entities that span across multiple pages.
// 1 - In visual order:
// When moving through an entity's children that span multiple pages,
// page layout takes precedence, and we move to other child elements on this page and avoid the ones on the next.
std::cout << "Traversing from first to last, elements between pages separated:" << std::endl;
TraverseLayoutForward(layoutEnumerator, 1);
// Our enumerator is now at the end of the collection. We can traverse the layout entities backwards to go back to the beginning.
std::cout << "Traversing from last to first, elements between pages separated:" << std::endl;
TraverseLayoutBackward(layoutEnumerator, 1);
// 2 - In logical order:
// When moving through an entity's children that span multiple pages,
// the enumerator will move between pages to traverse all the child entities.
std::cout << "Traversing from first to last, elements between pages mixed:" << std::endl;
TraverseLayoutForwardLogical(layoutEnumerator, 1);
std::cout << "Traversing from last to first, elements between pages mixed:" << std::endl;
TraverseLayoutBackwardLogical(layoutEnumerator, 1);
}
static void TraverseLayoutForward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNext());
}
static void TraverseLayoutBackward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePrevious());
}
static void TraverseLayoutForwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNextLogical());
}
static void TraverseLayoutBackwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePreviousLogical());
}
static void PrintCurrentEntity(SharedPtr<LayoutEnumerator> layoutEnumerator, int indent)
{
String tabs(u'\t', indent);
std::cout << (layoutEnumerator->get_Kind() == String::Empty
? String::Format(u"{0}-> Entity type: {1}", tabs, layoutEnumerator->get_Type())
: String::Format(u"{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator->get_Type(), layoutEnumerator->get_Kind()))
<< std::endl;
// Only spans can contain text.
if (layoutEnumerator->get_Type() == LayoutEntityType::Span)
{
std::cout << tabs << " Span contents: \"" << layoutEnumerator->get_Text() << "\"" << std::endl;
}
System::Drawing::RectangleF leRect = layoutEnumerator->get_Rectangle();
std::cout << tabs << " Rectangle dimensions " << leRect.get_Width() << "x" << leRect.get_Height() << ", X=" << leRect.get_X()
<< " Y=" << leRect.get_Y() << std::endl;
std::cout << tabs << " Page " << layoutEnumerator->get_PageIndex() << std::endl;
}

◆ MoveNextLogical()

bool Aspose::Words::Layout::LayoutEnumerator::MoveNextLogical ( )

Moves to the next sibling entity in a logical order. When iterating lines of a paragraph broken across pages this method will move to the next line even if it resides on another page.

Examples

Shows ways of traversing a document's layout entities.

void LayoutEnumerator_()
{
// 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.
// Each layout entity has a rectangular space that it occupies in the document body.
auto doc = MakeObject<Document>(MyDir + u"Layout entities.docx");
// Create an enumerator that can traverse these entities like a tree.
auto layoutEnumerator = MakeObject<LayoutEnumerator>(doc);
ASPOSE_ASSERT_EQ(doc, layoutEnumerator->get_Document());
layoutEnumerator->MoveParent(LayoutEntityType::Page);
ASSERT_EQ(LayoutEntityType::Page, layoutEnumerator->get_Type());
ASSERT_THROW(layoutEnumerator->get_Text(), System::InvalidOperationException);
// We can call this method to make sure that the enumerator will be at the first layout entity.
layoutEnumerator->Reset();
// There are two orders that determine how the layout enumerator continues traversing layout entities
// when it encounters entities that span across multiple pages.
// 1 - In visual order:
// When moving through an entity's children that span multiple pages,
// page layout takes precedence, and we move to other child elements on this page and avoid the ones on the next.
std::cout << "Traversing from first to last, elements between pages separated:" << std::endl;
TraverseLayoutForward(layoutEnumerator, 1);
// Our enumerator is now at the end of the collection. We can traverse the layout entities backwards to go back to the beginning.
std::cout << "Traversing from last to first, elements between pages separated:" << std::endl;
TraverseLayoutBackward(layoutEnumerator, 1);
// 2 - In logical order:
// When moving through an entity's children that span multiple pages,
// the enumerator will move between pages to traverse all the child entities.
std::cout << "Traversing from first to last, elements between pages mixed:" << std::endl;
TraverseLayoutForwardLogical(layoutEnumerator, 1);
std::cout << "Traversing from last to first, elements between pages mixed:" << std::endl;
TraverseLayoutBackwardLogical(layoutEnumerator, 1);
}
static void TraverseLayoutForward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNext());
}
static void TraverseLayoutBackward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePrevious());
}
static void TraverseLayoutForwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNextLogical());
}
static void TraverseLayoutBackwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePreviousLogical());
}
static void PrintCurrentEntity(SharedPtr<LayoutEnumerator> layoutEnumerator, int indent)
{
String tabs(u'\t', indent);
std::cout << (layoutEnumerator->get_Kind() == String::Empty
? String::Format(u"{0}-> Entity type: {1}", tabs, layoutEnumerator->get_Type())
: String::Format(u"{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator->get_Type(), layoutEnumerator->get_Kind()))
<< std::endl;
// Only spans can contain text.
if (layoutEnumerator->get_Type() == LayoutEntityType::Span)
{
std::cout << tabs << " Span contents: \"" << layoutEnumerator->get_Text() << "\"" << std::endl;
}
System::Drawing::RectangleF leRect = layoutEnumerator->get_Rectangle();
std::cout << tabs << " Rectangle dimensions " << leRect.get_Width() << "x" << leRect.get_Height() << ", X=" << leRect.get_X()
<< " Y=" << leRect.get_Y() << std::endl;
std::cout << tabs << " Page " << layoutEnumerator->get_PageIndex() << std::endl;
}

◆ MoveParent() [1/2]

bool Aspose::Words::Layout::LayoutEnumerator::MoveParent ( )

Moves to the parent entity.

Examples

Shows ways of traversing a document's layout entities.

void LayoutEnumerator_()
{
// 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.
// Each layout entity has a rectangular space that it occupies in the document body.
auto doc = MakeObject<Document>(MyDir + u"Layout entities.docx");
// Create an enumerator that can traverse these entities like a tree.
auto layoutEnumerator = MakeObject<LayoutEnumerator>(doc);
ASPOSE_ASSERT_EQ(doc, layoutEnumerator->get_Document());
layoutEnumerator->MoveParent(LayoutEntityType::Page);
ASSERT_EQ(LayoutEntityType::Page, layoutEnumerator->get_Type());
ASSERT_THROW(layoutEnumerator->get_Text(), System::InvalidOperationException);
// We can call this method to make sure that the enumerator will be at the first layout entity.
layoutEnumerator->Reset();
// There are two orders that determine how the layout enumerator continues traversing layout entities
// when it encounters entities that span across multiple pages.
// 1 - In visual order:
// When moving through an entity's children that span multiple pages,
// page layout takes precedence, and we move to other child elements on this page and avoid the ones on the next.
std::cout << "Traversing from first to last, elements between pages separated:" << std::endl;
TraverseLayoutForward(layoutEnumerator, 1);
// Our enumerator is now at the end of the collection. We can traverse the layout entities backwards to go back to the beginning.
std::cout << "Traversing from last to first, elements between pages separated:" << std::endl;
TraverseLayoutBackward(layoutEnumerator, 1);
// 2 - In logical order:
// When moving through an entity's children that span multiple pages,
// the enumerator will move between pages to traverse all the child entities.
std::cout << "Traversing from first to last, elements between pages mixed:" << std::endl;
TraverseLayoutForwardLogical(layoutEnumerator, 1);
std::cout << "Traversing from last to first, elements between pages mixed:" << std::endl;
TraverseLayoutBackwardLogical(layoutEnumerator, 1);
}
static void TraverseLayoutForward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNext());
}
static void TraverseLayoutBackward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePrevious());
}
static void TraverseLayoutForwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNextLogical());
}
static void TraverseLayoutBackwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePreviousLogical());
}
static void PrintCurrentEntity(SharedPtr<LayoutEnumerator> layoutEnumerator, int indent)
{
String tabs(u'\t', indent);
std::cout << (layoutEnumerator->get_Kind() == String::Empty
? String::Format(u"{0}-> Entity type: {1}", tabs, layoutEnumerator->get_Type())
: String::Format(u"{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator->get_Type(), layoutEnumerator->get_Kind()))
<< std::endl;
// Only spans can contain text.
if (layoutEnumerator->get_Type() == LayoutEntityType::Span)
{
std::cout << tabs << " Span contents: \"" << layoutEnumerator->get_Text() << "\"" << std::endl;
}
System::Drawing::RectangleF leRect = layoutEnumerator->get_Rectangle();
std::cout << tabs << " Rectangle dimensions " << leRect.get_Width() << "x" << leRect.get_Height() << ", X=" << leRect.get_X()
<< " Y=" << leRect.get_Y() << std::endl;
std::cout << tabs << " Page " << layoutEnumerator->get_PageIndex() << std::endl;
}

◆ MoveParent() [2/2]

bool Aspose::Words::Layout::LayoutEnumerator::MoveParent ( Aspose::Words::Layout::LayoutEntityType  types)

Moves to the parent entity of the specified type.

Parameters
typesThe parent entity type to move to. Use bitwise-OR to specify multiple parent types.
Examples

Shows ways of traversing a document's layout entities.

void LayoutEnumerator_()
{
// 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.
// Each layout entity has a rectangular space that it occupies in the document body.
auto doc = MakeObject<Document>(MyDir + u"Layout entities.docx");
// Create an enumerator that can traverse these entities like a tree.
auto layoutEnumerator = MakeObject<LayoutEnumerator>(doc);
ASPOSE_ASSERT_EQ(doc, layoutEnumerator->get_Document());
layoutEnumerator->MoveParent(LayoutEntityType::Page);
ASSERT_EQ(LayoutEntityType::Page, layoutEnumerator->get_Type());
ASSERT_THROW(layoutEnumerator->get_Text(), System::InvalidOperationException);
// We can call this method to make sure that the enumerator will be at the first layout entity.
layoutEnumerator->Reset();
// There are two orders that determine how the layout enumerator continues traversing layout entities
// when it encounters entities that span across multiple pages.
// 1 - In visual order:
// When moving through an entity's children that span multiple pages,
// page layout takes precedence, and we move to other child elements on this page and avoid the ones on the next.
std::cout << "Traversing from first to last, elements between pages separated:" << std::endl;
TraverseLayoutForward(layoutEnumerator, 1);
// Our enumerator is now at the end of the collection. We can traverse the layout entities backwards to go back to the beginning.
std::cout << "Traversing from last to first, elements between pages separated:" << std::endl;
TraverseLayoutBackward(layoutEnumerator, 1);
// 2 - In logical order:
// When moving through an entity's children that span multiple pages,
// the enumerator will move between pages to traverse all the child entities.
std::cout << "Traversing from first to last, elements between pages mixed:" << std::endl;
TraverseLayoutForwardLogical(layoutEnumerator, 1);
std::cout << "Traversing from last to first, elements between pages mixed:" << std::endl;
TraverseLayoutBackwardLogical(layoutEnumerator, 1);
}
static void TraverseLayoutForward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNext());
}
static void TraverseLayoutBackward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePrevious());
}
static void TraverseLayoutForwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNextLogical());
}
static void TraverseLayoutBackwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePreviousLogical());
}
static void PrintCurrentEntity(SharedPtr<LayoutEnumerator> layoutEnumerator, int indent)
{
String tabs(u'\t', indent);
std::cout << (layoutEnumerator->get_Kind() == String::Empty
? String::Format(u"{0}-> Entity type: {1}", tabs, layoutEnumerator->get_Type())
: String::Format(u"{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator->get_Type(), layoutEnumerator->get_Kind()))
<< std::endl;
// Only spans can contain text.
if (layoutEnumerator->get_Type() == LayoutEntityType::Span)
{
std::cout << tabs << " Span contents: \"" << layoutEnumerator->get_Text() << "\"" << std::endl;
}
System::Drawing::RectangleF leRect = layoutEnumerator->get_Rectangle();
std::cout << tabs << " Rectangle dimensions " << leRect.get_Width() << "x" << leRect.get_Height() << ", X=" << leRect.get_X()
<< " Y=" << leRect.get_Y() << std::endl;
std::cout << tabs << " Page " << layoutEnumerator->get_PageIndex() << std::endl;
}

◆ MovePrevious()

bool Aspose::Words::Layout::LayoutEnumerator::MovePrevious ( )

Moves to the previous sibling entity.

Examples

Shows ways of traversing a document's layout entities.

void LayoutEnumerator_()
{
// 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.
// Each layout entity has a rectangular space that it occupies in the document body.
auto doc = MakeObject<Document>(MyDir + u"Layout entities.docx");
// Create an enumerator that can traverse these entities like a tree.
auto layoutEnumerator = MakeObject<LayoutEnumerator>(doc);
ASPOSE_ASSERT_EQ(doc, layoutEnumerator->get_Document());
layoutEnumerator->MoveParent(LayoutEntityType::Page);
ASSERT_EQ(LayoutEntityType::Page, layoutEnumerator->get_Type());
ASSERT_THROW(layoutEnumerator->get_Text(), System::InvalidOperationException);
// We can call this method to make sure that the enumerator will be at the first layout entity.
layoutEnumerator->Reset();
// There are two orders that determine how the layout enumerator continues traversing layout entities
// when it encounters entities that span across multiple pages.
// 1 - In visual order:
// When moving through an entity's children that span multiple pages,
// page layout takes precedence, and we move to other child elements on this page and avoid the ones on the next.
std::cout << "Traversing from first to last, elements between pages separated:" << std::endl;
TraverseLayoutForward(layoutEnumerator, 1);
// Our enumerator is now at the end of the collection. We can traverse the layout entities backwards to go back to the beginning.
std::cout << "Traversing from last to first, elements between pages separated:" << std::endl;
TraverseLayoutBackward(layoutEnumerator, 1);
// 2 - In logical order:
// When moving through an entity's children that span multiple pages,
// the enumerator will move between pages to traverse all the child entities.
std::cout << "Traversing from first to last, elements between pages mixed:" << std::endl;
TraverseLayoutForwardLogical(layoutEnumerator, 1);
std::cout << "Traversing from last to first, elements between pages mixed:" << std::endl;
TraverseLayoutBackwardLogical(layoutEnumerator, 1);
}
static void TraverseLayoutForward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNext());
}
static void TraverseLayoutBackward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePrevious());
}
static void TraverseLayoutForwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNextLogical());
}
static void TraverseLayoutBackwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePreviousLogical());
}
static void PrintCurrentEntity(SharedPtr<LayoutEnumerator> layoutEnumerator, int indent)
{
String tabs(u'\t', indent);
std::cout << (layoutEnumerator->get_Kind() == String::Empty
? String::Format(u"{0}-> Entity type: {1}", tabs, layoutEnumerator->get_Type())
: String::Format(u"{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator->get_Type(), layoutEnumerator->get_Kind()))
<< std::endl;
// Only spans can contain text.
if (layoutEnumerator->get_Type() == LayoutEntityType::Span)
{
std::cout << tabs << " Span contents: \"" << layoutEnumerator->get_Text() << "\"" << std::endl;
}
System::Drawing::RectangleF leRect = layoutEnumerator->get_Rectangle();
std::cout << tabs << " Rectangle dimensions " << leRect.get_Width() << "x" << leRect.get_Height() << ", X=" << leRect.get_X()
<< " Y=" << leRect.get_Y() << std::endl;
std::cout << tabs << " Page " << layoutEnumerator->get_PageIndex() << std::endl;
}

◆ MovePreviousLogical()

bool Aspose::Words::Layout::LayoutEnumerator::MovePreviousLogical ( )

Moves to the previous sibling entity in a logical order. When iterating lines of a paragraph broken across pages this method will move to the previous line even if it resides on another page.

Examples

Shows ways of traversing a document's layout entities.

void LayoutEnumerator_()
{
// 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.
// Each layout entity has a rectangular space that it occupies in the document body.
auto doc = MakeObject<Document>(MyDir + u"Layout entities.docx");
// Create an enumerator that can traverse these entities like a tree.
auto layoutEnumerator = MakeObject<LayoutEnumerator>(doc);
ASPOSE_ASSERT_EQ(doc, layoutEnumerator->get_Document());
layoutEnumerator->MoveParent(LayoutEntityType::Page);
ASSERT_EQ(LayoutEntityType::Page, layoutEnumerator->get_Type());
ASSERT_THROW(layoutEnumerator->get_Text(), System::InvalidOperationException);
// We can call this method to make sure that the enumerator will be at the first layout entity.
layoutEnumerator->Reset();
// There are two orders that determine how the layout enumerator continues traversing layout entities
// when it encounters entities that span across multiple pages.
// 1 - In visual order:
// When moving through an entity's children that span multiple pages,
// page layout takes precedence, and we move to other child elements on this page and avoid the ones on the next.
std::cout << "Traversing from first to last, elements between pages separated:" << std::endl;
TraverseLayoutForward(layoutEnumerator, 1);
// Our enumerator is now at the end of the collection. We can traverse the layout entities backwards to go back to the beginning.
std::cout << "Traversing from last to first, elements between pages separated:" << std::endl;
TraverseLayoutBackward(layoutEnumerator, 1);
// 2 - In logical order:
// When moving through an entity's children that span multiple pages,
// the enumerator will move between pages to traverse all the child entities.
std::cout << "Traversing from first to last, elements between pages mixed:" << std::endl;
TraverseLayoutForwardLogical(layoutEnumerator, 1);
std::cout << "Traversing from last to first, elements between pages mixed:" << std::endl;
TraverseLayoutBackwardLogical(layoutEnumerator, 1);
}
static void TraverseLayoutForward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNext());
}
static void TraverseLayoutBackward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePrevious());
}
static void TraverseLayoutForwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNextLogical());
}
static void TraverseLayoutBackwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePreviousLogical());
}
static void PrintCurrentEntity(SharedPtr<LayoutEnumerator> layoutEnumerator, int indent)
{
String tabs(u'\t', indent);
std::cout << (layoutEnumerator->get_Kind() == String::Empty
? String::Format(u"{0}-> Entity type: {1}", tabs, layoutEnumerator->get_Type())
: String::Format(u"{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator->get_Type(), layoutEnumerator->get_Kind()))
<< std::endl;
// Only spans can contain text.
if (layoutEnumerator->get_Type() == LayoutEntityType::Span)
{
std::cout << tabs << " Span contents: \"" << layoutEnumerator->get_Text() << "\"" << std::endl;
}
System::Drawing::RectangleF leRect = layoutEnumerator->get_Rectangle();
std::cout << tabs << " Rectangle dimensions " << leRect.get_Width() << "x" << leRect.get_Height() << ", X=" << leRect.get_X()
<< " Y=" << leRect.get_Y() << std::endl;
std::cout << tabs << " Page " << layoutEnumerator->get_PageIndex() << std::endl;
}

◆ Reset()

void Aspose::Words::Layout::LayoutEnumerator::Reset ( )

Moves the enumerator to the first page of the document.

Examples

Shows ways of traversing a document's layout entities.

void LayoutEnumerator_()
{
// 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.
// Each layout entity has a rectangular space that it occupies in the document body.
auto doc = MakeObject<Document>(MyDir + u"Layout entities.docx");
// Create an enumerator that can traverse these entities like a tree.
auto layoutEnumerator = MakeObject<LayoutEnumerator>(doc);
ASPOSE_ASSERT_EQ(doc, layoutEnumerator->get_Document());
layoutEnumerator->MoveParent(LayoutEntityType::Page);
ASSERT_EQ(LayoutEntityType::Page, layoutEnumerator->get_Type());
ASSERT_THROW(layoutEnumerator->get_Text(), System::InvalidOperationException);
// We can call this method to make sure that the enumerator will be at the first layout entity.
layoutEnumerator->Reset();
// There are two orders that determine how the layout enumerator continues traversing layout entities
// when it encounters entities that span across multiple pages.
// 1 - In visual order:
// When moving through an entity's children that span multiple pages,
// page layout takes precedence, and we move to other child elements on this page and avoid the ones on the next.
std::cout << "Traversing from first to last, elements between pages separated:" << std::endl;
TraverseLayoutForward(layoutEnumerator, 1);
// Our enumerator is now at the end of the collection. We can traverse the layout entities backwards to go back to the beginning.
std::cout << "Traversing from last to first, elements between pages separated:" << std::endl;
TraverseLayoutBackward(layoutEnumerator, 1);
// 2 - In logical order:
// When moving through an entity's children that span multiple pages,
// the enumerator will move between pages to traverse all the child entities.
std::cout << "Traversing from first to last, elements between pages mixed:" << std::endl;
TraverseLayoutForwardLogical(layoutEnumerator, 1);
std::cout << "Traversing from last to first, elements between pages mixed:" << std::endl;
TraverseLayoutBackwardLogical(layoutEnumerator, 1);
}
static void TraverseLayoutForward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNext());
}
static void TraverseLayoutBackward(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackward(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePrevious());
}
static void TraverseLayoutForwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveFirstChild())
{
TraverseLayoutForwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MoveNextLogical());
}
static void TraverseLayoutBackwardLogical(SharedPtr<LayoutEnumerator> layoutEnumerator, int depth)
{
do
{
PrintCurrentEntity(layoutEnumerator, depth);
if (layoutEnumerator->MoveLastChild())
{
TraverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
layoutEnumerator->MoveParent();
}
} while (layoutEnumerator->MovePreviousLogical());
}
static void PrintCurrentEntity(SharedPtr<LayoutEnumerator> layoutEnumerator, int indent)
{
String tabs(u'\t', indent);
std::cout << (layoutEnumerator->get_Kind() == String::Empty
? String::Format(u"{0}-> Entity type: {1}", tabs, layoutEnumerator->get_Type())
: String::Format(u"{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator->get_Type(), layoutEnumerator->get_Kind()))
<< std::endl;
// Only spans can contain text.
if (layoutEnumerator->get_Type() == LayoutEntityType::Span)
{
std::cout << tabs << " Span contents: \"" << layoutEnumerator->get_Text() << "\"" << std::endl;
}
System::Drawing::RectangleF leRect = layoutEnumerator->get_Rectangle();
std::cout << tabs << " Rectangle dimensions " << leRect.get_Width() << "x" << leRect.get_Height() << ", X=" << leRect.get_X()
<< " Y=" << leRect.get_Y() << std::endl;
std::cout << tabs << " Page " << layoutEnumerator->get_PageIndex() << std::endl;
}

◆ set_Current()

void Aspose::Words::Layout::LayoutEnumerator::set_Current ( const System::SharedPtr< System::Object > &  value)

◆ Type()

static const System::TypeInfo& Aspose::Words::Layout::LayoutEnumerator::Type ( )
static