Index

D-Type Standard Engine Units

Pixels and Font Units

The D-Type API simplifies programming by utilizing a very simple set of units: pixels and font units.

Unit Associated Data Type

Pixels

DT_SLONG, DT_SFRAC or DT_FLOAT

Font units

DT_SWORD, DT_UWORD

Pixels

Pixels are used to specify font sizes[1], screen coordinates, clipping regions and bitmap dimensions. In most cases these are integers of the DT_SLONG type. However, since D-Type Rasterizer is a grayscale rasterizer designed to enhance screen resolution, a pixel value can also be represented as a real (floating point) value of the DT_FLOAT type or, alternatively, as a 24.8 fractional value of the DT_SFRAC type. For example, D-Type can render a rectangle that is 5.4 pixels wide and 3.2 pixels tall. Indeed, this rectangle will look slightly bigger than a rectangle that is 5 pixels wide and 3 pixels tall.

The DT_FLOAT type is recommended on machines that have a floating point math processor. Most modern CPUs (e.g. Intel, Motorola) include a floating point processor. However, if a floating point processor is not available (e.g. embedded systems and/or hand-held devices) or if simply the highest possible rendering speed is required, the DT_SFRAC type can be used. This type describes a 24.8 signed fractional value expressed as a 32-bit signed integer. Computations that use DT_SFRAC type are essentially computations with integers and are usually faster than the equivalent computations that use the DT_FLOAT type. To express a floating point number in the 24.8 signed fractional format, simply multiply its value by 256. Mathematically:

fractional_value_24dot8 = floating_point_value * 256
and
floating_point_value = fractional_value_24dot8 / 256

For example, the above rectangle that is 5.4 pixels wide and 3.2 pixels tall would be approximately 1382 fractional units wide and 819 fractional units tall in the 24.8 signed fractional pixel space.

It should be noted that D-Type API always provides support for both floating point and fractional values. When a floating point processor is not available, the floating point math is emulated. It is up to the developers to determine which type works best in their application(s).

Finally, care should be taken when using extremely large pixel values. Although the DT_SLONG type is capable of storing 32-bit integers (i.e. integers in the [-231 .. +231 - 1] range) while DT_FLOAT provides practically an unlimited floating point range, numerical overflows and unexpected rendering results may occur when pixel coordinates approach or exceed the limits imposed by 24-bit integers. This is because D-Type Standard Engine internally stores all pixel quantities as 24.8 signed fractional values in order to allow D-Type Rasterizer to render text and vectorial shapes using sub-pixel precision. In other words, it is important to remember that the final output coordinates (in whole pixels) are limited to the [-223 .. +223 - 1] range.

Font units

Font units are used to describe font and glyph/character dimensions, such as bounding boxes, width information, inter-character spacing, outline curve coordinates, kerning values etc.

For a given font and font size in pixels, font units can be converted to pixels and vice versa using a simple scaling formula. When the dtTypesetterSetTypeAttribs function is called to set the font width and height in pixels, the font's base width and height (also called em-square) will be scaled to this desired pixel value. Then, when the dtFontGetMetrics function is subsequently called to obtain the base font width and height in font units, the horizontal scaling factor is simply a ratio of the font width set in pixels and the base font width retrieved in font units. Similarly, the vertical scaling factor is simply a ratio of the font height set in pixels and the base font height retrieved in font units

For more information on font units, please see D-Type FAQ: Q-2-5.


________________

[1] In traditional typography, font size is measured in points. To see how points can be converted to pixels, please see D-Type FAQ: Q-2-2.
 

Index