Aspose::Words::Saving::FontSavingArgs Class Reference

Detailed Description

Provides data for the FontSaving() event.

When Aspose.Words saves a document to HTML or related formats and ExportFontResources is set to true, it saves each font subject for export into a separate file.

FontSavingArgs controls whether particular font resource should be exported and how.

FontSavingArgs also allows to redefine how font file names are generated or to completely circumvent saving of fonts into files by providing your own stream objects.

To decide whether to save a particular font resource, use the IsExportNeeded property.

To save fonts into streams instead of files, use the FontStream property.

Examples

Shows how to define custom logic for exporting fonts when saving to HTML.

void SaveExportedFonts()
{
auto doc = MakeObject<Document>(MyDir + u"Rendering.docx");
// Configure a SaveOptions object to export fonts to separate files.
// Set a callback that will handle font saving in a custom manner.
auto options = MakeObject<HtmlSaveOptions>();
options->set_ExportFontResources(true);
options->set_FontSavingCallback(MakeObject<ExHtmlSaveOptions::HandleFontSaving>());
// The callback will export .ttf files and save them alongside the output document.
doc->Save(ArtifactsDir + u"HtmlSaveOptions.SaveExportedFonts.html", options);
std::function<bool(String s)> endsWithTtf = [](String s)
{
return s.EndsWith(u".ttf");
};
for (String fontFilename : System::Array<String>::FindAll(System::IO::Directory::GetFiles(ArtifactsDir), endsWithTtf))
{
std::cout << fontFilename << std::endl;
}
}
class HandleFontSaving : public IFontSavingCallback
{
private:
void FontSaving(SharedPtr<FontSavingArgs> args) override
{
std::cout << "Font:\t" << args->get_FontFamilyName();
if (args->get_Bold())
{
std::cout << ", bold";
}
if (args->get_Italic())
{
std::cout << ", italic";
}
std::cout << "\nSource:\t" << args->get_OriginalFileName() << ", " << args->get_OriginalFileSize() << " bytes\n" << std::endl;
// We can also access the source document from here.
ASSERT_TRUE(args->get_Document()->get_OriginalFileName().EndsWith(u"Rendering.docx"));
ASSERT_TRUE(args->get_IsExportNeeded());
ASSERT_TRUE(args->get_IsSubsettingNeeded());
// There are two ways of saving an exported font.
// 1 - Save it to a local file system location:
args->set_FontFileName(args->get_OriginalFileName().Split(MakeArray<char16_t>({System::IO::Path::DirectorySeparatorChar}))->LINQ_Last());
// 2 - Save it to a stream:
args->set_FontStream(MakeObject<System::IO::FileStream>(
ArtifactsDir + args->get_OriginalFileName().Split(MakeArray<char16_t>({System::IO::Path::DirectorySeparatorChar}))->LINQ_Last(),
System::IO::FileMode::Create));
ASSERT_FALSE(args->get_KeepFontStreamOpen());
}
};

#include <Aspose.Words.Cpp/Saving/FontSavingArgs.h>

+ Inheritance diagram for Aspose::Words::Saving::FontSavingArgs:

Public Member Functions

bool get_Bold () const
 Indicates whether the current font is bold. More...
 
SharedPtr< Documentget_Document () const
 Gets the document object that is being saved. More...
 
String get_FontFamilyName () const
 Indicates the current font family name. More...
 
String get_FontFileName () const
 Gets or sets the file name (without path) where the font will be saved to. More...
 
SharedPtr< Streamget_FontStream () const
 Allows to specify the stream where the font will be saved to. More...
 
bool get_IsExportNeeded () const
 Allows to specify whether the current font will be exported as a font resource. Default is true. More...
 
bool get_IsSubsettingNeeded () const
 Allows to specify whether the current font will be subsetted before exporting as a font resource. More...
 
bool get_Italic () const
 Indicates whether the current font is italic. More...
 
bool get_KeepFontStreamOpen () const
 Specifies whether Aspose.Words should keep the stream open or close it after saving a font. More...
 
String get_OriginalFileName () const
 Gets the original font file name with an extension. More...
 
int32_t get_OriginalFileSize () const
 Gets the original font file size. More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
void set_FontFileName (const String &value)
 Setter for get_FontFileName. More...
 
void set_FontStream (const SharedPtr< Stream > &value)
 Setter for get_FontStream. More...
 
template<typename CharType , typename Traits >
void set_FontStream (std::basic_ostream< CharType, Traits > &value)
 
void set_IsExportNeeded (bool value)
 Setter for get_IsExportNeeded. More...
 
void set_IsSubsettingNeeded (bool value)
 Setter for get_IsSubsettingNeeded. More...
 
void set_KeepFontStreamOpen (bool value)
 Setter for get_KeepFontStreamOpen. More...
 

Static Public Member Functions

static const TypeInfoType ()
 

Member Function Documentation

◆ get_Bold()

bool Aspose::Words::Saving::FontSavingArgs::get_Bold ( ) const

Indicates whether the current font is bold.

Examples

Shows how to define custom logic for exporting fonts when saving to HTML.

void SaveExportedFonts()
{
auto doc = MakeObject<Document>(MyDir + u"Rendering.docx");
// Configure a SaveOptions object to export fonts to separate files.
// Set a callback that will handle font saving in a custom manner.
auto options = MakeObject<HtmlSaveOptions>();
options->set_ExportFontResources(true);
options->set_FontSavingCallback(MakeObject<ExHtmlSaveOptions::HandleFontSaving>());
// The callback will export .ttf files and save them alongside the output document.
doc->Save(ArtifactsDir + u"HtmlSaveOptions.SaveExportedFonts.html", options);
std::function<bool(String s)> endsWithTtf = [](String s)
{
return s.EndsWith(u".ttf");
};
for (String fontFilename : System::Array<String>::FindAll(System::IO::Directory::GetFiles(ArtifactsDir), endsWithTtf))
{
std::cout << fontFilename << std::endl;
}
}
class HandleFontSaving : public IFontSavingCallback
{
private:
void FontSaving(SharedPtr<FontSavingArgs> args) override
{
std::cout << "Font:\t" << args->get_FontFamilyName();
if (args->get_Bold())
{
std::cout << ", bold";
}
if (args->get_Italic())
{
std::cout << ", italic";
}
std::cout << "\nSource:\t" << args->get_OriginalFileName() << ", " << args->get_OriginalFileSize() << " bytes\n" << std::endl;
// We can also access the source document from here.
ASSERT_TRUE(args->get_Document()->get_OriginalFileName().EndsWith(u"Rendering.docx"));
ASSERT_TRUE(args->get_IsExportNeeded());
ASSERT_TRUE(args->get_IsSubsettingNeeded());
// There are two ways of saving an exported font.
// 1 - Save it to a local file system location:
args->set_FontFileName(args->get_OriginalFileName().Split(MakeArray<char16_t>({System::IO::Path::DirectorySeparatorChar}))->LINQ_Last());
// 2 - Save it to a stream:
args->set_FontStream(MakeObject<System::IO::FileStream>(
ArtifactsDir + args->get_OriginalFileName().Split(MakeArray<char16_t>({System::IO::Path::DirectorySeparatorChar}))->LINQ_Last(),
System::IO::FileMode::Create));
ASSERT_FALSE(args->get_KeepFontStreamOpen());
}
};

◆ get_Document()

System::SharedPtr< Aspose::Words::Document > Aspose::Words::Saving::FontSavingArgs::get_Document ( ) const

Gets the document object that is being saved.

Examples

Shows how to define custom logic for exporting fonts when saving to HTML.

void SaveExportedFonts()
{
auto doc = MakeObject<Document>(MyDir + u"Rendering.docx");
// Configure a SaveOptions object to export fonts to separate files.
// Set a callback that will handle font saving in a custom manner.
auto options = MakeObject<HtmlSaveOptions>();
options->set_ExportFontResources(true);
options->set_FontSavingCallback(MakeObject<ExHtmlSaveOptions::HandleFontSaving>());
// The callback will export .ttf files and save them alongside the output document.
doc->Save(ArtifactsDir + u"HtmlSaveOptions.SaveExportedFonts.html", options);
std::function<bool(String s)> endsWithTtf = [](String s)
{
return s.EndsWith(u".ttf");
};
for (String fontFilename : System::Array<String>::FindAll(System::IO::Directory::GetFiles(ArtifactsDir), endsWithTtf))
{
std::cout << fontFilename << std::endl;
}
}
class HandleFontSaving : public IFontSavingCallback
{
private:
void FontSaving(SharedPtr<FontSavingArgs> args) override
{
std::cout << "Font:\t" << args->get_FontFamilyName();
if (args->get_Bold())
{
std::cout << ", bold";
}
if (args->get_Italic())
{
std::cout << ", italic";
}
std::cout << "\nSource:\t" << args->get_OriginalFileName() << ", " << args->get_OriginalFileSize() << " bytes\n" << std::endl;
// We can also access the source document from here.
ASSERT_TRUE(args->get_Document()->get_OriginalFileName().EndsWith(u"Rendering.docx"));
ASSERT_TRUE(args->get_IsExportNeeded());
ASSERT_TRUE(args->get_IsSubsettingNeeded());
// There are two ways of saving an exported font.
// 1 - Save it to a local file system location:
args->set_FontFileName(args->get_OriginalFileName().Split(MakeArray<char16_t>({System::IO::Path::DirectorySeparatorChar}))->LINQ_Last());
// 2 - Save it to a stream:
args->set_FontStream(MakeObject<System::IO::FileStream>(
ArtifactsDir + args->get_OriginalFileName().Split(MakeArray<char16_t>({System::IO::Path::DirectorySeparatorChar}))->LINQ_Last(),
System::IO::FileMode::Create));
ASSERT_FALSE(args->get_KeepFontStreamOpen());
}
};

◆ get_FontFamilyName()

System::String Aspose::Words::Saving::FontSavingArgs::get_FontFamilyName ( ) const

Indicates the current font family name.

Examples

Shows how to define custom logic for exporting fonts when saving to HTML.

void SaveExportedFonts()
{
auto doc = MakeObject<Document>(MyDir + u"Rendering.docx");
// Configure a SaveOptions object to export fonts to separate files.
// Set a callback that will handle font saving in a custom manner.
auto options = MakeObject<HtmlSaveOptions>();
options->set_ExportFontResources(true);
options->set_FontSavingCallback(MakeObject<ExHtmlSaveOptions::HandleFontSaving>());
// The callback will export .ttf files and save them alongside the output document.
doc->Save(ArtifactsDir + u"HtmlSaveOptions.SaveExportedFonts.html", options);
std::function<bool(String s)> endsWithTtf = [](String s)
{
return s.EndsWith(u".ttf");
};
for (String fontFilename : System::Array<String>::FindAll(System::IO::Directory::GetFiles(ArtifactsDir), endsWithTtf))
{
std::cout << fontFilename << std::endl;
}
}
class HandleFontSaving : public IFontSavingCallback
{
private:
void FontSaving(SharedPtr<FontSavingArgs> args) override
{
std::cout << "Font:\t" << args->get_FontFamilyName();
if (args->get_Bold())
{
std::cout << ", bold";
}
if (args->get_Italic())
{
std::cout << ", italic";
}
std::cout << "\nSource:\t" << args->get_OriginalFileName() << ", " << args->get_OriginalFileSize() << " bytes\n" << std::endl;
// We can also access the source document from here.
ASSERT_TRUE(args->get_Document()->get_OriginalFileName().EndsWith(u"Rendering.docx"));
ASSERT_TRUE(args->get_IsExportNeeded());
ASSERT_TRUE(args->get_IsSubsettingNeeded());
// There are two ways of saving an exported font.
// 1 - Save it to a local file system location:
args->set_FontFileName(args->get_OriginalFileName().Split(MakeArray<char16_t>({System::IO::Path::DirectorySeparatorChar}))->LINQ_Last());
// 2 - Save it to a stream:
args->set_FontStream(MakeObject<System::IO::FileStream>(
ArtifactsDir + args->get_OriginalFileName().Split(MakeArray<char16_t>({System::IO::Path::DirectorySeparatorChar}))->LINQ_Last(),
System::IO::FileMode::Create));
ASSERT_FALSE(args->get_KeepFontStreamOpen());
}
};

◆ get_FontFileName()

System::String Aspose::Words::Saving::FontSavingArgs::get_FontFileName ( ) const

Gets or sets the file name (without path) where the font will be saved to.

This property allows you to redefine how the font file names are generated during export to HTML.

When the event is fired, this property contains the file name that was generated by Aspose.Words. You can change the value of this property to save the font into a different file. Note that file names must be unique.

Aspose.Words automatically generates a unique file name for every embedded font when exporting to HTML format. How the font file name is generated depends on whether you save the document to a file or to a stream.

When saving a document to a file, the generated font file name looks like %<document base file name>.<original file name><optional suffix>.<extension>.

When saving a document to a stream, the generated font file name looks like Aspose.Words.<document guid>.<original file name><optional suffix>.<extension>.

FontFileName must contain only the file name without the path. Aspose.Words determines the path for saving using the document file name, the FontsFolder and FontsFolderAlias properties.

See also
Aspose::Words::Saving::FontSavingArgs::get_FontStream
Aspose::Words::Saving::HtmlSaveOptions::get_FontsFolder
Aspose::Words::Saving::HtmlSaveOptions::get_FontsFolderAlias
Examples

Shows how to define custom logic for exporting fonts when saving to HTML.

void SaveExportedFonts()
{
auto doc = MakeObject<Document>(MyDir + u"Rendering.docx");
// Configure a SaveOptions object to export fonts to separate files.
// Set a callback that will handle font saving in a custom manner.
auto options = MakeObject<HtmlSaveOptions>();
options->set_ExportFontResources(true);
options->set_FontSavingCallback(MakeObject<ExHtmlSaveOptions::HandleFontSaving>());
// The callback will export .ttf files and save them alongside the output document.
doc->Save(ArtifactsDir + u"HtmlSaveOptions.SaveExportedFonts.html", options);
std::function<bool(String s)> endsWithTtf = [](String s)
{
return s.EndsWith(u".ttf");
};
for (String fontFilename : System::Array<String>::FindAll(System::IO::Directory::GetFiles(ArtifactsDir), endsWithTtf))
{
std::cout << fontFilename << std::endl;
}
}
class HandleFontSaving : public IFontSavingCallback
{
private:
void FontSaving(SharedPtr<FontSavingArgs> args) override
{
std::cout << "Font:\t" << args->get_FontFamilyName();
if (args->get_Bold())
{
std::cout << ", bold";
}
if (args->get_Italic())
{
std::cout << ", italic";
}
std::cout << "\nSource:\t" << args->get_OriginalFileName() << ", " << args->get_OriginalFileSize() << " bytes\n" << std::endl;
// We can also access the source document from here.
ASSERT_TRUE(args->get_Document()->get_OriginalFileName().EndsWith(u"Rendering.docx"));
ASSERT_TRUE(args->get_IsExportNeeded());
ASSERT_TRUE(args->get_IsSubsettingNeeded());
// There are two ways of saving an exported font.
// 1 - Save it to a local file system location:
args->set_FontFileName(args->get_OriginalFileName().Split(MakeArray<char16_t>({System::IO::Path::DirectorySeparatorChar}))->LINQ_Last());
// 2 - Save it to a stream:
args->set_FontStream(MakeObject<System::IO::FileStream>(
ArtifactsDir + args->get_OriginalFileName().Split(MakeArray<char16_t>({System::IO::Path::DirectorySeparatorChar}))->LINQ_Last(),
System::IO::FileMode::Create));
ASSERT_FALSE(args->get_KeepFontStreamOpen());
}
};

◆ get_FontStream()

System::SharedPtr< System::IO::Stream > Aspose::Words::Saving::FontSavingArgs::get_FontStream ( ) const

Allows to specify the stream where the font will be saved to.

This property allows you to save fonts to streams instead of files during HTML export.

The default value is null. When this property is null, the font will be saved to a file specified in the FontFileName property.

See also
Aspose::Words::Saving::FontSavingArgs::get_FontFileName
Aspose::Words::Saving::FontSavingArgs::get_KeepFontStreamOpen
Examples

Shows how to define custom logic for exporting fonts when saving to HTML.

void SaveExportedFonts()
{
auto doc = MakeObject<Document>(MyDir + u"Rendering.docx");
// Configure a SaveOptions object to export fonts to separate files.
// Set a callback that will handle font saving in a custom manner.
auto options = MakeObject<HtmlSaveOptions>();
options->set_ExportFontResources(true);
options->set_FontSavingCallback(MakeObject<ExHtmlSaveOptions::HandleFontSaving>());
// The callback will export .ttf files and save them alongside the output document.
doc->Save(ArtifactsDir + u"HtmlSaveOptions.SaveExportedFonts.html", options);
std::function<bool(String s)> endsWithTtf = [](String s)
{
return s.EndsWith(u".ttf");
};
for (String fontFilename : System::Array<String>::FindAll(System::IO::Directory::GetFiles(ArtifactsDir), endsWithTtf))
{
std::cout << fontFilename << std::endl;
}
}
class HandleFontSaving : public IFontSavingCallback
{
private:
void FontSaving(SharedPtr<FontSavingArgs> args) override
{
std::cout << "Font:\t" << args->get_FontFamilyName();
if (args->get_Bold())
{
std::cout << ", bold";
}
if (args->get_Italic())
{
std::cout << ", italic";
}
std::cout << "\nSource:\t" << args->get_OriginalFileName() << ", " << args->get_OriginalFileSize() << " bytes\n" << std::endl;
// We can also access the source document from here.
ASSERT_TRUE(args->get_Document()->get_OriginalFileName().EndsWith(u"Rendering.docx"));
ASSERT_TRUE(args->get_IsExportNeeded());
ASSERT_TRUE(args->get_IsSubsettingNeeded());
// There are two ways of saving an exported font.
// 1 - Save it to a local file system location:
args->set_FontFileName(args->get_OriginalFileName().Split(MakeArray<char16_t>({System::IO::Path::DirectorySeparatorChar}))->LINQ_Last());
// 2 - Save it to a stream:
args->set_FontStream(MakeObject<System::IO::FileStream>(
ArtifactsDir + args->get_OriginalFileName().Split(MakeArray<char16_t>({System::IO::Path::DirectorySeparatorChar}))->LINQ_Last(),
System::IO::FileMode::Create));
ASSERT_FALSE(args->get_KeepFontStreamOpen());
}
};

◆ get_IsExportNeeded()

bool Aspose::Words::Saving::FontSavingArgs::get_IsExportNeeded ( ) const

Allows to specify whether the current font will be exported as a font resource. Default is true.

Examples

Shows how to define custom logic for exporting fonts when saving to HTML.

void SaveExportedFonts()
{
auto doc = MakeObject<Document>(MyDir + u"Rendering.docx");
// Configure a SaveOptions object to export fonts to separate files.
// Set a callback that will handle font saving in a custom manner.
auto options = MakeObject<HtmlSaveOptions>();
options->set_ExportFontResources(true);
options->set_FontSavingCallback(MakeObject<ExHtmlSaveOptions::HandleFontSaving>());
// The callback will export .ttf files and save them alongside the output document.
doc->Save(ArtifactsDir + u"HtmlSaveOptions.SaveExportedFonts.html", options);
std::function<bool(String s)> endsWithTtf = [](String s)
{
return s.EndsWith(u".ttf");
};
for (String fontFilename : System::Array<String>::FindAll(System::IO::Directory::GetFiles(ArtifactsDir), endsWithTtf))
{
std::cout << fontFilename << std::endl;
}
}
class HandleFontSaving : public IFontSavingCallback
{
private:
void FontSaving(SharedPtr<FontSavingArgs> args) override
{
std::cout << "Font:\t" << args->get_FontFamilyName();
if (args->get_Bold())
{
std::cout << ", bold";
}
if (args->get_Italic())
{
std::cout << ", italic";
}
std::cout << "\nSource:\t" << args->get_OriginalFileName() << ", " << args->get_OriginalFileSize() << " bytes\n" << std::endl;
// We can also access the source document from here.
ASSERT_TRUE(args->get_Document()->get_OriginalFileName().EndsWith(u"Rendering.docx"));
ASSERT_TRUE(args->get_IsExportNeeded());
ASSERT_TRUE(args->get_IsSubsettingNeeded());
// There are two ways of saving an exported font.
// 1 - Save it to a local file system location:
args->set_FontFileName(args->get_OriginalFileName().Split(MakeArray<char16_t>({System::IO::Path::DirectorySeparatorChar}))->LINQ_Last());
// 2 - Save it to a stream:
args->set_FontStream(MakeObject<System::IO::FileStream>(
ArtifactsDir + args->get_OriginalFileName().Split(MakeArray<char16_t>({System::IO::Path::DirectorySeparatorChar}))->LINQ_Last(),
System::IO::FileMode::Create));
ASSERT_FALSE(args->get_KeepFontStreamOpen());
}
};

◆ get_IsSubsettingNeeded()

bool Aspose::Words::Saving::FontSavingArgs::get_IsSubsettingNeeded ( ) const

Allows to specify whether the current font will be subsetted before exporting as a font resource.

Fonts can be exported as complete original font files or subsetted to include only the characters that are used in the document. Subsetting allows to reduce the resulting font resource size.

By default, Aspose.Words decides whether to perform subsetting or not by comparing the original font file size with the one specified in FontResourcesSubsettingSizeThreshold. You can override this behavior for individual fonts by setting the IsSubsettingNeeded property.

Examples

Shows how to define custom logic for exporting fonts when saving to HTML.

void SaveExportedFonts()
{
auto doc = MakeObject<Document>(MyDir + u"Rendering.docx");
// Configure a SaveOptions object to export fonts to separate files.
// Set a callback that will handle font saving in a custom manner.
auto options = MakeObject<HtmlSaveOptions>();
options->set_ExportFontResources(true);
options->set_FontSavingCallback(MakeObject<ExHtmlSaveOptions::HandleFontSaving>());
// The callback will export .ttf files and save them alongside the output document.
doc->Save(ArtifactsDir + u"HtmlSaveOptions.SaveExportedFonts.html", options);
std::function<bool(String s)> endsWithTtf = [](String s)
{
return s.EndsWith(u".ttf");
};
for (String fontFilename : System::Array<String>::FindAll(System::IO::Directory::GetFiles(ArtifactsDir), endsWithTtf))
{
std::cout << fontFilename << std::endl;
}
}
class HandleFontSaving : public IFontSavingCallback
{
private:
void FontSaving(SharedPtr<FontSavingArgs> args) override
{
std::cout << "Font:\t" << args->get_FontFamilyName();
if (args->get_Bold())
{
std::cout << ", bold";
}
if (args->get_Italic())
{
std::cout << ", italic";
}
std::cout << "\nSource:\t" << args->get_OriginalFileName() << ", " << args->get_OriginalFileSize() << " bytes\n" << std::endl;
// We can also access the source document from here.
ASSERT_TRUE(args->get_Document()->get_OriginalFileName().EndsWith(u"Rendering.docx"));
ASSERT_TRUE(args->get_IsExportNeeded());
ASSERT_TRUE(args->get_IsSubsettingNeeded());
// There are two ways of saving an exported font.
// 1 - Save it to a local file system location:
args->set_FontFileName(args->get_OriginalFileName().Split(MakeArray<char16_t>({System::IO::Path::DirectorySeparatorChar}))->LINQ_Last());
// 2 - Save it to a stream:
args->set_FontStream(MakeObject<System::IO::FileStream>(
ArtifactsDir + args->get_OriginalFileName().Split(MakeArray<char16_t>({System::IO::Path::DirectorySeparatorChar}))->LINQ_Last(),
System::IO::FileMode::Create));
ASSERT_FALSE(args->get_KeepFontStreamOpen());
}
};

◆ get_Italic()

bool Aspose::Words::Saving::FontSavingArgs::get_Italic ( ) const

Indicates whether the current font is italic.

Examples

Shows how to define custom logic for exporting fonts when saving to HTML.

void SaveExportedFonts()
{
auto doc = MakeObject<Document>(MyDir + u"Rendering.docx");
// Configure a SaveOptions object to export fonts to separate files.
// Set a callback that will handle font saving in a custom manner.
auto options = MakeObject<HtmlSaveOptions>();
options->set_ExportFontResources(true);
options->set_FontSavingCallback(MakeObject<ExHtmlSaveOptions::HandleFontSaving>());
// The callback will export .ttf files and save them alongside the output document.
doc->Save(ArtifactsDir + u"HtmlSaveOptions.SaveExportedFonts.html", options);
std::function<bool(String s)> endsWithTtf = [](String s)
{
return s.EndsWith(u".ttf");
};
for (String fontFilename : System::Array<String>::FindAll(System::IO::Directory::GetFiles(ArtifactsDir), endsWithTtf))
{
std::cout << fontFilename << std::endl;
}
}
class HandleFontSaving : public IFontSavingCallback
{
private:
void FontSaving(SharedPtr<FontSavingArgs> args) override
{
std::cout << "Font:\t" << args->get_FontFamilyName();
if (args->get_Bold())
{
std::cout << ", bold";
}
if (args->get_Italic())
{
std::cout << ", italic";
}
std::cout << "\nSource:\t" << args->get_OriginalFileName() << ", " << args->get_OriginalFileSize() << " bytes\n" << std::endl;
// We can also access the source document from here.
ASSERT_TRUE(args->get_Document()->get_OriginalFileName().EndsWith(u"Rendering.docx"));
ASSERT_TRUE(args->get_IsExportNeeded());
ASSERT_TRUE(args->get_IsSubsettingNeeded());
// There are two ways of saving an exported font.
// 1 - Save it to a local file system location:
args->set_FontFileName(args->get_OriginalFileName().Split(MakeArray<char16_t>({System::IO::Path::DirectorySeparatorChar}))->LINQ_Last());
// 2 - Save it to a stream:
args->set_FontStream(MakeObject<System::IO::FileStream>(
ArtifactsDir + args->get_OriginalFileName().Split(MakeArray<char16_t>({System::IO::Path::DirectorySeparatorChar}))->LINQ_Last(),
System::IO::FileMode::Create));
ASSERT_FALSE(args->get_KeepFontStreamOpen());
}
};

◆ get_KeepFontStreamOpen()

bool Aspose::Words::Saving::FontSavingArgs::get_KeepFontStreamOpen ( ) const

Specifies whether Aspose.Words should keep the stream open or close it after saving a font.

Default is false and Aspose.Words will close the stream you provided in the FontStream property after writing a font into it. Specify true to keep the stream open.

See also
Aspose::Words::Saving::FontSavingArgs::get_FontStream
Examples

Shows how to define custom logic for exporting fonts when saving to HTML.

void SaveExportedFonts()
{
auto doc = MakeObject<Document>(MyDir + u"Rendering.docx");
// Configure a SaveOptions object to export fonts to separate files.
// Set a callback that will handle font saving in a custom manner.
auto options = MakeObject<HtmlSaveOptions>();
options->set_ExportFontResources(true);
options->set_FontSavingCallback(MakeObject<ExHtmlSaveOptions::HandleFontSaving>());
// The callback will export .ttf files and save them alongside the output document.
doc->Save(ArtifactsDir + u"HtmlSaveOptions.SaveExportedFonts.html", options);
std::function<bool(String s)> endsWithTtf = [](String s)
{
return s.EndsWith(u".ttf");
};
for (String fontFilename : System::Array<String>::FindAll(System::IO::Directory::GetFiles(ArtifactsDir), endsWithTtf))
{
std::cout << fontFilename << std::endl;
}
}
class HandleFontSaving : public IFontSavingCallback
{
private:
void FontSaving(SharedPtr<FontSavingArgs> args) override
{
std::cout << "Font:\t" << args->get_FontFamilyName();
if (args->get_Bold())
{
std::cout << ", bold";
}
if (args->get_Italic())
{
std::cout << ", italic";
}
std::cout << "\nSource:\t" << args->get_OriginalFileName() << ", " << args->get_OriginalFileSize() << " bytes\n" << std::endl;
// We can also access the source document from here.
ASSERT_TRUE(args->get_Document()->get_OriginalFileName().EndsWith(u"Rendering.docx"));
ASSERT_TRUE(args->get_IsExportNeeded());
ASSERT_TRUE(args->get_IsSubsettingNeeded());
// There are two ways of saving an exported font.
// 1 - Save it to a local file system location:
args->set_FontFileName(args->get_OriginalFileName().Split(MakeArray<char16_t>({System::IO::Path::DirectorySeparatorChar}))->LINQ_Last());
// 2 - Save it to a stream:
args->set_FontStream(MakeObject<System::IO::FileStream>(
ArtifactsDir + args->get_OriginalFileName().Split(MakeArray<char16_t>({System::IO::Path::DirectorySeparatorChar}))->LINQ_Last(),
System::IO::FileMode::Create));
ASSERT_FALSE(args->get_KeepFontStreamOpen());
}
};

◆ get_OriginalFileName()

System::String Aspose::Words::Saving::FontSavingArgs::get_OriginalFileName ( ) const

Gets the original font file name with an extension.

This property contains the original file name of the current font if it is known. Otherwise it can be an empty string.

See also
Aspose::Words::Saving::FontSavingArgs::get_OriginalFileSize
Examples

Shows how to define custom logic for exporting fonts when saving to HTML.

void SaveExportedFonts()
{
auto doc = MakeObject<Document>(MyDir + u"Rendering.docx");
// Configure a SaveOptions object to export fonts to separate files.
// Set a callback that will handle font saving in a custom manner.
auto options = MakeObject<HtmlSaveOptions>();
options->set_ExportFontResources(true);
options->set_FontSavingCallback(MakeObject<ExHtmlSaveOptions::HandleFontSaving>());
// The callback will export .ttf files and save them alongside the output document.
doc->Save(ArtifactsDir + u"HtmlSaveOptions.SaveExportedFonts.html", options);
std::function<bool(String s)> endsWithTtf = [](String s)
{
return s.EndsWith(u".ttf");
};
for (String fontFilename : System::Array<String>::FindAll(System::IO::Directory::GetFiles(ArtifactsDir), endsWithTtf))
{
std::cout << fontFilename << std::endl;
}
}
class HandleFontSaving : public IFontSavingCallback
{
private:
void FontSaving(SharedPtr<FontSavingArgs> args) override
{
std::cout << "Font:\t" << args->get_FontFamilyName();
if (args->get_Bold())
{
std::cout << ", bold";
}
if (args->get_Italic())
{
std::cout << ", italic";
}
std::cout << "\nSource:\t" << args->get_OriginalFileName() << ", " << args->get_OriginalFileSize() << " bytes\n" << std::endl;
// We can also access the source document from here.
ASSERT_TRUE(args->get_Document()->get_OriginalFileName().EndsWith(u"Rendering.docx"));
ASSERT_TRUE(args->get_IsExportNeeded());
ASSERT_TRUE(args->get_IsSubsettingNeeded());
// There are two ways of saving an exported font.
// 1 - Save it to a local file system location:
args->set_FontFileName(args->get_OriginalFileName().Split(MakeArray<char16_t>({System::IO::Path::DirectorySeparatorChar}))->LINQ_Last());
// 2 - Save it to a stream:
args->set_FontStream(MakeObject<System::IO::FileStream>(
ArtifactsDir + args->get_OriginalFileName().Split(MakeArray<char16_t>({System::IO::Path::DirectorySeparatorChar}))->LINQ_Last(),
System::IO::FileMode::Create));
ASSERT_FALSE(args->get_KeepFontStreamOpen());
}
};

◆ get_OriginalFileSize()

int32_t Aspose::Words::Saving::FontSavingArgs::get_OriginalFileSize ( ) const

Gets the original font file size.

This property contains the original file size of the current font if it is known. Otherwise it can be zero.

See also
Aspose::Words::Saving::FontSavingArgs::get_OriginalFileName
Aspose::Words::Saving::FontSavingArgs::get_IsSubsettingNeeded
Examples

Shows how to define custom logic for exporting fonts when saving to HTML.

void SaveExportedFonts()
{
auto doc = MakeObject<Document>(MyDir + u"Rendering.docx");
// Configure a SaveOptions object to export fonts to separate files.
// Set a callback that will handle font saving in a custom manner.
auto options = MakeObject<HtmlSaveOptions>();
options->set_ExportFontResources(true);
options->set_FontSavingCallback(MakeObject<ExHtmlSaveOptions::HandleFontSaving>());
// The callback will export .ttf files and save them alongside the output document.
doc->Save(ArtifactsDir + u"HtmlSaveOptions.SaveExportedFonts.html", options);
std::function<bool(String s)> endsWithTtf = [](String s)
{
return s.EndsWith(u".ttf");
};
for (String fontFilename : System::Array<String>::FindAll(System::IO::Directory::GetFiles(ArtifactsDir), endsWithTtf))
{
std::cout << fontFilename << std::endl;
}
}
class HandleFontSaving : public IFontSavingCallback
{
private:
void FontSaving(SharedPtr<FontSavingArgs> args) override
{
std::cout << "Font:\t" << args->get_FontFamilyName();
if (args->get_Bold())
{
std::cout << ", bold";
}
if (args->get_Italic())
{
std::cout << ", italic";
}
std::cout << "\nSource:\t" << args->get_OriginalFileName() << ", " << args->get_OriginalFileSize() << " bytes\n" << std::endl;
// We can also access the source document from here.
ASSERT_TRUE(args->get_Document()->get_OriginalFileName().EndsWith(u"Rendering.docx"));
ASSERT_TRUE(args->get_IsExportNeeded());
ASSERT_TRUE(args->get_IsSubsettingNeeded());
// There are two ways of saving an exported font.
// 1 - Save it to a local file system location:
args->set_FontFileName(args->get_OriginalFileName().Split(MakeArray<char16_t>({System::IO::Path::DirectorySeparatorChar}))->LINQ_Last());
// 2 - Save it to a stream:
args->set_FontStream(MakeObject<System::IO::FileStream>(
ArtifactsDir + args->get_OriginalFileName().Split(MakeArray<char16_t>({System::IO::Path::DirectorySeparatorChar}))->LINQ_Last(),
System::IO::FileMode::Create));
ASSERT_FALSE(args->get_KeepFontStreamOpen());
}
};

◆ GetType()

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

Reimplemented from System::Object.

◆ Is()

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

Reimplemented from System::Object.

◆ set_FontFileName()

void Aspose::Words::Saving::FontSavingArgs::set_FontFileName ( const System::String value)

◆ set_FontStream() [1/2]

void Aspose::Words::Saving::FontSavingArgs::set_FontStream ( const System::SharedPtr< System::IO::Stream > &  value)

◆ set_FontStream() [2/2]

template<typename CharType , typename Traits >
void Aspose::Words::Saving::FontSavingArgs::set_FontStream ( std::basic_ostream< CharType, Traits > &  value)
inline

◆ set_IsExportNeeded()

void Aspose::Words::Saving::FontSavingArgs::set_IsExportNeeded ( bool  value)

◆ set_IsSubsettingNeeded()

void Aspose::Words::Saving::FontSavingArgs::set_IsSubsettingNeeded ( bool  value)

◆ set_KeepFontStreamOpen()

void Aspose::Words::Saving::FontSavingArgs::set_KeepFontStreamOpen ( bool  value)

◆ Type()

static const System::TypeInfo & Aspose::Words::Saving::FontSavingArgs::Type ( )
static