diff --git a/backend/render.c b/backend/render.c index edcfcccf..20d70164 100644 --- a/backend/render.c +++ b/backend/render.c @@ -51,7 +51,7 @@ int render_plot(struct zint_symbol *symbol, unsigned int hide_text, float width, float addon_text_posn; float default_text_posn; float scaler = symbol->scale; - float w, h; + float w, h; const char *locale = NULL; // Allocate memory for the rendered version @@ -140,25 +140,23 @@ int render_plot(struct zint_symbol *symbol, unsigned int hide_text, float width, xoffset = symbol->border_width + symbol->whitespace_width; - // Calculate the initial scale factor if width provided - w = main_width + (xoffset * 2); - if (width) { - scaler = width / w; - } + // Calculate the initial scale factor if width provided + w = main_width + (xoffset * 2); + if (width) { + scaler = width / w; + } - /* - * Calculate the height - */ - if (height) { - symbol->height = height / scaler; // starting height - } else if (symbol->height == 0) { + // Calculate the height + if (height) { + symbol->height = height / scaler; // starting height + } else if (symbol->height == 0) { symbol->height = 50; - } + } // Update height for texts symbol->height -= textheight + textoffset; - // Determine if height should be overridden + // Determine if height should be overridden large_bar_count = 0; preset_height = 0.0; for(i = 0; i < symbol->rows; i++) { @@ -174,15 +172,15 @@ int render_plot(struct zint_symbol *symbol, unsigned int hide_text, float width, } yoffset = symbol->border_width; - // Calculate the scale factor from the height, incase it needs to be lowered for width + // Calculate the scale factor from the height, incase it needs to be lowered for width h = (symbol->height + textheight + textoffset + (yoffset * 2)); - if ((h * scaler) > height) { - scaler = height / h; - } + if ((h * scaler) > height) { + scaler = height / h; + } - // Set initial render dimensions - render->width = w * scaler; - render->height = h * scaler; + // Set initial render dimensions + render->width = w * scaler; + render->height = h * scaler; if(((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) { @@ -295,7 +293,7 @@ int render_plot(struct zint_symbol *symbol, unsigned int hide_text, float width, } textpart[4] = '\0'; textpos = 17; - textwidth = 28.0; + textwidth = 28.0; render_plot_add_string(symbol, textpart, (textpos + xoffset) * scaler, default_text_posn, 9.0 * scaler, textwidth * scaler, &last_string); for(i = 0; i < 4; i++) { textpart[i] = symbol->text[i + 4]; @@ -307,12 +305,12 @@ int render_plot(struct zint_symbol *symbol, unsigned int hide_text, float width, switch(strlen(addon)) { case 2: textpos = xoffset + 86; - textwidth = 2.0 * 7.0; + textwidth = 2.0 * 7.0; render_plot_add_string(symbol, addon, textpos * scaler, addon_text_posn * scaler, 9.0 * scaler, textwidth * scaler, &last_string); break; case 5: textpos = xoffset + 100; - textwidth = 5.0 * 7.0; + textwidth = 5.0 * 7.0; render_plot_add_string(symbol, addon, textpos * scaler, addon_text_posn * scaler, 9.0 * scaler, textwidth * scaler, &last_string); break; } @@ -337,7 +335,7 @@ int render_plot(struct zint_symbol *symbol, unsigned int hide_text, float width, textpart[0] = symbol->text[0]; textpart[1] = '\0'; textpos = -5; // 7 - textwidth = 7.0; + textwidth = 7.0; render_plot_add_string(symbol, textpart, (textpos + xoffset) * scaler, default_text_posn, 9.0 * scaler, textwidth * scaler, &last_string); for(i = 0; i < 6; i++) { @@ -345,7 +343,7 @@ int render_plot(struct zint_symbol *symbol, unsigned int hide_text, float width, } textpart[6] = '\0'; textpos = 25; - textwidth = 6.0 * 7.0; + textwidth = 6.0 * 7.0; render_plot_add_string(symbol, textpart, (textpos + xoffset) * scaler, default_text_posn, 9.0 * scaler, textwidth * scaler, &last_string); for(i = 0; i < 6; i++) { textpart[i] = symbol->text[i + 7]; @@ -357,23 +355,103 @@ int render_plot(struct zint_symbol *symbol, unsigned int hide_text, float width, switch(strlen(addon)) { case 2: textpos = xoffset + 114; - textwidth = 2.0 * 7.0; + textwidth = 2.0 * 7.0; render_plot_add_string(symbol, addon, textpos * scaler, addon_text_posn * scaler, 9.0 * scaler, textwidth * scaler, &last_string); break; case 5: textpos = xoffset + 128; - textwidth = 5.0 * 7.0; + textwidth = 5.0 * 7.0; render_plot_add_string(symbol, addon, textpos * scaler, addon_text_posn * scaler, 9.0 * scaler, textwidth * scaler, &last_string); break; } break; } } + + if (((symbol->symbology == BARCODE_UPCA) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCA_CC)) { + /* guard bar extensions and text formatting for UPCA */ + latch = 1; + + i = 0 + comp_offset; + do { + block_width = 0; + do { + block_width++; + } while (module_is_set(symbol, symbol->rows - 1, i + block_width) == module_is_set(symbol, symbol->rows - 1, i)); + if(latch == 1) { + /* a bar */ + line = render_plot_create_line((i + xoffset - comp_offset) * scaler, row_posn, block_width * scaler, 5.0 * scaler); + render_plot_add_line(symbol, line, &last_line); + latch = 0; + } else { + /* a space */ + latch = 1; + } + i += block_width; + } while (i < 11 + comp_offset); + line = render_plot_create_line((46 + xoffset) * scaler, row_posn, scaler, 5.0 * scaler); + render_plot_add_line(symbol, line, &last_line); + line = render_plot_create_line((48 + xoffset) * scaler, row_posn, scaler, 5.0 * scaler); + render_plot_add_line(symbol, line, &last_line); + latch = 1; + i = 85 + comp_offset; + do { + block_width = 0; + do { + block_width++; + } while (module_is_set(symbol, symbol->rows - 1, i + block_width) == module_is_set(symbol, symbol->rows - 1, i)); + if(latch == 1) { + /* a bar */ + line = render_plot_create_line((i + xoffset - comp_offset) * scaler, row_posn, block_width * scaler, 5.0 * scaler); + render_plot_add_line(symbol, line, &last_line); + latch = 0; + } else { + /* a space */ + latch = 1; + } + i += block_width; + } while (i < 96 + comp_offset); + textpart[0] = symbol->text[0]; + textpart[1] = '\0'; + textpos = -5; + textwidth = 7.0; + render_plot_add_string(symbol, textpart, (textpos + xoffset) * scaler, default_text_posn, 9.0 * scaler, textwidth * scaler, &last_string); + for(i = 0; i < 5; i++) { + textpart[i] = symbol->text[i + 1]; + } + textpart[5] = '\0'; + textpos = 27; + textwidth = 4.0 * 7.0; + render_plot_add_string(symbol, textpart, (textpos + xoffset) * scaler, default_text_posn, 9.0 * scaler, textwidth * scaler, &last_string); + for(i = 0; i < 5; i++) { + textpart[i] = symbol->text[i + 6]; + } + textpos = 68; + render_plot_add_string(symbol, textpart, (textpos + xoffset) * scaler, default_text_posn, 9.0 * scaler, textwidth * scaler, &last_string); + textpart[0] = symbol->text[11]; + textpart[1] = '\0'; + textpos = 100; + textwidth = 7.0; + render_plot_add_string(symbol, textpart, (textpos + xoffset) * scaler, default_text_posn, 9.0 * scaler, textwidth * scaler, &last_string); + textdone = 1; + switch(strlen(addon)) { + case 2: + textpos = xoffset + 116; + textwidth = 2.0 * 7.0; + render_plot_add_string(symbol, textpart, (textpos + xoffset) * scaler, default_text_posn, 9.0 * scaler, textwidth * scaler, &last_string); + break; + case 5: + textpos = xoffset + 130; + textwidth = 5.0 * 7.0; + render_plot_add_string(symbol, textpart, (textpos + xoffset) * scaler, default_text_posn, 9.0 * scaler, textwidth * scaler, &last_string); + break; + } + } /* Put normal human readable text at the bottom (and centered) */ if (textdone == 0) { // caculate start xoffset to center text - render_plot_add_string(symbol, (char *) symbol->text, (symbol->width / 2.0) * scaler, default_text_posn, 9.0 * scaler, 0.0, &last_string); + render_plot_add_string(symbol, (char *) symbol->text, (symbol->width / 2.0) * scaler, default_text_posn, 9.0 * scaler, 0.0, &last_string); } } @@ -429,20 +507,20 @@ int render_plot_add_string(struct zint_symbol *symbol, { struct zint_render_string *string; - string = malloc(sizeof(struct zint_render_string)); - string->next = NULL; - string->x = x; - string->y = y; - string->width = width; - string->fsize = fsize; - string->text = malloc(sizeof(char) * (ustrlen((unsigned char *) text) + 1)); - strcpy(string->text, text); + string = malloc(sizeof(struct zint_render_string)); + string->next = NULL; + string->x = x; + string->y = y; + string->width = width; + string->fsize = fsize; + string->text = malloc(sizeof(char) * (ustrlen((unsigned char *) text) + 1)); + strcpy(string->text, text); - if (*last_string) - (*last_string)->next = string; - else - symbol->rendered->strings = string; // First character - *last_string = string; + if (*last_string) + (*last_string)->next = string; + else + symbol->rendered->strings = string; // First character + *last_string = string; return 1; }