search/mag_sel search/close
Aspose::Words::WarningInfoCollection Class Reference

Represents a typed collection of WarningInfo objects.

You can use this collection object as the simplest form of IWarningCallback implementation to gather all warnings that Aspose.Words generates during a load or save operation. Create an instance of this class and assign it to the WarningCallback or WarningCallback property.

See also
Aspose::Words::WarningInfo
Aspose::Words::IWarningCallback
Examples

Shows how to set the property for finding the closest match for a missing font from the available font sources.

void EnableFontSubstitution()
{
// Open a document that contains text formatted with a font that does not exist in any of our font sources.
auto doc = MakeObject<Document>(MyDir + u"Missing font.docx");
// Assign a callback for handling font substitution warnings.
auto substitutionWarningHandler = MakeObject<ExFontSettings::HandleDocumentSubstitutionWarnings>();
doc->set_WarningCallback(substitutionWarningHandler);
// Set a default font name and enable font substitution.
auto fontSettings = MakeObject<FontSettings>();
fontSettings->get_SubstitutionSettings()->get_DefaultFontSubstitution()->set_DefaultFontName(u"Arial");
;
fontSettings->get_SubstitutionSettings()->get_FontInfoSubstitution()->set_Enabled(true);
// We will get a font substitution warning if we save a document with a missing font.
doc->set_FontSettings(fontSettings);
doc->Save(ArtifactsDir + u"FontSettings.EnableFontSubstitution.pdf");
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<WarningInfo>>> warnings = substitutionWarningHandler->FontWarnings->GetEnumerator();
while (warnings->MoveNext())
{
std::cout << warnings->get_Current()->get_Description() << std::endl;
}
}
// We can also verify warnings in the collection and clear them.
ASSERT_EQ(WarningSource::Layout, substitutionWarningHandler->FontWarnings->idx_get(0)->get_Source());
ASSERT_EQ(u"Font '28 Days Later' has not been found. Using 'Calibri' font instead. Reason: alternative name from document.",
substitutionWarningHandler->FontWarnings->idx_get(0)->get_Description());
substitutionWarningHandler->FontWarnings->Clear();
ASSERT_EQ(0, substitutionWarningHandler->FontWarnings->get_Count());
}
class HandleDocumentSubstitutionWarnings : public IWarningCallback
{
public:
SharedPtr<WarningInfoCollection> FontWarnings;
void Warning(SharedPtr<WarningInfo> info) override
{
if (info->get_WarningType() == WarningType::FontSubstitution)
{
FontWarnings->Warning(info);
}
}
HandleDocumentSubstitutionWarnings() : FontWarnings(MakeObject<WarningInfoCollection>())
{
}
};

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

+ Inheritance diagram for Aspose::Words::WarningInfoCollection:

Public Types

using const_iterator = typename const_iterator
 
using iterator = typename iterator
 
using iterator_holder_type = List< SharedPtr< WarningInfo > >
 

Public Member Functions

 WarningInfoCollection ()
 
const_iterator begin () const noexcept
 
iterator begin () noexcept
 
const_iterator cbegin () const noexcept
 
const_iterator cend () const noexcept
 
void Clear ()
 Removes all elements from the collection. More...
 
const_iterator end () const noexcept
 
iterator end () noexcept
 
int32_t get_Count ()
 Gets the number of elements contained in the collection. More...
 
SharedPtr< IEnumerator< SharedPtr< WarningInfo > > > GetEnumerator () override
 Returns an enumerator object that can be used to iterate over all items in the collection. More...
 
virtual const TypeInfoGetType () const override
 
SharedPtr< WarningInfoidx_get (int32_t index)
 Gets an item at the specified index. More...
 
virtual bool Is (const TypeInfo &target) const override
 
void Warning (SharedPtr< WarningInfo > info) override
 Implements the IWarningCallback interface. Adds a warning to this collection. More...
 

Static Public Member Functions

static const TypeInfoType ()
 

Member Typedef Documentation

◆ const_iterator

◆ iterator

◆ iterator_holder_type

Constructor & Destructor Documentation

◆ WarningInfoCollection()

Aspose::Words::WarningInfoCollection::WarningInfoCollection ( )

Member Function Documentation

◆ begin() [1/2]

const_iterator Aspose::Words::WarningInfoCollection::begin ( ) const
noexcept

◆ begin() [2/2]

iterator Aspose::Words::WarningInfoCollection::begin ( )
noexcept

◆ cbegin()

const_iterator Aspose::Words::WarningInfoCollection::cbegin ( ) const
noexcept

◆ cend()

const_iterator Aspose::Words::WarningInfoCollection::cend ( ) const
noexcept

◆ Clear()

void Aspose::Words::WarningInfoCollection::Clear ( )

Removes all elements from the collection.

Examples

Shows how to set the property for finding the closest match for a missing font from the available font sources.

void EnableFontSubstitution()
{
// Open a document that contains text formatted with a font that does not exist in any of our font sources.
auto doc = MakeObject<Document>(MyDir + u"Missing font.docx");
// Assign a callback for handling font substitution warnings.
auto substitutionWarningHandler = MakeObject<ExFontSettings::HandleDocumentSubstitutionWarnings>();
doc->set_WarningCallback(substitutionWarningHandler);
// Set a default font name and enable font substitution.
auto fontSettings = MakeObject<FontSettings>();
fontSettings->get_SubstitutionSettings()->get_DefaultFontSubstitution()->set_DefaultFontName(u"Arial");
;
fontSettings->get_SubstitutionSettings()->get_FontInfoSubstitution()->set_Enabled(true);
// We will get a font substitution warning if we save a document with a missing font.
doc->set_FontSettings(fontSettings);
doc->Save(ArtifactsDir + u"FontSettings.EnableFontSubstitution.pdf");
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<WarningInfo>>> warnings = substitutionWarningHandler->FontWarnings->GetEnumerator();
while (warnings->MoveNext())
{
std::cout << warnings->get_Current()->get_Description() << std::endl;
}
}
// We can also verify warnings in the collection and clear them.
ASSERT_EQ(WarningSource::Layout, substitutionWarningHandler->FontWarnings->idx_get(0)->get_Source());
ASSERT_EQ(u"Font '28 Days Later' has not been found. Using 'Calibri' font instead. Reason: alternative name from document.",
substitutionWarningHandler->FontWarnings->idx_get(0)->get_Description());
substitutionWarningHandler->FontWarnings->Clear();
ASSERT_EQ(0, substitutionWarningHandler->FontWarnings->get_Count());
}
class HandleDocumentSubstitutionWarnings : public IWarningCallback
{
public:
SharedPtr<WarningInfoCollection> FontWarnings;
void Warning(SharedPtr<WarningInfo> info) override
{
if (info->get_WarningType() == WarningType::FontSubstitution)
{
FontWarnings->Warning(info);
}
}
HandleDocumentSubstitutionWarnings() : FontWarnings(MakeObject<WarningInfoCollection>())
{
}
};

◆ end() [1/2]

const_iterator Aspose::Words::WarningInfoCollection::end ( ) const
noexcept

◆ end() [2/2]

iterator Aspose::Words::WarningInfoCollection::end ( )
noexcept

◆ get_Count()

int32_t Aspose::Words::WarningInfoCollection::get_Count ( )

Gets the number of elements contained in the collection.

◆ GetEnumerator()

System::SharedPtr<System::Collections::Generic::IEnumerator<System::SharedPtr<Aspose::Words::WarningInfo> > > Aspose::Words::WarningInfoCollection::GetEnumerator ( )
override

Returns an enumerator object that can be used to iterate over all items in the collection.

Examples

Shows how to set the property for finding the closest match for a missing font from the available font sources.

void EnableFontSubstitution()
{
// Open a document that contains text formatted with a font that does not exist in any of our font sources.
auto doc = MakeObject<Document>(MyDir + u"Missing font.docx");
// Assign a callback for handling font substitution warnings.
auto substitutionWarningHandler = MakeObject<ExFontSettings::HandleDocumentSubstitutionWarnings>();
doc->set_WarningCallback(substitutionWarningHandler);
// Set a default font name and enable font substitution.
auto fontSettings = MakeObject<FontSettings>();
fontSettings->get_SubstitutionSettings()->get_DefaultFontSubstitution()->set_DefaultFontName(u"Arial");
;
fontSettings->get_SubstitutionSettings()->get_FontInfoSubstitution()->set_Enabled(true);
// We will get a font substitution warning if we save a document with a missing font.
doc->set_FontSettings(fontSettings);
doc->Save(ArtifactsDir + u"FontSettings.EnableFontSubstitution.pdf");
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<WarningInfo>>> warnings = substitutionWarningHandler->FontWarnings->GetEnumerator();
while (warnings->MoveNext())
{
std::cout << warnings->get_Current()->get_Description() << std::endl;
}
}
// We can also verify warnings in the collection and clear them.
ASSERT_EQ(WarningSource::Layout, substitutionWarningHandler->FontWarnings->idx_get(0)->get_Source());
ASSERT_EQ(u"Font '28 Days Later' has not been found. Using 'Calibri' font instead. Reason: alternative name from document.",
substitutionWarningHandler->FontWarnings->idx_get(0)->get_Description());
substitutionWarningHandler->FontWarnings->Clear();
ASSERT_EQ(0, substitutionWarningHandler->FontWarnings->get_Count());
}
class HandleDocumentSubstitutionWarnings : public IWarningCallback
{
public:
SharedPtr<WarningInfoCollection> FontWarnings;
void Warning(SharedPtr<WarningInfo> info) override
{
if (info->get_WarningType() == WarningType::FontSubstitution)
{
FontWarnings->Warning(info);
}
}
HandleDocumentSubstitutionWarnings() : FontWarnings(MakeObject<WarningInfoCollection>())
{
}
};

◆ GetType()

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

◆ idx_get()

System::SharedPtr<Aspose::Words::WarningInfo> Aspose::Words::WarningInfoCollection::idx_get ( int32_t  index)

Gets an item at the specified index.

Parameters
indexZero-based index of the item.

◆ Is()

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

◆ Type()

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

◆ Warning()

void Aspose::Words::WarningInfoCollection::Warning ( System::SharedPtr< Aspose::Words::WarningInfo info)
overridevirtual

Implements the IWarningCallback interface. Adds a warning to this collection.

Examples

Shows how to set the property for finding the closest match for a missing font from the available font sources.

void EnableFontSubstitution()
{
// Open a document that contains text formatted with a font that does not exist in any of our font sources.
auto doc = MakeObject<Document>(MyDir + u"Missing font.docx");
// Assign a callback for handling font substitution warnings.
auto substitutionWarningHandler = MakeObject<ExFontSettings::HandleDocumentSubstitutionWarnings>();
doc->set_WarningCallback(substitutionWarningHandler);
// Set a default font name and enable font substitution.
auto fontSettings = MakeObject<FontSettings>();
fontSettings->get_SubstitutionSettings()->get_DefaultFontSubstitution()->set_DefaultFontName(u"Arial");
;
fontSettings->get_SubstitutionSettings()->get_FontInfoSubstitution()->set_Enabled(true);
// We will get a font substitution warning if we save a document with a missing font.
doc->set_FontSettings(fontSettings);
doc->Save(ArtifactsDir + u"FontSettings.EnableFontSubstitution.pdf");
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<WarningInfo>>> warnings = substitutionWarningHandler->FontWarnings->GetEnumerator();
while (warnings->MoveNext())
{
std::cout << warnings->get_Current()->get_Description() << std::endl;
}
}
// We can also verify warnings in the collection and clear them.
ASSERT_EQ(WarningSource::Layout, substitutionWarningHandler->FontWarnings->idx_get(0)->get_Source());
ASSERT_EQ(u"Font '28 Days Later' has not been found. Using 'Calibri' font instead. Reason: alternative name from document.",
substitutionWarningHandler->FontWarnings->idx_get(0)->get_Description());
substitutionWarningHandler->FontWarnings->Clear();
ASSERT_EQ(0, substitutionWarningHandler->FontWarnings->get_Count());
}
class HandleDocumentSubstitutionWarnings : public IWarningCallback
{
public:
SharedPtr<WarningInfoCollection> FontWarnings;
void Warning(SharedPtr<WarningInfo> info) override
{
if (info->get_WarningType() == WarningType::FontSubstitution)
{
FontWarnings->Warning(info);
}
}
HandleDocumentSubstitutionWarnings() : FontWarnings(MakeObject<WarningInfoCollection>())
{
}
};

Implements Aspose::Words::IWarningCallback.