字体转换。高级详细信息|爪哇

在某些情况下,在保存字体之前,可以读取/修改转换的字体数据的感觉。

方法 com.aspose.font.font.convert(fonttype fonttype)是为这种情况设计的。此方法将字体转换为指定类型的字体和 返回从 com.aspose.font.font类继承的对象,该类别对应于 fonttype值,将其传递到 convert()方法中。

下表显示了 fonttype值和对象之间的相干性图,该值是从基础 com.aspose.font.font.font类中继承的。

字体类型字体对象
TTFcom.aspose.font.TtfFont
Type1com.aspose.font.Type1Font
CFFcom.aspose.font.CffFont
OTFcom.aspose.font.TtfFont

在保存结果字体或保存结果字体之前,请使用结果字体对象访问/更改字体属性。

在当前时刻方法 convert()仅支持转换为trueType字体格式(fonttype.ttf),因此它始终返回 类型 ttffont类型的对象是由所使用的源字体独立于转换的结果。

下一个代码片段从磁盘加载CFF字体CenturyGothic,将其转换为TrueType格式,并将转换后的字体的名称更改为“CenturyGothic_Converted”。

首先,使用下一个语句:

 1 
 2    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;

执行下一个动作:

  1. 打开字体。
  2. 将字体转换为TrueType格式。
  3. 更改转换为字体的名称。
  4. 通知输出设置。
  5. 保存最终更改的名称。
 1 
 2    //打开CFF字体
 3    字符串fontpath = paths.get(getDatadir(),“ centurygothic.cff)toString();
 4    fontdefinition fontdefinition = new fontdefinition(fonttype.cffnew fontfiledefinition(`CFF`,new filesystemstreamsource(fontpath)));
 5    字体字体= font.open(fontDefinition);
 6
 7    //Convert font into TrueType format and cast font returned to com.aspose.font.TtfFont
 8    Font 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);	

用于使用aspose.font的完整示例用于 aspose.font.examples.sln解决方案,在 Java-examples aspose.font document.font documentgithub repository的文件夹中。

Have any questions about Aspose.Font?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.