2019-09-11 20:14:42 +12:00
|
|
|
/* svg.c - Scalable Vector Graphics */
|
|
|
|
/*
|
|
|
|
libzint - the open source barcode library
|
2022-07-15 03:01:30 +12:00
|
|
|
Copyright (C) 2009-2022 Robin Stuart <rstuart114@gmail.com>
|
2019-09-11 20:14:42 +12:00
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
3. Neither the name of the project nor the names of its contributors
|
|
|
|
may be used to endorse or promote products derived from this software
|
|
|
|
without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
|
|
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
SUCH DAMAGE.
|
|
|
|
*/
|
2022-07-15 03:01:30 +12:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause */
|
2019-09-11 20:14:42 +12:00
|
|
|
|
2021-06-10 22:15:39 +12:00
|
|
|
#include <errno.h>
|
2019-09-11 20:14:42 +12:00
|
|
|
#include <locale.h>
|
|
|
|
#include <math.h>
|
2022-07-15 03:01:30 +12:00
|
|
|
#include <stdio.h>
|
2019-09-11 20:14:42 +12:00
|
|
|
|
|
|
|
#include "common.h"
|
- API: add new zint_symbol `dpmm` field for output resolution (BMP/
EMF/PCX/PNG/TIF only, i.e. excluding EPS, GIF & SVG)
- Add support for specifying scale by X-dimension and resolution
with new option `--scalexdimdp` for CLI/Tcl & new API function
`ZBarcode_Scale_From_XdimDp()` (+ `ZBarcode_XdimDp_From_Scale()`
& `ZBarcode_Default_Xdim()`) and new GUI popup; manual: document
- BMP/EMF/PCX/PNG/TIF: use new `dpmm` resolution field (for EMF
following Inkscape)
- backend_qt: add `dpmm()`, `vectorWidth()`, `vectorHeight()`,
`noPng()`, `getVersion()`, `takesGS1AIData()`, & `XdimDp` stuff
incl. new `QZintXdimDp` struct for passing around scale vars &
use in `getAsCLI()`; add comments
- Raise `scale` limit to 200 (from 100) to allow for large dpmm
- output: create directories & subdirectories as necessary for
output path using new function `out_fopen()` and use in BMP/EMF/
EPS/GIF/PCX/PNG/SVG/TIF
- DPLEIT/DPIDENT: format HRT according to (incomplete)
documentation, and set default height to 72X (from 50X)
- CODE128B renamed to CODE128AB as can use subsets A and/or B
- CODABAR: fix minimum height calc
- EMF: fix indexing of handles (zero-based not 1-based)
- GUI: fix symbology zap (previous technique of clearing and
re-loading settings without doing a sync no longer works);
fix UPCEAN guard descent enable
- MAILMARK: better error message if input < 14 characters
- GUI: add "Default" button for DAFT tracker ratio & enable/disable
various default buttons; use new `takesGS1AIData()` to
enable/disable GS1-specific checkboxes
- CLI: use new `validate_float()` to parse float options (7
significant digits allowed only, no scientific notation)
- DATAMATRIX/GRIDMATRIX/PDF417/QR/ULTRA: micro-optimize structapp
ID parse
- library/CLI: fiddle with static asserts (make CHAR_BIT sensitive,
supposedly)
- win32/README: update building libpng (assembly removed)
- README.linux: document incompatibility of Qt6 >= 6.3
- manual: expand Barcode Studio waffle
- test suite: change range separator to hyphen and allow multiple
excludes
2022-12-03 10:39:01 +13:00
|
|
|
#include "output.h"
|
2019-09-11 20:14:42 +12:00
|
|
|
|
2020-10-27 01:21:43 +13:00
|
|
|
static void pick_colour(int colour, char colour_code[]) {
|
2021-06-10 22:15:39 +12:00
|
|
|
switch (colour) {
|
2022-07-15 03:01:30 +12:00
|
|
|
case 1: /* Cyan */
|
2019-12-19 07:33:18 +13:00
|
|
|
strcpy(colour_code, "00ffff");
|
|
|
|
break;
|
2022-07-15 03:01:30 +12:00
|
|
|
case 2: /* Blue */
|
2019-12-19 07:33:18 +13:00
|
|
|
strcpy(colour_code, "0000ff");
|
|
|
|
break;
|
2022-07-15 03:01:30 +12:00
|
|
|
case 3: /* Magenta */
|
2019-12-19 07:33:18 +13:00
|
|
|
strcpy(colour_code, "ff00ff");
|
|
|
|
break;
|
2022-07-15 03:01:30 +12:00
|
|
|
case 4: /* Red */
|
2019-12-19 07:33:18 +13:00
|
|
|
strcpy(colour_code, "ff0000");
|
|
|
|
break;
|
2022-07-15 03:01:30 +12:00
|
|
|
case 5: /* Yellow */
|
2019-12-19 07:33:18 +13:00
|
|
|
strcpy(colour_code, "ffff00");
|
|
|
|
break;
|
2022-07-15 03:01:30 +12:00
|
|
|
case 6: /* Green */
|
2019-12-19 07:33:18 +13:00
|
|
|
strcpy(colour_code, "00ff00");
|
|
|
|
break;
|
2022-07-15 03:01:30 +12:00
|
|
|
case 8: /* White */
|
2020-08-12 23:19:26 +12:00
|
|
|
strcpy(colour_code, "ffffff");
|
|
|
|
break;
|
2022-07-15 03:01:30 +12:00
|
|
|
default: /* Black */
|
2019-12-19 07:33:18 +13:00
|
|
|
strcpy(colour_code, "000000");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-10 22:15:39 +12:00
|
|
|
static void make_html_friendly(unsigned char *string, char *html_version) {
|
2019-10-30 21:40:26 +13:00
|
|
|
/* Converts text to use HTML entity codes */
|
|
|
|
|
2021-06-10 22:15:39 +12:00
|
|
|
int i, len, html_pos;
|
2019-10-30 21:40:26 +13:00
|
|
|
|
|
|
|
html_pos = 0;
|
|
|
|
html_version[html_pos] = '\0';
|
2021-06-10 22:15:39 +12:00
|
|
|
len = (int) ustrlen(string);
|
2019-10-30 21:40:26 +13:00
|
|
|
|
2021-06-10 22:15:39 +12:00
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
switch (string[i]) {
|
2019-10-30 21:40:26 +13:00
|
|
|
case '>':
|
|
|
|
strcat(html_version, ">");
|
2019-10-17 06:42:22 +13:00
|
|
|
html_pos += 4;
|
2019-10-30 21:40:26 +13:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '<':
|
|
|
|
strcat(html_version, "<");
|
2019-10-17 06:42:22 +13:00
|
|
|
html_pos += 4;
|
2019-10-30 21:40:26 +13:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '&':
|
|
|
|
strcat(html_version, "&");
|
2019-10-17 06:42:22 +13:00
|
|
|
html_pos += 5;
|
2019-10-30 21:40:26 +13:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '"':
|
|
|
|
strcat(html_version, """);
|
|
|
|
html_pos += 6;
|
|
|
|
break;
|
|
|
|
|
2019-11-04 00:51:12 +13:00
|
|
|
case '\'':
|
|
|
|
strcat(html_version, "'");
|
|
|
|
html_pos += 6;
|
2019-10-30 21:40:26 +13:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2019-10-17 06:42:22 +13:00
|
|
|
html_version[html_pos] = string[i];
|
|
|
|
html_pos++;
|
|
|
|
html_version[html_pos] = '\0';
|
|
|
|
break;
|
|
|
|
}
|
2019-10-30 21:40:26 +13:00
|
|
|
}
|
2019-10-17 06:42:22 +13:00
|
|
|
}
|
|
|
|
|
2019-12-19 13:37:55 +13:00
|
|
|
INTERNAL int svg_plot(struct zint_symbol *symbol) {
|
2019-09-11 20:14:42 +12:00
|
|
|
FILE *fsvg;
|
|
|
|
int error_number = 0;
|
|
|
|
const char *locale = NULL;
|
|
|
|
float ax, ay, bx, by, cx, cy, dx, dy, ex, ey, fx, fy;
|
2020-10-27 01:21:43 +13:00
|
|
|
float previous_diameter;
|
|
|
|
float radius, half_radius, half_sqrt3_radius;
|
2019-11-18 07:30:55 +13:00
|
|
|
int i;
|
2020-08-03 09:26:39 +12:00
|
|
|
char fgcolour_string[7];
|
|
|
|
char bgcolour_string[7];
|
|
|
|
int bg_alpha = 0xff;
|
|
|
|
int fg_alpha = 0xff;
|
2020-10-27 01:21:43 +13:00
|
|
|
float fg_alpha_opacity = 0.0f, bg_alpha_opacity = 0.0f;
|
2021-10-21 11:05:30 +13:00
|
|
|
const char font_family[] = "Helvetica, sans-serif";
|
2020-10-01 00:19:12 +13:00
|
|
|
int bold;
|
2019-10-30 21:40:26 +13:00
|
|
|
|
2019-09-11 20:14:42 +12:00
|
|
|
struct zint_vector_rect *rect;
|
|
|
|
struct zint_vector_hexagon *hex;
|
|
|
|
struct zint_vector_circle *circle;
|
|
|
|
struct zint_vector_string *string;
|
2019-10-30 21:40:26 +13:00
|
|
|
|
2019-12-19 07:33:18 +13:00
|
|
|
char colour_code[7];
|
2021-06-10 22:15:39 +12:00
|
|
|
int len, html_len;
|
2019-12-19 07:33:18 +13:00
|
|
|
|
2022-12-20 05:28:15 +13:00
|
|
|
const int output_to_stdout = symbol->output_options & BARCODE_STDOUT;
|
2021-06-10 22:15:39 +12:00
|
|
|
char *html_string;
|
2019-11-18 07:30:55 +13:00
|
|
|
|
2020-08-03 09:26:39 +12:00
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
fgcolour_string[i] = symbol->fgcolour[i];
|
|
|
|
bgcolour_string[i] = symbol->bgcolour[i];
|
|
|
|
}
|
|
|
|
fgcolour_string[6] = '\0';
|
|
|
|
bgcolour_string[6] = '\0';
|
2021-06-10 22:15:39 +12:00
|
|
|
|
2020-08-03 09:26:39 +12:00
|
|
|
if (strlen(symbol->fgcolour) > 6) {
|
|
|
|
fg_alpha = (16 * ctoi(symbol->fgcolour[6])) + ctoi(symbol->fgcolour[7]);
|
2020-10-27 01:21:43 +13:00
|
|
|
if (fg_alpha != 0xff) {
|
|
|
|
fg_alpha_opacity = (float) (fg_alpha / 255.0);
|
|
|
|
}
|
2020-08-03 09:26:39 +12:00
|
|
|
}
|
|
|
|
if (strlen(symbol->bgcolour) > 6) {
|
|
|
|
bg_alpha = (16 * ctoi(symbol->bgcolour[6])) + ctoi(symbol->bgcolour[7]);
|
2020-10-27 01:21:43 +13:00
|
|
|
if (bg_alpha != 0xff) {
|
|
|
|
bg_alpha_opacity = (float) (bg_alpha / 255.0);
|
|
|
|
}
|
2020-08-03 09:26:39 +12:00
|
|
|
}
|
2019-10-30 21:40:26 +13:00
|
|
|
|
2021-06-10 22:15:39 +12:00
|
|
|
len = (int) ustrlen(symbol->text);
|
|
|
|
html_len = len + 1;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
switch (symbol->text[i]) {
|
2019-10-30 21:40:26 +13:00
|
|
|
case '>':
|
|
|
|
case '<':
|
|
|
|
case '"':
|
|
|
|
case '&':
|
2019-11-04 00:51:12 +13:00
|
|
|
case '\'':
|
|
|
|
html_len += 6;
|
2019-10-30 21:40:26 +13:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-15 03:01:30 +12:00
|
|
|
html_string = (char *) z_alloca(html_len);
|
2019-09-11 20:14:42 +12:00
|
|
|
|
|
|
|
/* Check for no created vector set */
|
|
|
|
/* E-Mail Christian Schmitz 2019-09-10: reason unknown Ticket #164*/
|
|
|
|
if (symbol->vector == NULL) {
|
2021-07-27 02:29:05 +12:00
|
|
|
strcpy(symbol->errtxt, "681: Vector header NULL");
|
2019-09-11 20:14:42 +12:00
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
}
|
2022-12-20 05:28:15 +13:00
|
|
|
if (output_to_stdout) {
|
2019-09-11 20:14:42 +12:00
|
|
|
fsvg = stdout;
|
|
|
|
} else {
|
- API: add new zint_symbol `dpmm` field for output resolution (BMP/
EMF/PCX/PNG/TIF only, i.e. excluding EPS, GIF & SVG)
- Add support for specifying scale by X-dimension and resolution
with new option `--scalexdimdp` for CLI/Tcl & new API function
`ZBarcode_Scale_From_XdimDp()` (+ `ZBarcode_XdimDp_From_Scale()`
& `ZBarcode_Default_Xdim()`) and new GUI popup; manual: document
- BMP/EMF/PCX/PNG/TIF: use new `dpmm` resolution field (for EMF
following Inkscape)
- backend_qt: add `dpmm()`, `vectorWidth()`, `vectorHeight()`,
`noPng()`, `getVersion()`, `takesGS1AIData()`, & `XdimDp` stuff
incl. new `QZintXdimDp` struct for passing around scale vars &
use in `getAsCLI()`; add comments
- Raise `scale` limit to 200 (from 100) to allow for large dpmm
- output: create directories & subdirectories as necessary for
output path using new function `out_fopen()` and use in BMP/EMF/
EPS/GIF/PCX/PNG/SVG/TIF
- DPLEIT/DPIDENT: format HRT according to (incomplete)
documentation, and set default height to 72X (from 50X)
- CODE128B renamed to CODE128AB as can use subsets A and/or B
- CODABAR: fix minimum height calc
- EMF: fix indexing of handles (zero-based not 1-based)
- GUI: fix symbology zap (previous technique of clearing and
re-loading settings without doing a sync no longer works);
fix UPCEAN guard descent enable
- MAILMARK: better error message if input < 14 characters
- GUI: add "Default" button for DAFT tracker ratio & enable/disable
various default buttons; use new `takesGS1AIData()` to
enable/disable GS1-specific checkboxes
- CLI: use new `validate_float()` to parse float options (7
significant digits allowed only, no scientific notation)
- DATAMATRIX/GRIDMATRIX/PDF417/QR/ULTRA: micro-optimize structapp
ID parse
- library/CLI: fiddle with static asserts (make CHAR_BIT sensitive,
supposedly)
- win32/README: update building libpng (assembly removed)
- README.linux: document incompatibility of Qt6 >= 6.3
- manual: expand Barcode Studio waffle
- test suite: change range separator to hyphen and allow multiple
excludes
2022-12-03 10:39:01 +13:00
|
|
|
if (!(fsvg = out_fopen(symbol->outfile, "w"))) {
|
2021-07-27 02:29:05 +12:00
|
|
|
sprintf(symbol->errtxt, "680: Could not open output file (%d: %.30s)", errno, strerror(errno));
|
|
|
|
return ZINT_ERROR_FILE_ACCESS;
|
|
|
|
}
|
2019-09-11 20:14:42 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
locale = setlocale(LC_ALL, "C");
|
|
|
|
|
|
|
|
/* Start writing the header */
|
2022-12-20 05:28:15 +13:00
|
|
|
fputs("<?xml version=\"1.0\" standalone=\"no\"?>\n"
|
|
|
|
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n"
|
|
|
|
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n", fsvg);
|
2021-06-10 22:15:39 +12:00
|
|
|
fprintf(fsvg, "<svg width=\"%d\" height=\"%d\" version=\"1.1\"\n",
|
2021-07-27 02:29:05 +12:00
|
|
|
(int) ceilf(symbol->vector->width), (int) ceilf(symbol->vector->height));
|
2022-12-20 05:28:15 +13:00
|
|
|
fputs(" xmlns=\"http://www.w3.org/2000/svg\">\n"
|
|
|
|
" <desc>Zint Generated Symbol\n"
|
|
|
|
" </desc>\n", fsvg);
|
2020-08-03 09:26:39 +12:00
|
|
|
fprintf(fsvg, "\n <g id=\"barcode\" fill=\"#%s\">\n", fgcolour_string);
|
2019-09-11 20:14:42 +12:00
|
|
|
|
2020-08-03 09:26:39 +12:00
|
|
|
if (bg_alpha != 0) {
|
2021-06-10 22:15:39 +12:00
|
|
|
fprintf(fsvg, " <rect x=\"0\" y=\"0\" width=\"%d\" height=\"%d\" fill=\"#%s\"",
|
2021-07-27 02:29:05 +12:00
|
|
|
(int) ceilf(symbol->vector->width), (int) ceilf(symbol->vector->height), bgcolour_string);
|
2020-08-03 09:26:39 +12:00
|
|
|
if (bg_alpha != 0xff) {
|
2020-10-27 01:21:43 +13:00
|
|
|
fprintf(fsvg, " opacity=\"%.3f\"", bg_alpha_opacity);
|
2020-08-03 09:26:39 +12:00
|
|
|
}
|
2022-12-20 05:28:15 +13:00
|
|
|
fputs(" />\n", fsvg);
|
2020-08-03 09:26:39 +12:00
|
|
|
}
|
2019-09-11 20:14:42 +12:00
|
|
|
|
|
|
|
rect = symbol->vector->rectangles;
|
|
|
|
while (rect) {
|
2021-06-10 22:15:39 +12:00
|
|
|
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\"",
|
|
|
|
rect->x, rect->y, rect->width, rect->height);
|
2020-08-03 09:26:39 +12:00
|
|
|
if (rect->colour != -1) {
|
2019-12-19 07:33:18 +13:00
|
|
|
pick_colour(rect->colour, colour_code);
|
2020-08-03 09:26:39 +12:00
|
|
|
fprintf(fsvg, " fill=\"#%s\"", colour_code);
|
|
|
|
}
|
|
|
|
if (fg_alpha != 0xff) {
|
2020-10-27 01:21:43 +13:00
|
|
|
fprintf(fsvg, " opacity=\"%.3f\"", fg_alpha_opacity);
|
2019-12-19 07:33:18 +13:00
|
|
|
}
|
2022-12-20 05:28:15 +13:00
|
|
|
fputs(" />\n", fsvg);
|
2019-09-11 20:14:42 +12:00
|
|
|
rect = rect->next;
|
|
|
|
}
|
2019-10-30 21:40:26 +13:00
|
|
|
|
2020-10-27 01:21:43 +13:00
|
|
|
previous_diameter = radius = half_radius = half_sqrt3_radius = 0.0f;
|
2019-09-11 20:14:42 +12:00
|
|
|
hex = symbol->vector->hexagons;
|
|
|
|
while (hex) {
|
2020-10-27 01:21:43 +13:00
|
|
|
if (previous_diameter != hex->diameter) {
|
|
|
|
previous_diameter = hex->diameter;
|
|
|
|
radius = (float) (0.5 * previous_diameter);
|
|
|
|
half_radius = (float) (0.25 * previous_diameter);
|
|
|
|
half_sqrt3_radius = (float) (0.43301270189221932338 * previous_diameter);
|
|
|
|
}
|
2020-08-06 08:23:11 +12:00
|
|
|
if ((hex->rotation == 0) || (hex->rotation == 180)) {
|
2020-10-27 01:21:43 +13:00
|
|
|
ay = hex->y + radius;
|
|
|
|
by = hex->y + half_radius;
|
|
|
|
cy = hex->y - half_radius;
|
|
|
|
dy = hex->y - radius;
|
|
|
|
ey = hex->y - half_radius;
|
|
|
|
fy = hex->y + half_radius;
|
2020-08-06 08:23:11 +12:00
|
|
|
ax = hex->x;
|
2020-10-27 01:21:43 +13:00
|
|
|
bx = hex->x + half_sqrt3_radius;
|
|
|
|
cx = hex->x + half_sqrt3_radius;
|
2020-08-06 08:23:11 +12:00
|
|
|
dx = hex->x;
|
2020-10-27 01:21:43 +13:00
|
|
|
ex = hex->x - half_sqrt3_radius;
|
|
|
|
fx = hex->x - half_sqrt3_radius;
|
2020-08-06 08:23:11 +12:00
|
|
|
} else {
|
|
|
|
ay = hex->y;
|
2020-10-27 01:21:43 +13:00
|
|
|
by = hex->y + half_sqrt3_radius;
|
|
|
|
cy = hex->y + half_sqrt3_radius;
|
2020-08-06 08:23:11 +12:00
|
|
|
dy = hex->y;
|
2020-10-27 01:21:43 +13:00
|
|
|
ey = hex->y - half_sqrt3_radius;
|
|
|
|
fy = hex->y - half_sqrt3_radius;
|
|
|
|
ax = hex->x - radius;
|
|
|
|
bx = hex->x - half_radius;
|
|
|
|
cx = hex->x + half_radius;
|
|
|
|
dx = hex->x + radius;
|
|
|
|
ex = hex->x + half_radius;
|
|
|
|
fx = hex->x - half_radius;
|
2020-08-06 08:23:11 +12:00
|
|
|
}
|
2021-06-10 22:15:39 +12:00
|
|
|
fprintf(fsvg, " <path d=\"M %.2f %.2f L %.2f %.2f L %.2f %.2f L %.2f %.2f L %.2f %.2f L %.2f %.2f Z\"",
|
|
|
|
ax, ay, bx, by, cx, cy, dx, dy, ex, ey, fx, fy);
|
2020-08-03 09:26:39 +12:00
|
|
|
if (fg_alpha != 0xff) {
|
2020-10-27 01:21:43 +13:00
|
|
|
fprintf(fsvg, " opacity=\"%.3f\"", fg_alpha_opacity);
|
2020-08-03 09:26:39 +12:00
|
|
|
}
|
2022-12-20 05:28:15 +13:00
|
|
|
fputs(" />\n", fsvg);
|
2019-09-11 20:14:42 +12:00
|
|
|
hex = hex->next;
|
|
|
|
}
|
2019-10-30 21:40:26 +13:00
|
|
|
|
2020-10-27 01:21:43 +13:00
|
|
|
previous_diameter = radius = 0.0f;
|
2019-09-11 20:14:42 +12:00
|
|
|
circle = symbol->vector->circles;
|
|
|
|
while (circle) {
|
2020-10-27 01:21:43 +13:00
|
|
|
if (previous_diameter != circle->diameter) {
|
|
|
|
previous_diameter = circle->diameter;
|
|
|
|
radius = (float) (0.5 * previous_diameter);
|
|
|
|
}
|
2021-08-23 00:59:01 +12:00
|
|
|
fprintf(fsvg, " <circle cx=\"%.2f\" cy=\"%.2f\" r=\"%.*f\"",
|
|
|
|
circle->x, circle->y, circle->width ? 3 : 2, radius);
|
2021-06-10 22:15:39 +12:00
|
|
|
|
2019-09-11 20:14:42 +12:00
|
|
|
if (circle->colour) {
|
2021-08-23 00:59:01 +12:00
|
|
|
if (circle->width) {
|
|
|
|
fprintf(fsvg, " stroke=\"#%s\" stroke-width=\"%.3f\" fill=\"none\"", bgcolour_string, circle->width);
|
|
|
|
} else {
|
|
|
|
fprintf(fsvg, " fill=\"#%s\"", bgcolour_string);
|
|
|
|
}
|
2020-08-03 09:26:39 +12:00
|
|
|
if (bg_alpha != 0xff) {
|
2022-07-15 03:01:30 +12:00
|
|
|
/* This doesn't work how the user is likely to expect - more work needed! */
|
2020-10-27 01:21:43 +13:00
|
|
|
fprintf(fsvg, " opacity=\"%.3f\"", bg_alpha_opacity);
|
2020-08-03 09:26:39 +12:00
|
|
|
}
|
2019-09-11 20:14:42 +12:00
|
|
|
} else {
|
2021-08-23 00:59:01 +12:00
|
|
|
if (circle->width) {
|
|
|
|
fprintf(fsvg, " stroke=\"#%s\" stroke-width=\"%.3f\" fill=\"none\"", fgcolour_string, circle->width);
|
|
|
|
}
|
2020-08-03 09:26:39 +12:00
|
|
|
if (fg_alpha != 0xff) {
|
2020-10-27 01:21:43 +13:00
|
|
|
fprintf(fsvg, " opacity=\"%.3f\"", fg_alpha_opacity);
|
2020-08-03 09:26:39 +12:00
|
|
|
}
|
2019-09-11 20:14:42 +12:00
|
|
|
}
|
2022-12-20 05:28:15 +13:00
|
|
|
fputs(" />\n", fsvg);
|
2019-09-11 20:14:42 +12:00
|
|
|
circle = circle->next;
|
|
|
|
}
|
2019-10-30 21:40:26 +13:00
|
|
|
|
2021-06-10 22:15:39 +12:00
|
|
|
bold = (symbol->output_options & BOLD_TEXT)
|
|
|
|
&& (!is_extendable(symbol->symbology) || (symbol->output_options & SMALL_TEXT));
|
2019-09-11 20:14:42 +12:00
|
|
|
string = symbol->vector->strings;
|
|
|
|
while (string) {
|
2021-10-21 11:05:30 +13:00
|
|
|
const char *const halign = string->halign == 2 ? "end" : string->halign == 1 ? "start" : "middle";
|
2020-10-01 00:19:12 +13:00
|
|
|
fprintf(fsvg, " <text x=\"%.2f\" y=\"%.2f\" text-anchor=\"%s\"\n", string->x, string->y, halign);
|
|
|
|
fprintf(fsvg, " font-family=\"%s\" font-size=\"%.1f\"", font_family, string->fsize);
|
|
|
|
if (bold) {
|
2022-12-20 05:28:15 +13:00
|
|
|
fputs(" font-weight=\"bold\"", fsvg);
|
2020-10-01 00:19:12 +13:00
|
|
|
}
|
2020-08-03 09:26:39 +12:00
|
|
|
if (fg_alpha != 0xff) {
|
2020-10-27 01:21:43 +13:00
|
|
|
fprintf(fsvg, " opacity=\"%.3f\"", fg_alpha_opacity);
|
2020-08-03 09:26:39 +12:00
|
|
|
}
|
2020-08-06 08:23:11 +12:00
|
|
|
if (string->rotation != 0) {
|
|
|
|
fprintf(fsvg, " transform=\"rotate(%d,%.2f,%.2f)\"", string->rotation, string->x, string->y);
|
|
|
|
}
|
2022-12-20 05:28:15 +13:00
|
|
|
fputs(" >\n", fsvg);
|
2019-10-17 06:42:22 +13:00
|
|
|
make_html_friendly(string->text, html_string);
|
|
|
|
fprintf(fsvg, " %s\n", html_string);
|
2022-12-20 05:28:15 +13:00
|
|
|
fputs(" </text>\n", fsvg);
|
2019-09-11 20:14:42 +12:00
|
|
|
string = string->next;
|
|
|
|
}
|
|
|
|
|
2022-12-20 05:28:15 +13:00
|
|
|
fputs(" </g>\n"
|
|
|
|
"</svg>\n", fsvg);
|
2019-09-11 20:14:42 +12:00
|
|
|
|
|
|
|
if (locale)
|
|
|
|
setlocale(LC_ALL, locale);
|
|
|
|
|
2022-12-20 05:28:15 +13:00
|
|
|
if (ferror(fsvg)) {
|
|
|
|
sprintf(symbol->errtxt, "682: Incomplete write to output (%d: %.30s)", errno, strerror(errno));
|
|
|
|
if (!output_to_stdout) {
|
|
|
|
(void) fclose(fsvg);
|
|
|
|
}
|
|
|
|
return ZINT_ERROR_FILE_WRITE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (output_to_stdout) {
|
|
|
|
if (fflush(fsvg) != 0) {
|
|
|
|
sprintf(symbol->errtxt, "683: Incomplete flush to output (%d: %.30s)", errno, strerror(errno));
|
|
|
|
return ZINT_ERROR_FILE_WRITE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (fclose(fsvg) != 0) {
|
|
|
|
sprintf(symbol->errtxt, "684: Failure on closing output file (%d: %.30s)", errno, strerror(errno));
|
|
|
|
return ZINT_ERROR_FILE_WRITE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-11 20:14:42 +12:00
|
|
|
return error_number;
|
|
|
|
}
|
2022-07-15 03:01:30 +12:00
|
|
|
|
|
|
|
/* vim: set ts=4 sw=4 et : */
|