Improved rendering of seperator bars for Codablock-F

This commit is contained in:
Robin Stuart 2016-09-12 21:47:40 +01:00
parent 8af885a3b8
commit 16511da26d
8 changed files with 101 additions and 43 deletions

View File

@ -845,7 +845,7 @@ int codablock(struct zint_symbol *symbol, unsigned char source[], int length) {
); );
} }
/* >>> Data */ /* >>> Data */
emptyColumns=useColumns; emptyColumns=useColumns;
/* +++ One liner don't have start/stop code */ /* +++ One liner don't have start/stop code */
if (rows == 1) if (rows == 1)
emptyColumns +=2; emptyColumns +=2;
@ -987,5 +987,9 @@ int codablock(struct zint_symbol *symbol, unsigned char source[], int length) {
if (!(symbol->output_options & BARCODE_BIND)) { if (!(symbol->output_options & BARCODE_BIND)) {
symbol->output_options += BARCODE_BIND; symbol->output_options += BARCODE_BIND;
} }
if (symbol->border_width < 2) {
symbol->border_width = 2;
}
return 0; return 0;
} }

View File

@ -177,7 +177,7 @@ int is_stackable(const int symbology) {
case BARCODE_TELEPEN_NUM: case BARCODE_TELEPEN_NUM:
case BARCODE_ITF14: case BARCODE_ITF14:
case BARCODE_CODE32: case BARCODE_CODE32:
case BARCODE_CODABLOCK: case BARCODE_CODABLOCKF:
retval = 1; retval = 1;
} }

View File

@ -402,7 +402,7 @@ static int gs1_compliant(const int symbology) {
case BARCODE_CODE49: case BARCODE_CODE49:
case BARCODE_QRCODE: case BARCODE_QRCODE:
case BARCODE_DOTCODE: case BARCODE_DOTCODE:
case BARCODE_CODABLOCK: case BARCODE_CODABLOCKF:
result = 1; result = 1;
break; break;
} }
@ -549,7 +549,7 @@ int ZBarcode_ValidID(int symbol_id) {
case BARCODE_GRIDMATRIX: case BARCODE_GRIDMATRIX:
case BARCODE_HANXIN: case BARCODE_HANXIN:
case BARCODE_DOTCODE: case BARCODE_DOTCODE:
case BARCODE_CODABLOCK: case BARCODE_CODABLOCKF:
result = 1; result = 1;
break; break;
} }
@ -779,7 +779,7 @@ static int reduced_charset(struct zint_symbol *symbol, const unsigned char *sour
break; break;
case BARCODE_DOTCODE: error_number = dotcode(symbol, preprocessed, in_length); case BARCODE_DOTCODE: error_number = dotcode(symbol, preprocessed, in_length);
break; break;
case BARCODE_CODABLOCK: error_number = codablock(symbol, preprocessed, in_length); case BARCODE_CODABLOCKF: error_number = codablock(symbol, preprocessed, in_length);
break; break;
} }
@ -880,7 +880,7 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int in_le
symbol->symbology = BARCODE_AUSPOST; symbol->symbology = BARCODE_AUSPOST;
} }
if (symbol->symbology == 73) { if (symbol->symbology == 73) {
symbol->symbology = BARCODE_CODABLOCK; symbol->symbology = BARCODE_CODABLOCKF;
symbol->input_mode = GS1_MODE; symbol->input_mode = GS1_MODE;
} }
if (symbol->symbology == 78) { if (symbol->symbology == 78) {

View File

@ -881,8 +881,14 @@ int ps_plot(struct zint_symbol *symbol) {
} else { } else {
fprintf(feps, "%.2f %.2f %.2f %.2f setcmykcolor\n", cyan_ink, magenta_ink, yellow_ink, black_ink); fprintf(feps, "%.2f %.2f %.2f %.2f setcmykcolor\n", cyan_ink, magenta_ink, yellow_ink, black_ink);
} }
for (r = 1; r < symbol->rows; r++) { if (symbol->symbology != BARCODE_CODABLOCKF) {
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", 2.0 * scaler, ((r * row_height) + textoffset + yoffset - 1) * scaler, xoffset * scaler, symbol->width * scaler); for (r = 1; r < symbol->rows; r++) {
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", 2.0 * scaler, ((r * row_height) + textoffset + yoffset - 1) * scaler, xoffset * scaler, symbol->width * scaler);
}
} else {
for (r = 1; r < symbol->rows; r++) {
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", 2.0 * scaler, ((r * row_height) + textoffset + yoffset - 1) * scaler, (xoffset + 11) * scaler, (symbol->width - 25) * scaler);
}
} }
} }
} }
@ -893,8 +899,13 @@ int ps_plot(struct zint_symbol *symbol) {
} else { } else {
fprintf(feps, "%.2f %.2f %.2f %.2f setcmykcolor\n", cyan_ink, magenta_ink, yellow_ink, black_ink); fprintf(feps, "%.2f %.2f %.2f %.2f setcmykcolor\n", cyan_ink, magenta_ink, yellow_ink, black_ink);
} }
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", symbol->border_width * scaler, textoffset * scaler, 0.0, (symbol->width + xoffset + xoffset) * scaler); if (symbol->symbology != BARCODE_CODABLOCKF) {
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", symbol->border_width * scaler, (textoffset + symbol->height + symbol->border_width) * scaler, 0.0, (symbol->width + xoffset + xoffset) * scaler); fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", symbol->border_width * scaler, textoffset * scaler, 0.0, (symbol->width + xoffset + xoffset) * scaler);
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", symbol->border_width * scaler, (textoffset + symbol->height + symbol->border_width) * scaler, 0.0, (symbol->width + xoffset + xoffset) * scaler);
} else {
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", symbol->border_width * scaler, textoffset * scaler, xoffset * scaler, symbol->width * scaler);
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", symbol->border_width * scaler, (textoffset + symbol->height + symbol->border_width) * scaler, xoffset * scaler, symbol->width * scaler);
}
} }
if (symbol->output_options & BARCODE_BOX) { if (symbol->output_options & BARCODE_BOX) {
/* side bars */ /* side bars */

View File

@ -171,6 +171,21 @@ void draw_bar(char *pixelbuf, int xpos, int xlen, int ypos, int ylen, int image_
} }
} }
void draw_circle(char *pixelbuf, int image_width, int image_height, int x0, int y0, int radius, char fill) {
int x, y;
for (y = -radius; y <= radius; y++) {
for (x = -radius; x <= radius; x++) {
if ((x * x) + (y * y) <= (radius * radius)) {
if ((y + y0 >= 0) && (y + y0 < image_height)
&& (x + x0 >= 0) && (x + x0 < image_width)) {
*(pixelbuf + ((y + y0) * image_width) + (x + x0)) = fill;
}
}
}
}
}
int bullseye_pixel(int row, int col) { int bullseye_pixel(int row, int col) {
int block_val, block_pos, return_val; int block_val, block_pos, return_val;
@ -185,18 +200,31 @@ int bullseye_pixel(int row, int col) {
return return_val; return return_val;
} }
void draw_bullseye(char *pixelbuf, int image_width, int xoffset, int yoffset) { void draw_bullseye(char *pixelbuf, int image_width, int image_height, int xoffset, int yoffset) {
/* Central bullseye in Maxicode symbols */ /* Central bullseye in Maxicode symbols */
int i, j; int i, j;
for (j = 103; j < 196; j++) { for (j = 103; j < 196; j++) {
for (i = 0; i < 93; i++) { for (i = 0; i < 93; i++) {
if (bullseye_pixel(j - 103, i)) { if (bullseye_pixel(j - 103, i)) {
/* if(bullseye[(((j - 103) * 93) + i)] == 1) { */
*(pixelbuf + (image_width * j) + (image_width * yoffset) + i + 99 + xoffset) = '1'; *(pixelbuf + (image_width * j) + (image_width * yoffset) + i + 99 + xoffset) = '1';
} }
} }
} }
/*
// At some point (probably after 2.5 release) the above clumsy drawing method should
// be replaced by something more like the code below
int scaler = 10;
draw_circle(pixelbuf, image_width, image_height, (14.5 * scaler) + xoffset, (int)(15 * scaler) + yoffset, (int)(4.57 * scaler), '1');
draw_circle(pixelbuf, image_width, image_height, (14.5 * scaler) + xoffset, (int)(15 * scaler) + yoffset, (int)(3.78 * scaler), '0');
draw_circle(pixelbuf, image_width, image_height, (14.5 * scaler) + xoffset, (int)(15 * scaler) + yoffset, (int)(2.99 * scaler), '1');
draw_circle(pixelbuf, image_width, image_height, (14.5 * scaler) + xoffset, (int)(15 * scaler) + yoffset, (int)(2.20 * scaler), '0');
draw_circle(pixelbuf, image_width, image_height, (14.5 * scaler) + xoffset, (int)(15 * scaler) + yoffset, (int)(1.39 * scaler), '1');
draw_circle(pixelbuf, image_width, image_height, (14.5 * scaler) + xoffset, (int)(15 * scaler) + yoffset, (int)(0.60 * scaler), '0');
*/
} }
void draw_hexagon(char *pixelbuf, int image_width, int xposn, int yposn) { void draw_hexagon(char *pixelbuf, int image_width, int xposn, int yposn) {
@ -378,7 +406,7 @@ int plot_raster_maxicode(struct zint_symbol *symbol, int rotate_angle, int data_
} }
} }
draw_bullseye(pixelbuf, image_width, (2 * xoffset), (2 * yoffset)); draw_bullseye(pixelbuf, image_width, image_height, (2 * xoffset), (2 * yoffset));
for (row = 0; row < symbol->rows; row++) { for (row = 0; row < symbol->rows; row++) {
yposn = row * 9; yposn = row * 9;
@ -478,21 +506,6 @@ void to_latin1(unsigned char source[], unsigned char preprocessed[]) {
return; return;
} }
void draw_circle(char *pixelbuf, int image_width, int image_height, int x0, int y0, int radius) {
int x, y;
for (y = -radius; y <= radius; y++) {
for (x = -radius; x <= radius; x++) {
if ((x * x) + (y * y) <= (radius * radius)) {
if ((y + y0 >= 0) && (y + y0 < image_height)
&& (x + x0 >= 0) && (x + x0 < image_width)) {
*(pixelbuf + ((y + y0) * image_width) + (x + x0)) = '1';
}
}
}
}
}
int plot_raster_dotty(struct zint_symbol *symbol, int rotate_angle, int data_type) { int plot_raster_dotty(struct zint_symbol *symbol, int rotate_angle, int data_type) {
float scaler = 2 * symbol->scale; float scaler = 2 * symbol->scale;
char *scaled_pixelbuf; char *scaled_pixelbuf;
@ -531,7 +544,8 @@ int plot_raster_dotty(struct zint_symbol *symbol, int rotate_angle, int data_typ
draw_circle(scaled_pixelbuf, scale_width, scale_height, draw_circle(scaled_pixelbuf, scale_width, scale_height,
(int) ((i + xoffset) * scaler) + (scaler / 2.0), (int) ((i + xoffset) * scaler) + (scaler / 2.0),
(int) ((r + yoffset) * scaler) + (scaler / 2.0), (int) ((r + yoffset) * scaler) + (scaler / 2.0),
(int) (scaler / 2.0)); (int) (scaler / 2.0),
'1');
} }
} }
} }
@ -948,13 +962,24 @@ int plot_raster_default(struct zint_symbol *symbol, int rotate_angle, int data_t
/* Put boundary bars or box around symbol */ /* Put boundary bars or box around symbol */
if ((symbol->output_options & BARCODE_BOX) || (symbol->output_options & BARCODE_BIND)) { if ((symbol->output_options & BARCODE_BOX) || (symbol->output_options & BARCODE_BIND)) {
/* boundary bars */ /* boundary bars */
draw_bar(pixelbuf, 0, (symbol->width + xoffset + xoffset) * 2, textoffset * 2, symbol->border_width * 2, image_width, image_height); if (symbol->symbology != BARCODE_CODABLOCKF) {
draw_bar(pixelbuf, 0, (symbol->width + xoffset + xoffset) * 2, (textoffset + symbol->height + symbol->border_width) * 2, symbol->border_width * 2, image_width, image_height); draw_bar(pixelbuf, 0, (symbol->width + xoffset + xoffset) * 2, textoffset * 2, symbol->border_width * 2, image_width, image_height);
draw_bar(pixelbuf, 0, (symbol->width + xoffset + xoffset) * 2, (textoffset + symbol->height + symbol->border_width) * 2, symbol->border_width * 2, image_width, image_height);
} else {
draw_bar(pixelbuf, xoffset * 2, symbol->width * 2, textoffset * 2, symbol->border_width * 2, image_width, image_height);
draw_bar(pixelbuf, xoffset * 2, symbol->width * 2, (textoffset + symbol->height + symbol->border_width) * 2, symbol->border_width * 2, image_width, image_height);
}
if ((symbol->output_options & BARCODE_BIND) != 0) { if ((symbol->output_options & BARCODE_BIND) != 0) {
if ((symbol->rows > 1) && (is_stackable(symbol->symbology) == 1)) { if ((symbol->rows > 1) && (is_stackable(symbol->symbology) == 1)) {
/* row binding */ /* row binding */
for (r = 1; r < symbol->rows; r++) { if (symbol->symbology != BARCODE_CODABLOCKF) {
draw_bar(pixelbuf, xoffset * 2, symbol->width * 2, ((r * row_height) + textoffset + yoffset - 1) * 2, 2 * 2, image_width, image_height); for (r = 1; r < symbol->rows; r++) {
draw_bar(pixelbuf, xoffset * 2, symbol->width * 2, ((r * row_height) + textoffset + yoffset - 1) * 2, 2 * 2, image_width, image_height);
}
} else {
for (r = 1; r < symbol->rows; r++) {
draw_bar(pixelbuf, (xoffset + 11) * 2 , (symbol->width - 25) * 2, ((r * row_height) + textoffset + yoffset - 1) * 2, 2 * 2, image_width, image_height);
}
} }
} }
} }

View File

@ -617,14 +617,25 @@ int svg_plot(struct zint_symbol *symbol) {
if (symbol->output_options & BARCODE_BIND) { if (symbol->output_options & BARCODE_BIND) {
if ((symbol->rows > 1) && (is_stackable(symbol->symbology) == 1)) { if ((symbol->rows > 1) && (is_stackable(symbol->symbology) == 1)) {
/* row binding */ /* row binding */
for (r = 1; r < symbol->rows; r++) { if (symbol->symbology != BARCODE_CODABLOCKF) {
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", xoffset * scaler, ((r * row_height) + yoffset - 1) * scaler, symbol->width * scaler, 2.0 * scaler); for (r = 1; r < symbol->rows; r++) {
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", xoffset * scaler, ((r * row_height) + yoffset - 1) * scaler, symbol->width * scaler, 2.0 * scaler);
}
} else {
for (r = 1; r < symbol->rows; r++) {
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (xoffset + 11) * scaler, ((r * row_height) + yoffset - 1) * scaler, (symbol->width - 25) * scaler, 2.0 * scaler);
}
} }
} }
} }
if ((symbol->output_options & BARCODE_BOX) || (symbol->output_options & BARCODE_BIND)) { if ((symbol->output_options & BARCODE_BOX) || (symbol->output_options & BARCODE_BIND)) {
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", 0.0, 0.0, (symbol->width + xoffset + xoffset) * scaler, symbol->border_width * scaler); if (symbol->symbology != BARCODE_CODABLOCKF) {
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", 0.0, (symbol->height + symbol->border_width) * scaler, (symbol->width + xoffset + xoffset) * scaler, symbol->border_width * scaler); fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", 0.0, 0.0, (symbol->width + xoffset + xoffset) * scaler, symbol->border_width * scaler);
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", 0.0, (symbol->height + symbol->border_width) * scaler, (symbol->width + xoffset + xoffset) * scaler, symbol->border_width * scaler);
} else {
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", xoffset * scaler, 0.0, symbol->width * scaler, symbol->border_width * scaler);
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", xoffset * scaler, (symbol->height + symbol->border_width) * scaler, symbol->width * scaler, symbol->border_width * scaler);
}
} }
if (symbol->output_options & BARCODE_BOX) { if (symbol->output_options & BARCODE_BOX) {
/* side bars */ /* side bars */

View File

@ -143,7 +143,7 @@ extern "C" {
#define BARCODE_RM4SCC 70 #define BARCODE_RM4SCC 70
#define BARCODE_DATAMATRIX 71 #define BARCODE_DATAMATRIX 71
#define BARCODE_EAN14 72 #define BARCODE_EAN14 72
#define BARCODE_CODABLOCK 74 #define BARCODE_CODABLOCKF 74
#define BARCODE_NVE18 75 #define BARCODE_NVE18 75
#define BARCODE_JAPANPOST 76 #define BARCODE_JAPANPOST 76
#define BARCODE_KOREAPOST 77 #define BARCODE_KOREAPOST 77

View File

@ -394,8 +394,13 @@ namespace Zint {
yoffset = m_borderWidth; yoffset = m_borderWidth;
break; break;
case BIND: case BIND:
painter.fillRect(0, 0, m_zintSymbol->width + xoffset + xoffset, m_borderWidth, QBrush(m_fgColor)); if (m_zintSymbol->symbology != BARCODE_CODABLOCKF) {
painter.fillRect(0, m_zintSymbol->height + m_borderWidth, m_zintSymbol->width + xoffset + xoffset, m_borderWidth, QBrush(m_fgColor)); painter.fillRect(0, 0, m_zintSymbol->width + xoffset + xoffset, m_borderWidth, QBrush(m_fgColor));
painter.fillRect(0, m_zintSymbol->height, m_zintSymbol->width + xoffset + xoffset, m_borderWidth, QBrush(m_fgColor));
} else {
painter.fillRect(xoffset, 0, m_zintSymbol->width, m_borderWidth, QBrush(m_fgColor));
painter.fillRect(xoffset, m_zintSymbol->height, m_zintSymbol->width, m_borderWidth, QBrush(m_fgColor));
}
painter.translate(m_zintSymbol->whitespace_width, m_borderWidth); painter.translate(m_zintSymbol->whitespace_width, m_borderWidth);
yoffset = m_borderWidth; yoffset = m_borderWidth;
break; break;
@ -516,10 +521,12 @@ namespace Zint {
} }
/* Add row binding */ /* Add row binding */
if (((m_zintSymbol->symbology == BARCODE_CODE16K) if (((m_zintSymbol->symbology == BARCODE_CODE16K)
|| (m_zintSymbol->symbology == BARCODE_CODE49) || (m_zintSymbol->symbology == BARCODE_CODE49)) && (row != 0)) {
|| (m_zintSymbol->symbology == BARCODE_CODABLOCK)) && (row != 0)) {
painter.fillRect(0, y - 1, m_zintSymbol->width, 2, QBrush(m_fgColor)); painter.fillRect(0, y - 1, m_zintSymbol->width, 2, QBrush(m_fgColor));
} }
if ((m_zintSymbol->symbology == BARCODE_CODABLOCKF) && (row != 0)) {
painter.fillRect(11, y - 1, m_zintSymbol->width - 25, 2, QBrush(m_fgColor));
}
y += m_zintSymbol->row_height[row]; y += m_zintSymbol->row_height[row];
} }
} }