diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2024-07-03 10:19:30 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2024-07-03 10:19:30 +0200 |
commit | a14a7a0ccc9de76aeab0b2e4bbf58f1a79deedc2 (patch) | |
tree | e469179df67a0e0db49161a43cbf8076a189f6f4 /app/bin/svgoutput.c | |
parent | 5d2c2b27a6323e2666378b986129b2a7c2c39e5c (diff) |
New upstream version 5.3.0GAupstream/5.3.0GAupstream
Diffstat (limited to 'app/bin/svgoutput.c')
-rw-r--r-- | app/bin/svgoutput.c | 462 |
1 files changed, 231 insertions, 231 deletions
diff --git a/app/bin/svgoutput.c b/app/bin/svgoutput.c index a8224be..e4ff66b 100644 --- a/app/bin/svgoutput.c +++ b/app/bin/svgoutput.c @@ -17,22 +17,21 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <stdio.h> #include <string.h> #include <time.h> #ifdef WINDOWS - #include <io.h> - #define UTFCONVERT +#include <io.h> +#define UTFCONVERT #else - #include <errno.h> +#include <errno.h> #endif #include <xtrkcad-config.h> #include <locale.h> -#include <assert.h> #include <mxml.h> #include <dynstring.h> @@ -53,6 +52,8 @@ static struct wFilSel_t * exportSVGFile_fs; static coOrd roomSize; +static int svgLineWidth[4] = {10, 10, 20, 30}; + /** * get line style for element * @@ -64,35 +65,35 @@ static coOrd roomSize; static unsigned SvgDrawGetLineStyle(drawCmd_p d) { - unsigned long notSolid = DC_NOTSOLIDLINE; - unsigned long opt = d->options & notSolid; - unsigned lineOpt; - - switch (opt) { - case DC_DASH: - lineOpt = wDrawLineDash; - break; - case DC_DOT: - lineOpt = wDrawLineDot; - break; - case DC_DASHDOT: - lineOpt = wDrawLineDashDot; - break; - case DC_DASHDOTDOT: - lineOpt = wDrawLineDashDotDot; - break; - case DC_CENTER: - lineOpt = wDrawLineCenter; - break; - case DC_PHANTOM: - lineOpt = wDrawLinePhantom; - break; - default: - lineOpt = wDrawLineSolid; - break; - } - - return (lineOpt); + unsigned long notSolid = DC_NOTSOLIDLINE; + unsigned long opt = d->options & notSolid; + unsigned lineOpt; + + switch (opt) { + case DC_DASH: + lineOpt = wDrawLineDash; + break; + case DC_DOT: + lineOpt = wDrawLineDot; + break; + case DC_DASHDOT: + lineOpt = wDrawLineDashDot; + break; + case DC_DASHDOTDOT: + lineOpt = wDrawLineDashDotDot; + break; + case DC_CENTER: + lineOpt = wDrawLineCenter; + break; + case DC_PHANTOM: + lineOpt = wDrawLinePhantom; + break; + default: + lineOpt = wDrawLineSolid; + break; + } + + return (lineOpt); } /** @@ -106,22 +107,22 @@ SvgDrawGetLineStyle(drawCmd_p d) */ static void SvgDrawLine( - drawCmd_p d, - coOrd p0, - coOrd p1, - wDrawWidth width, - wDrawColor color) + drawCmd_p d, + coOrd p0, + coOrd p1, + wDrawWidth width, + wDrawColor color) { - unsigned lineOpt = SvgDrawGetLineStyle(d); + unsigned lineOpt = SvgDrawGetLineStyle(d); - width = (wDrawWidth)(width > MININMUMLINEWIDTH ? width : MININMUMLINEWIDTH); + width = (wDrawWidth)(width >= MINIMUMLINEWIDTH ? width : svgLineWidth[width]); - SvgLineCommand((SVGParent *)(d->d), - p0.x, roomSize.y - p0.y, - p1.x, roomSize.y - p1.y, - (double)width, - wDrawGetRGB(color), - lineOpt); + SvgLineCommand((SVGParent *)(d->d), + p0.x, roomSize.y - p0.y, + p1.x, roomSize.y - p1.y, + (double)width, + wDrawGetRGB(color), + lineOpt); } /** @@ -138,38 +139,39 @@ static void SvgDrawLine( */ static void SvgDrawArc( - drawCmd_p d, - coOrd p, - DIST_T r, - ANGLE_T angle0, - ANGLE_T angle1, - BOOL_T drawCenter, - wDrawWidth width, - wDrawColor color) + drawCmd_p d, + coOrd p, + DIST_T r, + ANGLE_T angle0, + ANGLE_T angle1, + BOOL_T drawCenter, + wDrawWidth width, + wDrawColor color) { - unsigned lineOpt = SvgDrawGetLineStyle(d); - - if (angle1 >= 360.0) { - SvgCircleCommand((SVGParent *)(d->d), - p.x, - roomSize.y - p.y, - r, - (width > MININMUMLINEWIDTH ? width : MININMUMLINEWIDTH), - wDrawGetRGB(color), - false, - lineOpt); - } else { - SvgArcCommand((SVGParent *)(d->d), - p.x, - roomSize.y-p.y, - r, - angle0, - angle1, - drawCenter, - (width > MININMUMLINEWIDTH ? width: MININMUMLINEWIDTH), - wDrawGetRGB(color), - lineOpt); - } + unsigned lineOpt = SvgDrawGetLineStyle(d); + wDrawWidth w = (width >= MINIMUMLINEWIDTH ? width : svgLineWidth[width]); + + if (angle1 >= 360.0) { + SvgCircleCommand((SVGParent *)(d->d), + p.x, + roomSize.y - p.y, + r, + w, + wDrawGetRGB(color), + false, + lineOpt); + } else { + SvgArcCommand((SVGParent *)(d->d), + p.x, + roomSize.y-p.y, + r, + angle0, + angle1, + drawCenter, + w, + wDrawGetRGB(color), + lineOpt); + } } @@ -186,28 +188,28 @@ static void SvgDrawArc( */ static void SvgDrawString( - drawCmd_p d, - coOrd p, - ANGLE_T a, - char * s, - wFont_p fp, - FONTSIZE_T fontSize, - wDrawColor color) + drawCmd_p d, + coOrd p, + ANGLE_T a, + char * s, + wFont_p fp, + FONTSIZE_T fontSize, + wDrawColor color) { - char *text = MyStrdup(s); + char *text = MyStrdup(s); #ifdef UTFCONVERT - text = Convert2UTF8(text); + text = Convert2UTF8(text); #endif // UTFCONVERT - SvgTextCommand((SVGParent *)(d->d), - p.x, - roomSize.y - p.y, - fontSize, - wDrawGetRGB(color), - text); + SvgTextCommand((SVGParent *)(d->d), + p.x, + roomSize.y - p.y, + fontSize, + wDrawGetRGB(color), + text); - MyFree(text); + MyFree(text); } /** @@ -220,10 +222,10 @@ static void SvgDrawString( */ static void SvgDrawBitmap( - drawCmd_p d, - coOrd p, - wDrawBitMap_p bm, - wDrawColor color) + drawCmd_p d, + coOrd p, + wDrawBitMap_p bm, + wDrawColor color) { } @@ -240,37 +242,34 @@ static void SvgDrawBitmap( */ static void SvgDrawFillPoly( - drawCmd_p d, - int cnt, - coOrd * pts, - int * pointer, - wDrawColor color, wDrawWidth width, drawFill_e fillStyle) + drawCmd_p d, + int cnt, + coOrd * pts, + int * pointer, + wDrawColor color, wDrawWidth width, drawFill_e fillStyle) { - int i; - double *points = malloc((cnt + 1) * 2 * sizeof(double)); - - unsigned lineOpt = SvgDrawGetLineStyle(d); - - if (!points) { - puts("memory for poly line coordinates could not be allocated!"); - abort(); - } - for (i = 0; i < cnt; i++) { - points[i * 2] = pts[i].x; - points[i * 2 + 1] = roomSize.y - pts[i].y; - } - - if (fillStyle == DRAW_CLOSED || fillStyle == DRAW_FILL) { - points[i * 2] = points[0]; - points[i * 2 + 1] = points[1]; - cnt++; - } - - width = (wDrawWidth)(width > MININMUMLINEWIDTH ? width : MININMUMLINEWIDTH); - SvgPolyLineCommand((SVGParent *)(d->d), cnt, points, wDrawGetRGB(color), - (double)width, fillStyle == DRAW_FILL, lineOpt); - - free(points); + int i; + double *points = malloc((cnt + 1) * 2 * sizeof(double)); + CHECK( points ); + + unsigned lineOpt = SvgDrawGetLineStyle(d); + + for (i = 0; i < cnt; i++) { + points[i * 2] = pts[i].x; + points[i * 2 + 1] = roomSize.y - pts[i].y; + } + + if (fillStyle == DRAW_CLOSED || fillStyle == DRAW_FILL) { + points[i * 2] = points[0]; + points[i * 2 + 1] = points[1]; + cnt++; + } + + width = (wDrawWidth)(width >= MINIMUMLINEWIDTH ? width : svgLineWidth[width]); + SvgPolyLineCommand((SVGParent *)(d->d), cnt, points, wDrawGetRGB(color), + (double)width, fillStyle == DRAW_FILL, lineOpt); + + free(points); } /** @@ -285,14 +284,14 @@ static void SvgDrawFillPoly( static void SvgDrawFillCircle(drawCmd_p d, coOrd center, DIST_T radius, wDrawColor color) { - SvgCircleCommand((SVGParent *)(d->d), - center.x, - roomSize.y - center.y, - radius, - 0, - wDrawGetRGB(color), - true, - 0); + SvgCircleCommand((SVGParent *)(d->d), + center.x, + roomSize.y - center.y, + radius, + 0, + wDrawGetRGB(color), + true, + 0); } /** @@ -309,25 +308,25 @@ static void SvgDrawRectangle(drawCmd_p d, coOrd corner1, coOrd corner2, wDrawColor color, drawFill_e fillOpt) { - SvgRectCommand((SVGParent *)(d->d), - corner1.x, roomSize.y - corner1.y, - corner2.x, roomSize.y - corner2.y, - wDrawGetRGB(color), - fillOpt); + SvgRectCommand((SVGParent *)(d->d), + corner1.x, roomSize.y - corner1.y, + corner2.x, roomSize.y - corner2.y, + wDrawGetRGB(color), + fillOpt); } static drawFuncs_t svgDrawFuncs = { - SvgDrawLine, - SvgDrawArc, - SvgDrawString, - SvgDrawBitmap, - SvgDrawFillPoly, - SvgDrawFillCircle, - SvgDrawRectangle + SvgDrawLine, + SvgDrawArc, + SvgDrawString, + SvgDrawBitmap, + SvgDrawFillPoly, + SvgDrawFillCircle, + SvgDrawRectangle }; static drawCmd_t svgD = { - NULL, &svgDrawFuncs, 0, 1.0, 0.0, {0.0,0.0}, {0.0,0.0}, Pix2CoOrd, CoOrd2Pix, 100.0 + NULL, &svgDrawFuncs, 0, 1.0, 0.0, {0.0,0.0}, {0.0,0.0}, Pix2CoOrd, CoOrd2Pix, 100.0 }; /** @@ -344,30 +343,30 @@ static drawCmd_t svgD = { static char * CreateValidId(char *base) { - const char *idHead = "id"; - char *out = MyMalloc(strlen(idHead) + strlen(base) + 1); - char *tmp; - int j; - - strcpy(out, idHead); - j = strlen(out); - - for (unsigned int i = 0; i < strlen(base); i++) { - if (isblank(base[i])) { - i++; - } else { - out[j++] = base[i]; - } - } - - out[j] = '\0'; - - // strip off the extension - tmp = strchr(out, '.'); - if (tmp) { - *tmp = '\0'; - } - return (out); + const char *idHead = "id"; + char *out = MyMalloc(strlen(idHead) + strlen(base) + 1); + char *tmp; + int j; + + strcpy(out, idHead); + j = strlen(out); + + for (unsigned int i = 0; i < strlen(base); i++) { + if (isblank(base[i])) { + i++; + } else { + out[j++] = base[i]; + } + } + + out[j] = '\0'; + + // strip off the extension + tmp = strchr(out, '.'); + if (tmp) { + *tmp = '\0'; + } + return (out); } /** @@ -378,17 +377,17 @@ CreateValidId(char *base) static char * SvgGetId(void) { - char *fileName = GetLayoutFilename(); - char *id = NULL; + char *fileName = GetLayoutFilename(); + char *id = NULL; - if (fileName) { - id = CreateValidId(fileName); + if (fileName) { + id = CreateValidId(fileName); #ifdef UTFCONVERT - id = Convert2UTF8(id); + id = Convert2UTF8(id); #endif - } + } - return (id); + return (id); } /** @@ -400,17 +399,17 @@ static char * SvgGetId(void) static void SvgSetTitle(drawCmd_p d) { - char *tmp = GetLayoutTitle(); - char *title; + char *tmp = GetLayoutTitle(); + char *title; - if (tmp) { - title = MyStrdup(tmp); + if (tmp) { + title = MyStrdup(tmp); #ifdef UTFCONVERT - title = Convert2UTF8(title); + title = Convert2UTF8(title); #endif - SvgAddTitle((SVGParent *)(d->d), title); - MyFree(title); - } + SvgAddTitle((SVGParent *)(d->d), title); + MyFree(title); + } } @@ -425,66 +424,67 @@ static void SvgSetTitle(drawCmd_p d) */ static int DoExportSVGTracks( - int cnt, - char ** fileName, - void * data) + int cnt, + char ** fileName, + void * data) { - DynString command = NaS; - SVGDocument *svg; - SVGParent *svgData; - char *id; + DynString command = NaS; + SVGDocument *svg; + SVGParent *svgData; + BOOL_T all = (selectedTrackCount == 0); + char *id; - assert(fileName != NULL); - assert(cnt == 1); + CHECK(fileName != NULL); + CHECK(cnt == 1); - SetCLocale(); - GetLayoutRoomSize(&roomSize); + SetCLocale(); + GetLayoutRoomSize(&roomSize); - SetCurrentPath(SVGPATHKEY, fileName[ 0 ]); + SetCurrentPath(SVGPATHKEY, fileName[ 0 ]); - svg = SvgCreateDocument(); - id = SvgGetId(); - svgData = SvgPrologue(svg, id, 0, 0.0, 0.0, roomSize.x, roomSize.y); - MyFree(id); + svg = SvgCreateDocument(); + id = SvgGetId(); + svgData = SvgPrologue(svg, id, 0, 0.0, 0.0, roomSize.x, roomSize.y); + MyFree(id); - wSetCursor(mainD.d, wCursorWait); + wSetCursor(mainD.d, wCursorWait); // time(&clock); - svgD.d = (wDraw_p)svgData; - - DrawSelectedTracks(&svgD); - SvgAddCSSStyle((SVGParent *)svgD.d); - SvgSetTitle(&svgD); // make sure this is the last element - - if (!SvgSaveFile(svg, fileName[0])) { - NoticeMessage(MSG_OPEN_FAIL, _("Cancel"), NULL, "SVG", fileName[0], - strerror(errno)); - - SvgDestroyDocument(svg); - wSetCursor(mainD.d, wCursorNormal); - SetUserLocale(); - return FALSE; - } - SvgDestroyDocument(svg); - Reset(); /**<TODO: was tut das? */ - wSetCursor(mainD.d, wCursorNormal); - SetUserLocale(); - return TRUE; + svgD.d = (wDraw_p)svgData; + + DrawSelectedTracks(&svgD,all); + SvgAddCSSStyle((SVGParent *)svgD.d); + SvgSetTitle(&svgD); // make sure this is the last element + + if (!SvgSaveFile(svg, fileName[0])) { + NoticeMessage(MSG_OPEN_FAIL, _("Cancel"), NULL, "SVG", fileName[0], + strerror(errno)); + + SvgDestroyDocument(svg); + wSetCursor(mainD.d, wCursorNormal); + SetUserLocale(); + return FALSE; + } + SvgDestroyDocument(svg); + Reset(); /**<TODO: was tut das? */ + wSetCursor(mainD.d, wCursorNormal); + SetUserLocale(); + return TRUE; } /** * Create and show the dialog for selecting the DXF export filename */ -void DoExportSVG(void) +void DoExportSVG(void * unused) { - assert(selectedTrackCount > 0); + // CHECK(selectedTrackCount > 0); - if (exportSVGFile_fs == NULL) - exportSVGFile_fs = wFilSelCreate(mainW, FS_SAVE, 0, _("Export to SVG"), - sSVGFilePattern, DoExportSVGTracks, NULL); + if (exportSVGFile_fs == NULL) + exportSVGFile_fs = wFilSelCreate(mainW, FS_SAVE, 0, _("Export to SVG"), + sSVGFilePattern, DoExportSVGTracks, NULL); - wFilSelect(exportSVGFile_fs, GetCurrentPath(SVGPATHKEY)); + wFilSelect(exportSVGFile_fs, GetCurrentPath(SVGPATHKEY)); } |