Aspose::Words::Fonts::FontInfoCollection class

FontInfoCollection class

Represents a collection of fonts used in a document. To learn more, visit the Working with Fonts documentation article.

class FontInfoCollection : public System::Collections::Generic::IEnumerable<System::SharedPtr<Aspose::Words::Fonts::FontInfo>>

Methods

MethodDescription
begin()
begin() const
cbegin() const
cend() const
Contains(const System::String&)Determines whether the collection contains a font with the given name.
end()
end() const
get_Count()Gets the number of elements contained in the collection.
get_EmbedSystemFonts() constSpecifies whether or not to embed System fonts into the document. Default value for this property is false. This option works only when EmbedTrueTypeFonts option is set to true.
get_EmbedTrueTypeFonts() constSpecifies whether or not to embed TrueType fonts in a document when it is saved. Default value for this property is false.
get_SaveSubsetFonts() constSpecifies whether or not to save a subset of the embedded TrueType fonts with the document. Default value for this property is false. This option works only when EmbedTrueTypeFonts property is set to true.
GetEnumerator() overrideReturns an enumerator object that can be used to iterate over all items in the collection.
GetType() const override
idx_get(const System::String&)Gets a font with the specified name.
idx_get(int32_t)Gets a font at the specified index.
Is(const System::TypeInfo&) const override
set_EmbedSystemFonts(bool)Setter for Aspose::Words::Fonts::FontInfoCollection::get_EmbedSystemFonts.
set_EmbedTrueTypeFonts(bool)Setter for Aspose::Words::Fonts::FontInfoCollection::get_EmbedTrueTypeFonts.
set_SaveSubsetFonts(bool)Setter for Aspose::Words::Fonts::FontInfoCollection::get_SaveSubsetFonts.
static Type()
virtualizeBeginConstIterator() const override
virtualizeBeginIterator() override
virtualizeEndConstIterator() const override
virtualizeEndIterator() override

Typedefs

TypedefDescription
const_iterator
iterator
iterator_holder_type
virtualized_iterator
virtualized_iterator_element

Remarks

Items are FontInfo objects.

You do not create instances of this class directly. Use the FontInfos property to access the collection of fonts defined in the document.

Examples

Shows how to print the details of what fonts are present in a document.

auto doc = MakeObject<Document>(MyDir + u"Embedded font.docx");

SharedPtr<Aspose::Words::Fonts::FontInfoCollection> allFonts = doc->get_FontInfos();

// Print all the used and unused fonts in the document.
for (int i = 0; i < allFonts->get_Count(); i++)
{
    std::cout << "Font index #" << i << std::endl;
    std::cout << "\tName: " << allFonts->idx_get(i)->get_Name() << std::endl;
    std::cout << "\tIs " << (allFonts->idx_get(i)->get_IsTrueType() ? String(u"") : String(u"not ")) << "a trueType font" << std::endl;
}

Shows how to save a document with embedded TrueType fonts.

auto doc = MakeObject<Document>(MyDir + u"Document.docx");

SharedPtr<Aspose::Words::Fonts::FontInfoCollection> fontInfos = doc->get_FontInfos();
fontInfos->set_EmbedTrueTypeFonts(embedAllFonts);
fontInfos->set_EmbedSystemFonts(embedAllFonts);
fontInfos->set_SaveSubsetFonts(embedAllFonts);

doc->Save(ArtifactsDir + u"Font.FontInfoCollection.docx");

if (embedAllFonts)
{
    ASSERT_LT(25000, MakeObject<System::IO::FileInfo>(ArtifactsDir + u"Font.FontInfoCollection.docx")->get_Length());
}
else
{
    ASSERT_GE(15000, MakeObject<System::IO::FileInfo>(ArtifactsDir + u"Font.FontInfoCollection.docx")->get_Length());
}

See Also