Filled Areas
It is an area filled with the foreground color, but it depends on the current interior style. The SOLID style depends only on the foreground color. The HATCH style depends on the foreground color and on the back opacity attribute. The hatch lines drawn with this style do not depend on the line attributes. The STIPPLE style depends on the foreground color, the background color and the back opacity attribute. The PATTERN style depends only on global canvas attributes.
The fillings can have only one color, using the foreground color, they can be hatched with several styles, and can be made with a color or monochromatic pattern using either the foreground or the background color. The hatched and monochromatic fillings are affected by the back opacity - if it is transparent, then the background is not drawn with the background color. If either the background or the foreground color are modified, the hatched and monochromatic fillings must be modified again in order to be updated.
Note that when a Filling Attribute is modified, the active filling style is now that of the modified attribute (hatch, stipple or pattern). Notice that this is not true for the clipping area. When the clipping area is modified, the clipping is only affected if it is active.
Filled Polygons
Filled polygons can be created using cdBegin(CD_FILL)/cdVertex(x,y)/.../cdEnd().
See the documentation of cdBegin/cdVertex/cdEnd.
void cdBox(int
xmin, int xmax, int ymin, int ymax); [in C]
void wdBox(double xmin, double xmax, double ymin, double
ymax); (WC) [in C]
cd.Box(xmin, xmax, ymin, ymax: number) [in Lua]
cd.wBox(xmin,
xmax, ymin, ymax: number) (WC) [in Lua]
Fills a rectangle according to the current interior style. All points in the interval x_min<=x<=x_max, y_min<=y<=y_max will be painted. When the interior style CD_HOLLOW is defined, the function behaves like its equivalent cdRect.
void
cdSector(int xc, int yc, int w, int h, double
angle1, double angle2); [in C]
void wdSector(double xc, double yc, double w, double h,
double angle1, double angle2); (WC) [in C]
cd.Sector(xc, yc, w, h, angle1, angle2: number) [in Lua]
cd.wSector(xc, yc, w, h, angle1, angle2: number)
(WC) [in Lua]
Fills the arc of an ellipse aligned with the axis, according to the current interior style, in the shape of a pie. It is drawn counter-clockwise. The coordinate (xc,yc) defines the center of the ellipse. Dimensions w and h define the elliptic axes X and Y, respectively.
Angles angle1 and angle2, in degrees, define the arc's beginning and end, but they are not the angle relative to the center, except when w==h and the ellipse is reduced to a circle. The arc starts at the point (xc+(w/2)*cos(angle1),yc+(h/2)*sin(angle1)) and ends at (xc+(w/2)*cos(angle2),yc+(h/2)*sin(angle2)). A complete ellipse can be drawn using 0 and 360 as the angles.
The angles are specified so if the size of the ellipse (w x h) is changed, its shape is preserved. So the angles relative to the center are dependent from the ellipse size. The actual angle can be obtained using rangle = atan2((h/2)*sin(angle),(w/2)*cos(angle)).
The angles are given in degrees. To specify the angle in radians, you can use the definition CD_RAD2DEG to multiply the value in radians before passing the angle to CD.
When the interior style CD_HOLLOW is defined, the function behaves like its equivalent cdArc, plus two lines connecting to the center.
Sector Parameters
void
cdChord(int xc, int yc, int w, int h, double
angle1, double angle2); [in C]
void wdChord(double xc, double yc, double w, double h,
double angle1, double angle2); (WC) [in C]
cd.Chord(xc, yc, w, h, angle1, angle2: number) [in Lua]
cd.wChord(xc, yc, w, h, angle1, angle2: number)
(WC) [in Lua]
Fills the arc of an ellipse aligned with the axis, according to the current interior style, the start and end points of the arc are connected. The parameters are the same as the cdSector.
When the interior style CD_HOLLOW is defined, the function behaves like its equivalent cdArc, plus a line connecting the arc start and end points.
Chord Parameters
Attributes
int
cdBackOpacity(int opacity);
[in C]
cd.BackOpacity(opacity: number) -> (old_opacity:
number) [in Lua]
Configures the background opacity to filling primitives based on the foreground and background colors. Values: CD_TRANSPARENT or CD_OPAQUE. If it is opaque, the text primitive, for instance, will erase whatever is in the bounding box with the background color. If it is transparent, only the foreground color is painted. The same occurs for the interior styles of hatch and stipple, and for lines with a style different from CD_CONTINUOUS. It returns the previous value. Default value: CD_TRANSPARENT. Value CD_QUERY simply returns the current value.
Back Opacity Attribute
int
cdFillMode(int mode); [in C]
cd.FillMode(mode: number) -> (old_mode:
number) [in Lua]
Selects a predefined polygon fill rule (CD_EVENODD or CD_WINDING). Returns the previous value. Default value: CD_EVENODD. Value CD_QUERY simply returns the current value.
Fill Modes
int
cdInteriorStyle(int style);
[in C]
cd.InteriorStyle(style: number) -> (old_style:
number) [in Lua]
Configures the current style for the area filling primitives: CD_SOLID, CD_HOLLOW, CD_HATCH, CD_STIPPLE or CD_PATTERN. Note that CD_HATCH and CD_STIPPLE are affected by the opacity of the current background. It returns the previous value. Default value: CD_SOLID. Value CD_QUERY simply returns the current value.
If a stipple or a pattern were not defined, the state of the attribute is not changed.
When the style CD_HOLLOW is defined, functions cdBox and cdSector behave as their equivalent cdRect and cdArc+Lines, and the polygons with style CD_FILL behave like CD_CLOSED_LINES.
int
cdHatch(int style); [in C]
cd.Hatch(style: number) -> (old_style: number)
[in Lua]
Selects a predefined hatch style (CD_HORIZONTAL, CD_VERTICAL, CD_FDIAGONAL, CD_BDIAGONAL, CD_CROSS or CD_DIAGCROSS) and sets the interior style to CD_HATCH. Returns the previous value. Default value: CD_HORIZONTAL. Value CD_QUERY simply returns the current value.
Hatch Styles
void
cdStipple(int w, int h, unsigned char *fgbg) [in
C]
cd.Stipple(stipple: stipple_tag) [in Lua]
Defines a wxh matrix of zeros and ones. The zeros are mapped to the background color or are transparent, according to the background opacity attribute. The ones are mapped to the foreground color. The function sets the interior style to CD_STIPPLE. To avoid having to deal with matrices in C, the element (i,j) of fgbg is stored as fgbg[j*w+i]. The origin is the left bottom corner of the image. It cannot be queried. It does not need to be stored by the application, as it is internally replicated by the library.
void
wdStipple(int w, int h, unsigned char *fgbg,
double w_mm, double h_mm); [in C]
cd.wStipple(stipple: stipple_tag, w_mm, h_mm:
number) [in Lua]
Allows specifying the stipple in world coordinates. Another stipple will be created with the size in pixels corresponding to the specified size in millimeters. The use of this function may produce very large or very small stipples.
unsigned char *
cdGetStipple(int* w, int*
h); [in C]
cd.GetStipple() - > (stipple: stipple_tag) [in
Lua]
Returns the current stipple and its dimensions. Returns NULL if no stipple was defined.
void
cdPattern(int w, int h, long int *color); [in C]
cd.Pattern(pattern: pattern_tag) [in Lua]
Defines a new wxh color matrix and sets the interior style to CD_PATTERN. To avoid having to deal with matrices in C, the color element (i,j) is stored as color[j*w+i]. The origin is the left bottom corner of the image. It cannot be queried. It does not need to be stored by the application, as it is internally replicated by the library.
void
wdPattern(int w, int h, long int *color, double
w_mm, double h_mm); [in C]
cd.wPattern(pattern: pattern_tag, w_mm, h_mm:
number) [in Lua]
Allows specifying the pattern in world coordinates. Another pattern will be created with the size in pixels corresponding to the specified size in millimeters. The use of this function may produce very large or very small patterns.
long int *
cdGetPattern(int* w, int*
h); [in C]
cd.GetPattern() - > (pattern: pattern_tag) [in
Lua]
Returns the current pattern and its dimensions. Returns NULL if no pattern was defined.
Extras in Lua
cd.CreatePattern(width, height: number) -> (pattern: pattern_tag)
Creates a pattern in Lua.
cd.KillPattern(pattern: pattern_tag)
Destroys the created pattern and liberates allocated memory.
cd.CreateStipple(width, height: number) -> (stipple: stipple_tag)
Creates a stipple in Lua.
cd.KillStipple(stipple: stipple_tag)
Destroys the created stipple and liberates allocated memory.
Data Access
Data access in Lua is done directly using the operator "[y*width + x]".
All new types can have their values checked or changed directly as if they were Lua tables:
pattern[y*16 + x] = cd.EncodeColor(r, g, b) ... color = pattern[y*16 + x] r, g, b = cd.DecodeColor(color) ... cd.Pattern(pattern)Notice that the type of value returned or received by pattern[i] is a color_tag, the same type used with functions cdEncodeColor, cdDecodeColor, cdPixel, cdForeground and cdBackground. The value returned or received by stipple[i] is a number.