C++ で PowerPoint フォントをカスタマイズ

Load Custom Fonts

Aspose.Slides は、システムにインストールせずにプレゼンテーションで使用されるフォントをロードできます。これにより、PDF や画像などのエクスポート出力が環境間で一貫した外観になります。フォントはカスタム ディレクトリからロードされます。

  1. フォント ファイルが格納されたフォルダーを 1 つ以上指定します。
  2. 静的な FontsLoader::loadExternalFonts メソッドを呼び出して、これらのフォルダーからフォントをロードします。
  3. プレゼンテーションをロードし、レンダリング/エクスポートします。
  4. FontsLoader.clearCache を呼び出してフォント キャッシュをクリアします。

以下のコード例は、フォントのロード プロセスを示しています:

// カスタムフォントファイルが含まれるフォルダーを定義します。
auto fontFolders = MakeObject<Array<String>>(1, externalFontFolder );

// 指定されたフォルダーからカスタムフォントをロードします。
FontsLoader::LoadExternalFonts(fontFolders);

auto presentation = MakeObject<Presentation>(u"sample.pptx");

// ロードしたフォントを使用してプレゼンテーションをレンダリング/エクスポートします(例: PDF、画像、または他の形式)。
presentation->Save(u"output.pdf", SaveFormat::Pdf);
presentation->Dispose();

// 作業が完了したらフォントキャッシュをクリアします。
FontsLoader::ClearCache();

Get Custom Font Folders

Aspose.Slides は、フォント フォルダーを検索できるように FontsLoader::GetFontFolders() を提供します。このメソッドは LoadExternalFonts メソッドで追加されたフォルダーとシステム フォント フォルダーを返します。

この C++ コードは、FontsLoader::GetFontFolders() の使用方法を示しています:

// この行はフォントファイルがチェックされるフォルダーを出力します。
// それらはLoadExternalFontsメソッドで追加されたフォルダーとシステムのフォントフォルダーです。
auto fontFolders = FontsLoader::GetFontFolders();

Specify Custom Fonts Used with a Presentation

Aspose.Slides は、プレゼンテーションで使用する外部フォントを指定できるように LoadOptions::set_DocumentLevelFontSources プロパティを提供します。

この C++ コードは、LoadOptions::set_DocumentLevelFontSources プロパティの使用方法を示しています:

auto memoryFont1 = File::ReadAllBytes(u"customfonts\\CustomFont1.ttf");
auto memoryFont2 = File::ReadAllBytes(u"customfonts\\CustomFont2.ttf");

auto loadOptions = System::MakeObject<LoadOptions>();
loadOptions->get_DocumentLevelFontSources()->set_FontFolders(System::MakeArray<String>({u"assets\\fonts", u"global\\fonts"}));
loadOptions->get_DocumentLevelFontSources()->set_MemoryFonts(System::MakeArray<ArrayPtr<uint8_t>>({memoryFont1, memoryFont2}));
{
    auto presentation = System::MakeObject<Presentation>(u"MyPresentation.pptx", loadOptions);
    //プレゼンテーションで作業します
    //CustomFont1、CustomFont2 および assets\fonts と global\fonts フォルダーおよびそのサブフォルダー内のフォントはすべてプレゼンテーションで使用可能です
}

Manage Fonts Externally

Aspose.Slides は、外部フォントをバイト配列にロードできるように FontsLoader::LoadExternalFont メソッドを提供します。

この C++ コードは、バイト配列フォントのロード プロセスを示しています:

// ドキュメントディレクトリへのパス
const String outPath = u"../out/SpecifyFontsUsedWithPresentation.pptx";
const String templatePath = u"../templates/AccessSlides.pptx";

ArrayPtr<String> fontsLocation =  MakeArray<System::String>({ u"assets\\fonts", u"global\\fonts" });// ;
ArrayPtr<ArrayPtr<uint8_t>> memoryfontsLocation = MakeArray < ArrayPtr<uint8_t>>({ File::ReadAllBytes(u"../templates/CustomFont1.ttf"), File::ReadAllBytes(u"../templates/CustomFont2.ttf") });

SharedPtr < Aspose::Slides::LoadOptions > loadOptions = MakeObject <Aspose::Slides::LoadOptions>();

loadOptions->get_DocumentLevelFontSources()->set_FontFolders(fontsLocation);
loadOptions->get_DocumentLevelFontSources()->set_MemoryFonts(memoryfontsLocation);
	
SharedPtr<Presentation> pres = MakeObject<Presentation>(templatePath, loadOptions);

FAQ

Do custom fonts affect export to all formats (PDF, PNG, SVG, HTML)?

はい。接続されたフォントは、すべてのエクスポート形式でレンダラーによって使用されます。

Are custom fonts automatically embedded into the resulting PPTX?

いいえ。レンダリング用にフォントを登録することと、PPTX に埋め込むことは同じではありません。プレゼンテーション ファイル内にフォントを保持する必要がある場合は、明示的な embedding features を使用してください。

Can I control fallback behavior when a custom font lacks certain glyphs?

はい。font substitutionreplacement rulesfallback sets を構成して、要求されたグリフが欠落している場合に使用されるフォントを正確に定義できます。

Can I use fonts in Linux/Docker containers without installing them system-wide?

はい。独自のフォント フォルダーを指すか、バイト配列からフォントをロードしてください。これにより、コンテナ イメージ内でシステム フォント ディレクトリへの依存がなくなります。

What about licensing—can I embed any custom font without restrictions?

フォントのライセンス遵守はご利用者の責任です。ライセンス条件はさまざまで、埋め込みや商用利用を禁止するものもあります。出力物を配布する前に必ずフォントの EULA を確認してください。