Aspose::Words::Saving::IFontSavingCallback Interface Referenceabstract

Detailed Description

Implement this interface if you want to receive notifications and control how Aspose.Words saves fonts when exporting a document to HTML format.

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/IFontSavingCallback.h>

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

Public Member Functions

virtual void FontSaving (SharedPtr< FontSavingArgs > args)=0
 Called when Aspose.Words is about to save a font resource. More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 

Static Public Member Functions

static const TypeInfoType ()
 

Member Function Documentation

◆ FontSaving()

virtual void Aspose::Words::Saving::IFontSavingCallback::FontSaving ( System::SharedPtr< Aspose::Words::Saving::FontSavingArgs args)
pure virtual

Called when Aspose.Words is about to save a font resource.

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::IFontSavingCallback::GetType ( ) const
overridevirtual

Reimplemented from System::Object.

◆ Is()

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

Reimplemented from System::Object.

◆ Type()

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