CD - Canvas Draw

Simulation Base Driver

The Simulation driver was created to simulate functions that were not supported by some CD drivers. It works jointly with the other driver (known as "client"), using its pixel, line and text functions to simulate arcs, sectors, polygons, boxes, clipping and fillings with styles.

Important: All simulation primitives are based in the client's Pixel, Image and/or Line functions.


Use

The Simulation driver is used in several parts of the CD library. For example, most drivers do not contain the mark primitive - in this case, the mark's simulation is automatically used.

In many drivers, the behavior of a given primitive may not be the expected. Usually this is documented in the manual. Should you wish to activate the simulation of a primitive, simply call function cdSimulate with the code of the primitive to be simulated.


Behavior of Functions

Coordinate System and Clipping

  • Complex Regions: not supported.

Attributes

  • cdNativeFont: selects a True Type font file for the FreeType library to render the text. The string format includes the name and size ("filename, size" or, in C style, "%s %d"). Notice that TTF fonts have different file for different font styles, like bold and italic. Font files can be in the current directory, in the directory pointed by the CDDIR environment variable, in Windows in the system defined Font directory, or using the full path of the file. size is given in points or in pixels. The FreeType library was configured to support only TrueType fonts, but it can be configured to support Type 1 fonts also. You may remove the FreeType code from the CD library and use any other distribution.
  • cdFillMode: only CD_EVENODD is supported.
  • cdLineCap: only CD_CAPFLAT is supported.
  • cdLineJoin: only CD_MITER is supported.
  • cdFont: see the font mapping table for the equivalence used to map CD fonts into TrueType font files:
Font Mapping
CD Fonts TTF
CD_SYSTEM cour.ttf
CD_COURIER cour.ttf
CD_TIMES_ROMAN times.ttf
CD_HELVETICA arial.ttf

The file name suffix "bd", "i" and "bi" are used for bold, italic and bold-italic fonts.

Primitives

  • cdPixel: always uses the client's pixel function. When clipping simulation is active, it executes area and polygon clipping.
  • cdLine: draws lines pixel per pixel. The line clipping simulation, when possible, divides the line in several portions and draws each portion with the line function, which can be either simulated or not.
  • cdRect: the simulation is made by means of the line function.
  • cdMark: the simulation is made by means of the line function or the polygon function.
  • cdArc: simulates using the client's cdPixel. If clipping simulation is active, then the primitive will necessarily be simulated.
  • cdSector: simulates using the line function or cdPixel, depending on the interior style. If clipping simulation is active, then the primitive will necessarily be simulated.
  • cdBox: simulates using the line function or cdPixel, depending on the interior style. If clipping simulation is active and it is polygon clipping, then the primitive will necessarily be simulated.
  • cdBegin, cdVertex and cdEnd: simulate using the line function or cdPixel, depending on the interior style. If clipping simulation is active, then the primitive will necessarily be simulated. Open and Closed are simulated by calling the line function.
  • cdText: text simulation is made using TrueType font files in a transparent way for the user. Oriented text is not supported. Clipping simulation is made by eliminating characters which are partially or completely out of the drawing region.