From 1be3ac4d5a1d0fc7d92fb30bd6ee436dabf8a08d Mon Sep 17 00:00:00 2001 From: Jojakim Stahl Date: Wed, 18 Oct 2017 09:24:27 +0200 Subject: [PATCH 1/7] Added a editorconfig file --- .editorconfig | 6 ++++++ win32/zint.sln | 5 +++++ 2 files changed, 11 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..de0f8a9e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,6 @@ +root=true + +[*] +end_of_line = crlf +indent_style = space +indent_size = 4 diff --git a/win32/zint.sln b/win32/zint.sln index 3a1de5d6..f82500be 100644 --- a/win32/zint.sln +++ b/win32/zint.sln @@ -7,6 +7,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zint", "zint.vcxproj", "{31 EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libzint", "libzint.vcxproj", "{5C08DC40-8F7D-475E-AA3C-814DED735A4B}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C246B2E9-C3A0-4505-BECA-1FDFC59C7BE5}" + ProjectSection(SolutionItems) = preProject + ..\.editorconfig = ..\.editorconfig + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 From c7d6256a6e32afef5954dceba11917cee62f6e0d Mon Sep 17 00:00:00 2001 From: Jojakim Stahl Date: Mon, 16 Oct 2017 09:49:44 +0200 Subject: [PATCH 2/7] Free symbol->rendered structures on ZBarcode_Clear and repeated calls of ZBarcode_Render --- backend/library.c | 46 ++++++------------------------------------ backend/render.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 40 deletions(-) diff --git a/backend/library.c b/backend/library.c index 02ebfbc2..6d77bb0f 100644 --- a/backend/library.c +++ b/backend/library.c @@ -76,6 +76,8 @@ struct zint_symbol *ZBarcode_Create() { return symbol; } +extern void render_free(struct zint_symbol *symbol); /* Free render structures */ + void ZBarcode_Clear(struct zint_symbol *symbol) { int i, j; @@ -94,6 +96,9 @@ void ZBarcode_Clear(struct zint_symbol *symbol) { } symbol->bitmap_width = 0; symbol->bitmap_height = 0; + + // If there is a rendered version, ensure its memory is released + render_free(symbol); } void ZBarcode_Delete(struct zint_symbol *symbol) { @@ -101,47 +106,8 @@ void ZBarcode_Delete(struct zint_symbol *symbol) { free(symbol->bitmap); // If there is a rendered version, ensure its memory is released - if (symbol->rendered != NULL) { - struct zint_render_line *line; - struct zint_render_string *string; - struct zint_render_ring *ring; - struct zint_render_hexagon *hexagon; + render_free(symbol); - // Free lines - line = symbol->rendered->lines; - while (line) { - struct zint_render_line *l = line; - line = line->next; - free(l); - } - // Free Strings - string = symbol->rendered->strings; - while (string) { - struct zint_render_string *s = string; - string = string->next; - free(s->text); - free(s); - } - - // Free Rings - ring = symbol->rendered->rings; - while (ring) { - struct zint_render_ring *r = ring; - ring = ring->next; - free(r); - } - - // Free Hexagons - hexagon = symbol->rendered->hexagons; - while (hexagon) { - struct zint_render_hexagon *h = hexagon; - hexagon = hexagon->next; - free(h); - } - - // Free Render - free(symbol->rendered); - } free(symbol); } diff --git a/backend/render.c b/backend/render.c index c0ebec7c..9e7a951f 100644 --- a/backend/render.c +++ b/backend/render.c @@ -55,6 +55,7 @@ struct zint_render_hexagon *render_plot_create_hexagon(float x, float y); int render_plot_add_hexagon(struct zint_symbol *symbol, struct zint_render_hexagon *hexagon, struct zint_render_hexagon **last_hexagon); int render_plot_add_string(struct zint_symbol *symbol, unsigned char *text, float x, float y, float fsize, float width, struct zint_render_string **last_string); +void render_free(struct zint_symbol *symbol); int render_plot(struct zint_symbol *symbol, const float width, const float height) { struct zint_render *render; @@ -78,6 +79,8 @@ int render_plot(struct zint_symbol *symbol, const float width, const float heigh float x_dimension; int upceanflag = 0; + // Free any previous rendering structures + render_free(symbol); // Allocate memory for the rendered version render = symbol->rendered = (struct zint_render *) malloc(sizeof (struct zint_render)); if (!symbol->rendered) return ZINT_ERROR_MEMORY; @@ -778,3 +781,51 @@ int render_plot_add_string(struct zint_symbol *symbol, return 1; } + +/* + * Free the data structures created by render_plot + */ +void render_free(struct zint_symbol *symbol) { + if (symbol->rendered != NULL) { + struct zint_render_line *line; + struct zint_render_string *string; + struct zint_render_ring *ring; + struct zint_render_hexagon *hexagon; + + // Free lines + line = symbol->rendered->lines; + while (line) { + struct zint_render_line *l = line; + line = line->next; + free(l); + } + // Free Strings + string = symbol->rendered->strings; + while (string) { + struct zint_render_string *s = string; + string = string->next; + free(s->text); + free(s); + } + + // Free Rings + ring = symbol->rendered->rings; + while (ring) { + struct zint_render_ring *r = ring; + ring = ring->next; + free(r); + } + + // Free Hexagons + hexagon = symbol->rendered->hexagons; + while (hexagon) { + struct zint_render_hexagon *h = hexagon; + hexagon = hexagon->next; + free(h); + } + + // Free Render + free(symbol->rendered); + symbol->rendered = NULL; + } +} From 0a913ad9e3182d56d41308f86ce4b120c3706af6 Mon Sep 17 00:00:00 2001 From: Jojakim Stahl Date: Mon, 16 Oct 2017 10:01:09 +0200 Subject: [PATCH 3/7] Adding hexagon height to zint_render_hexagon --- backend/render.c | 7 ++++--- backend/zint.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/backend/render.c b/backend/render.c index 9e7a951f..a3a5ea3c 100644 --- a/backend/render.c +++ b/backend/render.c @@ -51,7 +51,7 @@ struct zint_render_line *render_plot_create_line(float x, float y, float width, int render_plot_add_line(struct zint_symbol *symbol, struct zint_render_line *line, struct zint_render_line **last_line); struct zint_render_ring *render_plot_create_ring(float x, float y, float radius, float line_width); int render_plot_add_ring(struct zint_symbol *symbol, struct zint_render_ring *ring, struct zint_render_ring **last_ring); -struct zint_render_hexagon *render_plot_create_hexagon(float x, float y); +struct zint_render_hexagon *render_plot_create_hexagon(float x, float y, float height); int render_plot_add_hexagon(struct zint_symbol *symbol, struct zint_render_hexagon *hexagon, struct zint_render_hexagon **last_hexagon); int render_plot_add_string(struct zint_symbol *symbol, unsigned char *text, float x, float y, float fsize, float width, struct zint_render_string **last_string); @@ -351,7 +351,7 @@ int render_plot(struct zint_symbol *symbol, const float width, const float heigh for (r = 0; r < symbol->rows; r++) { for (i = 0; i < symbol->width; i++) { if (module_is_set(symbol, r, i)) { - struct zint_render_hexagon *hexagon = render_plot_create_hexagon(((i * 0.88) + ((r & 1) ? 1.76 : 1.32)) * scaler, ((r * 0.76) + 0.76) * scaler); + struct zint_render_hexagon *hexagon = render_plot_create_hexagon(((i * 0.88) + ((r & 1) ? 1.76 : 1.32)) * scaler, ((r * 0.76) + 0.76) * scaler, 1. * scaler); render_plot_add_hexagon(symbol, hexagon, &last_hexagon); } } @@ -731,7 +731,7 @@ int render_plot_add_ring(struct zint_symbol *symbol, struct zint_render_ring *ri return 1; } -struct zint_render_hexagon *render_plot_create_hexagon(float x, float y) { +struct zint_render_hexagon *render_plot_create_hexagon(float x, float y, float height) { struct zint_render_hexagon *hexagon; hexagon = (struct zint_render_hexagon*) malloc(sizeof (struct zint_render_hexagon)); @@ -739,6 +739,7 @@ struct zint_render_hexagon *render_plot_create_hexagon(float x, float y) { hexagon->next = NULL; hexagon->x = x; hexagon->y = y; + hexagon->height = height; return hexagon; } diff --git a/backend/zint.h b/backend/zint.h index 534575c1..4f46c5af 100644 --- a/backend/zint.h +++ b/backend/zint.h @@ -55,7 +55,7 @@ extern "C" { }; struct zint_render_hexagon { - float x, y; + float x, y, height; struct zint_render_hexagon *next; /* Pointer to next hexagon */ }; From 6b1421b895c5dc0c037b0fefad55c26834523421 Mon Sep 17 00:00:00 2001 From: Jojakim Stahl Date: Mon, 16 Oct 2017 10:10:08 +0200 Subject: [PATCH 4/7] Fixed general_rules declaration in composite.c after refactor in commit [4963a7] --- backend/composite.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/composite.c b/backend/composite.c index 5486f69f..d55eaa94 100644 --- a/backend/composite.c +++ b/backend/composite.c @@ -65,7 +65,7 @@ #define UINT unsigned short -extern int general_rules(char field[], char type[]); +extern int general_rules(char type[]); extern int eanx(struct zint_symbol *symbol, unsigned char source[], int length); extern int ean_128(struct zint_symbol *symbol, unsigned char source[], const size_t length); extern int rss14(struct zint_symbol *symbol, unsigned char source[], int length); @@ -1381,7 +1381,7 @@ static int cc_binary_string(struct zint_symbol *symbol, const char source[], cha } } - latch = general_rules(general_field, general_field_type); + latch = general_rules(general_field_type); i = 0; do { From 3bbc188217bb33cabf217c6affe1025c529a66d5 Mon Sep 17 00:00:00 2001 From: Jojakim Stahl Date: Wed, 18 Oct 2017 09:25:09 +0200 Subject: [PATCH 5/7] Fixed bug introduced in bfb183e5df53a2a7c3d0fa9afd75924710003e17 with utf8 input be trucated at length - 3 --- backend/library.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/library.c b/backend/library.c index 6d77bb0f..a0967dad 100644 --- a/backend/library.c +++ b/backend/library.c @@ -787,9 +787,9 @@ void strip_bom(unsigned char *source, int *input_length) { for (i = 3; i < *input_length; i++) { source[i - 3] = source[i]; } + *input_length -= 3; } } - *input_length -= 3; } int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source,int in_length) { From 2b79940d339a8686815f8a6d15929d40d7ba57b4 Mon Sep 17 00:00:00 2001 From: Jojakim Stahl Date: Wed, 18 Oct 2017 10:19:37 +0200 Subject: [PATCH 6/7] Fixed rendered->height calculation for EAN like barcodes --- backend/render.c | 61 +++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/backend/render.c b/backend/render.c index a3a5ea3c..a1cb0c9f 100644 --- a/backend/render.c +++ b/backend/render.c @@ -119,14 +119,6 @@ int render_plot(struct zint_symbol *symbol, const float width, const float heigh } addon[r] = '\0'; - if ((!symbol->show_hrt) || (ustrlen(symbol->text) == 0)) { - hide_text = 1; - text_height = text_offset = 0.0; - } else { - text_height = 9.0; - text_offset = 2.0; - } - /* * Calculate the width of the barcode, especially if there are any extra @@ -210,6 +202,17 @@ int render_plot(struct zint_symbol *symbol, const float width, const float heigh } } + if ((!symbol->show_hrt) || (ustrlen(symbol->text) == 0)) { + hide_text = 1; + text_height = text_offset = 0.0; + } + else { + text_height = upceanflag ? 11.0 : 9.0; + text_offset = 2.0; + } + if (symbol->output_options & SMALL_TEXT) + text_height *= 0.8; + total_symbol_width_x = 0.0 + main_symbol_width_x + addon_width_x; total_area_width_x = total_symbol_width_x + (2 * (symbol->border_width + symbol->whitespace_width)); @@ -447,24 +450,24 @@ int render_plot(struct zint_symbol *symbol, const float width, const float heigh textpart[4] = '\0'; textpos = 17; textwidth = 4.0 * 8.5; - render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn, 11.0 * scaler, textwidth * scaler, &last_string); + render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn, text_height * scaler, textwidth * scaler, &last_string); for (i = 0; i < 4; i++) { textpart[i] = symbol->text[i + 4]; } textpart[4] = '\0'; textpos = 50; - render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn, 11.0 * scaler, textwidth * scaler, &last_string); + render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn, text_height * scaler, textwidth * scaler, &last_string); textdone = 1; switch (strlen(addon)) { case 2: textpos = xoffset + 86; textwidth = 2.0 * 8.5; - render_plot_add_string(symbol, (unsigned char *) addon, textpos * scaler, addon_text_posn * scaler, 11.0 * scaler, textwidth * scaler, &last_string); + render_plot_add_string(symbol, (unsigned char *) addon, textpos * scaler, addon_text_posn * scaler, text_height * scaler, textwidth * scaler, &last_string); break; case 5: textpos = xoffset + 100; textwidth = 5.0 * 8.5; - render_plot_add_string(symbol, (unsigned char *) addon, textpos * scaler, addon_text_posn * scaler, 11.0 * scaler, textwidth * scaler, &last_string); + render_plot_add_string(symbol, (unsigned char *) addon, textpos * scaler, addon_text_posn * scaler, text_height * scaler, textwidth * scaler, &last_string); break; } @@ -491,7 +494,7 @@ int render_plot(struct zint_symbol *symbol, const float width, const float heigh textpart[1] = '\0'; textpos = -5; // 7 textwidth = 8.5; - render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn, 11.0 * scaler, textwidth * scaler, &last_string); + render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn, text_height * scaler, textwidth * scaler, &last_string); for (i = 0; i < 6; i++) { textpart[i] = symbol->text[i + 1]; @@ -499,24 +502,24 @@ int render_plot(struct zint_symbol *symbol, const float width, const float heigh textpart[6] = '\0'; textpos = 25; textwidth = 6.0 * 8.5; - render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn, 11.0 * scaler, textwidth * scaler, &last_string); + render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn, text_height * scaler, textwidth * scaler, &last_string); for (i = 0; i < 6; i++) { textpart[i] = symbol->text[i + 7]; } textpart[6] = '\0'; textpos = 72; - render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn, 11.0 * scaler, textwidth * scaler, &last_string); + render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn, text_height * scaler, textwidth * scaler, &last_string); textdone = 1; switch (strlen(addon)) { case 2: textpos = xoffset + 114; textwidth = 2.0 * 8.5; - render_plot_add_string(symbol, (unsigned char *) addon, textpos * scaler, addon_text_posn * scaler, 11.0 * scaler, textwidth * scaler, &last_string); + render_plot_add_string(symbol, (unsigned char *) addon, textpos * scaler, addon_text_posn * scaler, text_height * scaler, textwidth * scaler, &last_string); break; case 5: textpos = xoffset + 128; textwidth = 5.0 * 8.5; - render_plot_add_string(symbol, (unsigned char *) addon, textpos * scaler, addon_text_posn * scaler, 11.0 * scaler, textwidth * scaler, &last_string); + render_plot_add_string(symbol, (unsigned char *) addon, textpos * scaler, addon_text_posn * scaler, text_height * scaler, textwidth * scaler, &last_string); break; } } @@ -546,35 +549,35 @@ int render_plot(struct zint_symbol *symbol, const float width, const float heigh textpart[1] = '\0'; textpos = -5; textwidth = 6.2; - render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn + (2.0 * scaler), 8.0 * scaler, textwidth * scaler, &last_string); + render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn + (2.0 * scaler), text_height * (8.0 / 11.0) * scaler, textwidth * scaler, &last_string); for (i = 0; i < 5; i++) { textpart[i] = symbol->text[i + 1]; } textpart[5] = '\0'; textpos = 27; textwidth = 5.0 * 8.5; - render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn, 11.0 * scaler, textwidth * scaler, &last_string); + render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn, text_height * scaler, textwidth * scaler, &last_string); for (i = 0; i < 5; i++) { textpart[i] = symbol->text[i + 6]; } textpos = 68; - render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn, 11.0 * scaler, textwidth * scaler, &last_string); + render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn, text_height * scaler, textwidth * scaler, &last_string); textpart[0] = symbol->text[11]; textpart[1] = '\0'; textpos = 100; textwidth = 6.2; - render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn + (2.0 * scaler), 8.0 * scaler, textwidth * scaler, &last_string); + render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn + (2.0 * scaler), text_height * (8.0 / 11.0) * scaler, textwidth * scaler, &last_string); textdone = 1; switch (strlen(addon)) { case 2: textpos = xoffset + 116; textwidth = 2.0 * 8.5; - render_plot_add_string(symbol, (unsigned char *) addon, textpos * scaler, addon_text_posn * scaler, 11.0 * scaler, textwidth * scaler, &last_string); + render_plot_add_string(symbol, (unsigned char *) addon, textpos * scaler, addon_text_posn * scaler, text_height * scaler, textwidth * scaler, &last_string); break; case 5: textpos = xoffset + 130; textwidth = 5.0 * 8.5; - render_plot_add_string(symbol, (unsigned char *) addon, textpos * scaler, addon_text_posn * scaler, 11.0 * scaler, textwidth * scaler, &last_string); + render_plot_add_string(symbol, (unsigned char *) addon, textpos * scaler, addon_text_posn * scaler, text_height * scaler, textwidth * scaler, &last_string); break; } } @@ -599,30 +602,30 @@ int render_plot(struct zint_symbol *symbol, const float width, const float heigh textpart[1] = '\0'; textpos = -5; textwidth = 6.2; - render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn + (2.0 * scaler), 8.0 * scaler, textwidth * scaler, &last_string); + render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn + (2.0 * scaler), text_height * (8.0 / 11.0) * scaler, textwidth * scaler, &last_string); for (i = 0; i < 6; i++) { textpart[i] = symbol->text[i + 1]; } textpart[6] = '\0'; textpos = 24; textwidth = 6.0 * 8.5; - render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn, 11.0 * scaler, textwidth * scaler, &last_string); + render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn, text_height * scaler, textwidth * scaler, &last_string); textpart[0] = symbol->text[7]; textpart[1] = '\0'; textpos = 55; textwidth = 6.2; - render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn + (2.0 * scaler), 8.0 * scaler, textwidth * scaler, &last_string); + render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn + (2.0 * scaler), text_height * (8.0 / 11.0) * scaler, textwidth * scaler, &last_string); textdone = 1; switch (strlen(addon)) { case 2: textpos = xoffset + 70; textwidth = 2.0 * 8.5; - render_plot_add_string(symbol, (unsigned char *) addon, textpos * scaler, addon_text_posn * scaler, 11.0 * scaler, textwidth * scaler, &last_string); + render_plot_add_string(symbol, (unsigned char *) addon, textpos * scaler, addon_text_posn * scaler, text_height * scaler, textwidth * scaler, &last_string); break; case 5: textpos = xoffset + 84; textwidth = 5.0 * 8.5; - render_plot_add_string(symbol, (unsigned char *) addon, textpos * scaler, addon_text_posn * scaler, 11.0 * scaler, textwidth * scaler, &last_string); + render_plot_add_string(symbol, (unsigned char *) addon, textpos * scaler, addon_text_posn * scaler, text_height * scaler, textwidth * scaler, &last_string); break; } } @@ -630,7 +633,7 @@ int render_plot(struct zint_symbol *symbol, const float width, const float heigh /* Put normal human readable text at the bottom (and centered) */ if (textdone == 0) { // caculate start xoffset to center text - render_plot_add_string(symbol, symbol->text, ((symbol->width / 2.0) + xoffset) * scaler, default_text_posn, 9.0 * scaler, 0.0, &last_string); + render_plot_add_string(symbol, symbol->text, ((symbol->width / 2.0) + xoffset) * scaler, default_text_posn, text_height * scaler, symbol->width * scaler, &last_string); } } From aa64c5578702c0366d3cdc2a6650ce68f8db4f4e Mon Sep 17 00:00:00 2001 From: Jojakim Stahl Date: Wed, 18 Oct 2017 11:09:29 +0200 Subject: [PATCH 7/7] Height / width adjustment for certain symbologies with fixed requirements must be done before calculating the scaler --- backend/render.c | 165 +++++++++++++++++++++++++---------------------- 1 file changed, 89 insertions(+), 76 deletions(-) diff --git a/backend/render.c b/backend/render.c index a1cb0c9f..70d30154 100644 --- a/backend/render.c +++ b/backend/render.c @@ -57,7 +57,7 @@ int render_plot_add_hexagon(struct zint_symbol *symbol, struct zint_render_hexag int render_plot_add_string(struct zint_symbol *symbol, unsigned char *text, float x, float y, float fsize, float width, struct zint_render_string **last_string); void render_free(struct zint_symbol *symbol); -int render_plot(struct zint_symbol *symbol, const float width, const float height) { +int render_plot(struct zint_symbol *symbol, float width, float height) { struct zint_render *render; struct zint_render_line *line, *last_line = NULL; struct zint_render_string *last_string = NULL; @@ -219,6 +219,7 @@ int render_plot(struct zint_symbol *symbol, const float width, const float heigh xoffset = symbol->border_width + symbol->whitespace_width; yoffset = symbol->border_width; + // Determine if height should be overridden large_bar_count = 0; preset_height = 0.0; @@ -229,6 +230,93 @@ int render_plot(struct zint_symbol *symbol, const float width, const float heigh } } + + /* Set minimum size of symbol */ + /* Barcode must be at least 2mm high by 2mm across */ + if (width < (2.0 * GL_CONST)) { + width = (2.0 * GL_CONST); + } + x_dimension = width / total_area_width_x / GL_CONST; + if (height < ((x_dimension * ((2 * symbol->border_width) + text_offset + text_height)) + 2.0) * GL_CONST) { + height = ((x_dimension * ((2 * symbol->border_width) + text_offset + text_height)) + 2.0) * GL_CONST; + } + + if (symbol->symbology == BARCODE_CODABAR) { + /* The minimum X-dimension of Codabar is 0.191mm. The minimum bar height is 5mm */ + if (x_dimension < 0.191) { + x_dimension = 0.191; + width = 0.191 * GL_CONST * total_area_width_x; + } + if (height < ((x_dimension * ((2 * symbol->border_width) + text_offset + text_height)) + 5.0) * GL_CONST) { + height = ((x_dimension * ((2 * symbol->border_width) + text_offset + text_height)) + 5.0) * GL_CONST; + } + } + else if (symbol->symbology == BARCODE_CODE49) { + /* The minimum X-dimension of Code 49 is 0.191mm */ + if (x_dimension < 0.191) { + x_dimension = 0.191; + width = 0.191 * GL_CONST * total_area_width_x; + float encoded_symbol_aspect = total_area_width_x; + encoded_symbol_aspect /= (preset_height + (2 * yoffset) + text_offset + text_height); + height = width / encoded_symbol_aspect; + } + } + + if (upceanflag != 0) { + /* The X-dimension of UPC/EAN symbols is fixed at 0.330mm */ + /* The phrase before is questionable. It may scale in certain percentages (80% - 200%). + see https://internationalbarcodes.com/ean-13-specifications/ */ + /* NOTE: This code will need adjustment before it correctly deals with composite symbols */ + x_dimension = 0.330; + width = 0.330 * GL_CONST * total_area_width_x; + /* The height is also fixed */ + switch (upceanflag) { + case 6: + case 12: + case 13: + /* UPC-A, UPC-E and EAN-13 */ + /* Height of bars should be 22.85mm */ + height = ((0.330 * ((2 * symbol->border_width) + text_offset + text_height)) + 22.85) * GL_CONST; + break; + case 8: + /* EAN-8 */ + /* Height of bars should be 18.23mm */ + height = ((0.330 * ((2 * symbol->border_width) + text_offset + text_height)) + 18.23) * GL_CONST; + break; + default: + /* EAN-2 and EAN-5 */ + /* Height of bars should be 21.10mm */ + height = ((0.330 * ((2 * symbol->border_width) + text_offset + text_height)) + 21.10) * GL_CONST; + } + } + + if (symbol->symbology == BARCODE_ONECODE) { + /* The size of USPS Intelligent Mail barcode is fixed */ + x_dimension = 0.508; + width = 0.508 * GL_CONST * total_area_width_x; + height = 4.064 * GL_CONST; + } + else if ((symbol->symbology == BARCODE_POSTNET) || (symbol->symbology == BARCODE_PLANET)) { + /* The size of PostNet and PLANET are fized */ + x_dimension = 0.508; + width = 0.508 * GL_CONST * total_area_width_x; + height = 2.921 * GL_CONST; + } + else if (((symbol->symbology == BARCODE_AUSPOST) || (symbol->symbology == BARCODE_AUSREPLY)) || + ((symbol->symbology == BARCODE_AUSROUTE) || (symbol->symbology == BARCODE_AUSREDIRECT))) { + /* Australia Post use the same sizes as USPS */ + x_dimension = 0.508; + width = 0.508 * GL_CONST * total_area_width_x; + height = 4.064 * GL_CONST; + } + else if ((symbol->symbology == BARCODE_RM4SCC) || (symbol->symbology == BARCODE_KIX)) { + /* Royal Mail and KIX Code uses 22 bars per inch */ + x_dimension = 0.577; + width = 0.577 * GL_CONST * total_area_width_x; + height = 5.22 * GL_CONST; + } + + if (large_bar_count == 0) { float required_aspect = width / height; symbol_aspect = (total_symbol_width_x + (2 * xoffset)) / (preset_height + (2 * yoffset) + text_offset + text_height); @@ -259,81 +347,6 @@ int render_plot(struct zint_symbol *symbol, const float width, const float heigh default_text_posn = (symbol->height + text_offset + symbol->border_width) * scaler; } - x_dimension = render->width / total_area_width_x; - x_dimension /= GL_CONST; - - /* Set minimum size of symbol */ - /* Barcode must be at least 2mm high by 2mm across */ - if (render->height < ((x_dimension * ((2 * symbol->border_width) + text_offset + text_height)) + 2.0) * GL_CONST) { - render->height = ((x_dimension * ((2 * symbol->border_width) + text_offset + text_height)) + 2.0) * GL_CONST; - } - if (render->width < (2.0 * GL_CONST)) { - render->width = (2.0 * GL_CONST); - } - - if (symbol->symbology == BARCODE_CODABAR) { - /* The minimum X-dimension of Codabar is 0.191mm. The minimum bar height is 5mm */ - if (x_dimension < 0.191) { - render->width = 0.191 * GL_CONST * total_area_width_x; - } - if (render->height < ((x_dimension * ((2 * symbol->border_width) + text_offset + text_height)) + 5.0) * GL_CONST) { - render->height = ((x_dimension * ((2 * symbol->border_width) + text_offset + text_height)) + 5.0) * GL_CONST; - } - } - else if (symbol->symbology == BARCODE_CODE49) { - /* The minimum X-dimension of Code 49 is 0.191mm */ - if (x_dimension < 0.191) { - render->width = 0.191 * GL_CONST * total_area_width_x; - render->height = render->width / symbol_aspect; - } - } - - if (upceanflag != 0) { - /* The X-dimension of UPC/EAN symbols is fixed at 0.330mm */ - /* NOTE: This code will need adjustment before it correctly deals with composite symbols */ - render->width = 0.330 * GL_CONST * total_area_width_x; - /* The height is also fixed */ - switch (upceanflag) { - case 6: - case 12: - case 13: - /* UPC-A, UPC-E and EAN-13 */ - /* Height of bars should be 22.85mm */ - render->height = ((0.330 * ((2 * symbol->border_width) + text_offset + text_height)) + 22.85) * GL_CONST; - break; - case 8: - /* EAN-8 */ - /* Height of bars should be 18.23mm */ - render->height = ((0.330 * ((2 * symbol->border_width) + text_offset + text_height)) + 18.23) * GL_CONST; - break; - default: - /* EAN-2 and EAN-5 */ - /* Height of bars should be 21.10mm */ - render->height = ((0.330 * ((2 * symbol->border_width) + text_offset + text_height)) + 21.10) * GL_CONST; - } - } - - if (symbol->symbology == BARCODE_ONECODE) { - /* The size of USPS Intelligent Mail barcode is fixed */ - render->width = 0.508 * GL_CONST * total_area_width_x; - render->height = 4.064 * GL_CONST; - } - else if ((symbol->symbology == BARCODE_POSTNET) || (symbol->symbology == BARCODE_PLANET)) { - /* The size of PostNet and PLANET are fized */ - render->width = 0.508 * GL_CONST * total_area_width_x; - render->height = 2.921 * GL_CONST; - } - else if (((symbol->symbology == BARCODE_AUSPOST) || (symbol->symbology == BARCODE_AUSREPLY)) || - ((symbol->symbology == BARCODE_AUSROUTE) || (symbol->symbology == BARCODE_AUSREDIRECT))) { - /* Australia Post use the same sizes as USPS */ - render->width = 0.508 * GL_CONST * total_area_width_x; - render->height = 4.064 * GL_CONST; - } - else if ((symbol->symbology == BARCODE_RM4SCC) || (symbol->symbology == BARCODE_KIX)) { - /* Royal Mail and KIX Code uses 22 bars per inch */ - render->width = 0.577 * GL_CONST * total_area_width_x; - render->height = 5.22 * GL_CONST; - } if (symbol->symbology == BARCODE_MAXICODE) { struct zint_render_ring *ring;