CFFファイルからフォントをロード| .NET

このページでは、ファイルCenturygothic.cffに配置されたフォント「Centurygothic」の読み込み例を見てみましょう。


Aspose.Fontロードの基礎を読んでいない場合は、 フォントをロードする方法?ページ。

まず、ファイルの頭にある次の名前空間に通知する必要があります。

1    using System;
2    using Aspose.Font
3    using Aspose.Font.Sources;
4    using System.IO;

FileInfoオブジェクトを使用してファイルからロードします

アルゴリズムに従って、フォントのロードを満たします。

  1. ファイルへのパスを構築します。
  2. fontdefinitonfonttype値として渡すオブジェクトを開始します。
  3. 自動的に計算された値 fileExtensionを取得します。
  4. フォントをロードします。
 1    //ファイルへのパスを構築します。
 2    string fontpath = path.combine(datadir "Centurygothic.cff");
 3
 4    // Initialize FontDefinition object passing CFF as FontType value and using FontFileDefinition
 5    FontFileDefinition fileDef = new FontFileDefinition(new FileInfo(fontPath));     
 6
 7    // Based on FileInfo object, fileExtension value is calculated automatically from FileInfo fields.
 8    FontDefinition fontDef = new FontDefinition(FontType.CFF, fileDef);
 9
10    // Load the font 
11    Font font = Font.Open(fontDef);

バイト[]タイプ変数を使用して、bytecontentsStreamSourceタイプオブジェクトを使用してフォントロード

この方法でフォントをロードするには、次の手順を実行する必要があります。

  1. ファイルへのパスを構築します。
  2. FontDefiniton オブジェクトを初期化し、CFFFontType 値として、 fileExtension 値として渡し、fontBytes 配列に基づいて ByteContentStreamSource オブジェクトを渡します。
  3. フォントをロードします。
 1    //ファイルへのパスを構築します
 2    string fontpath = path.combine(datadir "Centurygothic.cff");
 3
 4    // Load font binary data into byte array
 5    byte[] fontBytes = 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    FontDefinition fontDef = new FontDefinition(FontType.CFF, "ttf", new ByteContentStreamSource(fontBytes));
10
11    // Load the font
12    Font font = Font.Open(fontDef);

Aspose.fontを使用する方法のその他の例 Aspose.font.examples.sln solutionAspose.Font documentationnet-examples

Have any questions about Aspose.Font?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.