International Features

Glossary


  • Typography: The process of displaying text in a variety of fonts, sizes, and styles.

One of the most significant features of GDI+ is its support for handling typography-that is, for dealing with the numerous kinds of fonts and scripts encountered in multilingual computing. GDI+ was designed to be language-agnostic and script-agnostic. Unlike GDI, it has no implicit assumptions about the relation between a character's code point and the glyphs used to represent a character in the font. In GDI+ the relation between a character's code point and the glyphs used in the font is many-to-many, which is a very important feature for multilingual computing. For example, two Unicode code points can be represented by one glyph or vice versa. GDI+ also offers optimal font support through various Graphics classes and methods, as discussed in the section that follows.

Another international feature of GDI+ that will make your job much easier is font fallback. Font fallback frees the application and the user from having to know about the scripts supported by each font on the system. If the application tries to display characters from a script that is not supported by the selected font in DrawString, GDI+ automatically switches to a font that can display those characters. Font fallback is also a great benefit for you as a developer, since it spares you from having to know about the scripts that each user might be working with. (For more information, see "Font Fallback" later in this chapter.) Other international features of GDI+ that will make your job less complicated are anti-aliasing and ClearType.

Typography Handling in GDI+

As mentioned, GDI+ is adept at handling typography because of its many-to-many relation between character code points and the glyphs used in a font. When dealing with typography in the context of GDI+, there are several key ideas to bear in mind. You must use Unicode for your text input. Also, you should take advantage of the multiple classes and methods available for font and text support, in addition to leveraging GDI+ support for a host of different scripts.

Unicode

GDI+ doesn't support text that is based on code pages; GDI+ APIs are entirely Unicode-based. Even when running on Microsoft Windows 98 and Microsoft Windows Millennium Edition (Me), GDI+ expects all the input to be in Unicode. If your application is still using code pages, you need to convert the text to Unicode before calling Graphics.DrawString.

The Use of Classes and Methods

GDI+ provides several Graphics classes and methods that allow your application to:

  • Enumerate fonts installed on the system.
  • Create font collections that are private to the application.
  • Obtain font design metrics.
  • Draw text horizontally or vertically.
  • Apply special formatting such as horizontal and vertical alignment, tab stops, and hot-key prefixes to the text.

Scripts and Writing Systems

To accommodate the vast number of writing systems in use today, GDI+ supports the same scripts as Windows XP, including the following:

  • Latin, Greek, and Cyrillic scripts. These scripts are used for English, French, Spanish, German, Greek, Russian, and many other languages' writing systems.
  • East Asian scripts. These scripts are used for Chinese, Japanese, Korean, Vietnamese, Thai, and Ancient Hangul.
  • Bidirectional scripts. These scripts are used in the Arabic writing system, which includes languages like Farsi and Urdu. They are also used in the Hebrew writing system, which includes languages like Hebrew, Yiddish, and Syriac.
  • South Asian scripts. These scripts are used in Devanagari, Tamil, Gujarati, Gurmukhi, and Kannada.

The fonts installed on the specific computer on which your application is running determine which scripts your GDI+ application can display. For example, if your application is running on Windows XP or later, you can display text from any of the scripts just listed1. Figure 13-1 demonstrates output from one of the Microsoft Windows Forms samples within the .NET Framework. The figure shows text from Arabic, Japanese, and Latin scripts, in addition to the enhanced graphics brushes that the application can apply to text.

figure 13.1 output from one of the windows forms samples within the .net framework.

Figure 13.1 - Output from one of the Windows Forms samples within the .NET Framework.

Font Fallback

One of the issues that arises when dealing with Unicode text is which font the application should use to cover all Unicode ranges. A given script in Unicode has specific typographic features and requirements that in many cases are in sharp contrast with those of other scripts. Since Windows XP and Windows .NET Server don't ship any font that covers all of Unicode, GDI+ uses font fallback. If the application attempts to display characters that are not supported by a font, GDI+ will automatically switch-or fall back-to another font on the computer that supports the script.

Suppose that the application is trying to display Hindi text using Arial font, which contains no glyphs for the Devanagari script. GDI+ will internally switch to the Mangal font, which does support Devanagari. Table 13-1 details which font GDI+ uses to fall back for a given script.

Table 13-1 Fallback fonts that GDI+ uses for given scripts.

Script

Font Face Name

Armenian

Sylfaen

East Asian Scripts (including Simplified Chinese, Traditional Chinese, Japanese, and Korean)

Microsoft Sans Serif2

Georgian

Sylfaen

Gujarati

Shruti

Gurmukhi (Punjabi)

Raavi

Hindi

Mangal

Kannada

Tunga

Syriac

Estrangello Edessa

Tamil

Latha

Telugu

Gautami

All other scripts (including Latin, Cyrillic, Greek, Arabic, Hebrew, Thai, and Vietnamese.

Microsoft Sans Serif (on Windows 2000 and Windows XP) Arial (on Microsoft Windows 95, Windows 98, Windows Me, and Microsoft Windows NT 4)

Clearly, if the original font the user or the application specified doesn't contain glyphs for particular characters, and if no fallback font is available on the system, GDI+ will not be able to perform font fallback. Instead, GDI+ will display the missing glyph as an empty square box. (For more information on font fallback, see Chapter 5, "Text Input, Output, and Display.")

Anti-Aliasing and ClearType

Glossary


  • Anti-aliasing: A software technique for smoothing the jagged appearance of curved or diagonal lines caused by poor resolution on a display screen.

Another benefit of using GDI+ is that it provides various quality levels for displaying text. Higher-quality text improves the readability of the text on the screen, which is important for applications designed for intensive reading. Typically, higher-quality rendering takes more processing time than lower-quality rendering.

In addition to traditional anti-aliasing supported by GDI, which is grid-fitted to pixel boundaries, GDI+ supports subpixel gray anti-aliasing and Microsoft's new text display technology called "ClearType." (ClearType technology is only supported on Windows XP and later.) ClearType font smoothing improves text readability on color LCD monitors that have a digital interface, such as on laptop screens and high-quality flat desktop displays. Readability on CRT screens is also somewhat improved.

The following code sample draws text with two different quality-level settings:

 FontFamily fontFamily(L"Times New Roman"); Font        font(&fontFamily, 32, FontStyleRegular, UnitPixel); SolidBrush  solidBrush(Color(255, 0, 0, 255)); WCHAR       string1[] = L"SingleBitPerPixel"; WCHAR       string2[] = L"AntiAlias"; graphics.SetTextRenderingHint(TextRenderingHintSingleBitPerPixel); graphics.DrawString(string1, -1, &font, PointF(10.0f, 10.0f),  &solidBrush); graphics.SetTextRenderingHint(TextRenderingHintAntiAlias); graphics.DrawString(string2, -1, &font, PointF(10.0f, 60.0f),  &solidBrush); 

Figure 13-2 shows the output of the preceding code.

figure 13.2 output of code that draws text with two different quality-level settings.

Figure 13.2 - Output of code that draws text with two different quality-level settings.

You have seen the many features that GDI+ offers to foster the development of world-ready applications. By following the best practices discussed in the next section, you can leverage all the capabilities of GDI+ even further.



Microsoft Corporation - Developing International Software
Developing International Software
ISBN: 0735615837
EAN: 2147483647
Year: 2003
Pages: 198

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net