Index

FAQs: Rasterization

Q-4-1. What is an 8-bit gray-scale? Is there a large difference between 8 levels of gray and 256 shades of gray?

Eight bit gray-scale means that 8 bits are used to represent different shades of gray. Therefore, with an 8-bit grayscale rasterizer it is possible to generate a maximum of 256 (28) levels of gray. Various experiments have shown that 256 levels of gray is a very good value for the human eye. D-Type is an 8-bit grayscale rasterizer. Some rasterizers use only 8 or 16 levels of gray. While this produces satisfactory results with relatively simple typefaces, it is not sufficient for complex characters (especially with many nearly horizontal or vertical edges). In these cases, there is a significant difference between 8 and 256 levels of gray.

Q-4-2. Can D-Type draw to any Windows HDC?

D-Type Engine provides basic support for any type of Windows Device Context (e.g. screen, window, memory bitmap, printer). Therefore, your application can use Windows functions to create a HDC that can be passed to D-Type via the dtOutputSetAsHDC function. D-Type will render shapes to this HDC as if this was the surface of the screen. This technique is useful when your application needs to generate off-screen bitmaps or print to the printer.

Q-4-3. How can I increase the speed of D-Type Shape Engine when rendering big shapes? Will D-Type Shape Engine return a pointer to the gray-scale bitmap data when my shape is very big?

In order to make D-Type Shape Engine faster when rendering large shapes, your application can increase the value of the the maximum width to render in a single pass and/or the maximum height to render in a single pass parameters in the dtype.inf initialization file. As an alternative, you may use the dtRasterizerRealloc function. In either case, when this value is e.g. 300x300, D-Type Shape Engine will render shapes smaller than 300x300 pixels in a single pass, but shapes larger than 300x300 pixels in multiple passes. As a result, the dtShapeDoOutput function will not be able to return the pointer to the bitmap data for e.g. a 600x600 pixel shape. However, if this value is e.g. 800x800, D-Type Shape Engine will render both the 300x300 and 600x600 pixel shapes in a single pass. As a result, the dtShapeDoOutput function will work faster and be able to return the pointer to the bitmap data for both shapes.

Q-4-4. The dtShapeDoOutput function still fails to return the pointer to my grayscale bitmap data. What is the problem?

Make sure that the bitmap_flag parameter is set to 1 (DV_BITMAP_ON).

Q-4-6. Circles generated by the dtsEllipse, dtsEllipseFilled and dtsEllipseDashed functions do not appear to be true mathematical circles.

These functions are not designed to generate true mathematical circles or ellipses. This is because they use several Bézier curves to approximate the shape of a circle or ellipse. Mathematically has been proven that Bézier curves cannot generate perfect circles and ellipses, just close approximations.

To generate true mathematical circles and ellipses use the dtsTrueEllipse, dtsTrueEllipseFilled and dtsTrueEllipseDashed functions defined in the dtshapes.cpp file.

/*
 * Functions to draw a true mathematical circle or ellipse:
 *
 * dtsTrueEllipseFilled - for filled ellipses
 * dtsTrueEllipseDashed - for dashed or solid ellipse outlines
 * dtsTrueEllipse - only for solid ellipse outlines, simplified version of dtsTrueEllipseDashed
 *
 *   engine - Standard Engine instance
 *   refx, refy - origin's position on screen, in pixels
 *   x, y - coordinate of ellipse's center point, in float-point pixels
 *   rx, ry - ellipse's horizontal and vertical radius, in float-point pixels
 *   ld - length of a single dashed segment in pixels, set to -1 for solid
 *   ld_shift - presently undocumented, must be set to DV_NULL
 *   t - thickness of ellipse's outline, in float-point pixels
 *   TM - optional Affine transform matrix (DV_NULL = no transform)
 */ 

DT_UBYTE* dtsTrueEllipseFilled_Build(DT_FLOAT x, DT_FLOAT y, DT_FLOAT rx, DT_FLOAT ry, const DT_TM2X2 TM, DT_RECT_SLONG* extent);
DT_SWORD dtsTrueEllipseFilled(DT_DTENGINE engine, DT_SLONG refx, DT_SLONG refy, DT_FLOAT x, DT_FLOAT y, DT_FLOAT rx, DT_FLOAT ry, const DT_TM2X2 TM);
DT_SWORD dtsTrueEllipse(DT_DTENGINE engine, DT_SLONG refx, DT_SLONG refy, DT_FLOAT x, DT_FLOAT y, DT_FLOAT rx, DT_FLOAT ry, DT_FLOAT t, const DT_TM2X2 TM);
DT_SWORD dtsTrueEllipseDashed(DT_DTENGINE engine, DT_SLONG refx, DT_SLONG refy, DT_FLOAT x, DT_FLOAT y, DT_FLOAT rx, DT_FLOAT ry, DT_FLOAT ld, DT_FLOAT* ld_shift, DT_FLOAT t, const DT_TM2X2 TM);

These functions can generate 100% true mathematical circles and ellipses based on the sin/cos formula.

Q-4-7. Does D-Type Font Engine pre-rasterize the whole font ahead of time or just as needed?

D-Type Font Engine does not pre-rasterize the whole font ahead of time. Instead, only glyphs that are needed are processed and rasterized. Processed glyphs are stored in the font cache for fast subsequent access.

Q-4-8. It may be necessary for us to reduce or even switch off anti-aliasing if rendering the text into a high resolution buffer. Is calling dtRasterizerSetGrayscale the best way to do this? If we want to switch off anti-aliasing altogether do we just pass 256 values where the first 128 are switched off and the next 128 are switched on?

Yes. Obviously, the quality of text output in this case will not be the best. This approach should be used only when the resolution is high enough. In all other cases at least 4 levels of gray should be used.

Q-4-9. Do you have any recommendations on the settings to use when rendering device independent text for printing? The text would be scaled for output between 300 and 400 DPI.

No. There is nothing fundamentally different between device independent text used for printing versus screen. We would only suggest reading our Workshop documents: Step by Step: How to Configure D-Type for the Highest Text Quality and Rendering Great Looking Text With D-Type. The resolution of 300 and 400 DPI is pretty good, so you could disable hinting, but this is not absolutely necessary.

 

Index