フォント変換。高度な詳細| Java
場合によっては、フォントを保存する前に変換されたフォントデータを読み取り/変更する感覚があります。
方法 com.aspose.font.Font.convert(FontType fontType)は、そのような場合のために設計されました。この方法は、フォントを指定された型に変換し、 com.aspose.font.Fontクラスから継承されたオブジェクトを返します。
次の表は、 FontType値とオブジェクトの間のコヒーレンスのマップを示しています。
| フォントタイプ | フォントオブジェクト |
|---|---|
TTF | com.aspose.font.TtfFont |
Type1 | com.aspose.font.Type1Font |
CFF | com.aspose.font.CffFont |
OTF | com.aspose.font.TtfFont |
結果のフォントを保存する前に、または結果のフォントを保存する代わりに、結果のフォントオブジェクトを使用してフォントプロパティにアクセス/変更します。
現在の瞬間にメソッド
convert()はTrueTypeフォント形式(FontType.TTF)にのみ変換をサポートしているため、常に返されます
使用されるソースフォントとは無関係に変換の結果として、
TtfFontのオブジェクト。
次のコードスニペットは、ディスクからCFFフォントCenturyGothicをロードし、TrueType形式に変換し、変換されたフォントの名前をCenturyGothic_Convertedに変更します。
まず、次のステートメントを使用します。
1
2 package com.aspose.font;
3
4 import java.io.FileOutputStream;
5 import java.io.IOException;
6 import java.nio.file.Files;
7 import java.nio.file.Paths;
8
9 import com.aspose.font.ByteContentStreamSource;
10 import com.aspose.font.FileSystemStreamSource;
11 import com.aspose.font.Font;
12 import com.aspose.font.FontDefinition;
13 import com.aspose.font.FontFileDefinition;
14 import com.aspose.font.FontSavingFormats;
15 import com.aspose.font.FontType;
16 import com.aspose.font.TtfFont;次のアクションを満たす:
- フォントを開きます。
- フォントを
TrueType形式に変換します。 - 変換されたフォントの名前を変更します。
- 出力設定に通知します。
- ちょうど変更された名前で結果を保存します。
1
2 // CFFフォントを開きます
3 String fontPath = Paths.get(getDataDir(), "CenturyGothic.cff").toString();
4 FontDefinition fontDefinition = new FontDefinition(FontType.CFF, new FontFileDefinition("cff", new FileSystemStreamSource(fontPath)));
5 Font font = Font.open(fontDefinition);
6
7 //Convert font into TrueType format and cast font returned to com.aspose.font.TtfFont
8 TtfFont destFont = (TtfFont)font.convert(FontType.TTF);
9
10 //Change name of converted font
11 destFont.setFontName("CenturyGothic_Converted");
12
13 // Output Ttf settings
14 String outPath = Paths.get(getOutputDir(), "CffToTtf_out.ttf").toString();
15
16 //Save the resultant font with the changed font name
17 destFont.save(outPath); JavaにAspose.fontを使用するためのすべての例は、 aspose.font.examples.sln solution、 java-examplesフォルダーに配置されます。