Home · Pages · Index · Overviews

SVG Drawing Module Reference

A module for generating 2D SVG drawings displayable on the www and editable with Inkscape. More...

 #include <svg.h>

Structures

  SVG_Point : struct
x : double
y : double
 
 

  SVG_Box : struct
w : double
h : double
 
 

  SVG_Frame : struct
corner : SVG_Point
window : SVG_Box
 
 

  SVG_Path : void

  SVG_Context : void

  SVG_Canvas : void

Enumerated Scalars

  SVG_Color : { SVG_alice_blue, SVG_antique_white, SVG_aqua, SVG_aquamarine, SVG_azure
    SVG_beige, SVG_bisque, SVG_black, SVG_blanched_almond, SVG_blue,
    SVG_blue_violet, SVG_brown, SVG_burly_wood, SVG_cadet_blue, SVG_chartreuse,
    SVG_chocolate, SVG_coral, SVG_cornflower_blue, SVG_cornsilk, SVG_crimson,
    SVG_Cyan, SVG_dark_blue, SVG_dark_cyan, SVG_dark_goldenrod, SVG_dark_gray,
    SVG_dark_green, SVG_dark_grey, SVG_dark_khaki, SVG_dark_magenta,
    SVG_dark_olive_green, SVG_dark_orange, SVG_dark_orchid, SVG_dark_red,
    SVG_dark_salmon, SVG_dark_sea_green, SVG_dark_slate_blue, SVG_dark_slate_gray,
    SVG_dark_slate_grey, SVG_dark_turquoise, SVG_dark_violet, SVG_deep_pink,
    SVG_deep_sky_blue, SVG_dim_gray, SVG_dim_grey, SVG_dodger_blue,
    SVG_fire_brick, SVG_floral_white, SVG_forest_green, SVG_fuchsia, SVG_gainsboro,
    SVG_ghost_white, SVG_gold, SVG_goldenrod, SVG_gray, SVG_grey, SVG_green,
    SVG_green_yellow, SVG_honey_dew, SVG_hot_pink, SVG_indian_red, SVG_indigo,
    SVG_ivory, SVG_khaki, SVG_lavender, SVG_lavender_blush, SVG_lawn_green,
    SVG_lemon_chiffon, SVG_light_blue, SVG_light_coral, SVG_light_cyan,
    SVG_light_goldenrod_yellow, SVG_light_gray, SVG_light_green, SVG_light_grey,
    SVG_light_pink, SVG_light_salmon, SVG_light_sea_green, SVG_light_sky_blue,
    SVG_light_slate_gray, SVG_light_slate_grey, SVG_light_steel_blue, SVG_light_yellow,
    SVG_lime, SVG_lime_green, SVG_linen, SVG_magenta, SVG_maroon,
    SVG_medium_aquamarine, SVG_medium_blue, SVG_medium_orchid,
    SVG_medium_purple, SVG_medium_sea_green, SVG_medium_slate_blue,
    SVG_medium_spring_green, SVG_medium_turquoise, SVG_medium_violet_red,
    SVG_midnight_blue, SVG_mint_cream, SVG_misty_rose, SVG_moccasin,
    SVG_navajo_white, SVG_navy, SVG_old_lace, SVG_olive, SVG_olive_drab,
    SVG_orange, SVG_orange_red, SVG_orchid, SVG_pale_goldenrod, SVG_pale_green,
    SVG_pale_turquoise, SVG_pale_violet_red, SVG_papaya_whip, SVG_peach_puff,
    SVG_peru, SVG_pink, SVG_plum, SVG_powder_blue, SVG_purple, SVG_red,
    SVG_rosy_brown, SVG_royal_blue, SVG_saddle_brown, SVG_salmon,
    SVG_sandy_brown, SVG_sea_green, SVG_sea_shell, SVG_sienna, SVG_silver,
    SVG_sky_blue, SVG_slate_blue, SVG_slate_gray, SVG_slate_grey, SVG_snow,
    SVG_spring_green, SVG_steel_blue, SVG_tan, SVG_teal, SVG_thistle, SVG_tomato,
    SVG_turquoise, SVG_violet, SVG_wheat, SVG_white, SVG_white_smoke, SVG_yellow,
    SVG_yellow_green }
 
 
  SVG_Join : { SVG_miter_join, SVG_round_join, SVG_bevel_join }
 
 
  SVG_Cap : { SVG_butt_cap, SVG_round_cap, SVG_square_cap }
 
 
  SVG_Arrow : { SVG_no_arrow, SVG_line_arrow, SVG_flat_arrow,
    SVG_plain_arrow, SVG_flint_arrow }
 
 
  SVG_Font : { SVG_serif, SVG_sans_serif, SVG_monospace, SVG_Arial,
    SVG_Arial_Black, SVG_Book_Antiqua, SVG_Charcoal, SVG_Courier
    SVG_Gadget,SVG_Geneva, SVG_Georgia, SVG_Helvetica, SVG_Impact,
    SVG_Lucida_Console, SVG_Lucida_Grande, SVG_Monaco, SVG_Palatino
    SVG_Tahoma, SVG_Times, SVG_Verdana }
 
 
  SVG_Style : { SVG_plain, SVG_italic, SVG_bold, SVG_bold_italic }
 
 
  SVG_Align : { SVG_left_align, SVG_center_align, SVG_right_align }
 

Routines

Graphics State

SVG_Context * Make_SVG_ContextG ()
SVG_Context * Set_To_Default_Context (SVG_Context *context M)

SVG_Context * Get_SVG_Context (SVG_Canvas *canvas)
void Set_SVG_Context (SVG_Canvas *canvas M, SVG_Context *context C)
void Set_Arrow_Context (SVG_Canvas *canvas M, SVG_Context *context C)

void SVG_Stroke_Off (SVG_Context *context M)
void SVG_Stroke_Color (SVG_Context *context M, SVG_Color color)
void SVG_Stroke_RGB (SVG_Context *context M, int red, int green, int blue)
void SVG_Stroke_Width (SVG_Context *context M, double thick)
void SVG_Stroke_Opacity (SVG_Context *context M, double pcnt)

void SVG_Join_Style (SVG_Context *context M, SVG_Join style)
void SVG_Cap_Style (SVG_Context *context M, SVG_Cap style)
void SVG_Miter_Limit (SVG_Context *context M, double limit)
void SVG_Dash_Spec (SVG_Context *context M, double offset, int n, double *dashlens)

void SVG_Fill_Off (SVG_Context *context M)
void SVG_Fill_Color (SVG_Context *context M, SVG_Color color)
void SVG_Fill_RGB (SVG_Context *context M, int red, int green, int blue)
void SVG_Fill_Opacity (SVG_Context *context M, double pcnt)

void SVG_Text_Font (SVG_Context *context M, SVG_Font font, SVG_Style style)
void SVG_Custom_Font (SVG_Context *context M, string css_font, SVG_Style style)
void SVG_Point_Size (SVG_Context *context M, double size)
void SVG_Text_Alignment (SVG_Context *context M, SVG_Align align)

void SVG_Arrow_Mode (SVG_Context *context M, boolean bin, SVG_Arrow beg,
                                                                           boolean ein, SVG_Arrow end)
void SVG_Arrow_Size (SVG_Context *context M, double width, double height)

2D Objects

SVG_Point * Make_SVG_PointG (double x, double y)
SVG_Box * Make_SVG_BoxG (double w, double h)
SVG_Frame * Make_SVG_FrameG (SVG_Point *corner F, SVG_Box *window F)

SVG_Path * Make_SVG_PathG (int n)
SVG_Path * Append_Move (SVG_Path *path RM, SVG_Point *pnt C)
SVG_Path * Append_Line (SVG_Path *path RM, SVG_Point *pnt C)
SVG_Path * Append_Bezier (SVG_Path *path RM, SVG_Point *in C,
                            SVG_Point *out C, SVG_Point *pnt C)
SVG_Path * Append_Arc (SVG_Path *path RM, SVG_Point *rad C, double xrot,
                        boolean large_arc, boolean sweep, SVG_Point *pnt C)
SVG_Path * Append_Close (SVG_Path *path RM)

Drawing

SVG_Canvas * Begin_SVG_DrawingG (string file_name, SVG_Box *viewport F, SVG_Frame *viewbox F)
void Finish_SVG_Drawing (SVG_Canvas *canvas K)

void Draw_SVG_Path (SVG_Canvas *canvas, SVG_Path *path)

void SVG_Rectangle (SVG_Canvas *canvas, SVG_Frame *rectangle F, double round)
void SVG_Ellipse (SVG_Canvas *canvas, SVG_Point *center F,
                        SVG_Point *radii F, double angle)
void SVG_Circle (SVG_Canvas *canvas, SVG_Point *center F, double radius)

void SVG_Text (SVG_Canvas *canvas, SVG_Point *anchor, double angle, string text)

Detailed Description

SVG is a web-based standard for describing 2-dimensional graphics based on XML. This module allows one to generate an SVG drawing programmatically by way of a collection of routine calls that draw objects according to a current graphics state.


Structure Documentation

SVG_Point : struct
x: double
y: double

A 2-dimensional real-valued point (x,y). A proper mylib object.

SVG_Box : struct
w: double
h: double

A rectangular region of width w and height h. A proper mylib object.

SVG_Frame : struct
corner: SVG_Point
window: SVG_Box

The rectangular region window positioned so that its upper-left corner is at the point corner. A proper mylib object.

SVG_Path : void

A series of one or more continuous stroke objects that can be line segments, bezier curve segments, or elliptical arcs. A proper mylib object.

SVG_Context : void

An object modeling a particular graphics state, i.e. a setting of stroke, fill, text drawing, and arrow attributes. A proper mylib object.

Precisely, a graphics state contains a specification of the following:

  1. a stroke color, stroke thickness, and stroke opacity, and whether stroking is on or off.
  2. whether a join between two consecutive strokes is mitered, rounded, or beveled, and if mitered a limit on how far the miter will extend.
  3. whether the end or beginning of a stroke not connected to another is to be given a square, round, or butt cap.
  4. a specification of a dashing pattern for a stroke, or that there is none.
  5. a fill color and fill opacity, and whether filling is on or off.
  6. whether or not an open curve should have arrowheads at its beginning and end, the style and size and of the arrowheads, and the graphics context to be used when drawing them.
  7. a font type and style for text, the point size for the text, and its alignment relative to the anchor point with respect to which it is to be drawn.

The fill color and opacity only apply if a stroked object is closed (e.g. a rectangle or a path that is closed with a call to Append_Close. Text is actually stroked and if the outline is closed the symbol or symbol part is filled. If an object is both stroked and filled then the stroke takes precedence over any area that would be covered by the fill. That is, when an object is filled but not stroked then the fill extends to the infintessimally thin border that defines the enclosed region, but when the object is stroked and filled, then the fill extends only to the boundary of the stroke that depends on the width of the stroke. Extra care (and SVG commands) are required to acheive this effect which we believe should be the correct semantics of a simultaneously filled and stroked object.

Arrowheads can either have NULL as their graphics context, in which case the current graphics context for the canvas is used to draw the arrow, or if they have had a graphics context assigned to them, said context is used. Thus one can, for example, have arrows that are of a different color and opacity then that of the curve they delimit. Moreover, arrows are carefully drawn so that their tip and tail both lie on the specified curve. This is not the same as SVG marks which are simply oriented according to the tangent of the curve at its endpoints.

SVG_Canvas : void

A drawing canvas corresponding to a .svg file under creation. This is not a proper object, it can only be created by Begin_SVG_Drawing, then used until a drawing is complete, where upon it is killed and the drawing completed with a call to Finish_SVG_Drawing. A canvas has its own graphics context or SVG_Context that is consulted when drawing objects onto the canvas. One can have any number of canvases in existence at a given time. The code is fully re-entrant.


Enumerated Scalars Documentation

SVG_Color: { SVG_alice_blue, SVG_antique_white, SVG_aqua, SVG_aquamarine, SVG_azure
    SVG_beige, SVG_bisque, SVG_black, SVG_blanched_almond, SVG_blue,
    SVG_blue_violet, SVG_brown, SVG_burly_wood, SVG_cadet_blue, SVG_chartreuse,
    SVG_chocolate, SVG_coral, SVG_cornflower_blue, SVG_cornsilk, SVG_crimson,
    SVG_Cyan, SVG_dark_blue, SVG_dark_cyan, SVG_dark_goldenrod, SVG_dark_gray,
    SVG_dark_green, SVG_dark_grey, SVG_dark_khaki, SVG_dark_magenta,
    SVG_dark_olive_green, SVG_dark_orange, SVG_dark_orchid, SVG_dark_red,
    SVG_dark_salmon, SVG_dark_sea_green, SVG_dark_slate_blue, SVG_dark_slate_gray,
    SVG_dark_slate_grey, SVG_dark_turquoise, SVG_dark_violet, SVG_deep_pink,
    SVG_deep_sky_blue, SVG_dim_gray, SVG_dim_grey, SVG_dodger_blue,
    SVG_fire_brick, SVG_floral_white, SVG_forest_green, SVG_fuchsia, SVG_gainsboro,
    SVG_ghost_white, SVG_gold, SVG_goldenrod, SVG_gray, SVG_grey, SVG_green,
    SVG_green_yellow, SVG_honey_dew, SVG_hot_pink, SVG_indian_red, SVG_indigo,
    SVG_ivory, SVG_khaki, SVG_lavender, SVG_lavender_blush, SVG_lawn_green,
    SVG_lemon_chiffon, SVG_light_blue, SVG_light_coral, SVG_light_cyan,
    SVG_light_goldenrod_yellow, SVG_light_gray, SVG_light_green, SVG_light_grey,
    SVG_light_pink, SVG_light_salmon, SVG_light_sea_green, SVG_light_sky_blue,
    SVG_light_slate_gray, SVG_light_slate_grey, SVG_light_steel_blue, SVG_light_yellow,
    SVG_lime, SVG_lime_green, SVG_linen, SVG_magenta, SVG_maroon,
    SVG_medium_aquamarine, SVG_medium_blue, SVG_medium_orchid,
    SVG_medium_purple, SVG_medium_sea_green, SVG_medium_slate_blue,
    SVG_medium_spring_green, SVG_medium_turquoise, SVG_medium_violet_red,
    SVG_midnight_blue, SVG_mint_cream, SVG_misty_rose, SVG_moccasin,
    SVG_navajo_white, SVG_navy, SVG_old_lace, SVG_olive, SVG_olive_drab,
    SVG_orange, SVG_orange_red, SVG_orchid, SVG_pale_goldenrod, SVG_pale_green,
    SVG_pale_turquoise, SVG_pale_violet_red, SVG_papaya_whip, SVG_peach_puff,
    SVG_peru, SVG_pink, SVG_plum, SVG_powder_blue, SVG_purple, SVG_red,
    SVG_rosy_brown, SVG_royal_blue, SVG_saddle_brown, SVG_salmon,
    SVG_sandy_brown, SVG_sea_green, SVG_sea_shell, SVG_sienna, SVG_silver,
    SVG_sky_blue, SVG_slate_blue, SVG_slate_gray, SVG_slate_grey, SVG_snow,
    SVG_spring_green, SVG_steel_blue, SVG_tan, SVG_teal, SVG_thistle, SVG_tomato,
    SVG_turquoise, SVG_violet, SVG_wheat, SVG_white, SVG_white_smoke, SVG_yellow,
    SVG_yellow_green }

A list of 147 predefined, named colors. The following two charts shows all of them:

SVG_Join: { SVG_miter_join, SVG_round_join, SVG_bevel_join }

The shape of corners formed when paths or basic shapes change direction while being stroked. The picture below illustrates the three possibilities:

SVG_Cap: { SVG_butt_cap, SVG_round_cap, SVG_square_cap }

The shape to be used at the end of open sub-paths when they are stroked. The picture below illustrates the three possibilities:

SVG_Arrow: { SVG_no_arrow, SVG_line_arrow, SVG_flat_arrow,
    SVG_plain_arrow, SVG_flint_arrow }

The type of arrow to be drawn (if any) at the end of open sub-paths. The underlying path is not stroked in the area occupied by the arrows. Arrows are drawn with respect to a special graphics context (see Set_Arrow_Context) that is part of each SVG_Canvas, unless it is NULL in which case the arrow is drawn with the same graphics context as the path. The figure below shows the four types of arrows and their possible orientations at each end. For each group, the leftmost arrow is drawn with the same context as the path (olive_drab, 7-width stroke, miter join, butt cap, and no fill). The next arrow to the right has both the stroke and fill color set to blue_violet, 4-width stroke, bevel joins and square caps. The next over has the same style as the previous except that it has red fill and both the join and cap styles are round. The rightmost arrow in each group is has the same style as the previous arrow except that the stroke opacity is .4 and the fill opacity is .6.

SVG_Font: { SVG_serif, SVG_sans_serif, SVG_monospace, SVG_Arial,
    SVG_Arial_Black, SVG_Book_Antiqua, SVG_Charcoal, SVG_Courier
    SVG_Gadget,SVG_Geneva, SVG_Georgia, SVG_Helvetica, SVG_Impact,
    SVG_Lucida_Console, SVG_Lucida_Grande, SVG_Monaco, SVG_Palatino
    SVG_Tahoma, SVG_Times, SVG_Verdana }

A number of named fonts are supported and shown below.

SVG_Style: { SVG_plain, SVG_italic, SVG_bold, SVG_bold_italic }

SVG_Align: { SVG_left_align, SVG_center_align, SVG_right_align }


Routine Documentation

SVG_Context * Make_SVG_ContextG ()

SVG_Context * Set_To_Default_Context (SVG_Context *context M)

SVG_Context * Get_SVG_Context (SVG_Canvas *canvas)

void Set_SVG_Context (SVG_Canvas *canvas M, SVG_Context *context C)

void Set_Arrow_Context (SVG_Canvas *canvas M, SVG_Context *context C)

void SVG_Stroke_Off (SVG_Context *context M)

void SVG_Stroke_Color (SVG_Context *context M, SVG_Color color)

void SVG_Stroke_RGB (SVG_Context *context M, int red, int green, int blue)

void SVG_Stroke_Width (SVG_Context *context M, double thick)

void SVG_Stroke_Opacity (SVG_Context *context M, double pcnt)

void SVG_Join_Style (SVG_Context *context M, SVG_Join style)

void SVG_Cap_Style (SVG_Context *context M, SVG_Cap style)

void SVG_Miter_Limit (SVG_Context *context M, double limit)

void SVG_Dash_Spec (SVG_Context *context M, double offset, int n, double *dashlens)

void SVG_Fill_Off (SVG_Context *context M)

void SVG_Fill_Color (SVG_Context *context M, SVG_Color color)

void SVG_Fill_RGB (SVG_Context *context M, int red, int green, int blue)

void SVG_Fill_Opacity (SVG_Context *context M, double pcnt)

void SVG_Text_Font (SVG_Context *context M, SVG_Font font, SVG_Style style)

void SVG_Custom_Font (SVG_Context *context M, string css_font, SVG_Style style)

void SVG_Point_Size (SVG_Context *context M, double size)

void SVG_Text_Alignment (SVG_Context *context M, SVG_Align align)

void SVG_Arrow_Mode (SVG_Context *context M, boolean bin, SVG_Arrow beg,
                                                                           boolean ein, SVG_Arrow end)

void SVG_Arrow_Size (SVG_Context *context M, double width, double height)

SVG_Point * Make_SVG_PointG (double x, double y)

SVG_Box * Make_SVG_BoxG (double w, double h)

SVG_Frame * Make_SVG_FrameG (SVG_Point *corner F, SVG_Box *window F)

SVG_Path * Make_SVG_PathG (int n)

SVG_Path * Append_Move (SVG_Path *path RM, SVG_Point *pnt C)

SVG_Path * Append_Line (SVG_Path *path RM, SVG_Point *pnt C)

SVG_Path * Append_Bezier (SVG_Path *path RM, SVG_Point *in C,
                            SVG_Point *out C, SVG_Point *pnt C)

SVG_Path * Append_Arc (SVG_Path *path RM, SVG_Point *rad C, double xrot,
                        boolean large_arc, boolean sweep, SVG_Point *pnt C)

SVG_Path * Append_Close (SVG_Path *path RM)

SVG_Canvas * Begin_SVG_DrawingG (string file_name, SVG_Box *viewport F, SVG_Frame *viewbox F)

void Finish_SVG_Drawing (SVG_Canvas *canvas K)

void Draw_SVG_Path (SVG_Canvas *canvas, SVG_Path *path)

void SVG_Rectangle (SVG_Canvas *canvas, SVG_Frame *rectangle F, double round)

void SVG_Ellipse (SVG_Canvas *canvas, SVG_Point *center F,
                        SVG_Point *radii F, double angle)

void SVG_Circle (SVG_Canvas *canvas, SVG_Point *center F, double radius)

void SVG_Text (SVG_Canvas *canvas, SVG_Point *anchor, double angle, string text)