VCLib Documentation  6.12.2

SVG File Output

SVG File Output

Output graphics to an SVG (scaleable vector graphics) file. More...

Macros

#define vc_svg_group_end(svg)   vc_svg_something_end(svg,0)
 Outputs the closing tag to an SVG. More...
 
#define vc_svg_defs_begin(svg)   vc_svg_something_begin("defs",NULL,NULL,NULL,0,svg)
 Outputs a <defs> tag to an SVG. More...
 
#define vc_svg_defs_end(svg)   vc_svg_something_end(svg,0)
 Outputs the closing tag to an SVG. More...
 
#define vc_svg_marker_end(svg)   vc_svg_something_end(svg,0)
 Outputs the closing tag to an SVG. More...
 
#define vc_svg_clipPath_end(svg)   vc_svg_something_end(svg,0)
 Outputs the closing tag to an SVG. More...
 

Functions

I32 vc_svg_init (F32 x0, F32 y0, F32 dx, F32 dy, char *filename, char *addArg, struct _VCSVGOut **svg)
 Opens an SVG file for output. More...
 
I32 vc_svg_deinit (struct _VCSVGOut **svg)
 Closes an SVG file after opening with vc_svg_init(). More...
 
I32 vc_svg_group_begin (char *groupname, I8 layerIff1, I8 hideIff1, char *addArg, struct _VCSVGOut *svg)
 Outputs a <group> tag to an SVG. More...
 
I32 vc_svg_circle (F32 cx, F32 cy, F32 rad, char *colFill, F32 sizeStroke, char *colStroke, char *addArg, struct _VCSVGOut *svg)
 Outputs a circle to an SVG. More...
 
I32 vc_svg_rect (F32 x0, F32 y0, F32 dx, F32 dy, char *colFill, F32 sizeStroke, char *colStroke, char *addArg, struct _VCSVGOut *svg)
 Outputs a rectangle to an SVG. More...
 
I32 vc_svg_line (F32 x1, F32 y1, F32 x2, F32 y2, F32 sizeStroke, char *colStroke, char *addArg, struct _VCSVGOut *svg)
 Outputs a line to an SVG. More...
 
I32 vc_svg_vcline (vcline *l, F32 xMin, F32 yMin, F32 xMax, F32 yMax, F32 sizeStroke, char *colStroke, char *addArg, struct _VCSVGOut *svg)
 Outputs a vcline to an SVG. More...
 
I32 vc_svg_slc (U16 *rlc, U16 *slc, U16 objNr, F32 sizeObjNr, char *colObjNr, F32 sizeStroke, char *colStroke, char *addArg, struct _VCSVGOut *svg)
 Outputs SLC data to an SVG. More...
 
I32 vc_svg_text_centered (F32 cx, F32 cy, F32 sizeTextPx, char *colFill, F32 sizeStroke, char *colStroke, char *addArg, struct _VCSVGOut *svg, const char *format,...)
 Outputs a text line to an SVG. More...
 
I32 vc_svg_text (I32 alignment, F32 cx, F32 cy, F32 sizeTextPx, char *colFill, F32 sizeStroke, char *colStroke, char *addArg, struct _VCSVGOut *svg, const char *format,...)
 Outputs a text line to an SVG. More...
 
I32 vc_svg_polyline_point (point *lstPt, U32 ptCnt, I8 closeEndIff1, char *colFill, F32 sizeStroke, char *colStroke, char *addArg, struct _VCSVGOut *svg)
 Outputs a polyline to an SVG. More...
 
I32 vc_svg_polynomial_as_polyline (VCPolynom1D1D *poly, F32 xMin, F32 xMax, U32 posCnt, char *colFill, F32 sizeStroke, char *colStroke, char *addArg, struct _VCSVGOut *svg)
 Outputs a polynomial to an SVG. More...
 
I32 vc_svg_polyline_projection (U32 *proj, U32 cnt, I32 x0, I32 y0, I32 maxSizePx, I8 verticalIff1, I8 addZeroAtEndsIff1, char *colFill, F32 sizeStroke, char *colStroke, char *addArg, struct _VCSVGOut *svg)
 Outputs Projection data to an SVG. More...
 
I32 vc_svg_image_link_raw (char *imgFilename, F32 x0, F32 y0, I32 dx, I32 dy, char *addArg, struct _VCSVGOut *svg)
 Links an image to an SVG. More...
 
I32 vc_svg_doc_view (char *docUnits, F32 cx, F32 cy, F32 zoom, char *addArg, struct _VCSVGOut *svg)
 Outputs a <sodipodi:namedview> tag to an SVG. More...
 
I32 vc_svg_use (U32 id, F32 x0, F32 y0, char *addArg, struct _VCSVGOut *svg)
 Outputs a <use> tag to an SVG. More...
 
I32 vc_svg_marker_begin (F32 xRef, F32 yRef, char *addArg, struct _VCSVGOut *svg)
 Outputs a <marker> tag to an SVG. More...
 
I32 vc_svg_clipPath_begin (char *addArg, struct _VCSVGOut *svg)
 Outputs a <clipPath> tag to an SVG. More...
 
I32 vc_svg_something_begin (char *something, char *attribs, char *moreAttribs, char *innerText, I8 endIff1, struct _VCSVGOut *svg)
 Outputs a tag to an SVG. More...
 
I32 vc_svg_something_end (struct _VCSVGOut *svg, I8 suppressLinebreakIff1)
 Outputs a closing tag to an SVG. More...
 

Detailed Description

We assume that you are familiar with the SVG standard. The functions here provide easy writeout.

Code Example:

I32 svg_example(image *img)
{
I32 rc, ee, id;
#ifdef __TI_COMPILER_VERSION__
char path[]="fd:/";
#else
char path[]="/tmp/";
#endif
char fileImg[]="testBMP.bmp";
char fileSvg[]="testSVG.svg";
char filename[256];
// The working struct
struct _VCSVGOut *svg = NULL;
// Store pixel image for image reference in SVG to work.
{
sprintf(filename, "%s%s", path, fileImg);
printf("Storing Pixel Image to: %s\n", filename);
rc = fwrite_image(filename, img);
if(rc<0){ee=-1+100*rc; goto fail;}
}
// Initialisation: Open SVG file for writing
{
sprintf(filename, "%s%s", path, fileSvg);
printf("Storing SVG Image to: %s\n", filename);
rc = vc_svg_init(0,0,img->dx,img->dy, filename, NULL, &svg);
if(rc<0){ee=-2+100*rc; goto fail;}
}
// Refer to pixel image, the offset of -0.5,-0.5 places e.g. circles at the center of a pixel.
rc = vc_svg_image_link_raw(fileImg, -0.5,-0.5, img->dx,img->dy, NULL, svg);
if(rc<0){ee=-3+100*rc; goto fail;}
// Example text
rc = vc_svg_text_centered(img->dx/2,img->dy/2, 24,"yellow", 0,NULL, NULL, svg, "Image File %s", fileImg);
if(rc<0){ee=-4+100*rc; goto fail;}
//SVG defs->use example
{
rc = vc_svg_group_begin("DefsUseExample", 1, 0, NULL, svg);
if(rc<0){ee=-5+100*rc; goto fail;}
{
rc = vc_svg_defs_begin(svg);
if(rc<0){ee=-6+100*rc; goto fail;}
rc = vc_svg_circle(0, 0, img->dy/4, "#00aa22", 2, "green", NULL, svg);
if(rc<0){ee=-7+100*rc; goto fail;}
id = rc;
rc = vc_svg_defs_end(svg);
if(rc<0){ee=-8+100*rc; goto fail;}
// Using it ..
rc = vc_svg_use(id, img->dx/4,img->dy/2, "fill-opacity=\"0.3\"", svg);
if(rc<0){ee=-9+100*rc; goto fail;}
}
rc = vc_svg_group_end(svg);
if(rc<0){ee=-10+100*rc; goto fail;}
}
ee=0;
fail:
// Deinitialisation: Close SVG file
if(ee!=0){printf("ERR: %d\n", ee);}
return(ee);
}

Macro Definition Documentation

◆ vc_svg_group_end

#define vc_svg_group_end (   svg)    vc_svg_something_end(svg,0)

This macro of vc_svg_something_end() outputs the closing tag to an SVG.

◆ vc_svg_defs_begin

#define vc_svg_defs_begin (   svg)    vc_svg_something_begin("defs",NULL,NULL,NULL,0,svg)

This macro of vc_svg_something_begin() outputsa <defs> tag to an SVG.

◆ vc_svg_defs_end

#define vc_svg_defs_end (   svg)    vc_svg_something_end(svg,0)

This macro of vc_svg_something_end() outputs the closing tag to an SVG.

◆ vc_svg_marker_end

#define vc_svg_marker_end (   svg)    vc_svg_something_end(svg,0)

This macro of vc_svg_something_end() outputs the closing tag to an SVG.

◆ vc_svg_clipPath_end

#define vc_svg_clipPath_end (   svg)    vc_svg_something_end(svg,0)

This macro of vc_svg_something_end() outputs the closing tag to an SVG.

Function Documentation

◆ vc_svg_init()

I32 vc_svg_init ( F32  x0,
F32  y0,
F32  dx,
F32  dy,
char *  filename,
char *  addArg,
struct _VCSVGOut **  svg 
)

This function opens an SVG file for output.

Parameters
x0,y0,dx,dyValues for the 'viewBox' attribute, you may choose 0,0, img->dx, img->dy.
filenameFilename for the SVG output.
addArgAdditional arguments for <svg> tag, set to NULL if not needed.
svgThe SVG Outputter struct to be initialized.
Return values
0on success.
<0on error, especially -1, if file could not be opened for writing.
See also
vc_svg_deinit().

◆ vc_svg_deinit()

I32 vc_svg_deinit ( struct _VCSVGOut **  svg)

This function closes an SVG file after opening with vc_svg_init().

Parameters
svgThe SVG Outputter struct to be deinitialized and closed.
Return values
0on success.
<0on error.
See also
vc_svg_init().

◆ vc_svg_group_begin()

I32 vc_svg_group_begin ( char *  groupname,
I8  layerIff1,
I8  hideIff1,
char *  addArg,
struct _VCSVGOut *  svg 
)

This function outputs a <group> tag to an SVG.

Parameters
groupnameName of the group, added as 'inkscape:label' attribute.
layerIff1If set to 1, the attribute 'inkscape:groupmode="layer"' is added.
hideIff1If set to 1, the attribute 'display="none"' is added.
addArgAdditional arguments for SVG element, set to NULL if not needed.
svgThe initialized SVG Outputter struct.
Returns
SVG element ID number.

◆ vc_svg_circle()

I32 vc_svg_circle ( F32  cx,
F32  cy,
F32  rad,
char *  colFill,
F32  sizeStroke,
char *  colStroke,
char *  addArg,
struct _VCSVGOut *  svg 
)

This function outputs a circle to an SVG.

Parameters
cx,cy,radInput circle.
colFillFill color, set to NULL if no filling should be applied.
sizeStrokeStroke size of line.
colStrokeStroke color, set to NULL if no stroke should be visible.
addArgAdditional arguments for SVG element, set to NULL if not needed.
svgThe initialized SVG Outputter struct.
Returns
SVG element ID number.

◆ vc_svg_rect()

I32 vc_svg_rect ( F32  x0,
F32  y0,
F32  dx,
F32  dy,
char *  colFill,
F32  sizeStroke,
char *  colStroke,
char *  addArg,
struct _VCSVGOut *  svg 
)

This function outputs a rectangle to an SVG.

Parameters
x0,y0,dx,dyInput rectangle.
colFillFill color, set to NULL if no filling should be applied.
sizeStrokeStroke size of line.
colStrokeStroke color, set to NULL if no stroke should be visible.
addArgAdditional arguments for SVG element, set to NULL if not needed.
svgThe initialized SVG Outputter struct.
Returns
SVG element ID number.

◆ vc_svg_line()

I32 vc_svg_line ( F32  x1,
F32  y1,
F32  x2,
F32  y2,
F32  sizeStroke,
char *  colStroke,
char *  addArg,
struct _VCSVGOut *  svg 
)

This function outputs a line to an SVG.

Parameters
x1,y1,x2,y2Input line.
sizeStrokeStroke size of line.
colStrokeStroke color, set to NULL if no stroke should be visible.
addArgAdditional arguments for SVG element, set to NULL if not needed.
svgThe initialized SVG Outputter struct.
Returns
SVG element ID number.

◆ vc_svg_vcline()

I32 vc_svg_vcline ( vcline l,
F32  xMin,
F32  yMin,
F32  xMax,
F32  yMax,
F32  sizeStroke,
char *  colStroke,
char *  addArg,
struct _VCSVGOut *  svg 
)

This function outputs a vcline to an SVG.

Parameters
lInput line.
xMin,yMin,xMax,yMaxBounding rectangle.
sizeStrokeStroke size of line.
colStrokeStroke color, set to NULL if no stroke should be visible.
addArgAdditional arguments for SVG element, set to NULL if not needed.
svgThe initialized SVG Outputter struct.
Returns
SVG element ID number.

◆ vc_svg_slc()

I32 vc_svg_slc ( U16 rlc,
U16 slc,
U16  objNr,
F32  sizeObjNr,
char *  colObjNr,
F32  sizeStroke,
char *  colStroke,
char *  addArg,
struct _VCSVGOut *  svg 
)

This function outputs SLC data to an SVG. If not colObjNr==NULL, the SVG number will be printed upon the region, which is formed as lines over the pixel regions: sizeStroke = 1 will fill the region fully, smaller ones make them look like a zebra.

Parameters
rlcpoints to input RLC.
slcpoints to corresponding input SLC.
objNrSLC Object number to output, use a loop for all.
sizeObjNrSLC Object number label height.
colObjNrColor of SLC Object number label, set to NULL for no label.
sizeStrokeStroke size of lines, set to 1 for an 'area' look.
colStrokeColor of the SLC object at the SVG.
addArgAdditional arguments for SVG element, set to NULL if not needed.
svgThe initialized SVG Outputter struct.
Returns
SVG element ID number.

◆ vc_svg_text_centered()

I32 vc_svg_text_centered ( F32  cx,
F32  cy,
F32  sizeTextPx,
char *  colFill,
F32  sizeStroke,
char *  colStroke,
char *  addArg,
struct _VCSVGOut *  svg,
const char *  format,
  ... 
)

This function outputs a text line to an SVG.

Parameters
cx,cyText position horizontal center.
sizeTextPxFont size applied in pixel.
colFillFill color, set to NULL if no filling should be applied.
sizeStrokeOutline size.
colStrokeOutline color, set to NULL if no outline should be visible.
addArgAdditional arguments for SVG element, set to NULL if not needed.
svgThe initialized SVG Outputter struct.
formatlike at printf().
Returns
SVG element ID number.

◆ vc_svg_text()

I32 vc_svg_text ( I32  alignment,
F32  cx,
F32  cy,
F32  sizeTextPx,
char *  colFill,
F32  sizeStroke,
char *  colStroke,
char *  addArg,
struct _VCSVGOut *  svg,
const char *  format,
  ... 
)

This function outputs a text line to an SVG.

Parameters
alignment<0: start, 0: middle, >0: end.
cx,cyText position horizontal center.
sizeTextPxFont size applied in pixel.
colFillFill color, set to NULL if no filling should be applied.
sizeStrokeOutline size.
colStrokeOutline color, set to NULL if no outline should be visible.
addArgAdditional arguments for SVG element, set to NULL if not needed.
svgThe initialized SVG Outputter struct.
formatlike at printf().
Returns
SVG element ID number.

◆ vc_svg_polyline_point()

I32 vc_svg_polyline_point ( point lstPt,
U32  ptCnt,
I8  closeEndIff1,
char *  colFill,
F32  sizeStroke,
char *  colStroke,
char *  addArg,
struct _VCSVGOut *  svg 
)

This function outputs a polyline to an SVG.

Parameters
lstPtInput point array.
cntSize of input array.
closeEndIff1Connects last point with first if set to 1.
colFillFill color, set to NULL if no filling should be applied.
sizeStrokeStroke size of line.
colStrokeStroke color, set to NULL if no stroke should be visible.
addArgAdditional arguments for SVG element, set to NULL if not needed.
svgThe initialized SVG Outputter struct.
Returns
SVG element ID number.

◆ vc_svg_polynomial_as_polyline()

I32 vc_svg_polynomial_as_polyline ( VCPolynom1D1D poly,
F32  xMin,
F32  xMax,
U32  posCnt,
char *  colFill,
F32  sizeStroke,
char *  colStroke,
char *  addArg,
struct _VCSVGOut *  svg 
)

This function outputs a polynomial to an SVG using line segments.

Parameters
polyInput polynomial.
xMin,xMaxValue range to be displayed.
posCntNumber of points on polynomial which form the line segments.
colFillFill color, set to NULL if no filling should be applied.
sizeStrokeStroke size of line.
colStrokeStroke color, set to NULL if no stroke should be visible.
addArgAdditional arguments for SVG element, set to NULL if not needed.
svgThe initialized SVG Outputter struct.
Returns
SVG element ID number.

◆ vc_svg_polyline_projection()

I32 vc_svg_polyline_projection ( U32 proj,
U32  cnt,
I32  x0,
I32  y0,
I32  maxSizePx,
I8  verticalIff1,
I8  addZeroAtEndsIf1,
char *  colFill,
F32  sizeStroke,
char *  colStroke,
char *  addArg,
struct _VCSVGOut *  svg 
)

This function outputs array data, for example from projh(), to an SVG. Data is remapped to the interval [0 .. maxSizePx].

Parameters
projInput array data.
cntSize of input array.
x0,y0Top-left position of data minimum value at first entry.
maxSizePxSize from the data minimum to maximum at display.
verticalIff1Data will be presented vertically if set to 1.
addZeroAtEndsIf1Adds a point at the first and last data point, at 0 if set to +1, or at maxSizePx if set to -1, helpful in connection with color filling.
colFillFill color, set to NULL if no filling should be applied.
sizeStrokeStroke size of line.
colStrokeStroke color, set to NULL if no stroke should be visible.
addArgAdditional arguments for SVG element, set to NULL if not needed.
svgThe initialized SVG Outputter struct.
Returns
SVG element ID number.

◆ vc_svg_image_link_raw()

I32 vc_svg_image_link_raw ( char *  imgFilename,
F32  x0,
F32  y0,
I32  dx,
I32  dy,
char *  addArg,
struct _VCSVGOut *  svg 
)

This function links an image to an SVG. Set x0, y0 to -0.5 to centerize for example the center of circles at the pixel square.

Parameters
imgFilenameFilename relative to the SVG file at any machine.
x0,y0,dx,dyPosition and size of the image (see description).
addArgAdditional arguments for SVG element, set to NULL if not needed.
svgThe initialized SVG Outputter struct.
Returns
SVG element ID number.

◆ vc_svg_doc_view()

I32 vc_svg_doc_view ( char *  docUnits,
F32  cx,
F32  cy,
F32  zoom,
char *  addArg,
struct _VCSVGOut *  svg 
)

This function outputs a <sodipodi:namedview> tag to an SVG.

Parameters
docUnitsEither "px" or "mm"
cx,cyPosition where the image view is centered.
zoomZoom level of image view.
svgThe initialized SVG Outputter struct.
Returns
SVG element ID number.

◆ vc_svg_use()

I32 vc_svg_use ( U32  id,
F32  x0,
F32  y0,
char *  addArg,
struct _VCSVGOut *  svg 
)

This function outputs a <use> tag to an SVG. It is needed to refer to objects declared in <defs>.

Parameters
idID of the object to show (usually the positive return value of an vc_svg_..() call).
x0,y0Position where the object is placed to.
addArgAdditional arguments for SVG element, set to NULL if not needed.
svgThe initialized SVG Outputter struct.
Returns
SVG element ID number.

◆ vc_svg_marker_begin()

I32 vc_svg_marker_begin ( F32  xRef,
F32  yRef,
char *  addArg,
struct _VCSVGOut *  svg 
)

This function outputs a <marker> tag to an SVG. It is needed to refer to objects declared in <defs>.

Parameters
xRef,yRefRelative position where the marker is placed to.
addArgAdditional arguments for SVG element, set to NULL if not needed.
svgThe initialized SVG Outputter struct.
Returns
SVG element ID number.

◆ vc_svg_clipPath_begin()

I32 vc_svg_clipPath_begin ( char *  addArg,
struct _VCSVGOut *  svg 
)

This function outputs a <clipPath> tag to an SVG.

Parameters
addArgAdditional arguments for SVG element, set to NULL if not needed.
svgThe initialized SVG Outputter struct.
Returns
SVG element ID number.

◆ vc_svg_something_begin()

I32 vc_svg_something_begin ( char *  something,
char *  attribs,
char *  moreAttribs,
char *  innerText,
I8  endIff1,
struct _VCSVGOut *  svg 
)

This function outputs a tag to an SVG. It is the core function for the SVG output:

<something attribs moreAttribs id="ID###" (/)>innerText

Parameters
somethingThe tag name.
attribsAttributes as string.
moreAttribsMore attributes as string.
innerTextText after the closing brace > (endIff1 should not be set to 1).
endIff1If set to 1, the tag is closed: <something .. /> instead of <something ..>..</something>.
svgThe initialized SVG Outputter struct.
Returns
element ID number; the ID number returned must be preceeded with 'ID' for xml validity reasons, example: printf("marker-mid=\"url(IDd)",id);
See also
vc_svg_something_end().

◆ vc_svg_something_end()

I32 vc_svg_something_end ( struct _VCSVGOut *  svg,
I8  suppressLinebreakIff1 
)

This function outputs the next valid closing tag to an SVG. It is the core function for the SVG output:

</something >

Parameters
svgThe initialized SVG Outputter struct.
suppressLinebreakIff1If set to 1, the closing tag is not at a new line.
Return values
0on success.
<0on error.
See also
vc_svg_something_begin().