CD - Canvas Draw

Computer Graphics Metafile - CGM - Driver (cdcgm.h)

This driver allows generating a Computer Graphics Metafile, which is an ANSI standard for the persistent storage of graphics primitives. The file usually has an extension .CGM.


Use

A CGM file is created by means of a call to the function cdCreateCanvas(CD_CGM, Data), which opens the file and writes its header. Then, other functions in the CD library can be called as usual. The Data parameter string has the following format:

"filename [widthxheight] [resolution] [-t] -p[precision]" or in C style "%s %gx%g %g %s"

Only the parameter filename is required. Width and height are provided in millimeters (note the lowercase "x" between them). When the canvas' size is not specified, the VDC Extension saved to the file is the image's bounding rectangle. The resolution is the number of pixels per millimeter; its default value is "3.8". Width, height and resolution are real values. Parameter -t modifies the codification. Width, height and resolution are used only by cdGetCanvasSize and in pixel-millimeter conversion. Parameter -p specifies the precision of integers, which can be 16 (default) or 32.

Any amount of such canvases may exist simultaneously. It is important to note that a call to function cdKillCanvas is required to close the file properly.

Coding - The CGM format supports binary and text coding. If you are not sure what to do, use binary coding, which is the default. Should you prefer text coding, add a "-t" string to the Data parameter.

Precision of Coordinates - The primitives can use coordinates in real numbers. However, for compatibility reasons, we use coordinates in integers.


Behavior of Functions

ControlĀ 

  • cdClear: does nothing.
  • cdFlush: creates a new image, preserving the previous one. The CGM format supports multiple images in a file.
  • cdPlay: works with files created with text or binary coding. There are several callbacks for this driver. If one of the callbacks returns a value different from zero, cdPlay's processing is interrupted. The driver implements the callback CD_SIZECB and other callbacks associated to CGM:
    CD_COUNTERCB - int(*cdcgmcountercb)(cdContext *driver, double percent) - Executed for each header of CGM commands; returns the percentage (0-100%) of headers read.
    CD_SCLMDECB - int(*cdcgmsclmdecb)(cdContext *driver, short scl_mde, short *drw_mode, double *factor) - Executed for the command CGM SCALE MODE. Returns the current CGM scale mode and allows the callback to modify the scale mode used by the cdPlay function (ABSTRACT=0, METRIC=1). Should you choose the METRIC or ABSTRACT scale mode but the original scale mode is METRIC, you must provide the conversion factor in mm per pixel.
    CD_VDCEXTCB - int(*cdcgmvdcextcb)(cdContext *driver, short type, void *xmn, void *ymn, void *xmx, void *ymx) - Executed for the CGM command CGM VDC EXTENT, returns the VDC SPACE.
    CD_BEGPICTCB - int(*cdcgmbegpictcb)(cdContext *driver, char *pict) - Executed for the command BEGIN PICTURE, returns the string that describes the image.
    CD_BEGPICTBCB - int(*cdcgmbegpictbcb)(cdContext *driver) - Executed for the command BEGIN PICTURE BODY.
    CD_CGMBEGMTFCB - int (*cdcgmbegmtfcb)(cdContext *driver, int *xmin, int *ymin, int *xmax, int *ymax) - Executed for the command BEGIN METAFILE, provides the drawing limits of the image in the file.

Coordinate System and Clipping

  • cdUpdateYAxis: does nothing. The axis orientation is the same as the CD library.

Primitives

  • cdBegin: if the parameter CD_CLIP is specified, does nothing.
  • cdMark: CD_DIAMOND, CD_HOLLOW_DIAMOND and CD_HOLLOW_BOX are equivalent to CD_BOX, and CD_HOLLOW_CIRCLE is equivalent to CD_CIRCLE.
  • cdPixel: does not exist in CGM, is simulated using a mark with size 1.

Attributes

Colors

Client ImagesĀ 

Server Images

  • All functions do nothing.