public static void Run() { string dataDir = RunExamples.GetDataDir_Data(); //ExStart: 1 string fileName = dataDir + "Montserrat-Regular.ttf"; //Font file name with full path FontDefinition fd = new FontDefinition(FontType.TTF, new FontFileDefinition("ttf", new FileSystemStreamSource(fileName))); TtfFont ttfFont = Aspose.Font.Font.Open(fd) as TtfFont; bool latinText = true; for (uint code = 65; code < 123; code++) { GlyphId gid = ttfFont.Encoding.DecodeToGid(code); if (gid == null || gid == GlyphUInt32Id.NotDefId) { latinText = false; } } if (latinText) { Console.WriteLine(string.Format("Font {0} supports latin symbols.", ttfFont.FontName)); } else { Console.WriteLine(string.Format("Latin symbols are not supported by font {0}.", ttfFont.FontName)); } //ExEnd: 1 }
public static void Run() { string dataDir = RunExamples.GetDataDir_Data(); //ExStart: 1 string fileName = dataDir + "Montserrat-Regular.ttf"; //Font file name with full path FontDefinition fd = new FontDefinition(FontType.TTF, new FontFileDefinition("ttf", new FileSystemStreamSource(fileName))); TtfFont font = Aspose.Font.Font.Open(fd) as TtfFont; string name = font.FontName; Console.WriteLine("Font name: " + name); Console.WriteLine("Glyph count: " + font.NumGlyphs); string metrics = string.Format( "Font metrics: ascender - {0}, descender - {1}, typo ascender = {2}, typo descender = {3}, UnitsPerEm = {4}", font.Metrics.Ascender, font.Metrics.Descender, font.Metrics.TypoAscender, font.Metrics.TypoDescender, font.Metrics.UnitsPerEM); Console.WriteLine(metrics); //Get cmap unicode encoding table from font as object TtfCMapFormatBaseTable to access information about font glyph for symbol 'A'. //Also check that font has object TtfGlyfTable (table 'glyf') to access glyph. Aspose.Font.TtfCMapFormats.TtfCMapFormatBaseTable cmapTable = null; if (font.TtfTables.CMapTable != null) { cmapTable = font.TtfTables.CMapTable.FindUnicodeTable(); } if (cmapTable != null && font.TtfTables.GlyfTable != null) { Console.WriteLine("Font cmap unicode table: PlatformID = " + cmapTable.PlatformId + ", PlatformSpecificID = " + cmapTable.PlatformSpecificId); //Code for 'A' symbol char unicode = (char)65; //Glyph index for 'A' uint glIndex = cmapTable.GetGlyphIndex(unicode); if (glIndex != 0) { //Glyph for 'A' Glyph glyph = font.GetGlyphById(glIndex); if (glyph != null) { //Print glyph metrics Console.WriteLine("Glyph metrics for 'A' symbol:"); string bbox = string.Format( "Glyph BBox: Xmin = {0}, Xmax = {1}" + ", Ymin = {2}, Ymax = {3}", glyph.GlyphBBox.XMin, glyph.GlyphBBox.XMax, glyph.GlyphBBox.YMin, glyph.GlyphBBox.YMax); Console.WriteLine(bbox); Console.WriteLine("Width:" + font.Metrics.GetGlyphWidth(new GlyphUInt32Id(glIndex))); } } } //ExEnd: 1 }
public static void Run() { string dataDir = RunExamples.GetDataDir_Data(); //ExStart: 1 string fileName = dataDir + "Montserrat-Regular.ttf"; //Font file name with full path FontDefinition fd = new FontDefinition(FontType.TTF, new FontFileDefinition("ttf", new FileSystemStreamSource(fileName))); TtfFont ttfFont = Aspose.Font.Font.Open(fd) as TtfFont; //ExEnd: 1 }
public static void Run() { //ExStart: 1 string dataDir = RunExamples.GetDataDir_Data(); //Font to check string fileName = dataDir + "Montserrat-Regular.ttf"; //Font file name with full path FontDefinition fd = new FontDefinition(FontType.TTF, new FontFileDefinition("ttf", new FileSystemStreamSource(fileName))); TtfFont font = Aspose.Font.Font.Open(fd) as TtfFont; LicenseFlags licenseFlags = null; if (font.TtfTables.Os2Table != null) { licenseFlags = font.TtfTables.Os2Table.GetLicenseFlags(); } if (licenseFlags == null || licenseFlags.FSTypeAbsent) { Console.WriteLine(string.Format("Font {0} has no embedded license restrictions", font.FontName)); } else { if (licenseFlags.IsEditableEmbedding) { Console.WriteLine( string.Format("Font {0} may be embedded, and may be temporarily loaded on other systems.", font.FontName) + " In addition, editing is permitted, including ability to format new text" + " using the embedded font, and changes may be saved."); } else if (licenseFlags.IsInstallableEmbedding) { Console.WriteLine( string.Format("Font {0} may be embedded, and may be permanently installed", font.FontName) + " for use on a remote systems, or for use by other users."); } else if (licenseFlags.IsPreviewAndPrintEmbedding) { Console.WriteLine( string.Format("Font {0} may be embedded, and may be temporarily loaded", font.FontName) + " on other systems for purposes of viewing or printing the document."); } else if (licenseFlags.IsRestrictedLicenseEmbedding) { Console.WriteLine( string.Format("Font {0} must not be modified, embedded or exchanged in any manner", font.FontName) + " without first obtaining explicit permission of the legal owner."); } } //ExEnd: 1 }
public static void Run() { //ExStart: 2 string dataDir = RunExamples.GetDataDir_Data(); string fileName1 = dataDir + "Montserrat-Bold.ttf"; //Font file name with full path FontDefinition fd1 = new FontDefinition(FontType.TTF, new FontFileDefinition("ttf", new FileSystemStreamSource(fileName1))); TtfFont ttfFont1 = Aspose.Font.Font.Open(fd1) as TtfFont; string fileName2 = dataDir + "Lora-Bold.ttf"; //Font file name with full path FontDefinition fd2 = new FontDefinition(FontType.TTF, new FontFileDefinition("ttf", new FileSystemStreamSource(fileName2))); TtfFont ttfFont2 = Aspose.Font.Font.Open(fd2) as TtfFont; DrawText("Hello world", ttfFont1, 14, Brushes.White, Brushes.Black, dataDir + "hello1_montserrat_out.jpg"); DrawText("Hello world", ttfFont2, 14, Brushes.Yellow, Brushes.Red, dataDir + "hello2_lora_out.jpg"); //ExEnd: 2 }
public static void Run() { //ExStart: 1 //byte array to load Font from string dataDir = RunExamples.GetDataDir_Data(); byte[] fontMemoryData = File.ReadAllBytes(dataDir + "Montserrat-Regular.ttf"); FontDefinition fd = new FontDefinition(FontType.TTF, new FontFileDefinition("ttf", new ByteContentStreamSource(fontMemoryData))); TtfFont ttfFont = Aspose.Font.Font.Open(fd) as TtfFont; //Work with data from just loaded TtfFont object //Save CffFont to disk //Output Font file name with full path string outputFile = RunExamples.GetDataDir_Data() + "Montserrat-Regular_out.ttf"; ttfFont.Save(outputFile); //ExEnd: 1 }