Font Overview

Terms

The term definitions shown here are used in documents relating to the G2D font/character (string) display library. These meanings may differ from the general meaning of these terms.

NITRO font A font used for character display by G2D.
Font resource The state of a NITRO font before it has been converted to a form that can be used by G2D. Also, a file that stores such a font.
Glyph The shape of a character.
Glyph image A word that refers to a glyph with special emphasis on image aspects.
Glyph index An ID number that is assigned to every glyph in a NITRO font.
Character code A number that is assigned to every character.
Character encoding A method of converting between a character code and a byte sequence. It is used when expressing a character code as a byte sequence.

NITRO font

The following information is stored in a NITRO font:

Text Characters

Each character in a NITRO font consists of a glyph image (NNS_G2dFontGetGlyphImage) and three types of width data that combine to form the character width: left space width, glyph width, and right space width (NNS_G2dFontGetCharWidths). (See figure below.) The glyph width is the width of the smallest rectangle that contains the glyph. The right space width and left space width are the widths of the areas to the left and right of the rectangle that require no drawing. The character width is the sum of the left space width, the glyph width, and the right space width. In G2D character drawing (NNS_G2dCharCanvasDrawChar), a glyph image is drawn using the glyph width after shifting the distance of the left space width. You can draw text strings by shifting the drawing position to the right by the character width. The left space width and right space width can be negative values and the character width can be smaller than the glyph width. In this case, the character will be drawn overlapping the characters before and after it.

Character Structure Element for NITRO font

Glyph heights for NITRO fonts are not stored for each text character. Instead, the font height (NNS_G2dFontGetHeight)—the height sufficient to display all characters in the font—is stored.

Cells

In a NITRO font, glyphs are stored as BMP images. Each glyph is stored in a BMP image measuring NNS_G2dFontGetCellWidth by NNS_G2dFontGetCellHeight pixels; this BMP image is called a cell.
Cell and Glyph Diagram
The glyph image is stored aligned against the left side of the cell, and its width can be obtained by using NNS_G2dFontGetCharWidths.

Alternate characters

In some functions, when a character not included in the NITRO font is specified, a replacement character is used. This replacement character is called an alternate character and is registered in the NITRO font (NNS_G2dFontGetAlternateGlyphIndex).

Character Codes

Font manipulation functions that take characters as arguments use 16-bit character codes to specify characters. Functions do not use these character codes as meaningful values. Character codes are immediately converted to glyph indices within functions using the conversion table in the NITRO font, and all actual processing is done with glyph indices. Therefore, once a character code conversion table is properly created in the NITRO font, any character set can be used. Conversely, a NITRO font must be prepared for each character set, and if the character set used in a program does not match the NITRO font character set, you will not get the result you want.

Font functions

The font functions can be divided into the following six large groups.

Font creation
These functions are used to create fonts.
NNS_G2dFontInitAuto()
NNS_G2dFontInitUTF8()
NNS_G2dFontInitUTF16()
NNS_G2dFontInitShiftJIS()
NNS_G2dFontInitCP1252()
Font accessors
These functions are used to get and set information about the overall font.
NNS_G2dFontGetType()
NNS_G2dFontGetHeight()
NNS_G2dFontGetCellHeight()
NNS_G2dFontGetCellWidth()
NNS_G2dFontGetBpp()
NNS_G2dFontGetBaselinePos()
NNS_G2dFontGetMaxCharWidth()
NNS_G2dFontGetLineFeed()
NNS_G2dFontSetLineFeed()
NNS_G2dFontGetDefaultCharWidths()
NNS_G2dFontSetDefaultCharWidths()
NNS_G2dFontGetAlternateGlyphIndex()
NNS_G2dFontSetAlternateGlyphIndex()
NNS_G2dFontSetAlternateChar()
Obtaining glyph information from the character code
These functions are used to obtain glyph information for a character using the character code as an argument.
NNS_G2dFontGetGlyph()
NNS_G2dFontGetGlyphImage()
NNS_G2dFontGetCharWidth()
NNS_G2dFontGetCharWidths()
Obtaining the glyph index
These functions are used to obtain the glyph index from the character code.
NNS_G2dFontFindGlyphIndex()
NNS_G2dFontGetGlyphIndex()
Obtaining glyph information from the glyph index
These functions are used to obtain glyph information for a character using the glyph index as an argument.
NNS_G2dFontGetGlyphImageFromIndex()
NNS_G2dFontGetGlyphFromIndex()
NNS_G2dFontGetCharWidthFromIndex()
NNS_G2dFontGetCharWidthsFromIndex()
Calculating the drawing size of a text string
These functions are used to calculate the drawing size of a text string.
NNS_G2dFontGetStringWidth()
NNS_G2dFontGetTextWidth()
NNS_G2dFontGetTextHeight()
NNS_G2dFontGetTextRect()

Written Vertically/Held Vertically

Simple support has been added for fonts written vertically/held vertically beginning from the 2007/03/14 release. Drawing of text written or held vertically can be done by using fonts that are written or held vertically. However, this is a simple implementation achieved by using some font resources differently from usual. There are therefore several limitations.

Functions that do not support fonts written vertically/held vertically

The following functions do not function normally with fonts written vertically/held vertically.

Functions requiring care when used

The following functions need care when using fonts written vertically/held vertically. For more details, refer to the specific function references.

Drawing origin

The drawing origin when writing horizontally is the upper left corner of the character, regardless of whether it is held vertically or horizontally.
The drawing origin when writing vertically is the upper right corner of the character, regardless of whether it is held vertically or horizontally.

See Also

Revision History

2007/03/14 Added the item "Written Vertically/Held Vertically."
2005/05/25 Initial version.


CONFIDENTIAL