Convert CFF | .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:
using Aspose.Font.Sources;
using System;
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:
- Open
CFF
font. - Notify the output settings.
- Run the conversion.
// Open cff font
string fontPath = Path.Combine(DataDir, "OpenSans-Regular.cff");
FontDefinition fontDefinition = new FontDefinition(FontType.CFF, new FontFileDefinition("cff", new FileSystemStreamSource(fontPath)));
Font font = Font.Open(fontDefinition);
// Ttf output settings
string outPath = Path.Combine(OutputDir, "CffToTtf_out1.ttf");
FileStream outStream = File.Create(outPath);
// Convert cff to ttf
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:
- Open
CFF
font. - Place the settings for the output font stream.
- Process the conversion.
// Open cff font
byte[] fontMemoryData = File.ReadAllBytes(Path.Combine(DataDir, "OpenSans-Regular.cff"));
FontDefinition fontDefinition = new FontDefinition(FontType.CFF, new FontFileDefinition("cff", new ByteContentStreamSource(fontMemoryData)));
Font font = Font.Open(fontDefinition);
// Woff output settings
string outPath = Path.Combine(OutputDir, "CffToWoff_out3.woff");
FileStream outStream = File.Create(outPath);
// Convert cff to woff
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:
- Open the
CFF
. - Notify the output settings.
- Convert
CFF
toWOFF2
and save the result.// Open cff font byte[] fontMemoryData = File.ReadAllBytes(Path.Combine(DataDir, "OpenSans-Regular.cff")); FontDefinition fontDefinition = new FontDefinition(FontType.CFF, new FontFileDefinition("cff", new ByteContentStreamSource(fontMemoryData))); Font font = Font.Open(fontDefinition); // Woff2 output settings string outPath = Path.Combine(OutputDir, "CffToWoff2_out4.woff2"); FileStream outStream = File.Create(outPath); // Convert cff to woff2 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.