CD - Canvas Draw

Vector Text

It is a text that uses a font created only with line segments. It is very useful to be scaled. You must set the text size before drawing any text. The functions ignore the new line character "\n"; only the wdMultiLineVectorText function will consider this character. The default direction is horizontal from left to right.

Vector Text Parameters


void cdVectorText(int x, int y, const char *text); [in C]
void wdVectorText(double x, double y, char * s); (WC) [in C]
cd.VectorText(x, y: number, text: string) [in Lua]
cd.wVectorText(x, y: number, text: string)
(WC) [in Lua]

Draws a vector text in position (x,y), respecting the alignment defined by cdTextAlignment. It ignores the configuration cdBackOpacity, being always transparent. It also ignores strings with multiple lines. It is ESSENTIAL to call cdVectorTextSize or cdVectorCharSize before using cdVectorText or cdMultiLineVetorText.

void cdMultiLineVectorText(int x, int y, const char *text); [in C]
void wdMultiLineVectorText(double x, double y, char * s); (WC) [in C]
cd.MultiLineVectorText(x, y: number, text: string) [in Lua]
cd.wMultiLineVectorText(x, y: number, text: string)
(WC) [in Lua]

Draws a vector text with several lines in position (x,y), respecting the alignment defined by cdTextAlignment. It ignores the configuration cdBackOpacity, being always transparent. Lines are broken by characters "\n". Each line respects the scale defined in cdVectorTextSize or cdVectorCharSize. This function's purpose is to make function cdVectorText more efficient, not being concerned with multiple lines.


Attributes

void cdVectorTextDirection(int x1, int y1, int x2, int y2); [in C]
void wdVectorTextDirection(double x1, double y1, double x2, double y2); (WC) [in C]
cd.VectorTextDirection(x1, y1, x2, y2: number) [in Lua]
cd.wVectorTextDirection(x1, y1, x2, y2: number) (WC) [in Lua]

Defines the text direction by means of two points, (x1,y1) and (x2,y2). The default direction is horizontal from left to right.

double* cdVectorTextTransform(double* matrix); [in C]
cd.VectorTextTransform(matrix: table) -> (old_matrix: table) [in Lua] 

Defines a transformation matrix with 6 elements. If the matrix is NULL, no transformation is set. The default direction is no transformation. The origin is the left bottom corner of matrix. It returns the previous matrix, and the returned vector is only valid until the following call to the function.

The matrix contains rotation and translation elements. It is applied after computing the position and orientation normal to the vector text. We can describe the elements as follows:

|x'|   | cos(ang)  -sin(ang)  trans_x |   |x|                 | 3   4   5| 
|y'| = | sin(ang)   cos(ang)  trans_y | * |y|  with indices   | 0   1   2|

void cdVectorTextSize(int w, int h, char *text); [in C]
void wdVectorTextSize(double size_x, double size_y, char *s); (WC) [in C]
cd.VectorTextSize(w, h: number, text: string) [in Lua]
cd.wVectorTextSize(w, h: number, text: string) (WC) [in Lua]

Modifies the scale of the vector text so that it corresponds to the string of the bounding box defined by w and h. It ignores strings with multiple lines.

double cdVectorCharSize(int size); [in C]
double wdVectorCharSize(double size); (WC) [in C]
cd.VectorCharSize(size: number) -> (old_size: number) [in Lua]
cd.wVectorCharSize(size: number) -> (old_size: number)
(WC) [in Lua]

Sets the height of the characters and adjusts the width according to it. Returns the previous value. CD_QUERY returns the current value.

char* cdVectorFont(char *filename); [in C]
cd.VectorFont(filename: string) -> (font_name: string) [in Lua]

Replaces the current vector font with a font stored in a file with a given name. Returns the name of the font loaded or NULL, if it fails. If filename is NULL, it activates the default font "Simplex II". There is no file associated to this font, it is an embedded font. The library will attempt to load a font from the directory defined by the environment variable "CDDIR", apart from the filename parameter. If it fails, it will attempt to load it using only the filename parameter. The file format is compatible with the GKS file format (text mode).


Properties

void cdGetVectorTextSize(char *text, int *w, int *h); [in C]
void wdGetVectorTextSize(char * s, double *x, double *y); (WC) [in C]
cd.GetVectorTextSize(text: string) -> (w, h: number) [in Lua]
cd.wGetVectorTextSize(text: string) -> (w, h: number)
(WC) [in Lua]

Queries the string's bounding box. Ignores strings with multiple lines. It is not necessary to provide all return pointers, you can provide only the desired values and NULL for the others.

void cdGetVectorTextBounds(char *s, int px, int py, int *rect); [in C]
void wdGetVectorTextBounds(char *s, double x, double y, double *rect); (WC) [in C]
cd.GetVectorTextBounds(s: string, px,py: number) -> (rect: table) [in Lua]
cd.wGetVectorTextBounds(s: string, px,py: number) -> (rect: table) (WC) [in Lua]

Returns the bounding rectangle of the text specified in the current vector font, alignment and direction. Eight values are returned, corresponding to pairs (x,y) of the rectangle's vertices ordered conter-clockwise, starting by the bottom left corner.