タイプ1フォントのグリフとメトリック| .NET

フォントメトリックを取得します

フォントメトリックには、ascenderascendertypoascendertypodescenderunitsperemなどの情報が含まれています。 .NET APIのAspose.Fontは、次のサンプルコードを使用してType1フォントファイルからフォントメトリック情報を読み取ることができます。

  1. FontDefinition を作成 – Type1 フォントファイルへのフルパス(例:string fontPath = Path.Combine(dataDir, "courier.pfb");)を作成し、.pfb 形式の FontFileDefinition を作成します。次に、FontType.Type1 とファイル定義を使用して FontDefinition を構築します。
  2. フォントを開いてメトリクスにアクセスFont オブジェクトを返す Aspose.Font.Font.Open(fd) を使用してフォントを開きます。これを Type1Font にキャストして Type1 固有のプロパティにアクセスし、AscenderDescenderTypoAscenderTypoDescenderUnitsPerEm などのメトリクスプロパティを読み取ります。
  3. メトリクスを使用する – これらの値は、レイアウト計算、スケーリング、またはアプリケーションに必要なタイポグラフィ処理に使用できます。
 1// For complete examples and data files, please go to https://github.com/aspose-font/Aspose.Font-for-.NET
 2string fileName = dataDir + "courier.pfb"; //Font file name with full path
 3
 4FontDefinition fd = new FontDefinition(FontType.Type1, new FontFileDefinition("pfb", new FileSystemStreamSource(fileName)));
 5Type1Font font = Aspose.Font.Font.Open(fd) as Type1Font;
 6
 7string name = font.FontName;
 8Console.WriteLine("Font name: " + name);
 9Console.WriteLine("Glyph count: " + font.NumGlyphs);
10string metrics = string.Format(
11    "Font metrics: ascender - {0}, descender - {1}, typo ascender = {2}, typo descender = {3}, UnitsPerEm = {4}",
12    font.Metrics.Ascender, font.Metrics.Descender,
13    font.Metrics.TypoAscender, font.Metrics.TypoDescender, font.Metrics.UnitsPerEM);
14
15Console.WriteLine(metrics);

ラテンシンボルを検出します

.netのAspose.fontでは、Type1フォントファイルからラテンシンボルを検出できます。これは、次のサンプルコードを使用して実現できます。

  1. Type1 フォントを読み込む.pfb ファイルの FontFileDefinition を作成し(例:string fontPath = Path.Combine(dataDir, "courier.pfb");)、FontType.Type1 とファイル定義を使用して FontDefinition を構築します。

  2. サポートされているラテン文字を検出する – フォントのグリフコレクションを反復処理し、DecodeToGid() を使用して各 Unicode 文字を内部グリフ ID に変換します。メソッドが 0 以外の ID を返す場合、そのグリフはフォント内に存在し、そのラテン文字がサポートされていることを示します。

 1// For complete examples and data files, please go to https://github.com/aspose-font/Aspose.Font-for-.NET
 2string fileName = dataDir + "courier.pfb"; //Font file name with full path
 3
 4FontDefinition fd = new FontDefinition(FontType.Type1, new FontFileDefinition("pfb", new FileSystemStreamSource(fileName)));
 5Type1Font font = Aspose.Font.Font.Open(fd) as Type1Font;
 6
 7bool latinText = true;
 8
 9
10for (uint code = 65; code < 123; code++)
11{
12    GlyphId gid = font.Encoding.DecodeToGid(code);
13    if (gid == null || gid == GlyphUInt32Id.NotDefId)
14    {
15        latinText = false;
16    }
17}
18
19if (latinText)
20{
21    Console.WriteLine(string.Format("Font {0} supports latin symbols.", font.FontName));
22}
23else
24{
25    Console.WriteLine(string.Format("Latin symbols are not supported by font {0}.", font.FontName));
26}

Have any questions about Aspose.Font?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.