diff --git a/cmSvgWriter.c b/cmSvgWriter.c index 5533bfb..cfb630e 100644 --- a/cmSvgWriter.c +++ b/cmSvgWriter.c @@ -186,6 +186,7 @@ void _cmSvgWriterFlipY( cmSvg_t* p, unsigned height ) } + cmSvgRC_t cmSvgWriterWrite( cmSvgH_t h, const cmChar_t* cssFn, const cmChar_t* outFn ) { cmSvgRC_t rc = kOkSvgRC; @@ -194,17 +195,34 @@ cmSvgRC_t cmSvgWriterWrite( cmSvgH_t h, const cmChar_t* cssFn, const cmChar_t* double svgHeight = 0; cmSvgEle_t* e = p->elist; cmFileH_t fH = cmFileNullHandle; + cmChar_t* s0 = NULL; + cmChar_t* s1 = NULL; + + cmChar_t hdr[] = + "" + "" + "
" + "" + "" + "" + "" + "" + "" + "\n\n\n")) == NULL ) { - rc = cmErrMsg(&p->err,kFileFailSvgRC,"File suffix write failed."); + rc = cmErrMsg(&p->err,kPrintFailSvgRC,"File suffix write failed."); goto errLabel; } + if( cmFileOpen(&fH,outFn,kWriteFileFl,p->err.rpt) != kOkFileRC ) + { + rc = cmErrMsg(&p->err,kFileFailSvgRC,"SVG file create failed for '%s'.",cmStringNullGuard(outFn)); + goto errLabel; + } + + if( cmFilePrint(fH,s0 = cmTextAppendSS(s0,s1)) != kOkFileRC ) + { + rc = cmErrMsg(&p->err,kFileFailSvgRC,"File write failed."); + goto errLabel; + } errLabel: cmFileClose(&fH); + cmMemFree(s0); + cmMemFree(s1); + return rc; } diff --git a/cmSvgWriter.h b/cmSvgWriter.h index 83470d0..01214cf 100644 --- a/cmSvgWriter.h +++ b/cmSvgWriter.h @@ -9,6 +9,7 @@ enum { kOkSvgRC = cmOkRC, kFileFailSvgRC, + kPrintFailSvgRC, kLHeapFailSvgRC }; @@ -25,6 +26,10 @@ enum cmSvgRC_t cmSvgWriterLine( cmSvgH_t h, double x0, double y0, double x1, double y1, const cmChar_t* cssClassLabel ); cmSvgRC_t cmSvgWriterText( cmSvgH_t h, double x, double y, const cmChar_t* text, const cmChar_t* cssClassLabel ); + // Write the SVG file. Note that header on this file references the CSS file 'cssFn' + // and the Javascript file svg-pan-zoom.min.js from https://github.com/ariutta/svg-pan-zoom. + // Both the CSS file and svg-pan-zoom.min.js should therefore be in the same directory + // as the output HTML file. cmSvgRC_t cmSvgWriterWrite( cmSvgH_t h, const cmChar_t* cssFn, const cmChar_t* outFn ); #ifdef __cplusplus