Add scale option and make whitespace and border options more consistent.

This commit is contained in:
hooper114 2008-12-24 21:29:31 +00:00
parent a2c76b76ae
commit 8a9e55fff1
4 changed files with 114 additions and 65 deletions

View File

@ -134,3 +134,20 @@ void expand(struct zint_symbol *symbol, char data[])
}
symbol->rows = symbol->rows + 1;
}
int is_stackable(int symbology) {
/* Indicates which symbologies can have row binding */
if(symbology < BARCODE_PDF417) { return 1; }
if(symbology == BARCODE_CODE128B) { return 1; }
if(symbology == BARCODE_ISBNX) { return 1; }
if(symbology == BARCODE_EAN14) { return 1; }
if(symbology == BARCODE_NVE18) { return 1; }
if(symbology == BARCODE_KOREAPOST) { return 1; }
if(symbology == BARCODE_PLESSEY) { return 1; }
if(symbology == BARCODE_TELEPEN_NUM) { return 1; }
if(symbology == BARCODE_ITF14) { return 1; }
if(symbology == BARCODE_CODE32) { return 1; }
return 0;
}

View File

@ -37,3 +37,4 @@ int is_sane(char test_string[], unsigned char source[]);
void lookup(char set_string[], char *table[], char data, char dest[]);
int posn(char set_string[], char data);
void expand(struct zint_symbol *symbol, char data[]);
int is_stackable(int symbology);

View File

@ -290,7 +290,7 @@ void draw_bar(char *pixelbuf, int xpos, int xlen, int ypos, int ylen, int image_
}
}
void draw_bullseye(char *pixelbuf)
void draw_bullseye(char *pixelbuf, int image_width, int xoffset, int yoffset)
{
/* Central bullseye in Maxicode symbols */
int i, j;
@ -298,13 +298,13 @@ void draw_bullseye(char *pixelbuf)
for(j = 103; j < 196; j++) {
for(i = 0; i < 93; i++) {
if(bullseye[(((j - 103) * 93) + i)] == 1) {
*(pixelbuf + (300 * j) + (i + 99)) = '1';
*(pixelbuf + (image_width * j) + (image_width * yoffset) + i + 99 + xoffset) = '1';
}
}
}
}
void draw_hexagon(char *pixelbuf, int xposn, int yposn)
void draw_hexagon(char *pixelbuf, int image_width, int xposn, int yposn)
{
/* Put a hexagon into the pixel buffer */
int i, j;
@ -312,7 +312,7 @@ void draw_hexagon(char *pixelbuf, int xposn, int yposn)
for(i = 0; i < 12; i++) {
for(j = 0; j < 10; j++) {
if(hexagon[(i * 10) + j] == 1) {
*(pixelbuf + (300 * i) + (300 * yposn) + xposn + j) = '1';
*(pixelbuf + (image_width * i) + (image_width * yposn) + xposn + j) = '1';
}
}
}
@ -373,9 +373,13 @@ int maxi_png_plot(struct zint_symbol *symbol, int rotate_angle)
int image_height, image_width;
char *pixelbuf;
int error_number;
int xoffset, yoffset;
int scaler = (int)(2 * symbol->scale);
image_width = 300;
image_height = 300;
xoffset = symbol->border_width + symbol->whitespace_width;
yoffset = symbol->border_width;
image_width = 300 + (2 * xoffset * scaler);
image_height = 300 + (2 * yoffset * scaler);
if (!(pixelbuf = (char *) malloc(image_width * image_height))) {
printf("Insifficient memory for pixel buffer [B9]");
@ -386,7 +390,7 @@ int maxi_png_plot(struct zint_symbol *symbol, int rotate_angle)
}
}
draw_bullseye(pixelbuf);
draw_bullseye(pixelbuf, image_width, (scaler * xoffset), (scaler * yoffset));
for(row = 0; row < symbol->rows; row++) {
yposn = row * 9;
@ -395,16 +399,28 @@ int maxi_png_plot(struct zint_symbol *symbol, int rotate_angle)
if(symbol->encoded_data[row][column] == '1') {
if((row % 2) == 0) {
/* Even (full) row */
draw_hexagon(pixelbuf, xposn, yposn);
draw_hexagon(pixelbuf, image_width, xposn + (scaler * xoffset), yposn + (scaler * yoffset));
} else {
/* Odd (reduced) row */
xposn += 5;
draw_hexagon(pixelbuf, xposn, yposn);
draw_hexagon(pixelbuf, image_width, xposn + (scaler * xoffset), yposn + (scaler * yoffset));
}
}
}
}
if(((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) {
/* boundary bars */
draw_bar(pixelbuf, 0, image_width, 0, symbol->border_width * scaler, image_width, image_height);
draw_bar(pixelbuf, 0, image_width, 300 + (symbol->border_width * scaler), symbol->border_width * scaler, image_width, image_height);
}
if((symbol->output_options & BARCODE_BOX) != 0) {
/* side bars */
draw_bar(pixelbuf, 0, symbol->border_width * scaler, 0, image_height, image_width, image_height);
draw_bar(pixelbuf, 300 + ((symbol->border_width + symbol->whitespace_width + symbol->whitespace_width) * scaler), symbol->border_width * scaler, 0, image_height, image_width, image_height);
}
error_number=png_to_file(symbol, image_height, image_width, pixelbuf, rotate_angle);
free(pixelbuf);
return error_number;
@ -765,10 +781,12 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle)
/* boundary bars */
draw_bar(pixelbuf, 0, (symbol->width + xoffset + xoffset) * scaler, textoffset * scaler, symbol->border_width * scaler, image_width, image_height);
draw_bar(pixelbuf, 0, (symbol->width + xoffset + xoffset) * scaler, (textoffset + symbol->height + symbol->border_width) * scaler, symbol->border_width * scaler, image_width, image_height);
if(symbol->rows > 1) {
/* row binding */
for(r = 1; r < symbol->rows; r++) {
draw_bar(pixelbuf, xoffset * scaler, symbol->width * scaler, ((r * row_height) + textoffset + yoffset - 1) * scaler, 2 * scaler, image_width, image_height);
if((symbol->symbology & BARCODE_BIND) != 0) {
if((symbol->rows > 1) && (is_stackable(symbol->symbology) == 1)) {
/* row binding */
for(r = 1; r < symbol->rows; r++) {
draw_bar(pixelbuf, xoffset * scaler, symbol->width * scaler, ((r * row_height) + textoffset + yoffset - 1) * scaler, 2 * scaler, image_width, image_height);
}
}
}
} else {

View File

@ -198,7 +198,7 @@ int ps_plot(struct zint_symbol *symbol)
if(symbol->symbology != BARCODE_MAXICODE) {
fprintf(feps, "%%%%BoundingBox: 0 0 %d %d\n", roundup((symbol->width + xoffset + xoffset) * scaler), roundup((symbol->height + textoffset + yoffset + yoffset) * scaler));
} else {
fprintf(feps, "%%%%BoundingBox: 0 0 %d %d\n", roundup(74.0 * scaler), roundup(72.0 * scaler));
fprintf(feps, "%%%%BoundingBox: 0 0 %d %d\n", roundup((74.0 + xoffset + xoffset) * scaler), roundup((72.0 + yoffset + yoffset) * scaler));
}
fprintf(feps, "%%%%EndComments\n");
@ -222,34 +222,50 @@ int ps_plot(struct zint_symbol *symbol)
/* Maxicode uses hexagons */
float ax, ay, bx, by, cx, cy, dx, dy, ex, ey, fx, fy, mx, my;
textoffset = 0.0;
if (((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) {
fprintf(feps, "TE\n");
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", symbol->border_width * scaler, textoffset * scaler, 0.0, (74.0 + xoffset + xoffset) * scaler);
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", symbol->border_width * scaler, (textoffset + 72.0 + symbol->border_width) * scaler, 0.0, (74.0 + xoffset + xoffset) * scaler);
}
if((symbol->output_options & BARCODE_BOX) != 0) {
/* side bars */
fprintf(feps, "TE\n");
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", (72.0 + (2 * symbol->border_width)) * scaler, textoffset * scaler, 0.0, symbol->border_width * scaler);
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", (72.0 + (2 * symbol->border_width)) * scaler, textoffset * scaler, (74.0 + xoffset + xoffset - symbol->border_width) * scaler, symbol->border_width * scaler);
}
fprintf(feps, "TE\n");
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
fprintf(feps, "%.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f TC\n", 35.76 * scaler, 35.60 * scaler, 10.85 * scaler, 35.76 * scaler, 35.60 * scaler, 8.97 * scaler, 44.73 * scaler, 35.60 * scaler);
fprintf(feps, "%.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f TC\n", 35.76 * scaler, 35.60 * scaler, 7.10 * scaler, 35.76 * scaler, 35.60 * scaler, 5.22 * scaler, 40.98 * scaler, 35.60 * scaler);
fprintf(feps, "%.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f TC\n", 35.76 * scaler, 35.60 * scaler, 3.31 * scaler, 35.76 * scaler, 35.60 * scaler, 1.43 * scaler, 37.19 * scaler, 35.60 * scaler);
fprintf(feps, "%.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f TC\n", (35.76 + xoffset) * scaler, (35.60 + yoffset) * scaler, 10.85 * scaler, (35.76 + xoffset) * scaler, (35.60 + yoffset) * scaler, 8.97 * scaler, (44.73 + xoffset) * scaler, (35.60 + yoffset) * scaler);
fprintf(feps, "%.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f TC\n", (35.76 + xoffset) * scaler, (35.60 + yoffset) * scaler, 7.10 * scaler, (35.76 + xoffset) * scaler, (35.60 + yoffset) * scaler, 5.22 * scaler, (40.98 + xoffset) * scaler, (35.60 + yoffset) * scaler);
fprintf(feps, "%.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f TC\n", (35.76 + xoffset) * scaler, (35.60 + yoffset) * scaler, 3.31 * scaler, (35.76 + xoffset) * scaler, (35.60 + yoffset) * scaler, 1.43 * scaler, (37.19 + xoffset) * scaler, (35.60 + yoffset) * scaler);
for(r = 0; r < symbol->rows; r++) {
for(i = 0; i < symbol->width; i++) {
if(symbol->encoded_data[r][i] == '1') {
/* Dump a hexagon */
my = ((symbol->rows - r - 1)) * 2.135 + 1.43;
ay = my + 1.0;
by = my + 0.5;
cy = my - 0.5;
dy = my - 1.0;
ey = my - 0.5;
fy = my + 0.5;
ay = my + 1.0 + yoffset;
by = my + 0.5 + yoffset;
cy = my - 0.5 + yoffset;
dy = my - 1.0 + yoffset;
ey = my - 0.5 + yoffset;
fy = my + 0.5 + yoffset;
if(r % 2 == 1) {
mx = (2.46 * i) + 1.23 + 1.23;
} else {
mx = (2.46 * i) + 1.23;
}
ax = mx;
bx = mx + 0.86;
cx = mx + 0.86;
dx = mx;
ex = mx - 0.86;
fx = mx - 0.86;
ax = mx + xoffset;
bx = mx + 0.86 + xoffset;
cx = mx + 0.86 + xoffset;
dx = mx + xoffset;
ex = mx - 0.86 + xoffset;
fx = mx - 0.86 + xoffset;
fprintf(feps, "%.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f TH\n", ax * scaler, ay * scaler, bx * scaler, by * scaler, cx * scaler, cy * scaler, dx * scaler, dy * scaler, ex * scaler, ey * scaler, fx * scaler, fy * scaler);
}
}
@ -685,52 +701,49 @@ int ps_plot(struct zint_symbol *symbol)
xoffset -= comp_offset;
/* Put boundary bars or box around symbol */
if (((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) {
if(symbol->symbology != BARCODE_CODABLOCKF) {
/* boundary bars */
fprintf(feps, "TE\n");
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", symbol->border_width * scaler, textoffset * scaler, 0.0, (symbol->width + xoffset + xoffset) * scaler);
fprintf(feps, "TE\n");
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
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);
if(symbol->rows > 1) {
/* row binding */
for(r = 1; r < symbol->rows; r++) {
fprintf(feps, "TE\n");
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", 2.0, ((r * row_height) + textoffset + yoffset - 1) * scaler, xoffset * scaler, symbol->width * scaler);
}
}
} else {
/* boundary bars */
switch(symbol->symbology) {
case BARCODE_CODABLOCKF:
fprintf(feps, "TE\n");
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", symbol->border_width * scaler, textoffset * scaler, xoffset * scaler, symbol->width * scaler);
fprintf(feps, "TE\n");
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
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->rows > 1) {
/* row binding */
fprintf(feps, "TE\n");
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
for(r = 1; r < symbol->rows; r++) {
fprintf(feps, "TE\n");
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", 2.0, ((r * row_height) + textoffset + yoffset - 1) * scaler, (xoffset + 11) * scaler, (symbol->width - 24) * scaler);
}
}
}
}
if((symbol->output_options & BARCODE_BOX) != 0) {
/* side bars */
fprintf(feps, "TE\n");
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", (symbol->height + (2 * symbol->border_width)) * scaler, textoffset * scaler, 0.0, symbol->border_width * scaler);
fprintf(feps, "TE\n");
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", (symbol->height + (2 * symbol->border_width)) * scaler, textoffset * scaler, (symbol->width + xoffset + xoffset - symbol->border_width) * scaler, symbol->border_width * scaler);
break;
case BARCODE_MAXICODE:
/* Do nothing! (It's already been done) */
break;
default:
if((symbol->output_options & BARCODE_BIND) != 0) {
if((symbol->rows > 1) && (is_stackable(symbol->symbology) == 1)) {
/* row binding */
fprintf(feps, "TE\n");
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
for(r = 1; r < symbol->rows; r++) {
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", 2.0, ((r * row_height) + textoffset + yoffset - 1) * scaler, xoffset * scaler, symbol->width * scaler);
}
}
}
if (((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) {
fprintf(feps, "TE\n");
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
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);
}
if((symbol->output_options & BARCODE_BOX) != 0) {
/* side bars */
fprintf(feps, "TE\n");
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", (symbol->height + (2 * symbol->border_width)) * scaler, textoffset * scaler, 0.0, symbol->border_width * scaler);
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", (symbol->height + (2 * symbol->border_width)) * scaler, textoffset * scaler, (symbol->width + xoffset + xoffset - symbol->border_width) * scaler, symbol->border_width * scaler);
}
break;
}
/* Put the human readable text at the bottom */