Convert CFF | API Solution for .NET

The article will explain to you with the code how to transform CFF format. Aspose solution now gives you the opportunity to convert CFF to TTF, CFF to WOFF, and CFF to WOFF2.


First, add the next namespaces at the top of the head of the title:

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

In How to convert the font into the desired format? section you can find the font conversion fundamentals.

Convert CFF to TTF

To fulfill the operation follow the next steps:

  1. Open CFF font.
  2. Notify the output settings.
  3. Run the conversion.
 1 
 2    // Open cff font
 3    string fontPath = Path.Combine(DataDir, "OpenSans-Regular.cff");
 4    FontDefinition fontDefinition = new FontDefinition(FontType.CFF, new FontFileDefinition("cff", new FileSystemStreamSource(fontPath)));
 5    Font font = Font.Open(fontDefinition);
 6
 7    // Ttf output settings
 8    string outPath = Path.Combine(OutputDir, "CffToTtf_out1.ttf");
 9    FileStream outStream = File.Create(outPath);
10
11    // Convert cff to ttf
12    font.SaveToFormat(outStream, FontSavingFormats.TTF);

Convert CFF to WOFF

To transform Compact Font Format to Web Open Font Format you will need to follow the algorithm:

  1. Open CFF font.
  2. Place the settings for the output font stream.
  3. Process the conversion.
 1 
 2    // Open cff font
 3    byte[] fontMemoryData = File.ReadAllBytes(Path.Combine(DataDir, "OpenSans-Regular.cff"));
 4    FontDefinition fontDefinition = new FontDefinition(FontType.CFF, new FontFileDefinition("cff", new ByteContentStreamSource(fontMemoryData)));
 5    Font font = Font.Open(fontDefinition);
 6
 7    // Woff output settings
 8    string outPath = Path.Combine(OutputDir, "CffToWoff_out3.woff");
 9    FileStream outStream = File.Create(outPath);
10
11    // Convert cff to woff
12    font.SaveToFormat(outStream, FontSavingFormats.WOFF);

Convert CFF to WOFF2

To fulfill Compact Font Format to Web Open Font Format version 2 conversion, take the three steps below:

  1. Open the CFF.
  2. Notify the output settings.
  3. Convert CFF to WOFF2 and save the result.
     1 
     2    // Open cff font
     3    byte[] fontMemoryData = File.ReadAllBytes(Path.Combine(DataDir, "OpenSans-Regular.cff"));
     4    FontDefinition fontDefinition = new FontDefinition(FontType.CFF, new FontFileDefinition("cff", new ByteContentStreamSource(fontMemoryData)));
     5    Font font = Font.Open(fontDefinition);
     6
     7    // Woff2 output settings
     8    string outPath = Path.Combine(OutputDir, "CffToWoff2_out4.woff2");
     9    FileStream outStream = File.Create(outPath);
    10
    11    // Convert cff to woff2
    12    font.SaveToFormat(outStream, FontSavingFormats.WOFF2);
                
            

If you need to learn more examples of using the solution to convert fonts you will find useful the Aspose.Font.Examples.sln solution, in the net-examples of the Aspose.Font Documentation/.

Try Font Conversion application in case you want to learn the functional online for free.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.