Aspose::Words::Fonts::FontInfo Class Reference

Detailed Description

Specifies information about a font used in the document.

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

See also
Aspose::Words::Fonts::FontInfoCollection
Aspose::Words::DocumentBase::get_FontInfos
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;
}

#include <Aspose.Words.Cpp/Fonts/FontInfo.h>

+ Inheritance diagram for Aspose::Words::Fonts::FontInfo:

Public Member Functions

String get_AltName () const
 Gets or sets the alternate name for the font. More...
 
int32_t get_Charset ()
 Gets or sets the character set for the font. More...
 
FontFamily get_Family () const
 Gets or sets the font family this font belongs to. More...
 
bool get_IsTrueType () const
 Indicates that this font is a TrueType or OpenType font as opposed to a raster or vector font. Default is true. More...
 
String get_Name () const
 Gets the name of the font. More...
 
ArrayPtr< uint8_t > get_Panose () const
 Gets or sets the PANOSE typeface classification number. More...
 
FontPitch get_Pitch () const
 The pitch indicates if the font is fixed pitch, proportionally spaced, or relies on a default setting. More...
 
ArrayPtr< uint8_t > GetEmbeddedFont (EmbeddedFontFormat format, EmbeddedFontStyle style)
 Gets a specific embedded font file. More...
 
ArrayPtr< uint8_t > GetEmbeddedFontAsOpenType (EmbeddedFontStyle style)
 Gets an embedded font file in OpenType format. Fonts in Embedded OpenType format are converted to OpenType. More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
void set_AltName (const String &value)
 Setter for get_AltName. More...
 
void set_Charset (int32_t value)
 Setter for get_Charset. More...
 
void set_Family (FontFamily value)
 Setter for get_Family. More...
 
void set_IsTrueType (bool value)
 Setter for get_IsTrueType. More...
 
void set_Panose (const ArrayPtr< uint8_t > &value)
 Setter for get_Panose. More...
 
void set_Pitch (FontPitch value)
 Setter for get_Pitch. More...
 

Static Public Member Functions

static const TypeInfoType ()
 

Member Function Documentation

◆ get_AltName()

System::String Aspose::Words::Fonts::FontInfo::get_AltName ( ) const

Gets or sets the alternate name for the font.

Cannot be null. Can be an empty string.

Examples

Shows how to access and print details of each font in a document.

auto doc = MakeObject<Document>(MyDir + u"Document.docx");
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<FontInfo>>> fontCollectionEnumerator = doc->get_FontInfos()->GetEnumerator();
while (fontCollectionEnumerator->MoveNext())
{
SharedPtr<FontInfo> fontInfo = fontCollectionEnumerator->get_Current();
if (fontInfo != nullptr)
{
std::cout << (String(u"Font name: ") + fontInfo->get_Name()) << std::endl;
// Alt names are usually blank.
std::cout << (String(u"Alt name: ") + fontInfo->get_AltName()) << std::endl;
std::cout << (String(u"\t- Family: ") + System::ObjectExt::ToString(fontInfo->get_Family())) << std::endl;
std::cout << (String(u"\t- ") + (fontInfo->get_IsTrueType() ? String(u"Is TrueType") : String(u"Is not TrueType"))) << std::endl;
std::cout << (String(u"\t- Pitch: ") + System::ObjectExt::ToString(fontInfo->get_Pitch())) << std::endl;
std::cout << (String(u"\t- Charset: ") + fontInfo->get_Charset()) << std::endl;
std::cout << "\t- Panose:" << std::endl;
std::cout << (String(u"\t\tFamily Kind: ") + fontInfo->get_Panose()[0]) << std::endl;
std::cout << (String(u"\t\tSerif Style: ") + fontInfo->get_Panose()[1]) << std::endl;
std::cout << (String(u"\t\tWeight: ") + fontInfo->get_Panose()[2]) << std::endl;
std::cout << (String(u"\t\tProportion: ") + fontInfo->get_Panose()[3]) << std::endl;
std::cout << (String(u"\t\tContrast: ") + fontInfo->get_Panose()[4]) << std::endl;
std::cout << (String(u"\t\tStroke Variation: ") + fontInfo->get_Panose()[5]) << std::endl;
std::cout << (String(u"\t\tArm Style: ") + fontInfo->get_Panose()[6]) << std::endl;
std::cout << (String(u"\t\tLetterform: ") + fontInfo->get_Panose()[7]) << std::endl;
std::cout << (String(u"\t\tMidline: ") + fontInfo->get_Panose()[8]) << std::endl;
std::cout << (String(u"\t\tX-Height: ") + fontInfo->get_Panose()[9]) << std::endl;
}
}

◆ get_Charset()

int32_t Aspose::Words::Fonts::FontInfo::get_Charset ( )

Gets or sets the character set for the font.

Examples

Shows how to access and print details of each font in a document.

auto doc = MakeObject<Document>(MyDir + u"Document.docx");
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<FontInfo>>> fontCollectionEnumerator = doc->get_FontInfos()->GetEnumerator();
while (fontCollectionEnumerator->MoveNext())
{
SharedPtr<FontInfo> fontInfo = fontCollectionEnumerator->get_Current();
if (fontInfo != nullptr)
{
std::cout << (String(u"Font name: ") + fontInfo->get_Name()) << std::endl;
// Alt names are usually blank.
std::cout << (String(u"Alt name: ") + fontInfo->get_AltName()) << std::endl;
std::cout << (String(u"\t- Family: ") + System::ObjectExt::ToString(fontInfo->get_Family())) << std::endl;
std::cout << (String(u"\t- ") + (fontInfo->get_IsTrueType() ? String(u"Is TrueType") : String(u"Is not TrueType"))) << std::endl;
std::cout << (String(u"\t- Pitch: ") + System::ObjectExt::ToString(fontInfo->get_Pitch())) << std::endl;
std::cout << (String(u"\t- Charset: ") + fontInfo->get_Charset()) << std::endl;
std::cout << "\t- Panose:" << std::endl;
std::cout << (String(u"\t\tFamily Kind: ") + fontInfo->get_Panose()[0]) << std::endl;
std::cout << (String(u"\t\tSerif Style: ") + fontInfo->get_Panose()[1]) << std::endl;
std::cout << (String(u"\t\tWeight: ") + fontInfo->get_Panose()[2]) << std::endl;
std::cout << (String(u"\t\tProportion: ") + fontInfo->get_Panose()[3]) << std::endl;
std::cout << (String(u"\t\tContrast: ") + fontInfo->get_Panose()[4]) << std::endl;
std::cout << (String(u"\t\tStroke Variation: ") + fontInfo->get_Panose()[5]) << std::endl;
std::cout << (String(u"\t\tArm Style: ") + fontInfo->get_Panose()[6]) << std::endl;
std::cout << (String(u"\t\tLetterform: ") + fontInfo->get_Panose()[7]) << std::endl;
std::cout << (String(u"\t\tMidline: ") + fontInfo->get_Panose()[8]) << std::endl;
std::cout << (String(u"\t\tX-Height: ") + fontInfo->get_Panose()[9]) << std::endl;
}
}

◆ get_Family()

Aspose::Words::Fonts::FontFamily Aspose::Words::Fonts::FontInfo::get_Family ( ) const

Gets or sets the font family this font belongs to.

Examples

Shows how to access and print details of each font in a document.

auto doc = MakeObject<Document>(MyDir + u"Document.docx");
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<FontInfo>>> fontCollectionEnumerator = doc->get_FontInfos()->GetEnumerator();
while (fontCollectionEnumerator->MoveNext())
{
SharedPtr<FontInfo> fontInfo = fontCollectionEnumerator->get_Current();
if (fontInfo != nullptr)
{
std::cout << (String(u"Font name: ") + fontInfo->get_Name()) << std::endl;
// Alt names are usually blank.
std::cout << (String(u"Alt name: ") + fontInfo->get_AltName()) << std::endl;
std::cout << (String(u"\t- Family: ") + System::ObjectExt::ToString(fontInfo->get_Family())) << std::endl;
std::cout << (String(u"\t- ") + (fontInfo->get_IsTrueType() ? String(u"Is TrueType") : String(u"Is not TrueType"))) << std::endl;
std::cout << (String(u"\t- Pitch: ") + System::ObjectExt::ToString(fontInfo->get_Pitch())) << std::endl;
std::cout << (String(u"\t- Charset: ") + fontInfo->get_Charset()) << std::endl;
std::cout << "\t- Panose:" << std::endl;
std::cout << (String(u"\t\tFamily Kind: ") + fontInfo->get_Panose()[0]) << std::endl;
std::cout << (String(u"\t\tSerif Style: ") + fontInfo->get_Panose()[1]) << std::endl;
std::cout << (String(u"\t\tWeight: ") + fontInfo->get_Panose()[2]) << std::endl;
std::cout << (String(u"\t\tProportion: ") + fontInfo->get_Panose()[3]) << std::endl;
std::cout << (String(u"\t\tContrast: ") + fontInfo->get_Panose()[4]) << std::endl;
std::cout << (String(u"\t\tStroke Variation: ") + fontInfo->get_Panose()[5]) << std::endl;
std::cout << (String(u"\t\tArm Style: ") + fontInfo->get_Panose()[6]) << std::endl;
std::cout << (String(u"\t\tLetterform: ") + fontInfo->get_Panose()[7]) << std::endl;
std::cout << (String(u"\t\tMidline: ") + fontInfo->get_Panose()[8]) << std::endl;
std::cout << (String(u"\t\tX-Height: ") + fontInfo->get_Panose()[9]) << std::endl;
}
}

◆ get_IsTrueType()

bool Aspose::Words::Fonts::FontInfo::get_IsTrueType ( ) const

Indicates that this font is a TrueType or OpenType font as opposed to a raster or vector font. Default is true.

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;
}

◆ get_Name()

System::String Aspose::Words::Fonts::FontInfo::get_Name ( ) const

Gets the name of the font.

Cannot be null. Can be an empty string.

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;
}

◆ get_Panose()

System::ArrayPtr< uint8_t > Aspose::Words::Fonts::FontInfo::get_Panose ( ) const

Gets or sets the PANOSE typeface classification number.

PANOSE is a compact 10-byte description of a fonts critical visual characteristics, such as contrast, weight, and serif style. The digits represent Family Kind, Serif Style, Weight, Proportion, Contrast, Stroke Variation, Arm Style, Letterform, Midline, and X-Height.

Can be null.

Examples

Shows how to access and print details of each font in a document.

auto doc = MakeObject<Document>(MyDir + u"Document.docx");
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<FontInfo>>> fontCollectionEnumerator = doc->get_FontInfos()->GetEnumerator();
while (fontCollectionEnumerator->MoveNext())
{
SharedPtr<FontInfo> fontInfo = fontCollectionEnumerator->get_Current();
if (fontInfo != nullptr)
{
std::cout << (String(u"Font name: ") + fontInfo->get_Name()) << std::endl;
// Alt names are usually blank.
std::cout << (String(u"Alt name: ") + fontInfo->get_AltName()) << std::endl;
std::cout << (String(u"\t- Family: ") + System::ObjectExt::ToString(fontInfo->get_Family())) << std::endl;
std::cout << (String(u"\t- ") + (fontInfo->get_IsTrueType() ? String(u"Is TrueType") : String(u"Is not TrueType"))) << std::endl;
std::cout << (String(u"\t- Pitch: ") + System::ObjectExt::ToString(fontInfo->get_Pitch())) << std::endl;
std::cout << (String(u"\t- Charset: ") + fontInfo->get_Charset()) << std::endl;
std::cout << "\t- Panose:" << std::endl;
std::cout << (String(u"\t\tFamily Kind: ") + fontInfo->get_Panose()[0]) << std::endl;
std::cout << (String(u"\t\tSerif Style: ") + fontInfo->get_Panose()[1]) << std::endl;
std::cout << (String(u"\t\tWeight: ") + fontInfo->get_Panose()[2]) << std::endl;
std::cout << (String(u"\t\tProportion: ") + fontInfo->get_Panose()[3]) << std::endl;
std::cout << (String(u"\t\tContrast: ") + fontInfo->get_Panose()[4]) << std::endl;
std::cout << (String(u"\t\tStroke Variation: ") + fontInfo->get_Panose()[5]) << std::endl;
std::cout << (String(u"\t\tArm Style: ") + fontInfo->get_Panose()[6]) << std::endl;
std::cout << (String(u"\t\tLetterform: ") + fontInfo->get_Panose()[7]) << std::endl;
std::cout << (String(u"\t\tMidline: ") + fontInfo->get_Panose()[8]) << std::endl;
std::cout << (String(u"\t\tX-Height: ") + fontInfo->get_Panose()[9]) << std::endl;
}
}

◆ get_Pitch()

Aspose::Words::Fonts::FontPitch Aspose::Words::Fonts::FontInfo::get_Pitch ( ) const

The pitch indicates if the font is fixed pitch, proportionally spaced, or relies on a default setting.

Examples

Shows how to access and print details of each font in a document.

auto doc = MakeObject<Document>(MyDir + u"Document.docx");
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<FontInfo>>> fontCollectionEnumerator = doc->get_FontInfos()->GetEnumerator();
while (fontCollectionEnumerator->MoveNext())
{
SharedPtr<FontInfo> fontInfo = fontCollectionEnumerator->get_Current();
if (fontInfo != nullptr)
{
std::cout << (String(u"Font name: ") + fontInfo->get_Name()) << std::endl;
// Alt names are usually blank.
std::cout << (String(u"Alt name: ") + fontInfo->get_AltName()) << std::endl;
std::cout << (String(u"\t- Family: ") + System::ObjectExt::ToString(fontInfo->get_Family())) << std::endl;
std::cout << (String(u"\t- ") + (fontInfo->get_IsTrueType() ? String(u"Is TrueType") : String(u"Is not TrueType"))) << std::endl;
std::cout << (String(u"\t- Pitch: ") + System::ObjectExt::ToString(fontInfo->get_Pitch())) << std::endl;
std::cout << (String(u"\t- Charset: ") + fontInfo->get_Charset()) << std::endl;
std::cout << "\t- Panose:" << std::endl;
std::cout << (String(u"\t\tFamily Kind: ") + fontInfo->get_Panose()[0]) << std::endl;
std::cout << (String(u"\t\tSerif Style: ") + fontInfo->get_Panose()[1]) << std::endl;
std::cout << (String(u"\t\tWeight: ") + fontInfo->get_Panose()[2]) << std::endl;
std::cout << (String(u"\t\tProportion: ") + fontInfo->get_Panose()[3]) << std::endl;
std::cout << (String(u"\t\tContrast: ") + fontInfo->get_Panose()[4]) << std::endl;
std::cout << (String(u"\t\tStroke Variation: ") + fontInfo->get_Panose()[5]) << std::endl;
std::cout << (String(u"\t\tArm Style: ") + fontInfo->get_Panose()[6]) << std::endl;
std::cout << (String(u"\t\tLetterform: ") + fontInfo->get_Panose()[7]) << std::endl;
std::cout << (String(u"\t\tMidline: ") + fontInfo->get_Panose()[8]) << std::endl;
std::cout << (String(u"\t\tX-Height: ") + fontInfo->get_Panose()[9]) << std::endl;
}
}

◆ GetEmbeddedFont()

System::ArrayPtr< uint8_t > Aspose::Words::Fonts::FontInfo::GetEmbeddedFont ( Aspose::Words::Fonts::EmbeddedFontFormat  format,
Aspose::Words::Fonts::EmbeddedFontStyle  style 
)

Gets a specific embedded font file.

Parameters
formatSpecifies the font format to retrieve.
styleSpecifies the font style to retrieve.
Returns
Returns null if the specified font is not embedded.
Examples

Shows how to extract an embedded font from a document, and save it to the local file system.

auto doc = MakeObject<Document>(MyDir + u"Embedded font.docx");
SharedPtr<FontInfo> embeddedFont = doc->get_FontInfos()->idx_get(u"Alte DIN 1451 Mittelschrift");
ArrayPtr<uint8_t> embeddedFontBytes = embeddedFont->GetEmbeddedFont(EmbeddedFontFormat::OpenType, EmbeddedFontStyle::Regular);
System::IO::File::WriteAllBytes(ArtifactsDir + u"Alte DIN 1451 Mittelschrift.ttf", embeddedFontBytes);
// Embedded font formats may be different in other formats such as .doc.
// We need to know the correct format before we can extract the font.
doc = MakeObject<Document>(MyDir + u"Embedded font.doc");
ASSERT_TRUE(doc->get_FontInfos()->idx_get(u"Alte DIN 1451 Mittelschrift")->GetEmbeddedFont(EmbeddedFontFormat::OpenType, EmbeddedFontStyle::Regular) ==
nullptr);
ASSERT_FALSE(
doc->get_FontInfos()->idx_get(u"Alte DIN 1451 Mittelschrift")->GetEmbeddedFont(EmbeddedFontFormat::EmbeddedOpenType, EmbeddedFontStyle::Regular) ==
nullptr);
// Also, we can convert embedded OpenType format, which comes from .doc documents, to OpenType.
embeddedFontBytes = doc->get_FontInfos()->idx_get(u"Alte DIN 1451 Mittelschrift")->GetEmbeddedFontAsOpenType(EmbeddedFontStyle::Regular);
System::IO::File::WriteAllBytes(ArtifactsDir + u"Alte DIN 1451 Mittelschrift.otf", embeddedFontBytes);

◆ GetEmbeddedFontAsOpenType()

System::ArrayPtr< uint8_t > Aspose::Words::Fonts::FontInfo::GetEmbeddedFontAsOpenType ( Aspose::Words::Fonts::EmbeddedFontStyle  style)

Gets an embedded font file in OpenType format. Fonts in Embedded OpenType format are converted to OpenType.

Parameters
styleSpecifies the font style to retrieve.
Returns
Returns null if the specified font is not embedded.
Examples

Shows how to extract an embedded font from a document, and save it to the local file system.

auto doc = MakeObject<Document>(MyDir + u"Embedded font.docx");
SharedPtr<FontInfo> embeddedFont = doc->get_FontInfos()->idx_get(u"Alte DIN 1451 Mittelschrift");
ArrayPtr<uint8_t> embeddedFontBytes = embeddedFont->GetEmbeddedFont(EmbeddedFontFormat::OpenType, EmbeddedFontStyle::Regular);
System::IO::File::WriteAllBytes(ArtifactsDir + u"Alte DIN 1451 Mittelschrift.ttf", embeddedFontBytes);
// Embedded font formats may be different in other formats such as .doc.
// We need to know the correct format before we can extract the font.
doc = MakeObject<Document>(MyDir + u"Embedded font.doc");
ASSERT_TRUE(doc->get_FontInfos()->idx_get(u"Alte DIN 1451 Mittelschrift")->GetEmbeddedFont(EmbeddedFontFormat::OpenType, EmbeddedFontStyle::Regular) ==
nullptr);
ASSERT_FALSE(
doc->get_FontInfos()->idx_get(u"Alte DIN 1451 Mittelschrift")->GetEmbeddedFont(EmbeddedFontFormat::EmbeddedOpenType, EmbeddedFontStyle::Regular) ==
nullptr);
// Also, we can convert embedded OpenType format, which comes from .doc documents, to OpenType.
embeddedFontBytes = doc->get_FontInfos()->idx_get(u"Alte DIN 1451 Mittelschrift")->GetEmbeddedFontAsOpenType(EmbeddedFontStyle::Regular);
System::IO::File::WriteAllBytes(ArtifactsDir + u"Alte DIN 1451 Mittelschrift.otf", embeddedFontBytes);

◆ GetType()

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

Reimplemented from System::Object.

◆ Is()

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

Reimplemented from System::Object.

◆ set_AltName()

void Aspose::Words::Fonts::FontInfo::set_AltName ( const System::String value)

◆ set_Charset()

void Aspose::Words::Fonts::FontInfo::set_Charset ( int32_t  value)

◆ set_Family()

void Aspose::Words::Fonts::FontInfo::set_Family ( Aspose::Words::Fonts::FontFamily  value)

◆ set_IsTrueType()

void Aspose::Words::Fonts::FontInfo::set_IsTrueType ( bool  value)

◆ set_Panose()

void Aspose::Words::Fonts::FontInfo::set_Panose ( const System::ArrayPtr< uint8_t > &  value)

◆ set_Pitch()

void Aspose::Words::Fonts::FontInfo::set_Pitch ( Aspose::Words::Fonts::FontPitch  value)

◆ Type()

static const System::TypeInfo & Aspose::Words::Fonts::FontInfo::Type ( )
static