Aspose::Words::Fonts Namespace Reference

Detailed Description

The Aspose.Words.Fonts namespace provides classes and enumerations to access information about fonts used in a document.

Classes

class  DefaultFontSubstitutionRule
 Default font substitution rule. To learn more, visit the Working with Fonts documentation article. More...
 
class  FileFontSource
 Represents the single TrueType font file stored in the file system. To learn more, visit the Working with Fonts documentation article. More...
 
class  FolderFontSource
 Represents the folder that contains TrueType font files. To learn more, visit the Working with Fonts documentation article. More...
 
class  FontConfigSubstitutionRule
 Font config substitution rule. To learn more, visit the Working with Fonts documentation article. More...
 
class  FontFallbackSettings
 Specifies font fallback mechanism settings. To learn more, visit the Working with Fonts documentation article. More...
 
class  FontInfo
 Specifies information about a font used in the document. To learn more, visit the Working with Fonts documentation article. More...
 
class  FontInfoCollection
 Represents a collection of fonts used in a document. To learn more, visit the Working with Fonts documentation article. More...
 
class  FontInfoSubstitutionRule
 Font info substitution rule. To learn more, visit the Working with Fonts documentation article. More...
 
class  FontNameSubstitutionRule
 Font substitution rule for processing font name. To learn more, visit the Working with Fonts documentation article. More...
 
class  FontSettings
 Specifies font settings for a document. To learn more, visit the Working with Fonts documentation article. More...
 
class  FontSourceBase
 This is an abstract base class for the classes that allow the user to specify various font sources. To learn more, visit the Working with Fonts documentation article. More...
 
class  FontSubstitutionRule
 This is an abstract base class for the font substitution rule. To learn more, visit the Working with Fonts documentation article. More...
 
class  FontSubstitutionSettings
 Specifies font substitution mechanism settings. To learn more, visit the Working with Fonts documentation article. More...
 
class  MemoryFontSource
 Represents the single TrueType font file stored in memory. To learn more, visit the Working with Fonts documentation article. More...
 
class  PhysicalFontInfo
 Specifies information about physical font available to Aspose.Words font engine. To learn more, visit the Working with Fonts documentation article. More...
 
class  StreamFontSource
 Base class for user-defined stream font source. To learn more, visit the Working with Fonts documentation article. More...
 
class  SystemFontSource
 Represents all TrueType fonts installed to the system. To learn more, visit the Working with Fonts documentation article. More...
 
class  TableSubstitutionRule
 Table font substitution rule. To learn more, visit the Working with Fonts documentation article. More...
 

Enumerations

enum class  EmbeddedFontFormat
 Specifies format of particular embedded font inside FontInfo object. When saving a document to a file, only embedded fonts of corresponding format are written down. More...
 
enum class  EmbeddedFontStyle
 Specifies the style of an embedded font inside a FontInfo object. More...
 
enum class  FontFamily
 Represents the font family. More...
 
enum class  FontPitch
 Represents the font pitch. More...
 
enum class  FontSourceType
 Specifies the type of a font source. More...
 

Enumeration Type Documentation

◆ EmbeddedFontFormat

Specifies format of particular embedded font inside FontInfo object. When saving a document to a file, only embedded fonts of corresponding format are written down.

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);
Enumerator
EmbeddedOpenType 

Specifies Embedded OpenType (EOT) File Format. This format of embedded fonts used in DOC files.

See http://www.w3.org/Submission/EOT for description of the format.

OpenType 

Specifies font, embedded as plain copy of OpenType (TrueType) font file. This format of embedded fonts used in Open Office XML format, including DOCX files.

◆ EmbeddedFontStyle

Specifies the style of an embedded font inside a FontInfo object.

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);
Enumerator
Regular 

Specifies the Regular embedded font.

Bold 

Specifies the Bold embedded font.

Italic 

Specifies the Italic embedded font.

BoldItalic 

Specifies the Bold-Italic embedded font.

◆ FontFamily

Represents the font family.

A font family is a set of fonts having common stroke width and serif characteristics.

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

Specifies a generic family name. This name is used when information about a font does not exist or does not matter. The default font is used.

Roman 

Specifies a proportional font with serifs. An example is Times New Roman.

Swiss 

Specifies a proportional font without serifs. An example is Arial.

Modern 

Specifies a monospace font with or without serifs. Monospace fonts are usually modern; examples include Pica, Elite, and Courier New.

Script 

Specifies a font that is designed to look like handwriting; examples include Script and Cursive.

Decorative 

Specifies a novelty font. An example is Old English.

◆ FontPitch

Represents the font pitch.

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

Specifies that no information is available about the pitch of a font.

Fixed 

Specifies that this is a fixed width font.

Variable 

Specifies that this is a proportional width font.

◆ FontSourceType

Specifies the type of a font source.

Examples

Shows how to use a font file in the local file system as a font source.

auto fileFontSource = MakeObject<FileFontSource>(MyDir + u"Alte DIN 1451 Mittelschrift.ttf", 0);
auto doc = MakeObject<Document>();
doc->set_FontSettings(MakeObject<FontSettings>());
doc->get_FontSettings()->SetFontsSources(MakeArray<SharedPtr<FontSourceBase>>({fileFontSource}));
ASSERT_EQ(MyDir + u"Alte DIN 1451 Mittelschrift.ttf", fileFontSource->get_FilePath());
ASSERT_EQ(FontSourceType::FontFile, fileFontSource->get_Type());
ASSERT_EQ(0, fileFontSource->get_Priority());
Enumerator
FontFile 

A FileFontSource object that represents single font file.

FontsFolder 

A FolderFontSource object that represents folder with font files.

MemoryFont 

A MemoryFontSource object that represents single font in memory.

SystemFonts 

A SystemFontSource object that represents all fonts installed to the system.

FontStream 

A StreamFontSource object that represents a stream with font data.