1
0
mirror of https://github.com/woo-j/zint.git synced 2024-12-24 17:34:05 +03:00

Patches from tgotic

This commit is contained in:
hooper114 2009-10-22 22:02:02 +00:00
parent a55b21704e
commit 1542cf5680
2 changed files with 37 additions and 24 deletions

View File

@ -20,6 +20,10 @@
*/
#include <stdio.h>
#ifdef _MSC_VER
#include <fcntl.h>
#include <io.h>
#endif
#include <stdlib.h>
#include <string.h>
#include "common.h"
@ -124,6 +128,12 @@ int png_to_file(struct zint_symbol *symbol, int image_height, int image_width, c
/* Open output file in binary mode */
if((symbol->output_options & BARCODE_STDOUT) != 0) {
#ifdef _MSC_VER
if (-1 == _setmode(_fileno(stdout), _O_BINARY)) {
strcpy(symbol->errtxt, "Can't open output file");
return ERROR_FILE_ACCESS;
}
#endif
graphic->outfile = stdout;
} else {
if (!(graphic->outfile = fopen(symbol->outfile, "wb"))) {

View File

@ -114,40 +114,43 @@ int estimate_binary_length(char mode[], int length)
char current = 0;
int a_count = 0;
int n_count = 0;
switch(mode[0]) {
case 'K': count = 12 + 4; current = 'K'; break;
case 'B': count = 16 + 4; current = 'B'; break;
case 'A': count = 13 + 4; current = 'A'; break;
case 'N': count = 14 + 4; current = 'N'; break;
}
for(i = 0; i < length; i++) {
if(mode[i] != current) {
if(current == 'N') {
switch(n_count) {
case 1: count += 4; break;
case 2: count += 7; break;
}
}
switch(mode[i]) {
case 'K': count += 12 + 4; current = 'K'; break;
case 'B': count += 16 + 4; current = 'B'; break;
case 'A': count += 13 + 4; current = 'A'; break;
case 'N': count += 14 + 4; current = 'N'; break;
case 'A': count += 13 + 4; current = 'A'; a_count = 0; break;
case 'N': count += 14 + 4; current = 'N'; n_count = 0; break;
}
}
switch(mode[i]) {
case 'K': count += 13; break;
case 'B': count += 8; break;
case 'A': a_count++; if((a_count % 2) == 0) { count += 11; a_count = 0; } break;
case 'N': n_count++; if((n_count % 3) == 0) { count += 10; n_count = 0; } break;
case 'K': count += 13; break;
case 'B': count += 8; break;
case 'A':
a_count++;
if((a_count % 2) == 0) {
count += 5; // 11 in total
a_count = 0;
}
else
count += 6;
break;
case 'N':
n_count++;
if((n_count % 3) == 0) {
count += 3; // 10 in total
n_count = 0;
}
else if ((n_count % 2) == 0)
count += 3; // 7 in total
else
count += 4;
break;
}
}
return count;
}