字体转换。高级详细信息| .NET

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

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

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

字体类型字体对象
TTFAspose.Font.Ttf.TtfFont
Type1Aspose.Font.Type1.Type1Font
CFFAspose.Font.Cff.CffFont
OTFAspose.Font.Ttf.TtfFont

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

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

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

执行下一个动作:

  1. 打开字体。
  2. 将字体转换为TrueType格式。
  3. 更改转换为字体的名称。
  4. 通知输出设置。
  5. 保存最终更改的名称。
 1 
 2    // Open cff font
 3    string fontPath = Path.Combine(DataDir, "CenturyGothic.cff");
 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 Aspose.Font.Ttf.TtfFont
 8    Aspose.Font.Ttf.TtfFont destFont = font.Convert(FontType.TTF) as Aspose.Font.Ttf.TtfFont;
 9
10    // Change name of converted font
11    destFont.FontName = "CenturyGothic_Converted";
12
13    // Ttf output settings
14    string outPath = Path.Combine(OutputDir, "CffToTtf_out.ttf");
15
16    // Save resultant font with font name changed
17    destFont.Save(outPath);

使用aspose.font for.net的完整示例放在 aspose.font.examples.sln解决方案中,在 net-examples aspose.font文档文件夹中。

Have any questions about Aspose.Font?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.