Add support for rendering UPC

Extended bars and text formatting for UPC barcodes now included in render.c
This commit is contained in:
Robin Stuart 2010-06-13 11:56:31 +01:00
parent 95e51cf96d
commit 807d9460d1

View File

@ -146,9 +146,7 @@ int render_plot(struct zint_symbol *symbol, unsigned int hide_text, float width,
scaler = width / w; scaler = width / w;
} }
/* // Calculate the height
* Calculate the height
*/
if (height) { if (height) {
symbol->height = height / scaler; // starting height symbol->height = height / scaler; // starting height
} else if (symbol->height == 0) { } else if (symbol->height == 0) {
@ -370,6 +368,86 @@ int render_plot(struct zint_symbol *symbol, unsigned int hide_text, float width,
} }
} }
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) */ /* Put normal human readable text at the bottom (and centered) */
if (textdone == 0) { if (textdone == 0) {
// caculate start xoffset to center text // caculate start xoffset to center text