Developer Tools
|
Office Productivity Applications
|
Platform-Agnostic APIs
|
Home | Online Demos | Downloads | Buy Now | Support | About Us | News | Working Together | Contact Us
Whenever a developer tries to use a component or a tool that renders text, then he/she has to deal with fonts. Whether the component is a GUI control such as a text label or a text box, or a non-GUI component that renders text on a printer canvas, it must be able to process fonts. Here, the choice of fonts that can be used with the component is limited to those that are installed on the system and also by the font types supported by the run-time environment (.NET and JRE). What if you wanted to use a font that is not installed or if you wanted to use a font type that is not supported by the run time?
Suppose you were going to create a Photoshop-on-the-web kind of application. How would you render text using fonts uploaded by the users? You can't just install any font file that is uploaded by users. Even if it were possible, doing so would be a security risk. Let us take another example, suppose you wanted to create a PDF viewer application. You will find that .NET or JRE can handle only complete fonts, not subset-embedded fonts, non-TrueType fonts and non-OpenType fonts that are typically found in PDF documents.
Thus, a need for advanced font processing becomes necessary. A popular solution for this need is the FreeType font engine. FreeType does a splendid job but it is a "C" library. If you used it in a .NET or Java application, you will not be able to label the application as 100% Java or 100% .NET software. Even if you could care less about labeling, there are situations where you wouldn't be allowed to make native Win32/Win64 calls to the FreeType library. A common example of such a situation is a ASP.NET website running under medium-trust on a shared-hosting server.
It is for these reasons that we created XtremeFontEngine. XtremeFontEngine will be a valuable addition to the toolbox of any Java/.NET developer. XtremeFontEngine enables you to process several types of fonts, and retrieve their font properties and glyph information. You will then be able to render those glyphs on a graphics surface. XtremeFontEngine supports most of the capabilities of FreeType and brings all the advantages of being a pure .NET or Java library. You can use it in all your desktop and web applications without any hassle or restrictions. It can independently provide the host application with all the font properties and glyph information that a font file/stream contains.
Before we go further on XtremeFontEngine, let us take a short refresher course on fonts.
A font is a collection of glyphs that describe how characters need to be displayed or printed.
A character is a symbol used in a written language.
A glyph is the visual representation of a character as specified in a font.
A ligature is a combination of two glyphs to create a special glyph.
A script is a collection of characters used by one or more languages. For example, Latin script is used by English, French, Spanish, and several other languages. Arabic script is used by Arabic, Persian, and Urdu.
A bitmap or raster font is a font whose glyphs are described using pixels placed on a rectangular grid. Bitmap fonts are easier to render and were popular on early display devices and those that had very limited processing ability. Bitmap fonts are not scalable.
An outline font is a font whose glyphs are described using vector drawing instructions or outlines. Outline fonts scale well, as the glyphs can be easily resized by applying simple mathematical transformations to the drawing instructions. At small font sizes, however, the transformations can suffer from artifacts that reduce legibility. To avoid those problems, outline fonts may resort to additional hinting information (in the form of size-specific bitmaps included in the font) or require external anti-aliasing support from the rendering application.
Hinting is a mechanism by which artifacts and other inconsistencies introduced by scaling operations on outlines are eliminated and the glyphs are properly aligned on the pixel grid of the target device.
Type 1 fonts were developed by Adobe. It uses a simplified subset of Postscript instructions to describe glyph outlines in the font. Outline descriptions in Type 1 fonts were described using cubic Bézier curves. To aid legibility at very small sizes, the fonts had additional hinting information (in the form of bitmaps) or required external anti-aliasing support. Type 1 fonts have extensions - pfb and pfm in Windows and pfa and afm in Linux and Mac.
Type 2 fonts were developed by Adobe. It is a lossless compact form of a Type 1 font. It uses the same set of PostScript instructions as Type 1 fonts to describe glyph outlines. Type 2 fonts uses the same PostScript instructions to store additional hinting information also. In other words, Type 2 does not use bitmaps. Type 2 fonts are also known as Compact Font Format or CFF fonts. Embedded fonts in PDF documents use CFF. It is also the basis of OpenType.
TrueType is an outline font type developed by Apple as a competitor to Adobe's Type 1. TrueType fonts were released in 1991 along with Mac OS System 7. Microsoft licensed TrueType from Apple and made it part of 32-bit Windows OS. TrueType had hinting support that provided a high-degree of control right down to pixel level at various font sizes. Techniques such as anti-aliasing and sub-pixel rendering were developed to reduce the reliance on hinting information. Later improvements in display technology have allowed Apple to totally eliminate reliance on hinting information.
OpenType is an outline font type developed by Microsoft and Adobe in 1996. OpenType has a higher glyph limit (64k). OpenType supports both PostScript Type 1 and TrueType outlines. It also supports advanced typographical features such as true small caps, different styles of figures, and extensive sets of ligatures and alternates, as well as complete sets of accented characters and diacritical marks.
XtremeFontEngine .NET is a 100% .NET font engine and XtremeFontEngine (for Java) is a 100% Java font engine. XtremeFontEngine can read fonts and obtain glyph outlines at various sizes. This information can be used to create reusable vector and raster graphic objects for each glyph. Specifically, XtremeFontEngine features include:
Now, we will see how to create a glyph viewer application using XtremeFontEngine .NET.
using
directives:
using System.Drawing.Drawing2D; using Gnostice.XtremeFontEngine;
Filter
property of the OpenFileDialog
component to
Font files |*.ttf;*.ttc;*.pfb;*.pfm;*.afm;*.cff;*.cidcff|All files (*.*)|*.*
// font object IFont font1; // flag for a list box SelectedIndexChanged event handler Boolean bReady = false;
private void button1_Click(object sender, EventArgs e) { listBox1.Items.Clear(); listBox2.Items.Clear(); // Prompt user to select a font if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { // Update check box with file pathname textBox1.Text = openFileDialog1.FileName; try { // Initialize font object with font selected by user font1 = FontFactory.Load(textBox1.Text, "your-license-key"); } catch (Exception err) { MessageBox.Show("Error: " + err.Message); return; } this.Text = "XFE Demo - " + font1.FontName; // Obtain encodings supported by the font List<EncodingType> lstEncoding = font1.GetSupportedEncodings(); if (lstEncoding != null) { // Populate list box with supported font encodings foreach (EncodingType et in lstEncoding) { listBox1.Items.Add(et.ToString()); } } else { listBox1.Items.Add("None"); } // Automatically select an encoding listBox1.SelectedIndex = 0; // Retrieve all glyphs in the font file SortedDictionary<int, string> sd = font1.GetGlyphIdNameDict(); // Populate other listbox with retrieved glyph names foreach (KeyValuePair<int, string> kvp in sd) { listBox2.Items.Add(kvp.Value); } // Set flag for SelectedIndexChanged event handler of list box bReady = true; // Automatically select a glyph name listBox2.SelectedIndex = 0; } }
SelectedIndexChanged
event handler.
// Called when a glyph name has been selected in the second list box private void listBox2_SelectedIndexChanged(object sender, EventArgs e) { RectangleF glyphRect; Matrix mtrx = new Matrix(); float fSize = 170; EncodingType et; // Create a graphics object out of the picture box Graphics gph = pictureBox1.CreateGraphics(); gph.Clear(Form1.DefaultBackColor); gph.CompositingQuality = CompositingQuality.HighQuality; gph.SmoothingMode = SmoothingMode.AntiAlias; // Identify encoding from first list box Enum.TryParse(listBox2.SelectedIndex.ToString(), true, out et); // Proceed only if the second list box hash been populated if (bReady) { // Load the outlines for the selected glphy name GraphicsPath gp = font1.GetOutlineForGlyphName( listBox2.SelectedItem.ToString(), // glyph name fSize, // font size 72, // dpi et); // encoding if (gp != null) { try { // Obtain the bounding box of the outlines of the glyph glyphRect = gp.GetBounds(); // Apply transformations to the outlines so that they can // be centered on the picture box mtrx.Translate( (pictureBox1.Width - glyphRect.Left - glyphRect.Right)/2, (pictureBox1.Height - glyphRect.Top - glyphRect.Bottom)/2 ); gp.Transform(mtrx); // Render the outlines on the picture box gph.DrawPath(Pens.Green, gp); gph.FillPath(Brushes.Green, gp); } catch (Exception err2) { MessageBox.Show("Error: " + err2.Message); } } } }
The download file for XtremeFontEngine (for Java) contains a demo application that demonstrates the capabilities of XtremeFontEngine. In the following video, I show you how to download XtremeFontEngine and test the demo application. (Please watch the video using "Full Screen" and "720p HD" settings.)
---o0O0o---
Our .NET Developer Tools | |
---|---|
![]() Gnostice Document Studio .NETMulti-format document-processing component suite for .NET developers. |
![]() PDFOne .NETA .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications. |
Our Delphi/C++Builder developer tools | |
---|---|
![]() Gnostice Document Studio DelphiMulti-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms. |
![]() eDocEngine VCLA Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools. |
![]() PDFtoolkit VCLA Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents. |
Our Java developer tools | |
---|---|
![]() Gnostice Document Studio JavaMulti-format document-processing component suite for Java developers. |
![]() PDFOne (for Java)A Java PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java applications. |
Our Platform-Agnostic Cloud and On-Premises APIs | |
---|---|
![]() StarDocsCloud-hosted and On-Premises REST-based document-processing and document-viewing APIs |
Privacy | Legal | Feedback | Newsletter | Blog | Resellers | © 2002-2023 Gnostice Information Technologies Private Limited. All rights reserved. |