Added smalltext option

Added an option which allows use of reduced size text.
Reduced size font information added to font.h.
This commit is contained in:
Robin Stuart 2010-12-19 22:23:59 +00:00
parent ae44cf2d33
commit 1c540a6382
4 changed files with 1720 additions and 61 deletions

File diff suppressed because it is too large Load Diff

View File

@ -557,7 +557,7 @@ void draw_hexagon(char *pixelbuf, int image_width, int xposn, int yposn)
} }
} }
void draw_letter(char *pixelbuf, unsigned char letter, int xposn, int yposn, int image_width, int image_height) void draw_letter(char *pixelbuf, unsigned char letter, int xposn, int yposn, int smalltext, int image_width, int image_height)
{ {
/* Put a letter into a position */ /* Put a letter into a position */
int skip, i, j, glyph_no, alphabet; int skip, i, j, glyph_no, alphabet;
@ -576,8 +576,23 @@ void draw_letter(char *pixelbuf, unsigned char letter, int xposn, int yposn, int
glyph_no = letter - 33; glyph_no = letter - 33;
} }
if(smalltext) {
for(i = 0; i <= 8; i++) {
for(j = 0; j < 5; j++) {
if(alphabet == 0) {
if(small_font[(glyph_no * 5) + (i * 475) + j - 1] == 1) {
*(pixelbuf + (i * image_width) + (yposn * image_width) + xposn + j) = '1';
}
} else {
if(small_font_extended[(glyph_no * 5) + (i * 475) + j - 1] == 1) {
*(pixelbuf + (i * image_width) + (yposn * image_width) + xposn + j) = '1';
}
}
}
}
} else {
for(i = 0; i <= 13; i++) { for(i = 0; i <= 13; i++) {
for(j = 0; j < 7; j++) { for(j = 0; j < 7 ; j++) {
if(alphabet == 0) { if(alphabet == 0) {
if(ascii_font[(glyph_no * 7) + (i * 665) + j - 1] == 1) { if(ascii_font[(glyph_no * 7) + (i * 665) + j - 1] == 1) {
*(pixelbuf + (i * image_width) + (yposn * image_width) + xposn + j) = '1'; *(pixelbuf + (i * image_width) + (yposn * image_width) + xposn + j) = '1';
@ -590,9 +605,10 @@ void draw_letter(char *pixelbuf, unsigned char letter, int xposn, int yposn, int
} }
} }
} }
}
} }
void draw_string(char *pixbuf, char input_string[], int xposn, int yposn, int image_width, int image_height) void draw_string(char *pixbuf, char input_string[], int xposn, int yposn, int smalltext, int image_width, int image_height)
{ {
/* Plot a string into the pixel buffer */ /* Plot a string into the pixel buffer */
int i, string_length, string_left_hand; int i, string_length, string_left_hand;
@ -601,7 +617,7 @@ void draw_string(char *pixbuf, char input_string[], int xposn, int yposn, int im
string_left_hand = xposn - ((7 * string_length) / 2); string_left_hand = xposn - ((7 * string_length) / 2);
for(i = 0; i < string_length; i++) { for(i = 0; i < string_length; i++) {
draw_letter(pixbuf, input_string[i], string_left_hand + (i * 7), yposn, image_width, image_height); draw_letter(pixbuf, input_string[i], string_left_hand + (i * 7), yposn, smalltext, image_width, image_height);
} }
} }
@ -702,7 +718,7 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
float addon_text_posn, preset_height, large_bar_height; float addon_text_posn, preset_height, large_bar_height;
int i, r, textoffset, yoffset, xoffset, latch, image_width, image_height; int i, r, textoffset, yoffset, xoffset, latch, image_width, image_height;
char *pixelbuf; char *pixelbuf;
int addon_latch = 0; int addon_latch = 0, smalltext = 0;
int this_row, block_width, plot_height, plot_yposn, textpos; int this_row, block_width, plot_height, plot_yposn, textpos;
float row_height, row_posn; float row_height, row_posn;
int error_number; int error_number;
@ -726,6 +742,9 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
comp_offset = 0; comp_offset = 0;
addon_text_posn = 0.0; addon_text_posn = 0.0;
row_height = 0; row_height = 0;
if(symbol->output_options &= SMALL_TEXT) {
smalltext = 1;
}
if (symbol->height == 0) { if (symbol->height == 0) {
symbol->height = 50; symbol->height = 50;
@ -891,22 +910,22 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
textpart[4] = '\0'; textpart[4] = '\0';
textpos = 2 * (17 + xoffset); textpos = 2 * (17 + xoffset);
draw_string(pixelbuf, textpart, textpos, default_text_posn, image_width, image_height); draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
for(i = 0; i < 4; i++) { for(i = 0; i < 4; i++) {
textpart[i] = symbol->text[i + 4]; textpart[i] = symbol->text[i + 4];
} }
textpart[4] = '\0'; textpart[4] = '\0';
textpos = 2 * (50 + xoffset); textpos = 2 * (50 + xoffset);
draw_string(pixelbuf, textpart, textpos, default_text_posn, image_width, image_height); draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
textdone = 1; textdone = 1;
switch(strlen(addon)) { switch(strlen(addon)) {
case 2: case 2:
textpos = 2 * (xoffset + 86); textpos = 2 * (xoffset + 86);
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, image_width, image_height); draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height);
break; break;
case 5: case 5:
textpos = 2 * (xoffset + 100); textpos = 2 * (xoffset + 100);
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, image_width, image_height); draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height);
break; break;
} }
@ -924,28 +943,28 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
textpart[0] = symbol->text[0]; textpart[0] = symbol->text[0];
textpart[1] = '\0'; textpart[1] = '\0';
textpos = 2 * (-7 + xoffset); textpos = 2 * (-7 + xoffset);
draw_string(pixelbuf, textpart, textpos, default_text_posn, image_width, image_height); draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
for(i = 0; i < 6; i++) { for(i = 0; i < 6; i++) {
textpart[i] = symbol->text[i + 1]; textpart[i] = symbol->text[i + 1];
} }
textpart[6] = '\0'; textpart[6] = '\0';
textpos = 2 * (24 + xoffset); textpos = 2 * (24 + xoffset);
draw_string(pixelbuf, textpart, textpos, default_text_posn, image_width, image_height); draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
for(i = 0; i < 6; i++) { for(i = 0; i < 6; i++) {
textpart[i] = symbol->text[i + 7]; textpart[i] = symbol->text[i + 7];
} }
textpart[6] = '\0'; textpart[6] = '\0';
textpos = 2 * (71 + xoffset); textpos = 2 * (71 + xoffset);
draw_string(pixelbuf, textpart, textpos, default_text_posn, image_width, image_height); draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
textdone = 1; textdone = 1;
switch(strlen(addon)) { switch(strlen(addon)) {
case 2: case 2:
textpos = 2 * (xoffset + 114); textpos = 2 * (xoffset + 114);
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, image_width, image_height); draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height);
break; break;
case 5: case 5:
textpos = 2 * (xoffset + 128); textpos = 2 * (xoffset + 128);
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, image_width, image_height); draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height);
break; break;
} }
break; break;
@ -995,32 +1014,32 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
textpart[0] = symbol->text[0]; textpart[0] = symbol->text[0];
textpart[1] = '\0'; textpart[1] = '\0';
textpos = 2 * (-5 + xoffset); textpos = 2 * (-5 + xoffset);
draw_string(pixelbuf, textpart, textpos, default_text_posn, image_width, image_height); draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
for(i = 0; i < 5; i++) { for(i = 0; i < 5; i++) {
textpart[i] = symbol->text[i + 1]; textpart[i] = symbol->text[i + 1];
} }
textpart[5] = '\0'; textpart[5] = '\0';
textpos = 2 * (27 + xoffset); textpos = 2 * (27 + xoffset);
draw_string(pixelbuf, textpart, textpos, default_text_posn, image_width, image_height); draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
for(i = 0; i < 5; i++) { for(i = 0; i < 5; i++) {
textpart[i] = symbol->text[i + 6]; textpart[i] = symbol->text[i + 6];
} }
textpart[6] = '\0'; textpart[6] = '\0';
textpos = 2 * (68 + xoffset); textpos = 2 * (68 + xoffset);
draw_string(pixelbuf, textpart, textpos, default_text_posn, image_width, image_height); draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
textpart[0] = symbol->text[11]; textpart[0] = symbol->text[11];
textpart[1] = '\0'; textpart[1] = '\0';
textpos = 2 * (100 + xoffset); textpos = 2 * (100 + xoffset);
draw_string(pixelbuf, textpart, textpos, default_text_posn, image_width, image_height); draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
textdone = 1; textdone = 1;
switch(strlen(addon)) { switch(strlen(addon)) {
case 2: case 2:
textpos = 2 * (xoffset + 116); textpos = 2 * (xoffset + 116);
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, image_width, image_height); draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height);
break; break;
case 5: case 5:
textpos = 2 * (xoffset + 130); textpos = 2 * (xoffset + 130);
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, image_width, image_height); draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height);
break; break;
} }
@ -1037,26 +1056,26 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
textpart[0] = symbol->text[0]; textpart[0] = symbol->text[0];
textpart[1] = '\0'; textpart[1] = '\0';
textpos = 2 * (-5 + xoffset); textpos = 2 * (-5 + xoffset);
draw_string(pixelbuf, textpart, textpos, default_text_posn, image_width, image_height); draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
for(i = 0; i < 6; i++) { for(i = 0; i < 6; i++) {
textpart[i] = symbol->text[i + 1]; textpart[i] = symbol->text[i + 1];
} }
textpart[6] = '\0'; textpart[6] = '\0';
textpos = 2 * (24 + xoffset); textpos = 2 * (24 + xoffset);
draw_string(pixelbuf, textpart, textpos, default_text_posn, image_width, image_height); draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
textpart[0] = symbol->text[7]; textpart[0] = symbol->text[7];
textpart[1] = '\0'; textpart[1] = '\0';
textpos = 2 * (55 + xoffset); textpos = 2 * (55 + xoffset);
draw_string(pixelbuf, textpart, textpos, default_text_posn, image_width, image_height); draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height);
textdone = 1; textdone = 1;
switch(strlen(addon)) { switch(strlen(addon)) {
case 2: case 2:
textpos = 2 * (xoffset + 70); textpos = 2 * (xoffset + 70);
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, image_width, image_height); draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height);
break; break;
case 5: case 5:
textpos = 2 * (xoffset + 84); textpos = 2 * (xoffset + 84);
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, image_width, image_height); draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height);
break; break;
} }
@ -1088,7 +1107,7 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
/* Put the human readable text at the bottom */ /* Put the human readable text at the bottom */
if((textdone == 0) && (ustrlen(local_text) != 0)) { if((textdone == 0) && (ustrlen(local_text) != 0)) {
textpos = (image_width / 2); textpos = (image_width / 2);
draw_string(pixelbuf, (char*)local_text, textpos, default_text_posn, image_width, image_height); draw_string(pixelbuf, (char*)local_text, textpos, default_text_posn, smalltext, image_width, image_height);
} }
error_number=png_to_file(symbol, image_height, image_width, pixelbuf, rotate_angle, data_type); error_number=png_to_file(symbol, image_height, image_width, pixelbuf, rotate_angle, data_type);

View File

@ -182,6 +182,7 @@ struct zint_symbol {
#define BARCODE_BOX 4 #define BARCODE_BOX 4
#define BARCODE_STDOUT 8 #define BARCODE_STDOUT 8
#define READER_INIT 16 #define READER_INIT 16
#define SMALL_TEXT 32
#define DATA_MODE 0 #define DATA_MODE 0
#define UNICODE_MODE 1 #define UNICODE_MODE 1

View File

@ -103,6 +103,7 @@ void usage(void)
" --notext Remove human readable text\n" " --notext Remove human readable text\n"
" --square Force Data Matrix symbols to be square\n" " --square Force Data Matrix symbols to be square\n"
" --init Create reader initialisation symbol (Code 128)\n" " --init Create reader initialisation symbol (Code 128)\n"
" --smalltext Use half-size text in PNG images\n"
, ZINT_VERSION); , ZINT_VERSION);
} }
@ -220,6 +221,7 @@ int main(int argc, char **argv)
{"notext", 0, 0, 0}, {"notext", 0, 0, 0},
{"square", 0, 0, 0}, {"square", 0, 0, 0},
{"init", 0, 0, 0}, {"init", 0, 0, 0},
{"smalltext", 0, 0, 0},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
c = getopt_long(argc, argv, "htb:w:d:o:i:rcmp", long_options, &option_index); c = getopt_long(argc, argv, "htb:w:d:o:i:rcmp", long_options, &option_index);
@ -236,6 +238,9 @@ int main(int argc, char **argv)
if(!strcmp(long_options[option_index].name, "init")) { if(!strcmp(long_options[option_index].name, "init")) {
my_symbol->output_options += READER_INIT; my_symbol->output_options += READER_INIT;
} }
if(!strcmp(long_options[option_index].name, "smalltext")) {
my_symbol->output_options += SMALL_TEXT;
}
if(!strcmp(long_options[option_index].name, "directeps")) { if(!strcmp(long_options[option_index].name, "directeps")) {
my_symbol->output_options += BARCODE_STDOUT; my_symbol->output_options += BARCODE_STDOUT;
strncpy(my_symbol->outfile, "dummy.eps", 10); strncpy(my_symbol->outfile, "dummy.eps", 10);