mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
Patches from tgotic
This commit is contained in:
parent
a55b21704e
commit
1542cf5680
@ -20,6 +20,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <io.h>
|
||||||
|
#endif
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "common.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 */
|
/* Open output file in binary mode */
|
||||||
if((symbol->output_options & BARCODE_STDOUT) != 0) {
|
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;
|
graphic->outfile = stdout;
|
||||||
} else {
|
} else {
|
||||||
if (!(graphic->outfile = fopen(symbol->outfile, "wb"))) {
|
if (!(graphic->outfile = fopen(symbol->outfile, "wb"))) {
|
||||||
|
45
backend/qr.c
45
backend/qr.c
@ -115,37 +115,40 @@ int estimate_binary_length(char mode[], int length)
|
|||||||
int a_count = 0;
|
int a_count = 0;
|
||||||
int n_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++) {
|
for(i = 0; i < length; i++) {
|
||||||
if(mode[i] != current) {
|
if(mode[i] != current) {
|
||||||
if(current == 'N') {
|
|
||||||
switch(n_count) {
|
|
||||||
case 1: count += 4; break;
|
|
||||||
case 2: count += 7; break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch(mode[i]) {
|
switch(mode[i]) {
|
||||||
case 'K': count += 12 + 4; current = 'K'; break;
|
case 'K': count += 12 + 4; current = 'K'; break;
|
||||||
case 'B': count += 16 + 4; current = 'B'; break;
|
case 'B': count += 16 + 4; current = 'B'; break;
|
||||||
case 'A': count += 13 + 4; current = 'A'; break;
|
case 'A': count += 13 + 4; current = 'A'; a_count = 0; break;
|
||||||
case 'N': count += 14 + 4; current = 'N'; break;
|
case 'N': count += 14 + 4; current = 'N'; n_count = 0; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(mode[i]) {
|
switch(mode[i]) {
|
||||||
case 'K': count += 13; break;
|
case 'K': count += 13; break;
|
||||||
case 'B': count += 8; break;
|
case 'B': count += 8; break;
|
||||||
case 'A': a_count++; if((a_count % 2) == 0) { count += 11; a_count = 0; } break;
|
case 'A':
|
||||||
case 'N': n_count++; if((n_count % 3) == 0) { count += 10; n_count = 0; } break;
|
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;
|
return count;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user