search/mag_sel search/close
Aspose::Words::TabStop Class Referencefinal

Represents a single custom tab stop. The TabStop object is a member of the TabStopCollection collection.

Normally, a tab stop specifies a position where a tab stop exists. But because tab stops can be inherited from parent styles, it might be needed for the child object to define explicitly that there is no tab stop at a given position. To clear an inherited tab stop at a given position, create a TabStop object and set Alignment to TabAlignment.Clear.

For more information see TabStopCollection.

See also
Aspose::Words::ParagraphFormat
Aspose::Words::TabStopCollection
Aspose::Words::Document::get_DefaultTabStop
Examples

Shows how to modify the position of the right tab stop in TOC related paragraphs.

auto doc = MakeObject<Document>(MyDir + u"Table of contents.docx");
// Iterate through all paragraphs with TOC result-based styles; this is any style between TOC and TOC9.
for (const auto& para : System::IterateOver(doc->GetChildNodes(NodeType::Paragraph, true)->LINQ_OfType<SharedPtr<Paragraph>>()))
{
if (para->get_ParagraphFormat()->get_Style()->get_StyleIdentifier() >= StyleIdentifier::Toc1 &&
para->get_ParagraphFormat()->get_Style()->get_StyleIdentifier() <= StyleIdentifier::Toc9)
{
// Get the first tab used in this paragraph, this should be the tab used to align the page numbers.
SharedPtr<TabStop> tab = para->get_ParagraphFormat()->get_TabStops()->idx_get(0);
// Replace the first default tab, stop with a custom tab stop.
para->get_ParagraphFormat()->get_TabStops()->RemoveByPosition(tab->get_Position());
para->get_ParagraphFormat()->get_TabStops()->Add(tab->get_Position() - 50, tab->get_Alignment(), tab->get_Leader());
}
}
doc->Save(ArtifactsDir + u"Styles.ChangeTocsTabStops.docx");

#include <Aspose.Words.Cpp/TabStop.h>

+ Inheritance diagram for Aspose::Words::TabStop:

Public Member Functions

 TabStop (double position)
 Initializes a new instance of this class. More...
 
 TabStop (double position, TabAlignment alignment, TabLeader leader)
 Initializes a new instance of this class. More...
 
bool Equals (SharedPtr< TabStop > rhs)
 Compares with the specified TabStop. More...
 
TabAlignment get_Alignment () const
 Gets or sets the alignment of text at this tab stop. More...
 
bool get_IsClear ()
 Returns true if this tab stop clears any existing tab stops in this position. More...
 
TabLeader get_Leader () const
 Gets or sets the type of the leader line displayed under the tab character. More...
 
double get_Position ()
 Gets the position of the tab stop in points. More...
 
int32_t GetHashCode () const override
 Calculates hash code for this object. More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
void set_Alignment (TabAlignment value)
 Setter for get_Alignment. More...
 
void set_Leader (TabLeader value)
 Setter for get_Leader. More...
 

Static Public Member Functions

static const TypeInfoType ()
 

Constructor & Destructor Documentation

◆ TabStop() [1/2]

Aspose::Words::TabStop::TabStop ( double  position)

Initializes a new instance of this class.

Examples

Shows how to work with a document's collection of tab stops.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<TabStopCollection> tabStops = builder->get_ParagraphFormat()->get_TabStops();
// 72 points is one "inch" on the Microsoft Word tab stop ruler.
tabStops->Add(MakeObject<TabStop>(72.0));
tabStops->Add(MakeObject<TabStop>(432.0, TabAlignment::Right, TabLeader::Dashes));
ASSERT_EQ(2, tabStops->get_Count());
ASSERT_FALSE(tabStops->idx_get(0)->get_IsClear());
ASSERT_FALSE(System::ObjectExt::Equals(tabStops->idx_get(0), tabStops->idx_get(1)));
// Every "tab" character takes the builder's cursor to the location of the next tab stop.
builder->Writeln(u"Start\tTab 1\tTab 2");
SharedPtr<ParagraphCollection> paragraphs = doc->get_FirstSection()->get_Body()->get_Paragraphs();
ASSERT_EQ(2, paragraphs->get_Count());
// Each paragraph gets its tab stop collection, which clones its values from the document builder's tab stop collection.
ASPOSE_ASSERT_EQ(paragraphs->idx_get(0)->get_ParagraphFormat()->get_TabStops(), paragraphs->idx_get(1)->get_ParagraphFormat()->get_TabStops());
ASPOSE_ASSERT_NS(paragraphs->idx_get(0)->get_ParagraphFormat()->get_TabStops(), paragraphs->idx_get(1)->get_ParagraphFormat()->get_TabStops());
// A tab stop collection can point us to TabStops before and after certain positions.
ASPOSE_ASSERT_EQ(72.0, tabStops->Before(100.0)->get_Position());
ASPOSE_ASSERT_EQ(432.0, tabStops->After(100.0)->get_Position());
// We can clear a paragraph's tab stop collection to revert to the default tabbing behavior.
paragraphs->idx_get(1)->get_ParagraphFormat()->get_TabStops()->Clear();
ASSERT_EQ(0, paragraphs->idx_get(1)->get_ParagraphFormat()->get_TabStops()->get_Count());
doc->Save(ArtifactsDir + u"TabStopCollection.TabStopCollection.docx");

◆ TabStop() [2/2]

Aspose::Words::TabStop::TabStop ( double  position,
Aspose::Words::TabAlignment  alignment,
Aspose::Words::TabLeader  leader 
)

Initializes a new instance of this class.

Parameters
positionThe position of the tab stop in points.
alignmentA TabAlignment value that specifies the alignment of text at this tab stop.
leaderA TabLeader value that specifies the type of the leader line displayed under the tab character.
Examples

Shows how to work with a document's collection of tab stops.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<TabStopCollection> tabStops = builder->get_ParagraphFormat()->get_TabStops();
// 72 points is one "inch" on the Microsoft Word tab stop ruler.
tabStops->Add(MakeObject<TabStop>(72.0));
tabStops->Add(MakeObject<TabStop>(432.0, TabAlignment::Right, TabLeader::Dashes));
ASSERT_EQ(2, tabStops->get_Count());
ASSERT_FALSE(tabStops->idx_get(0)->get_IsClear());
ASSERT_FALSE(System::ObjectExt::Equals(tabStops->idx_get(0), tabStops->idx_get(1)));
// Every "tab" character takes the builder's cursor to the location of the next tab stop.
builder->Writeln(u"Start\tTab 1\tTab 2");
SharedPtr<ParagraphCollection> paragraphs = doc->get_FirstSection()->get_Body()->get_Paragraphs();
ASSERT_EQ(2, paragraphs->get_Count());
// Each paragraph gets its tab stop collection, which clones its values from the document builder's tab stop collection.
ASPOSE_ASSERT_EQ(paragraphs->idx_get(0)->get_ParagraphFormat()->get_TabStops(), paragraphs->idx_get(1)->get_ParagraphFormat()->get_TabStops());
ASPOSE_ASSERT_NS(paragraphs->idx_get(0)->get_ParagraphFormat()->get_TabStops(), paragraphs->idx_get(1)->get_ParagraphFormat()->get_TabStops());
// A tab stop collection can point us to TabStops before and after certain positions.
ASPOSE_ASSERT_EQ(72.0, tabStops->Before(100.0)->get_Position());
ASPOSE_ASSERT_EQ(432.0, tabStops->After(100.0)->get_Position());
// We can clear a paragraph's tab stop collection to revert to the default tabbing behavior.
paragraphs->idx_get(1)->get_ParagraphFormat()->get_TabStops()->Clear();
ASSERT_EQ(0, paragraphs->idx_get(1)->get_ParagraphFormat()->get_TabStops()->get_Count());
doc->Save(ArtifactsDir + u"TabStopCollection.TabStopCollection.docx");

Member Function Documentation

◆ Equals()

bool Aspose::Words::TabStop::Equals ( System::SharedPtr< Aspose::Words::TabStop rhs)

Compares with the specified TabStop.

Examples

Shows how to work with a document's collection of tab stops.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<TabStopCollection> tabStops = builder->get_ParagraphFormat()->get_TabStops();
// 72 points is one "inch" on the Microsoft Word tab stop ruler.
tabStops->Add(MakeObject<TabStop>(72.0));
tabStops->Add(MakeObject<TabStop>(432.0, TabAlignment::Right, TabLeader::Dashes));
ASSERT_EQ(2, tabStops->get_Count());
ASSERT_FALSE(tabStops->idx_get(0)->get_IsClear());
ASSERT_FALSE(System::ObjectExt::Equals(tabStops->idx_get(0), tabStops->idx_get(1)));
// Every "tab" character takes the builder's cursor to the location of the next tab stop.
builder->Writeln(u"Start\tTab 1\tTab 2");
SharedPtr<ParagraphCollection> paragraphs = doc->get_FirstSection()->get_Body()->get_Paragraphs();
ASSERT_EQ(2, paragraphs->get_Count());
// Each paragraph gets its tab stop collection, which clones its values from the document builder's tab stop collection.
ASPOSE_ASSERT_EQ(paragraphs->idx_get(0)->get_ParagraphFormat()->get_TabStops(), paragraphs->idx_get(1)->get_ParagraphFormat()->get_TabStops());
ASPOSE_ASSERT_NS(paragraphs->idx_get(0)->get_ParagraphFormat()->get_TabStops(), paragraphs->idx_get(1)->get_ParagraphFormat()->get_TabStops());
// A tab stop collection can point us to TabStops before and after certain positions.
ASPOSE_ASSERT_EQ(72.0, tabStops->Before(100.0)->get_Position());
ASPOSE_ASSERT_EQ(432.0, tabStops->After(100.0)->get_Position());
// We can clear a paragraph's tab stop collection to revert to the default tabbing behavior.
paragraphs->idx_get(1)->get_ParagraphFormat()->get_TabStops()->Clear();
ASSERT_EQ(0, paragraphs->idx_get(1)->get_ParagraphFormat()->get_TabStops()->get_Count());
doc->Save(ArtifactsDir + u"TabStopCollection.TabStopCollection.docx");

◆ get_Alignment()

Aspose::Words::TabAlignment Aspose::Words::TabStop::get_Alignment ( ) const

Gets or sets the alignment of text at this tab stop.

Examples

Shows how to modify the position of the right tab stop in TOC related paragraphs.

auto doc = MakeObject<Document>(MyDir + u"Table of contents.docx");
// Iterate through all paragraphs with TOC result-based styles; this is any style between TOC and TOC9.
for (const auto& para : System::IterateOver(doc->GetChildNodes(NodeType::Paragraph, true)->LINQ_OfType<SharedPtr<Paragraph>>()))
{
if (para->get_ParagraphFormat()->get_Style()->get_StyleIdentifier() >= StyleIdentifier::Toc1 &&
para->get_ParagraphFormat()->get_Style()->get_StyleIdentifier() <= StyleIdentifier::Toc9)
{
// Get the first tab used in this paragraph, this should be the tab used to align the page numbers.
SharedPtr<TabStop> tab = para->get_ParagraphFormat()->get_TabStops()->idx_get(0);
// Replace the first default tab, stop with a custom tab stop.
para->get_ParagraphFormat()->get_TabStops()->RemoveByPosition(tab->get_Position());
para->get_ParagraphFormat()->get_TabStops()->Add(tab->get_Position() - 50, tab->get_Alignment(), tab->get_Leader());
}
}
doc->Save(ArtifactsDir + u"Styles.ChangeTocsTabStops.docx");

◆ get_IsClear()

bool Aspose::Words::TabStop::get_IsClear ( )

Returns true if this tab stop clears any existing tab stops in this position.

Examples

Shows how to work with a document's collection of tab stops.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<TabStopCollection> tabStops = builder->get_ParagraphFormat()->get_TabStops();
// 72 points is one "inch" on the Microsoft Word tab stop ruler.
tabStops->Add(MakeObject<TabStop>(72.0));
tabStops->Add(MakeObject<TabStop>(432.0, TabAlignment::Right, TabLeader::Dashes));
ASSERT_EQ(2, tabStops->get_Count());
ASSERT_FALSE(tabStops->idx_get(0)->get_IsClear());
ASSERT_FALSE(System::ObjectExt::Equals(tabStops->idx_get(0), tabStops->idx_get(1)));
// Every "tab" character takes the builder's cursor to the location of the next tab stop.
builder->Writeln(u"Start\tTab 1\tTab 2");
SharedPtr<ParagraphCollection> paragraphs = doc->get_FirstSection()->get_Body()->get_Paragraphs();
ASSERT_EQ(2, paragraphs->get_Count());
// Each paragraph gets its tab stop collection, which clones its values from the document builder's tab stop collection.
ASPOSE_ASSERT_EQ(paragraphs->idx_get(0)->get_ParagraphFormat()->get_TabStops(), paragraphs->idx_get(1)->get_ParagraphFormat()->get_TabStops());
ASPOSE_ASSERT_NS(paragraphs->idx_get(0)->get_ParagraphFormat()->get_TabStops(), paragraphs->idx_get(1)->get_ParagraphFormat()->get_TabStops());
// A tab stop collection can point us to TabStops before and after certain positions.
ASPOSE_ASSERT_EQ(72.0, tabStops->Before(100.0)->get_Position());
ASPOSE_ASSERT_EQ(432.0, tabStops->After(100.0)->get_Position());
// We can clear a paragraph's tab stop collection to revert to the default tabbing behavior.
paragraphs->idx_get(1)->get_ParagraphFormat()->get_TabStops()->Clear();
ASSERT_EQ(0, paragraphs->idx_get(1)->get_ParagraphFormat()->get_TabStops()->get_Count());
doc->Save(ArtifactsDir + u"TabStopCollection.TabStopCollection.docx");

◆ get_Leader()

Aspose::Words::TabLeader Aspose::Words::TabStop::get_Leader ( ) const

Gets or sets the type of the leader line displayed under the tab character.

Examples

Shows how to modify the position of the right tab stop in TOC related paragraphs.

auto doc = MakeObject<Document>(MyDir + u"Table of contents.docx");
// Iterate through all paragraphs with TOC result-based styles; this is any style between TOC and TOC9.
for (const auto& para : System::IterateOver(doc->GetChildNodes(NodeType::Paragraph, true)->LINQ_OfType<SharedPtr<Paragraph>>()))
{
if (para->get_ParagraphFormat()->get_Style()->get_StyleIdentifier() >= StyleIdentifier::Toc1 &&
para->get_ParagraphFormat()->get_Style()->get_StyleIdentifier() <= StyleIdentifier::Toc9)
{
// Get the first tab used in this paragraph, this should be the tab used to align the page numbers.
SharedPtr<TabStop> tab = para->get_ParagraphFormat()->get_TabStops()->idx_get(0);
// Replace the first default tab, stop with a custom tab stop.
para->get_ParagraphFormat()->get_TabStops()->RemoveByPosition(tab->get_Position());
para->get_ParagraphFormat()->get_TabStops()->Add(tab->get_Position() - 50, tab->get_Alignment(), tab->get_Leader());
}
}
doc->Save(ArtifactsDir + u"Styles.ChangeTocsTabStops.docx");

◆ get_Position()

double Aspose::Words::TabStop::get_Position ( )

Gets the position of the tab stop in points.

Examples

Shows how to modify the position of the right tab stop in TOC related paragraphs.

auto doc = MakeObject<Document>(MyDir + u"Table of contents.docx");
// Iterate through all paragraphs with TOC result-based styles; this is any style between TOC and TOC9.
for (const auto& para : System::IterateOver(doc->GetChildNodes(NodeType::Paragraph, true)->LINQ_OfType<SharedPtr<Paragraph>>()))
{
if (para->get_ParagraphFormat()->get_Style()->get_StyleIdentifier() >= StyleIdentifier::Toc1 &&
para->get_ParagraphFormat()->get_Style()->get_StyleIdentifier() <= StyleIdentifier::Toc9)
{
// Get the first tab used in this paragraph, this should be the tab used to align the page numbers.
SharedPtr<TabStop> tab = para->get_ParagraphFormat()->get_TabStops()->idx_get(0);
// Replace the first default tab, stop with a custom tab stop.
para->get_ParagraphFormat()->get_TabStops()->RemoveByPosition(tab->get_Position());
para->get_ParagraphFormat()->get_TabStops()->Add(tab->get_Position() - 50, tab->get_Alignment(), tab->get_Leader());
}
}
doc->Save(ArtifactsDir + u"Styles.ChangeTocsTabStops.docx");

◆ GetHashCode()

int32_t Aspose::Words::TabStop::GetHashCode ( ) const
overridevirtual

Calculates hash code for this object.

Reimplemented from System::Object.

◆ GetType()

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

Reimplemented from System::Object.

◆ Is()

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

Reimplemented from System::Object.

◆ set_Alignment()

void Aspose::Words::TabStop::set_Alignment ( Aspose::Words::TabAlignment  value)

◆ set_Leader()

void Aspose::Words::TabStop::set_Leader ( Aspose::Words::TabLeader  value)

◆ Type()

static const System::TypeInfo& Aspose::Words::TabStop::Type ( )
static