CFFファイルからフォントをロード| C++
Contents
[
Hide
Show
]このページでは、ファイルCenturygothic.cffに配置されたフォント「Centurygothic」の読み込み例を見てみましょう。
Aspose.Fontロードの基礎を読んでいない場合は、 フォントをロードする方法?ページ。
まず、ファイルの頭にある次の名前空間に通知する必要があります。
1using namespace Aspose::Font;
2using namespace Aspose::Font::Sources;
3using namespace System.IO;
FileInfoオブジェクトを使用してファイルからロードします
アルゴリズムに従って、フォントのロードを満たします。
- ファイルへのパスを構築します。
- fontdefinitonを fonttype値として渡すオブジェクトを開始します。
- 自動的に計算された値 fileExtensionを取得します。
- フォントをロードします。
1 // Construct path to the file.
2 System::String fontPath = System::IO::Path::Combine(get_DataDir(), u"CenturyGothic.cff");
3
4 // Initialize FontDefinition object passing CFF as FontType value and using FontFileDefinition
5 // based on FileInfo object, fileExtension value is calculated automatically from FileInfo fields.
6 System::SharedPtr<FontFileDefinition> fileDef = System::MakeObject<FontFileDefinition>(System::MakeObject<System::IO::FileInfo>(fontPath));
7 System::SharedPtr<FontDefinition> fontDef = System::MakeObject<FontDefinition>(Aspose::Font::FontType::CFF, fileDef);
8
9 // Load the font
10 System::SharedPtr<Aspose::Font::Font> font = Aspose::Font::Font::Open(fontDef);
バイト[]タイプ変数を使用して、bytecontentsStreamSourceタイプオブジェクトを使用してフォントロード
この方法でフォントをロードするには、次の手順を実行する必要があります。
- ファイルへのパスを構築します。
- fontdefinitoncff`を fonttype値として渡すオブジェクト、 fileextension値としてfiritionized fontents treamsource*](8)fontystes arrayに基づく bytecontentstreamsourceas fileextensionのオブジェクトを初期化します。
- フォントをロードします。
1 // Construct path to the file
2 System::String fontPath = System::IO::Path::Combine(get_DataDir(), u"CenturyGothic.cff");
3
4 // Load font binary data into byte array
5 System::ArrayPtr<uint8_t> fontBytes = System::IO::File::ReadAllBytes(fontPath);
6
7 // Initialize FontDefinition object passing CFF as FontType value, "cff" as fileExtension value,
8 // and ByteContentStreamSource object based on fontBytes array
9 System::SharedPtr<FontDefinition> fontDef = System::MakeObject<FontDefinition>(Aspose::Font::FontType::CFF, u"ttf", System::MakeObject<ByteContentStreamSource>(fontBytes));
10
11 // Load font and print results
12 System::SharedPtr<Aspose::Font::Font> font = Aspose::Font::Font::Open(fontDef);
Aspose.fontの使用方法に関するその他の例 Aspose.font.examples.cpp.sln solution、 cpp-examplesの Aspose.Font documentation。