From 40a4bb9da0b200977d3eafb82569072873fa1dbd Mon Sep 17 00:00:00 2001 From: gitlost Date: Fri, 15 Dec 2023 10:51:51 +0000 Subject: [PATCH] vector: make sure BIND_TOP trumps BIND/BOX always (fixes extraneous whjitespace at bottom of CODABLOCKF/CODE16K/CODE49 if BIND_TOP set); add left/right fudge to guard whitespace placements so appear closer to edge for SVG/qzint (undone by EMF/EPS) --- backend/emf.c | 56 +++++++----- backend/output.c | 2 +- backend/ps.c | 9 +- backend/raster.c | 10 ++- .../emf/ean13_5addon_ggs_5.2.2.5.2-2_gws.emf | Bin 1968 -> 1968 bytes .../data/emf/ean13_ggs_5.2.2.1-1_gws.emf | Bin 1496 -> 1496 bytes .../tests/data/emf/ean8_gss_5.2.2.2-1_gws.emf | Bin 1296 -> 1296 bytes .../emf/upca_2addon_ggs_5.2.6.6-5_gws.emf | Bin 1952 -> 1952 bytes backend/tests/data/emf/upce_2addon_gws.emf | Bin 1552 -> 1552 bytes .../data/emf/upce_2addon_small_bold_gws.emf | Bin 1552 -> 1552 bytes .../eps/ean13_2addon_ggs_5.2.2.5.1-2_gws.eps | 3 +- .../data/eps/ean13_ggs_5.2.2.1-1_gws.eps | 3 +- backend/tests/data/eps/ean5_gws.eps | 3 +- .../tests/data/eps/ean8_gss_5.2.2.2-1_gws.eps | 6 +- .../eps/upca_2addon_ggs_5.2.6.6-5_gws.eps | 3 +- ...ca_2addon_ggs_5.2.6.6-5_gws_rotate_180.eps | 3 +- backend/tests/data/eps/upce_5addon_gws.eps | 3 +- .../data/eps/upce_5addon_small_bold_gws.eps | 3 +- .../svg/ean13_2addon_ggs_5.2.2.5.1-2_gws.svg | 2 +- .../svg/ean13_5addon_ggs_5.2.2.5.2-2_gws.svg | 2 +- .../data/svg/ean13_cc_2addon_cca_4x4_gws.svg | 2 +- .../data/svg/ean13_cc_5addon_ccb_3x4_gws.svg | 2 +- .../tests/data/svg/ean13_cc_cca_5x4_gws.svg | 2 +- .../data/svg/ean13_ggs_5.2.2.1-1_gws.svg | 2 +- .../svg/ean13_ggs_5.2.2.1-1_gws_embed.svg | 2 +- backend/tests/data/svg/ean2_gws.svg | 2 +- backend/tests/data/svg/ean5_gws.svg | 2 +- backend/tests/data/svg/ean8_2addon_gws.svg | 4 +- backend/tests/data/svg/ean8_5addon_gws.svg | 4 +- .../data/svg/ean8_cc_2addon_cca_4x3_gws.svg | 4 +- .../data/svg/ean8_cc_5addon_ccb_8x3_gws.svg | 4 +- .../tests/data/svg/ean8_gss_5.2.2.2-1_gws.svg | 4 +- .../svg/upca_2addon_ggs_5.2.6.6-5_gws.svg | 2 +- backend/tests/data/svg/upca_5addon_gws.svg | 2 +- .../data/svg/upca_cc_2addon_cca_3x4_gws.svg | 2 +- .../data/svg/upca_cc_5addon_ccb_4x4_gws.svg | 2 +- backend/tests/data/svg/upce_2addon_gws.svg | 2 +- .../tests/data/svg/upce_5addon_small_gws.svg | 2 +- .../data/svg/upce_cc_2addon_cca_5x2_gws.svg | 2 +- .../data/svg/upce_cc_5addon_ccb_8x2_gws.svg | 2 +- backend/tests/test_output.c | 84 ++++++++++++++++++ backend/tests/test_raster.c | 6 ++ backend/tests/test_vector.c | 32 ++++--- backend/vector.c | 48 +++++----- docs/images/eanx8_gws.svg | 4 +- docs/images/isbnx_gws.svg | 2 +- docs/images/upca_5_gws.svg | 2 +- docs/images/upce_2_gws.svg | 2 +- 48 files changed, 231 insertions(+), 107 deletions(-) diff --git a/backend/emf.c b/backend/emf.c index 384ea42f..2a023374 100644 --- a/backend/emf.c +++ b/backend/emf.c @@ -91,29 +91,29 @@ static int emf_count_hexagons(const struct zint_symbol *symbol) { static int emf_count_strings(const struct zint_symbol *symbol, float *fsize, float *fsize2, int *halign_left, int *halign_right) { int strings = 0; - const struct zint_vector_string *str; + const struct zint_vector_string *string; *fsize = *fsize2 = 0.0f; *halign_left = *halign_right = 0; - str = symbol->vector->strings; - while (str) { + string = symbol->vector->strings; + while (string) { /* Allow 2 font sizes */ if (*fsize == 0.0f) { - *fsize = str->fsize; - } else if (str->fsize != *fsize && *fsize2 == 0.0f) { - *fsize2 = str->fsize; + *fsize = string->fsize; + } else if (string->fsize != *fsize && *fsize2 == 0.0f) { + *fsize2 = string->fsize; } /* Only 3 haligns possible and centre align always assumed used */ - if (str->halign) { /* Left or right align */ - if (str->halign == 1) { /* Left align */ - *halign_left = str->halign; + if (string->halign) { /* Left or right align */ + if (string->halign == 1) { /* Left align */ + *halign_left = string->halign; } else { /* Right align */ - *halign_right = str->halign; + *halign_right = string->halign; } } strings++; - str = str->next; + string = string->next; } return strings; @@ -190,12 +190,13 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) { int draw_background = 1; int bold; + const int upcean = is_upcean(symbol->symbology); const int output_to_stdout = symbol->output_options & BARCODE_STDOUT; struct zint_vector_rect *rect; struct zint_vector_circle *circ; struct zint_vector_hexagon *hex; - struct zint_vector_string *str; + struct zint_vector_string *string; /* Allow for up to 6 strings (current max 3 for UPC/EAN) */ unsigned char *this_string[6]; @@ -617,24 +618,24 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) { this_text = 0; /* Loop over font sizes so that they're grouped together, so only have to select font twice at most */ for (i = 0, current_fsize = fsize; i < 2 && current_fsize; i++, current_fsize = fsize2) { - str = symbol->vector->strings; + string = symbol->vector->strings; current_halign = -1; - while (str) { + while (string) { int utfle_len; int bumped_len; - if (str->fsize != current_fsize) { - str = str->next; + if (string->fsize != current_fsize) { + string = string->next; continue; } - text_fsizes[this_text] = str->fsize; - text_haligns[this_text] = str->halign; + text_fsizes[this_text] = string->fsize; + text_haligns[this_text] = string->halign; if (text_haligns[this_text] != current_halign) { current_halign = text_haligns[this_text]; bytecount += 12; recordcount++; } - assert(str->length > 0); - utfle_len = emf_utfle_length(str->text, str->length); + assert(string->length > 0); + utfle_len = emf_utfle_length(string->text, string->length); bumped_len = emf_bump_up(utfle_len); if (!(this_string[this_text] = (unsigned char *) malloc(bumped_len))) { for (i = 0; i < this_text; i++) { @@ -653,8 +654,15 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) { text[this_text].i_graphics_mode = 0x00000002; /* GM_ADVANCED */ text[this_text].ex_scale = 1.0f; text[this_text].ey_scale = 1.0f; - text[this_text].w_emr_text.reference.x = (int32_t) str->x; - text[this_text].w_emr_text.reference.y = (int32_t) str->y; + /* Unhack the guard whitespace `gws_left_fudge`/`gws_right_fudge` hack */ + if (upcean && string->halign == 1 && string->text[0] == '<') { + text[this_text].w_emr_text.reference.x = 0; + } else if (upcean && string->halign == 2 && string->text[0] == '>') { + text[this_text].w_emr_text.reference.x = (int32_t) (symbol->vector->width - 1); + } else { + text[this_text].w_emr_text.reference.x = (int32_t) string->x; + } + text[this_text].w_emr_text.reference.y = (int32_t) string->y; text[this_text].w_emr_text.chars = utfle_len; text[this_text].w_emr_text.off_string = 76; text[this_text].w_emr_text.options = 0; @@ -663,12 +671,12 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) { text[this_text].w_emr_text.rectangle.right = 0xffffffff; text[this_text].w_emr_text.rectangle.bottom = 0xffffffff; text[this_text].w_emr_text.off_dx = 0; - emf_utfle_copy(this_string[this_text], str->text, str->length); + emf_utfle_copy(this_string[this_text], string->text, string->length); bytecount += 76 + bumped_len; recordcount++; this_text++; - str = str->next; + string = string->next; } } /* Suppress clang-tidy clang-analyzer-core.UndefinedBinaryOperatorResult warning */ diff --git a/backend/output.c b/backend/output.c index 665dcf56..79ef9309 100644 --- a/backend/output.c +++ b/backend/output.c @@ -706,7 +706,7 @@ INTERNAL void out_set_whitespace_offsets(const struct zint_symbol *symbol, const *p_boffset = symbol->whitespace_height + qz_bottom; if (symbol->output_options & (BARCODE_BOX | BARCODE_BIND | BARCODE_BIND_TOP)) { *p_yoffset += symbol->border_width; - if (symbol->output_options & (BARCODE_BOX | BARCODE_BIND)) { + if (!(symbol->output_options & BARCODE_BIND_TOP)) { /* Trumps BARCODE_BOX & BARCODE_BIND */ *p_boffset += symbol->border_width; } } diff --git a/backend/ps.c b/backend/ps.c index 8e9ac42d..be67d3d7 100644 --- a/backend/ps.c +++ b/backend/ps.c @@ -483,7 +483,14 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) { fputs(" scalefont setfont\n", feps); previous_fsize = string->fsize; } - out_putsf(" ", 2, string->x, feps); + /* Unhack the guard whitespace `gws_left_fudge`/`gws_right_fudge` hack */ + if (upcean && string->halign == 1 && string->text[0] == '<') { + out_putsf(" ", 2, 0, feps); + } else if (upcean && string->halign == 2 && string->text[0] == '>') { + out_putsf(" ", 2, symbol->vector->width, feps); + } else { + out_putsf(" ", 2, string->x, feps); + } out_putsf(" ", 2, symbol->vector->height - string->y, feps); fputs(" moveto\n", feps); if (string->rotation != 0) { diff --git a/backend/raster.c b/backend/raster.c index 9c1f0681..6017b123 100644 --- a/backend/raster.c +++ b/backend/raster.c @@ -1176,8 +1176,9 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl const int upcea_height_adj = ((UPCEAN_FONT_HEIGHT - UPCEAN_SMALL_FONT_HEIGHT) * si + 1) / 2; int text_yposn = yoffset_si + symbol_height_si + (int) (symbol->text_gap * si); - if (symbol->border_width > 0 && (symbol->output_options & (BARCODE_BOX | BARCODE_BIND))) { - text_yposn += symbol->border_width * si; /* Note not needed for BARCODE_BIND_TOP */ + if (symbol->border_width > 0 && (symbol->output_options & (BARCODE_BOX | BARCODE_BIND)) + && !(symbol->output_options & BARCODE_BIND_TOP)) { /* Trumps BARCODE_BOX & BARCODE_BIND */ + text_yposn += symbol->border_width * si; } if (upceanflag == 6) { /* UPC-E */ @@ -1297,8 +1298,9 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl unsigned char local_text[sizeof(symbol->text)] = {0}; int text_xposn = (int) ((main_width / 2.0f) * si) + xoffset_si; int text_yposn = yoffset_si + symbol_height_si + (int) (symbol->text_gap * si); - if (symbol->border_width > 0 && (symbol->output_options & (BARCODE_BOX | BARCODE_BIND))) { - text_yposn += symbol->border_width * si; /* Note not needed for BARCODE_BIND_TOP */ + if (symbol->border_width > 0 && (symbol->output_options & (BARCODE_BOX | BARCODE_BIND)) + && !(symbol->output_options & BARCODE_BIND_TOP)) { /* Trumps BARCODE_BOX & BARCODE_BIND */ + text_yposn += symbol->border_width * si; } to_iso8859_1(symbol->text, local_text); /* Put the human readable text at the bottom */ diff --git a/backend/tests/data/emf/ean13_5addon_ggs_5.2.2.5.2-2_gws.emf b/backend/tests/data/emf/ean13_5addon_ggs_5.2.2.5.2-2_gws.emf index 49bcca7d85c927d5a8874396b53804e1374eb1e8..5eaada75f56a5e73edaadb9e35a021394eb49bd9 100644 GIT binary patch delta 17 YcmdnMzkz>)2m9n3tQw4-lMC7H0XSs^ssI20 delta 19 acmdnMzkz>)2Roz0>L0qf)l77fOSlN(voCm&#y003Hd2b2H+ delta 23 fcmcb?eS>>L0V|`#VyXwb diff --git a/backend/tests/data/emf/ean8_gss_5.2.2.2-1_gws.emf b/backend/tests/data/emf/ean8_gss_5.2.2.2-1_gws.emf index 453269df4aca060176e039f9ec27490f91f585a7..febb44cd2332ecbfc1282df1bf820ad74cf49b43 100644 GIT binary patch delta 27 jcmbQhHGylx4CcuzSTq2LLt41?2z$ delta 19 bcmbQhGl6Hr3RXsm$%ZWIjH@SKWVHtXJIw|1 diff --git a/backend/tests/data/emf/upce_2addon_small_bold_gws.emf b/backend/tests/data/emf/upce_2addon_small_bold_gws.emf index cda40e4787fb811fdfff9ac50ff5dc71768a756d..ebe907a7a9aba42c9695d7aaa90982130d6dd121 100644 GIT binary patch delta 17 ZcmbQhGl6Hr3f9R6EE2LLt41?2z$ delta 19 bcmbQhGl6Hr3RXsm$%ZWIjH@SKWVHtXJIw|1 diff --git a/backend/tests/data/eps/ean13_2addon_ggs_5.2.2.5.1-2_gws.eps b/backend/tests/data/eps/ean13_2addon_ggs_5.2.2.5.1-2_gws.eps index 3de837b0..fa8340b8 100644 --- a/backend/tests/data/eps/ean13_2addon_ggs_5.2.2.5.1-2_gws.eps +++ b/backend/tests/data/eps/ean13_2addon_ggs_5.2.2.5.1-2_gws.eps @@ -59,5 +59,6 @@ I 256 2 R 246 102.4 moveto (12) stringwidth pop -2 div 0 rmoveto (12) show - 264 102.4 moveto + 276 102.4 moveto + (>) stringwidth pop neg 0 rmoveto (>) show diff --git a/backend/tests/data/eps/ean13_ggs_5.2.2.1-1_gws.eps b/backend/tests/data/eps/ean13_ggs_5.2.2.1-1_gws.eps index 22986c54..3c3f3d37 100644 --- a/backend/tests/data/eps/ean13_ggs_5.2.2.1-1_gws.eps +++ b/backend/tests/data/eps/ean13_ggs_5.2.2.1-1_gws.eps @@ -49,5 +49,6 @@ I 192 6 R 163 0.8 moveto (531000) stringwidth pop -2 div 0 rmoveto (531000) show - 214 0.8 moveto + 226 0.8 moveto + (>) stringwidth pop neg 0 rmoveto (>) show diff --git a/backend/tests/data/eps/ean5_gws.eps b/backend/tests/data/eps/ean5_gws.eps index 3e57ec9c..9ca68721 100644 --- a/backend/tests/data/eps/ean5_gws.eps +++ b/backend/tests/data/eps/ean5_gws.eps @@ -29,5 +29,6 @@ I 82 6 R 47 102.4 moveto (98765) stringwidth pop -2 div 0 rmoveto (98765) show - 91.5 102.4 moveto + 104 102.4 moveto + (>) stringwidth pop neg 0 rmoveto (>) show diff --git a/backend/tests/data/eps/ean8_gss_5.2.2.2-1_gws.eps b/backend/tests/data/eps/ean8_gss_5.2.2.2-1_gws.eps index aaeab4fb..49e20c09 100644 --- a/backend/tests/data/eps/ean8_gss_5.2.2.2-1_gws.eps +++ b/backend/tests/data/eps/ean8_gss_5.2.2.2-1_gws.eps @@ -32,8 +32,7 @@ I 128 2 R 110 8 I 142 2 R 146 2 R /Helvetica findfont 21.4 scalefont setfont - 12.5 0.8 moveto - (<) stringwidth pop neg 0 rmoveto + 0 0.8 moveto (<) show 49 0.8 moveto (9501) stringwidth pop -2 div 0 rmoveto @@ -41,5 +40,6 @@ I 128 2 R 113 0.8 moveto (2346) stringwidth pop -2 div 0 rmoveto (2346) show - 149.6 0.8 moveto + 162 0.8 moveto + (>) stringwidth pop neg 0 rmoveto (>) show diff --git a/backend/tests/data/eps/upca_2addon_ggs_5.2.6.6-5_gws.eps b/backend/tests/data/eps/upca_2addon_ggs_5.2.6.6-5_gws.eps index f7b0f2f2..cff1e696 100644 --- a/backend/tests/data/eps/upca_2addon_ggs_5.2.6.6-5_gws.eps +++ b/backend/tests/data/eps/upca_2addon_ggs_5.2.6.6-5_gws.eps @@ -64,5 +64,6 @@ I 254 2 R 246 102.4 moveto (24) stringwidth pop -2 div 0 rmoveto (24) show - 263.6 102.4 moveto + 276 102.4 moveto + (>) stringwidth pop neg 0 rmoveto (>) show diff --git a/backend/tests/data/eps/upca_2addon_ggs_5.2.6.6-5_gws_rotate_180.eps b/backend/tests/data/eps/upca_2addon_ggs_5.2.6.6-5_gws_rotate_180.eps index fa38e521..5569dd13 100644 --- a/backend/tests/data/eps/upca_2addon_ggs_5.2.6.6-5_gws_rotate_180.eps +++ b/backend/tests/data/eps/upca_2addon_ggs_5.2.6.6-5_gws_rotate_180.eps @@ -79,8 +79,9 @@ I 20 2 R (24) stringwidth pop -2 div 0 rmoveto (24) show grestore - 12.4 15.6 moveto + 276 15.6 moveto gsave 180 rotate + (>) stringwidth pop neg 0 rmoveto (>) show grestore diff --git a/backend/tests/data/eps/upce_5addon_gws.eps b/backend/tests/data/eps/upce_5addon_gws.eps index c1d10dc3..23a1ce8a 100644 --- a/backend/tests/data/eps/upce_5addon_gws.eps +++ b/backend/tests/data/eps/upce_5addon_gws.eps @@ -57,5 +57,6 @@ I 216 4 R 182 102.4 moveto (12345) stringwidth pop -2 div 0 rmoveto (12345) show - 225.6 102.4 moveto + 238 102.4 moveto + (>) stringwidth pop neg 0 rmoveto (>) show diff --git a/backend/tests/data/eps/upce_5addon_small_bold_gws.eps b/backend/tests/data/eps/upce_5addon_small_bold_gws.eps index aafd299d..e21133dc 100644 --- a/backend/tests/data/eps/upce_5addon_small_bold_gws.eps +++ b/backend/tests/data/eps/upce_5addon_small_bold_gws.eps @@ -57,5 +57,6 @@ I 216 4 R 182 102.28 moveto (12345) stringwidth pop -2 div 0 rmoveto (12345) show - 225.6 102.28 moveto + 238 102.28 moveto + (>) stringwidth pop neg 0 rmoveto (>) show diff --git a/backend/tests/data/svg/ean13_2addon_ggs_5.2.2.5.1-2_gws.svg b/backend/tests/data/svg/ean13_2addon_ggs_5.2.2.5.1-2_gws.svg index 1f0c2984..e7fbfff5 100644 --- a/backend/tests/data/svg/ean13_2addon_ggs_5.2.2.5.1-2_gws.svg +++ b/backend/tests/data/svg/ean13_2addon_ggs_5.2.2.5.1-2_gws.svg @@ -17,7 +17,7 @@ 12 - + > diff --git a/backend/tests/data/svg/ean13_5addon_ggs_5.2.2.5.2-2_gws.svg b/backend/tests/data/svg/ean13_5addon_ggs_5.2.2.5.2-2_gws.svg index 4f73eeb1..24218ef5 100644 --- a/backend/tests/data/svg/ean13_5addon_ggs_5.2.2.5.2-2_gws.svg +++ b/backend/tests/data/svg/ean13_5addon_ggs_5.2.2.5.2-2_gws.svg @@ -17,7 +17,7 @@ 54321 - + > diff --git a/backend/tests/data/svg/ean13_cc_2addon_cca_4x4_gws.svg b/backend/tests/data/svg/ean13_cc_2addon_cca_4x4_gws.svg index 39e6bceb..f70f89d7 100644 --- a/backend/tests/data/svg/ean13_cc_2addon_cca_4x4_gws.svg +++ b/backend/tests/data/svg/ean13_cc_2addon_cca_4x4_gws.svg @@ -17,7 +17,7 @@ 12 - + > diff --git a/backend/tests/data/svg/ean13_cc_5addon_ccb_3x4_gws.svg b/backend/tests/data/svg/ean13_cc_5addon_ccb_3x4_gws.svg index 5abcbe29..b04aef50 100644 --- a/backend/tests/data/svg/ean13_cc_5addon_ccb_3x4_gws.svg +++ b/backend/tests/data/svg/ean13_cc_5addon_ccb_3x4_gws.svg @@ -17,7 +17,7 @@ 54321 - + > diff --git a/backend/tests/data/svg/ean13_cc_cca_5x4_gws.svg b/backend/tests/data/svg/ean13_cc_cca_5x4_gws.svg index f21c9ad5..45881799 100644 --- a/backend/tests/data/svg/ean13_cc_cca_5x4_gws.svg +++ b/backend/tests/data/svg/ean13_cc_cca_5x4_gws.svg @@ -14,7 +14,7 @@ 890128 - + > diff --git a/backend/tests/data/svg/ean13_ggs_5.2.2.1-1_gws.svg b/backend/tests/data/svg/ean13_ggs_5.2.2.1-1_gws.svg index 128706c0..ae0a4ab1 100644 --- a/backend/tests/data/svg/ean13_ggs_5.2.2.1-1_gws.svg +++ b/backend/tests/data/svg/ean13_ggs_5.2.2.1-1_gws.svg @@ -14,7 +14,7 @@ 531000 - + > diff --git a/backend/tests/data/svg/ean13_ggs_5.2.2.1-1_gws_embed.svg b/backend/tests/data/svg/ean13_ggs_5.2.2.1-1_gws_embed.svg index 972686d4..7dd18875 100644 --- a/backend/tests/data/svg/ean13_ggs_5.2.2.1-1_gws_embed.svg +++ b/backend/tests/data/svg/ean13_ggs_5.2.2.1-1_gws_embed.svg @@ -15,7 +15,7 @@ 531000 - + > diff --git a/backend/tests/data/svg/ean2_gws.svg b/backend/tests/data/svg/ean2_gws.svg index c794352f..7b290553 100644 --- a/backend/tests/data/svg/ean2_gws.svg +++ b/backend/tests/data/svg/ean2_gws.svg @@ -8,7 +8,7 @@ 12 - + > diff --git a/backend/tests/data/svg/ean5_gws.svg b/backend/tests/data/svg/ean5_gws.svg index b0b972b4..493516e7 100644 --- a/backend/tests/data/svg/ean5_gws.svg +++ b/backend/tests/data/svg/ean5_gws.svg @@ -8,7 +8,7 @@ 12345 - + > diff --git a/backend/tests/data/svg/ean8_2addon_gws.svg b/backend/tests/data/svg/ean8_2addon_gws.svg index fa8af465..bff67e31 100644 --- a/backend/tests/data/svg/ean8_2addon_gws.svg +++ b/backend/tests/data/svg/ean8_2addon_gws.svg @@ -5,7 +5,7 @@ - + < @@ -17,7 +17,7 @@ 12 - + > diff --git a/backend/tests/data/svg/ean8_5addon_gws.svg b/backend/tests/data/svg/ean8_5addon_gws.svg index df953cfd..993fdc6e 100644 --- a/backend/tests/data/svg/ean8_5addon_gws.svg +++ b/backend/tests/data/svg/ean8_5addon_gws.svg @@ -5,7 +5,7 @@ - + < @@ -17,7 +17,7 @@ 12345 - + > diff --git a/backend/tests/data/svg/ean8_cc_2addon_cca_4x3_gws.svg b/backend/tests/data/svg/ean8_cc_2addon_cca_4x3_gws.svg index 13b76fc4..ab1d61f1 100644 --- a/backend/tests/data/svg/ean8_cc_2addon_cca_4x3_gws.svg +++ b/backend/tests/data/svg/ean8_cc_2addon_cca_4x3_gws.svg @@ -5,7 +5,7 @@ - + < @@ -17,7 +17,7 @@ 65 - + > diff --git a/backend/tests/data/svg/ean8_cc_5addon_ccb_8x3_gws.svg b/backend/tests/data/svg/ean8_cc_5addon_ccb_8x3_gws.svg index 83d23ee8..508307c6 100644 --- a/backend/tests/data/svg/ean8_cc_5addon_ccb_8x3_gws.svg +++ b/backend/tests/data/svg/ean8_cc_5addon_ccb_8x3_gws.svg @@ -5,7 +5,7 @@ - + < @@ -17,7 +17,7 @@ 74083 - + > diff --git a/backend/tests/data/svg/ean8_gss_5.2.2.2-1_gws.svg b/backend/tests/data/svg/ean8_gss_5.2.2.2-1_gws.svg index d54d669a..f57932df 100644 --- a/backend/tests/data/svg/ean8_gss_5.2.2.2-1_gws.svg +++ b/backend/tests/data/svg/ean8_gss_5.2.2.2-1_gws.svg @@ -5,7 +5,7 @@ - + < @@ -14,7 +14,7 @@ 2346 - + > diff --git a/backend/tests/data/svg/upca_2addon_ggs_5.2.6.6-5_gws.svg b/backend/tests/data/svg/upca_2addon_ggs_5.2.6.6-5_gws.svg index e9f34f08..905ed9ec 100644 --- a/backend/tests/data/svg/upca_2addon_ggs_5.2.6.6-5_gws.svg +++ b/backend/tests/data/svg/upca_2addon_ggs_5.2.6.6-5_gws.svg @@ -20,7 +20,7 @@ 24 - + > diff --git a/backend/tests/data/svg/upca_5addon_gws.svg b/backend/tests/data/svg/upca_5addon_gws.svg index f87a5b04..062d8574 100644 --- a/backend/tests/data/svg/upca_5addon_gws.svg +++ b/backend/tests/data/svg/upca_5addon_gws.svg @@ -20,7 +20,7 @@ 12345 - + > diff --git a/backend/tests/data/svg/upca_cc_2addon_cca_3x4_gws.svg b/backend/tests/data/svg/upca_cc_2addon_cca_3x4_gws.svg index d49f5a6d..f232c73a 100644 --- a/backend/tests/data/svg/upca_cc_2addon_cca_3x4_gws.svg +++ b/backend/tests/data/svg/upca_cc_2addon_cca_3x4_gws.svg @@ -20,7 +20,7 @@ 12 - + > diff --git a/backend/tests/data/svg/upca_cc_5addon_ccb_4x4_gws.svg b/backend/tests/data/svg/upca_cc_5addon_ccb_4x4_gws.svg index fc1e6b40..fcbcb392 100644 --- a/backend/tests/data/svg/upca_cc_5addon_ccb_4x4_gws.svg +++ b/backend/tests/data/svg/upca_cc_5addon_ccb_4x4_gws.svg @@ -20,7 +20,7 @@ 12121 - + > diff --git a/backend/tests/data/svg/upce_2addon_gws.svg b/backend/tests/data/svg/upce_2addon_gws.svg index cbcc01bd..26cedf27 100644 --- a/backend/tests/data/svg/upce_2addon_gws.svg +++ b/backend/tests/data/svg/upce_2addon_gws.svg @@ -17,7 +17,7 @@ 12 - + > diff --git a/backend/tests/data/svg/upce_5addon_small_gws.svg b/backend/tests/data/svg/upce_5addon_small_gws.svg index f6950890..79769d7b 100644 --- a/backend/tests/data/svg/upce_5addon_small_gws.svg +++ b/backend/tests/data/svg/upce_5addon_small_gws.svg @@ -17,7 +17,7 @@ 12345 - + > diff --git a/backend/tests/data/svg/upce_cc_2addon_cca_5x2_gws.svg b/backend/tests/data/svg/upce_cc_2addon_cca_5x2_gws.svg index ea987f93..1f30dd92 100644 --- a/backend/tests/data/svg/upce_cc_2addon_cca_5x2_gws.svg +++ b/backend/tests/data/svg/upce_cc_2addon_cca_5x2_gws.svg @@ -17,7 +17,7 @@ 89 - + > diff --git a/backend/tests/data/svg/upce_cc_5addon_ccb_8x2_gws.svg b/backend/tests/data/svg/upce_cc_5addon_ccb_8x2_gws.svg index ce08ca2b..6d3cf104 100644 --- a/backend/tests/data/svg/upce_cc_5addon_ccb_8x2_gws.svg +++ b/backend/tests/data/svg/upce_cc_5addon_ccb_8x2_gws.svg @@ -17,7 +17,7 @@ 56789 - + > diff --git a/backend/tests/test_output.c b/backend/tests/test_output.c index 42fe3e12..0e855e85 100644 --- a/backend/tests/test_output.c +++ b/backend/tests/test_output.c @@ -231,6 +231,89 @@ static void test_quiet_zones(const testCtx *const p_ctx) { testFinish(); } +static void test_set_whitespace_offsets(const testCtx *const p_ctx) { + + struct item { + int symbology; + int whitespace_width; + int whitespace_height; + int border_width; + int output_options; + int hide_text; + int comp_xoffset; + float scaler; + + float expected_xoffset; + float expected_yoffset; + float expected_roffset; + float expected_boffset; + float expected_qz_right; + }; + /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ + struct item data[] = { + /* 0*/ { BARCODE_CODE128, 1, 0, 0, 0, 0, 0, 0.0f, /*expected*/ 1.0f, 0.0f, 1.0f, 0.0f, 0.0f }, + /* 1*/ { BARCODE_CODE128, 2, 0, 0, 0, 0, 0, 1.0f, /*expected*/ 2.0f, 0.0f, 2.0f, 0.0f, 0.0f }, + /* 2*/ { BARCODE_CODE128, 2, 3, 0, 0, 0, 0, 1.0f, /*expected*/ 2.0f, 3.0f, 2.0f, 3.0f, 0.0f }, + /* 3*/ { BARCODE_CODE128, 2, 3, 1, 0, 0, 0, 1.0f, /*expected*/ 2.0f, 3.0f, 2.0f, 3.0f, 0.0f }, + /* 4*/ { BARCODE_CODE128, 2, 3, 1, BARCODE_BIND, 0, 0, 1.0f, /*expected*/ 2.0f, 4.0f, 2.0f, 4.0f, 0.0f }, + /* 5*/ { BARCODE_CODE128, 2, 3, 1, BARCODE_BIND_TOP, 0, 0, 1.0f, /*expected*/ 2.0f, 4.0f, 2.0f, 3.0f, 0.0f }, + /* 6*/ { BARCODE_CODE128, 2, 3, 1, BARCODE_BIND_TOP | BARCODE_BIND, 0, 0, 1.0f, /*expected*/ 2.0f, 4.0f, 2.0f, 3.0f, 0.0f }, /* BIND_TOP wins */ + /* 7*/ { BARCODE_CODE128, 2, 3, 1, BARCODE_BOX, 0, 0, 1.0f, /*expected*/ 3.0f, 4.0f, 3.0f, 4.0f, 0.0f }, + /* 8*/ { BARCODE_CODE128, 2, 3, 1, BARCODE_BIND_TOP | BARCODE_BOX, 0, 0, 1.0f, /*expected*/ 3.0f, 4.0f, 3.0f, 3.0f, 0.0f }, /* BIND_TOP wins */ + /* 9*/ { BARCODE_CODE128, 2, 3, 1, BARCODE_BOX | BARCODE_BIND, 0, 0, 1.0f, /*expected*/ 3.0f, 4.0f, 3.0f, 4.0f, 0.0f }, /* BIND_BOX wins */ + /* 10*/ { BARCODE_CODE128, 2, 3, 1, BARCODE_BIND_TOP | BARCODE_BOX | BARCODE_BIND, 0, 0, 1.0f, /*expected*/ 3.0f, 4.0f, 3.0f, 3.0f, 0.0f }, /* BIND_TOP wins */ + /* 11*/ { BARCODE_CODE128, 2, 3, 1, BARCODE_BOX | BARCODE_QUIET_ZONES, 0, 0, 1.0f, /*expected*/ 13.0f, 4.0f, 13.0f, 4.0f, 10.0f }, + }; + int data_size = ARRAY_SIZE(data); + int i; + struct zint_symbol symbol = {0}; + float xoffset, yoffset, roffset, boffset, qz_right; + int xoffset_si, yoffset_si, roffset_si, boffset_si, qz_right_si; + + testStart("test_set_whitespace_offsets"); + + for (i = 0; i < data_size; i++) { + if (testContinue(p_ctx, i)) continue; + + xoffset = yoffset = roffset = boffset = qz_right = 0.0f; + xoffset_si = yoffset_si = roffset_si = boffset_si = qz_right_si = 0; + + symbol.symbology = data[i].symbology; + symbol.whitespace_width = data[i].whitespace_width; + symbol.whitespace_height = data[i].whitespace_height; + symbol.border_width = data[i].border_width; + symbol.output_options = data[i].output_options; + out_set_whitespace_offsets(&symbol, data[i].hide_text, data[i].comp_xoffset, + &xoffset, &yoffset, &roffset, &boffset, &qz_right, data[i].scaler, + &xoffset_si, &yoffset_si, &roffset_si, &boffset_si, &qz_right_si); + assert_equal(xoffset, data[i].expected_xoffset, "i:%d xoffset %g != %g\n", i, xoffset, data[i].expected_xoffset); + assert_equal(yoffset, data[i].expected_yoffset, "i:%d yoffset %g != %g\n", i, yoffset, data[i].expected_yoffset); + assert_equal(roffset, data[i].expected_roffset, "i:%d roffset %g != %g\n", i, roffset, data[i].expected_roffset); + assert_equal(boffset, data[i].expected_boffset, "i:%d boffset %g != %g\n", i, boffset, data[i].expected_boffset); + assert_equal(qz_right, data[i].expected_qz_right, "i:%d qz_right %g != %g\n", i, qz_right, data[i].expected_qz_right); + if (data[i].scaler) { + int expected_xoffset_si = (int) (data[i].expected_xoffset * data[i].scaler); + int expected_yoffset_si = (int) (data[i].expected_yoffset * data[i].scaler); + int expected_roffset_si = (int) (data[i].expected_roffset * data[i].scaler); + int expected_boffset_si = (int) (data[i].expected_boffset * data[i].scaler); + int expected_qz_right_si = (int) (data[i].expected_qz_right * data[i].scaler); + assert_equal(xoffset_si, expected_xoffset_si, "i:%d xoffset_si %d != %d\n", i, xoffset_si, expected_xoffset_si); + assert_equal(yoffset_si, expected_yoffset_si, "i:%d yoffset_si %d != %d\n", i, yoffset_si, expected_yoffset_si); + assert_equal(roffset_si, expected_roffset_si, "i:%d roffset_si %d != %d\n", i, roffset_si, expected_roffset_si); + assert_equal(boffset_si, expected_boffset_si, "i:%d boffset_si %d != %d\n", i, boffset_si, expected_boffset_si); + assert_equal(qz_right_si, expected_qz_right_si, "i:%d qz_right_si %d != %d\n", i, qz_right_si, expected_qz_right_si); + } else { + assert_zero(xoffset_si, "i:%d xoffset_si %d non-zero\n", i, xoffset_si); + assert_zero(yoffset_si, "i:%d yoffset_si %d non-zero\n", i, yoffset_si); + assert_zero(roffset_si, "i:%d roffset_si %d non-zero\n", i, roffset_si); + assert_zero(boffset_si, "i:%d boffset_si %d non-zero\n", i, boffset_si); + assert_zero(qz_right_si, "i:%d qz_right_si %d non-zero\n", i, qz_right_si); + } + } + + testFinish(); +} + #ifdef _WIN32 #define TEST_OUT_SEP '\\' #define TEST_OUT_SEP_STR "\\" @@ -411,6 +494,7 @@ int main(int argc, char *argv[]) { { "test_colour_get_rgb", test_colour_get_rgb }, { "test_colour_get_cmyk", test_colour_get_cmyk }, { "test_quiet_zones", test_quiet_zones }, + { "test_set_whitespace_offsets", test_set_whitespace_offsets }, { "test_fopen", test_fopen }, { "test_out_putsf", test_out_putsf }, }; diff --git a/backend/tests/test_raster.c b/backend/tests/test_raster.c index d22856ea..7c84d7d2 100644 --- a/backend/tests/test_raster.c +++ b/backend/tests/test_raster.c @@ -936,6 +936,12 @@ static void test_output_options(const testCtx *const p_ctx) { /* 87*/ { BARCODE_ITF14, -1, -1, 0, BARCODE_BOX, 0, 0, "123", 0, 50, 1, 135, 310, 116, 0, 100, 0 }, /* 88*/ { BARCODE_ITF14, -1, -1, -1, OUT_BUFFER_INTERMEDIATE, 0, 0, "123", 0, 50, 1, 135, 330, 136, 1, 110, 0 }, /* 89*/ { BARCODE_ITF14, -1, -1, -1, OUT_BUFFER_INTERMEDIATE, 90, 0, "123", 0, 50, 1, 135, 136, 330, 1, 0, 110 }, + /* 90*/ { BARCODE_CODABLOCKF, -1, -1, -1, -1, 0, 0, "A123", 0, 20, 2, 101, 242, 44, 1, 43, 24 }, + /* 91*/ { BARCODE_CODABLOCKF, -1, -1, -1, BARCODE_BIND_TOP, 0, 0, "A123", 0, 20, 2, 101, 242, 42, 0, 41, 24 }, + /* 92*/ { BARCODE_CODE16K, -1, -1, -1, -1, 0, 0, "A123", 0, 20, 2, 70, 162, 44, 1, 43, 0 }, + /* 93*/ { BARCODE_CODE16K, -1, -1, -1, BARCODE_BIND_TOP, 0, 0, "A123", 0, 20, 2, 70, 162, 42, 0, 41, 0 }, + /* 94*/ { BARCODE_CODE49, -1, -1, -1, -1, 0, 0, "A123", 0, 20, 2, 70, 162, 44, 1, 43, 0 }, + /* 95*/ { BARCODE_CODE49, -1, -1, -1, BARCODE_BIND_TOP, 0, 0, "A123", 0, 20, 2, 70, 162, 42, 0, 41, 0 }, }; int data_size = ARRAY_SIZE(data); int i, length, ret; diff --git a/backend/tests/test_vector.c b/backend/tests/test_vector.c index 9ad6365a..e70909c3 100644 --- a/backend/tests/test_vector.c +++ b/backend/tests/test_vector.c @@ -919,22 +919,22 @@ static void test_upcean_hrt(const testCtx *const p_ctx) { struct item data[] = { /* 0*/ { BARCODE_EANX, -1, -1, "123456789012", 0, 50, 1, 95, 226, 118, 12.2, 117.2, -1, -1, 3 }, /* EAN-13 */ /* 1*/ { BARCODE_EANX, 0, -1, "123456789012", 0, 50, 1, 95, 226, 110, -1, -1, -1, -1, 0 }, /* EAN-13 */ - /* 2*/ { BARCODE_EANX, -1, EANUPC_GUARD_WHITESPACE, "123456789012", 0, 50, 1, 95, 226, 118, 12.2, 117.2, 214, 117.2, 4 }, /* EAN-13 */ + /* 2*/ { BARCODE_EANX, -1, EANUPC_GUARD_WHITESPACE, "123456789012", 0, 50, 1, 95, 226, 118, 12.2, 117.2, 227, 117.2, 4 }, /* EAN-13 */ /* 3*/ { BARCODE_EANX_CHK, -1, -1, "1234567890128", 0, 50, 1, 95, 226, 118, 12.2, 117.2, -1, -1, 3 }, /* EAN-13 */ /* 4*/ { BARCODE_EANX_CHK, 0, -1, "1234567890128", 0, 50, 1, 95, 226, 110, -1, -1, -1, -1, 0 }, /* EAN-13 */ - /* 5*/ { BARCODE_EANX_CHK, -1, EANUPC_GUARD_WHITESPACE, "1234567890128", 0, 50, 1, 95, 226, 118, 12.2, 117.2, 214, 117.2, 4 }, /* EAN-13 */ + /* 5*/ { BARCODE_EANX_CHK, -1, EANUPC_GUARD_WHITESPACE, "1234567890128", 0, 50, 1, 95, 226, 118, 12.2, 117.2, 227, 117.2, 4 }, /* EAN-13 */ /* 6*/ { BARCODE_ISBNX, -1, -1, "9784567890120", 0, 50, 1, 95, 226, 118, 12.2, 117.2, -1, -1, 3 }, /* 7*/ { BARCODE_ISBNX, 0, -1, "9784567890120", 0, 50, 1, 95, 226, 110, -1, -1, -1, -1, 0 }, - /* 8*/ { BARCODE_ISBNX, -1, EANUPC_GUARD_WHITESPACE, "9784567890120", 0, 50, 1, 95, 226, 118, 12.2, 117.2, 214, 117.2, 4 }, + /* 8*/ { BARCODE_ISBNX, -1, EANUPC_GUARD_WHITESPACE, "9784567890120", 0, 50, 1, 95, 226, 118, 12.2, 117.2, 227, 117.2, 4 }, /* 9*/ { BARCODE_EANX, -1, -1, "1234567", 0, 50, 1, 67, 162, 118, 49, 117.2, -1, -1, 2 }, /* EAN-8 */ /* 10*/ { BARCODE_EANX, 0, -1, "1234567", 0, 50, 1, 67, 162, 110, -1, -1, -1, -1, 0 }, /* EAN-8 */ - /* 11*/ { BARCODE_EANX, -1, EANUPC_GUARD_WHITESPACE, "1234567", 0, 50, 1, 67, 162, 118, 49, 117.2, 12.5, 117.2, 4 }, /* EAN-8 */ + /* 11*/ { BARCODE_EANX, -1, EANUPC_GUARD_WHITESPACE, "1234567", 0, 50, 1, 67, 162, 118, 49, 117.2, -1, 117.2, 4 }, /* EAN-8 */ /* 12*/ { BARCODE_EANX, -1, -1, "1234", 0, 50, 1, 47, 104, 118, 47, 15.6, -1, -1, 1 }, /* EAN-5 */ /* 13*/ { BARCODE_EANX, 0, -1, "1234", 0, 50, 1, 47, 104, 100, -1, -1, -1, -1, 0 }, /* EAN-5 */ - /* 14*/ { BARCODE_EANX, -1, EANUPC_GUARD_WHITESPACE, "1234", 0, 50, 1, 47, 104, 118, 47, 15.6, 91.5, 15.6, 2 }, /* EAN-5 */ + /* 14*/ { BARCODE_EANX, -1, EANUPC_GUARD_WHITESPACE, "1234", 0, 50, 1, 47, 104, 118, 47, 15.6, 105, 15.6, 2 }, /* EAN-5 */ /* 15*/ { BARCODE_EANX, -1, -1, "12", 0, 50, 1, 20, 50, 118, 20, 15.6, -1, -1, 1 }, /* EAN-2 */ /* 16*/ { BARCODE_EANX, 0, -1, "12", 0, 50, 1, 20, 50, 100, -1, -1, -1, -1, 0 }, /* EAN-2 */ - /* 17*/ { BARCODE_EANX, -1, EANUPC_GUARD_WHITESPACE, "12", 0, 50, 1, 20, 50, 118, 20, 15.6, -1, -1, 2 }, /* EAN-2 */ + /* 17*/ { BARCODE_EANX, -1, EANUPC_GUARD_WHITESPACE, "12", 0, 50, 1, 20, 50, 118, 20, 15.6, 51, 15.6, 2 }, /* EAN-2 */ /* 18*/ { BARCODE_UPCA, -1, -1, "12345678901", 0, 50, 1, 95, 226, 118, 8.7, 117.2, -1, -1, 4 }, /* 19*/ { BARCODE_UPCA, 0, -1, "12345678901", 0, 50, 1, 95, 226, 110, -1, -1, -1, -1, 0 }, /* 20*/ { BARCODE_UPCA, -1, EANUPC_GUARD_WHITESPACE, "12345678901", 0, 50, 1, 95, 226, 118, 8.7, 117.2, -1, -1, 4 }, @@ -952,31 +952,31 @@ static void test_upcean_hrt(const testCtx *const p_ctx) { /* 32*/ { BARCODE_EANX, -1, EANUPC_GUARD_WHITESPACE, "123456789012+12", 0, 50, 1, 122, 276.0, 118, 12.2, 117.2, 246, 15.6, 5 }, /* EAN-13 + EAN-2 */ /* 33*/ { BARCODE_ISBNX, -1, -1, "9784567890120+12", 0, 50, 1, 122, 276.0, 118, 12.2, 117.2, 246, 15.6, 4 }, /* ISBN + EAN-2 */ /* 34*/ { BARCODE_ISBNX, 0, -1, "9784567890120+12", 0, 50, 1, 122, 276.0, 110, -1, -1, -1, -1, 0 }, /* ISBN + EAN-2 */ - /* 35*/ { BARCODE_ISBNX, -1, EANUPC_GUARD_WHITESPACE, "9784567890120+12", 0, 50, 1, 122, 276.0, 118, 246, 15.6, 264, 15.6, 5 }, /* ISBN + EAN-2 */ + /* 35*/ { BARCODE_ISBNX, -1, EANUPC_GUARD_WHITESPACE, "9784567890120+12", 0, 50, 1, 122, 276.0, 118, 246, 15.6, 277, 15.6, 5 }, /* ISBN + EAN-2 */ /* 36*/ { BARCODE_EANX, -1, -1, "123456789012+12345", 0, 50, 1, 149, 330.0, 118, 12.2, 117.2, 274, 15.6, 4 }, /* EAN-13 + EAN-5 */ /* 37*/ { BARCODE_EANX, 0, -1, "123456789012+12345", 0, 50, 1, 149, 330.0, 110, -1, -1, -1, -1, 0 }, /* EAN-13 + EAN-5 */ /* 38*/ { BARCODE_EANX, -1, EANUPC_GUARD_WHITESPACE, "123456789012+12345", 0, 50, 1, 149, 330.0, 118, 12.2, 117.2, 274, 15.6, 5 }, /* EAN-13 + EAN-5 */ /* 39*/ { BARCODE_ISBNX, -1, -1, "9784567890120+12345", 0, 50, 1, 149, 330.0, 118, 12.2, 117.2, 274, 15.6, 4 }, /* ISBN + EAN-5 */ /* 40*/ { BARCODE_ISBNX, 0, -1, "9784567890120+12345", 0, 50, 1, 149, 330.0, 110, -1, -1, -1, -1, 0 }, /* ISBN + EAN-5 */ - /* 41*/ { BARCODE_ISBNX, -1, EANUPC_GUARD_WHITESPACE, "9784567890120+12345", 0, 50, 1, 149, 330.0, 118, 274, 15.6, 318, 15.6, 5 }, /* ISBN + EAN-5 */ + /* 41*/ { BARCODE_ISBNX, -1, EANUPC_GUARD_WHITESPACE, "9784567890120+12345", 0, 50, 1, 149, 330.0, 118, 274, 15.6, 331, 15.6, 5 }, /* ISBN + EAN-5 */ /* 42*/ { BARCODE_EANX, -1, -1, "1234567+12", 0, 50, 1, 94, 212, 118, 49, 117.2, 182, 15.6, 3 }, /* EAN-8 + EAN-2 */ /* 43*/ { BARCODE_EANX, 0, -1, "1234567+12", 0, 50, 1, 94, 212, 110, -1, -1, -1, -1, 0 }, /* EAN-8 + EAN-2 */ - /* 44*/ { BARCODE_EANX, -1, EANUPC_GUARD_WHITESPACE, "1234567+12", 0, 50, 1, 94, 212, 118, 182, 15.6, 199.6, 15.6, 5 }, /* EAN-8 + EAN-2 */ + /* 44*/ { BARCODE_EANX, -1, EANUPC_GUARD_WHITESPACE, "1234567+12", 0, 50, 1, 94, 212, 118, 182, 15.6, 213, 15.6, 5 }, /* EAN-8 + EAN-2 */ /* 45*/ { BARCODE_EANX, -1, -1, "1234567+12345", 0, 50, 1, 121, 266, 118, 49, 117.2, 210, 15.6, 3 }, /* EAN-8 + EAN-5 */ /* 46*/ { BARCODE_EANX, 0, -1, "1234567+12345", 0, 50, 1, 121, 266, 110, -1, -1, -1, -1, 0 }, /* EAN-8 + EAN-5 */ /* 47*/ { BARCODE_EANX, -1, EANUPC_GUARD_WHITESPACE, "1234567+12345", 0, 50, 1, 121, 266, 118, 210, 15.6, 210, 15.6, 5 }, /* EAN-8 + EAN-5 */ /* 48*/ { BARCODE_UPCA, -1, -1, "12345678901+12", 0, 50, 1, 124, 276, 118, 8.7, 117.2, 246, 15.6, 5 }, /* 49*/ { BARCODE_UPCA, 0, -1, "12345678901+12", 0, 50, 1, 124, 276, 110, -1, -1, -1, -1, 0 }, - /* 50*/ { BARCODE_UPCA, -1, EANUPC_GUARD_WHITESPACE, "12345678901+12", 0, 50, 1, 124, 276, 118, 8.7, 117.2, 263.6, 15.6, 6 }, + /* 50*/ { BARCODE_UPCA, -1, EANUPC_GUARD_WHITESPACE, "12345678901+12", 0, 50, 1, 124, 276, 118, 8.7, 117.2, 277, 15.6, 6 }, /* 51*/ { BARCODE_UPCA, -1, -1, "12345678901+12345", 0, 50, 1, 151, 330, 118, 8.7, 117.2, 274, 15.6, 5 }, /* 52*/ { BARCODE_UPCA, 0, -1, "12345678901+12345", 0, 50, 1, 151, 330, 110, -1, -1, -1, -1, 0 }, - /* 53*/ { BARCODE_UPCA, -1, EANUPC_GUARD_WHITESPACE, "12345678901+12345", 0, 50, 1, 151, 330, 118, 274, 15.6, 317.6, 15.6, 6 }, + /* 53*/ { BARCODE_UPCA, -1, EANUPC_GUARD_WHITESPACE, "12345678901+12345", 0, 50, 1, 151, 330, 118, 274, 15.6, 331, 15.6, 6 }, /* 54*/ { BARCODE_UPCE, -1, -1, "1234567+12", 0, 50, 1, 78, 184.0, 118, 8.7, 117.2, 154, 15.6, 4 }, /* 55*/ { BARCODE_UPCE, 0, -1, "1234567+12", 0, 50, 1, 78, 184.0, 110, -1, -1, -1, -1, 0 }, - /* 56*/ { BARCODE_UPCE, -1, EANUPC_GUARD_WHITESPACE, "1234567+12", 0, 50, 1, 78, 184.0, 118, 8.7, 117.2, 171.6, 15.6, 5 }, + /* 56*/ { BARCODE_UPCE, -1, EANUPC_GUARD_WHITESPACE, "1234567+12", 0, 50, 1, 78, 184.0, 118, 8.7, 117.2, 185, 15.6, 5 }, /* 57*/ { BARCODE_UPCE, -1, -1, "1234567+12345", 0, 50, 1, 105, 238.0, 118, 8.7, 117.2, 182, 15.6, 4 }, /* 58*/ { BARCODE_UPCE, 0, -1, "1234567+12345", 0, 50, 1, 105, 238.0, 110, -1, -1, -1, -1, 0 }, - /* 59*/ { BARCODE_UPCE, -1, EANUPC_GUARD_WHITESPACE, "1234567+12345", 0, 50, 1, 105, 238.0, 118, 182, 15.6, 225.6, 15.6, 5 }, + /* 59*/ { BARCODE_UPCE, -1, EANUPC_GUARD_WHITESPACE, "1234567+12345", 0, 50, 1, 105, 238.0, 118, 182, 15.6, 239, 15.6, 5 }, }; int data_size = ARRAY_SIZE(data); int i, length, ret; @@ -1278,6 +1278,12 @@ static void test_output_options(const testCtx *const p_ctx) { /* 48*/ { BARCODE_ITF14, -1, -1, -1, -1, "123", 0, 50, 1, 135, 330, 136.28, 1, 320, 10 }, /* 49*/ { BARCODE_ITF14, -1, -1, 0, -1, "123", 0, 50, 1, 135, 330, 136.28, 1, 320, 10 }, /* 50*/ { BARCODE_ITF14, -1, -1, 0, BARCODE_BOX, "123", 0, 50, 1, 135, 310, 116.28, 0, 300, 0 }, /* No zero-width/height rectangles */ + /* 51*/ { BARCODE_CODABLOCKF, -1, -1, -1, -1, "A123", 0, 20, 2, 101, 242, 44, 1, 20, 42 }, + /* 52*/ { BARCODE_CODABLOCKF, -1, -1, -1, BARCODE_BIND_TOP, "A123", 0, 20, 2, 101, 242, 42, 0, 20, 42 }, + /* 53*/ { BARCODE_CODE16K, -1, -1, -1, -1, "A123", 0, 20, 2, 70, 162, 44, 1, 0, 42 }, + /* 54*/ { BARCODE_CODE16K, -1, -1, -1, BARCODE_BIND_TOP, "A123", 0, 20, 2, 70, 162, 42, 0, 0, 42 }, + /* 55*/ { BARCODE_CODE49, -1, -1, -1, -1, "A123", 0, 20, 2, 70, 162, 44, 1, 0, 42 }, + /* 56*/ { BARCODE_CODE49, -1, -1, -1, BARCODE_BIND_TOP, "A123", 0, 20, 2, 70, 162, 42, 0, 0, 42 }, }; int data_size = ARRAY_SIZE(data); int i, length, ret; diff --git a/backend/vector.c b/backend/vector.c index c9d3eb56..71396d12 100644 --- a/backend/vector.c +++ b/backend/vector.c @@ -388,7 +388,7 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ int addon_len = 0; int addon_gap = 0; float addon_text_yposn = 0.0f; - float xoffset, yoffset, roffset, boffset; + float xoffset, yoffset, roffset, boffset, qz_right; float textoffset; int upceanflag = 0; int addon_latch = 0; @@ -412,6 +412,8 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ float addon_row_yposn; float addon_row_height; int upcae_outside_font_height = 0; /* UPC-A/E outside digits font size */ + const float gws_left_fudge = 0.5f; /* These make the guard whitespaces appear closer to the edge for SVG/qzint */ + const float gws_right_fudge = 0.5f; /* (undone by EMF/EPS) */ /* Note using "ascender" to mean height above digits as "ascent" usually measured from baseline */ const float digit_ascender_factor = 0.22f; /* Assuming digit ascender height roughly 22% of font size */ float digit_ascender = 0.0f; /* Avoid gcc -Wmaybe-uninitialized */ @@ -473,7 +475,7 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ hide_text = ((!symbol->show_hrt) || (ustrlen(symbol->text) == 0)); - out_set_whitespace_offsets(symbol, hide_text, comp_xoffset, &xoffset, &yoffset, &roffset, &boffset, NULL, + out_set_whitespace_offsets(symbol, hide_text, comp_xoffset, &xoffset, &yoffset, &roffset, &boffset, &qz_right, 0 /*scaler*/, NULL, NULL, NULL, NULL, NULL); xoffset_comp = xoffset + comp_xoffset; @@ -740,8 +742,9 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ if (upceanflag >= 6) { /* UPC-E, EAN-8, UPC-A, EAN-13 */ float text_yposn = yoffset + symbol->height + font_height + text_gap - antialias_fudge; /* Baseline */ - if (symbol->border_width > 0 && (symbol->output_options & (BARCODE_BOX | BARCODE_BIND))) { - text_yposn += symbol->border_width; /* Note not needed for BARCODE_BIND_TOP */ + if (symbol->border_width > 0 && (symbol->output_options & (BARCODE_BOX | BARCODE_BIND)) + && !(symbol->output_options & BARCODE_BIND_TOP)) { /* Trumps BARCODE_BOX & BARCODE_BIND */ + text_yposn += symbol->border_width; } if (upceanflag == 6) { /* UPC-E */ @@ -763,20 +766,20 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ if (!vector_add_string(symbol, addon, addon_len, text_xposn, addon_text_yposn, font_height, textwidth, 0 /*centre align*/, &last_string)) return ZINT_ERROR_MEMORY; if (upcean_guard_whitespace) { - text_xposn = (addon_len == 2 ? 70.0f : 97.0f) - 0.2f + xoffset_comp + addon_gap; + text_xposn = symbol->width + gws_right_fudge + qz_right + xoffset; textwidth = 8.5f; if (!vector_add_string(symbol, (const unsigned char *) ">", 1, text_xposn, addon_text_yposn, - font_height, textwidth, 1 /*left align*/, &last_string)) return ZINT_ERROR_MEMORY; + font_height, textwidth, 2 /*right align*/, &last_string)) return ZINT_ERROR_MEMORY; } } } else if (upceanflag == 8) { /* EAN-8 */ float text_xposn; if (upcean_guard_whitespace) { - text_xposn = -0.75f + xoffset_comp; + text_xposn = -7.0f - gws_left_fudge + xoffset_comp; textwidth = 8.5f; if (!vector_add_string(symbol, (const unsigned char *) "<", 1, text_xposn, text_yposn, - font_height, textwidth, 2 /*right align*/, &last_string)) return ZINT_ERROR_MEMORY; + font_height, textwidth, 1 /*left align*/, &last_string)) return ZINT_ERROR_MEMORY; } text_xposn = (17.0f + 0.5f) + xoffset_comp; textwidth = 4.0f * 8.5f; @@ -791,16 +794,16 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ if (!vector_add_string(symbol, addon, addon_len, text_xposn, addon_text_yposn, font_height, textwidth, 0 /*centre align*/, &last_string)) return ZINT_ERROR_MEMORY; if (upcean_guard_whitespace) { - text_xposn = (addon_len == 2 ? 86.0f : 113.0f) - 0.2f + xoffset_comp + addon_gap; + text_xposn = symbol->width + gws_right_fudge + qz_right + xoffset; textwidth = 8.5f; if (!vector_add_string(symbol, (const unsigned char *) ">", 1, text_xposn, addon_text_yposn, - font_height, textwidth, 1 /*left align*/, &last_string)) return ZINT_ERROR_MEMORY; + font_height, textwidth, 2 /*right align*/, &last_string)) return ZINT_ERROR_MEMORY; } } else if (upcean_guard_whitespace) { - text_xposn = (68.0f - 0.2f) + xoffset_comp; + text_xposn = symbol->width + gws_right_fudge + qz_right + xoffset; textwidth = 8.5f; if (!vector_add_string(symbol, (const unsigned char *) ">", 1, text_xposn, text_yposn, - font_height, textwidth, 1 /*left align*/, &last_string)) return ZINT_ERROR_MEMORY; + font_height, textwidth, 2 /*right align*/, &last_string)) return ZINT_ERROR_MEMORY; } } else if (upceanflag == 12) { /* UPC-A */ @@ -827,10 +830,10 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ if (!vector_add_string(symbol, addon, addon_len, text_xposn, addon_text_yposn, font_height, textwidth, 0 /*centre align*/, &last_string)) return ZINT_ERROR_MEMORY; if (upcean_guard_whitespace) { - text_xposn = (addon_len == 2 ? 114.0f : 141.0f) - 0.2f + xoffset_comp + addon_gap; + text_xposn = symbol->width + gws_right_fudge + qz_right + xoffset; textwidth = 8.5f; if (!vector_add_string(symbol, (const unsigned char *) ">", 1, text_xposn, addon_text_yposn, - font_height, textwidth, 1 /*left align*/, &last_string)) return ZINT_ERROR_MEMORY; + font_height, textwidth, 2 /*right align*/, &last_string)) return ZINT_ERROR_MEMORY; } } @@ -852,16 +855,16 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ if (!vector_add_string(symbol, addon, addon_len, text_xposn, addon_text_yposn, font_height, textwidth, 0 /*centre align*/, &last_string)) return ZINT_ERROR_MEMORY; if (upcean_guard_whitespace) { - text_xposn = (addon_len == 2 ? 114.0f : 141.0f) + xoffset_comp + addon_gap; + text_xposn = symbol->width + gws_right_fudge + qz_right + xoffset; textwidth = 8.5f; if (!vector_add_string(symbol, (const unsigned char *) ">", 1, text_xposn, addon_text_yposn, - font_height, textwidth, 1 /*left align*/, &last_string)) return ZINT_ERROR_MEMORY; + font_height, textwidth, 2 /*right align*/, &last_string)) return ZINT_ERROR_MEMORY; } } else if (upcean_guard_whitespace) { - text_xposn = 96.0f + xoffset_comp; + text_xposn = symbol->width + gws_right_fudge + qz_right + xoffset; textwidth = 8.5f; if (!vector_add_string(symbol, (const unsigned char *) ">", 1, text_xposn, text_yposn, - font_height, textwidth, 1 /*left align*/, &last_string)) return ZINT_ERROR_MEMORY; + font_height, textwidth, 2 /*right align*/, &last_string)) return ZINT_ERROR_MEMORY; } } @@ -881,10 +884,10 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ if (!vector_add_string(symbol, symbol->text, addon_len, text_xposn, text_yposn, font_height, textwidth, 0 /*centre align*/, &last_string)) return ZINT_ERROR_MEMORY; if (upcean_guard_whitespace) { - text_xposn = (addon_len == 2 ? 18.75f : 45.75f) + xoffset + addon_gap; + text_xposn = symbol->width + gws_right_fudge + qz_right + xoffset; textwidth = 8.5f; if (!vector_add_string(symbol, (const unsigned char *) ">", 1, text_xposn, text_yposn, - font_height, textwidth, 1 /*left align*/, &last_string)) return ZINT_ERROR_MEMORY; + font_height, textwidth, 2 /*right align*/, &last_string)) return ZINT_ERROR_MEMORY; } } else { @@ -892,8 +895,9 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ float text_xposn = main_width / 2.0f + xoffset_comp; float text_yposn = yoffset + symbol->height + font_height + text_gap; /* Calculated to bottom of text */ text_yposn -= symbol->output_options & SMALL_TEXT ? descent_small : descent; - if (symbol->border_width > 0 && (symbol->output_options & (BARCODE_BOX | BARCODE_BIND))) { - text_yposn += symbol->border_width; /* Note not needed for BARCODE_BIND_TOP */ + if (symbol->border_width > 0 && (symbol->output_options & (BARCODE_BOX | BARCODE_BIND)) + && !(symbol->output_options & BARCODE_BIND_TOP)) { /* Trumps BARCODE_BOX & BARCODE_BIND */ + text_yposn += symbol->border_width; } if (!vector_add_string(symbol, symbol->text, -1, text_xposn, text_yposn, font_height, symbol->width, 0, &last_string)) return ZINT_ERROR_MEMORY; diff --git a/docs/images/eanx8_gws.svg b/docs/images/eanx8_gws.svg index d78722d6..1b1b7da9 100644 --- a/docs/images/eanx8_gws.svg +++ b/docs/images/eanx8_gws.svg @@ -5,7 +5,7 @@ - + < @@ -14,7 +14,7 @@ 3654 - + > diff --git a/docs/images/isbnx_gws.svg b/docs/images/isbnx_gws.svg index 1419b358..cd5d3b38 100644 --- a/docs/images/isbnx_gws.svg +++ b/docs/images/isbnx_gws.svg @@ -14,7 +14,7 @@ 055124 - + > diff --git a/docs/images/upca_5_gws.svg b/docs/images/upca_5_gws.svg index bd183bb6..7faa2e67 100644 --- a/docs/images/upca_5_gws.svg +++ b/docs/images/upca_5_gws.svg @@ -20,7 +20,7 @@ 12345 - + > diff --git a/docs/images/upce_2_gws.svg b/docs/images/upce_2_gws.svg index fa6a12c5..025ce734 100644 --- a/docs/images/upce_2_gws.svg +++ b/docs/images/upce_2_gws.svg @@ -17,7 +17,7 @@ 12 - + >