Skip to content

Commit

Permalink
Add font size option for SVG and EPS
Browse files Browse the repository at this point in the history
  • Loading branch information
woo-j committed Feb 11, 2018
1 parent 8bb4d2c commit 78d85bd
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 42 deletions.
1 change: 1 addition & 0 deletions backend/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ struct zint_symbol *ZBarcode_Create() {
symbol->option_2 = 0;
symbol->option_3 = 928; // PDF_MAX
symbol->show_hrt = 1; // Show human readable text
symbol->fontsize = 8;
symbol->input_mode = DATA_MODE;
strcpy(symbol->primary, "");
memset(&(symbol->encoded_data[0][0]), 0, sizeof (symbol->encoded_data));
Expand Down
43 changes: 22 additions & 21 deletions backend/ps.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ int ps_plot(struct zint_symbol *symbol) {
float scaler = symbol->scale;
float default_text_posn;
const char *locale = NULL;
float fontsize = symbol->fontsize * scaler;
#ifndef _MSC_VER
unsigned char local_text[ustrlen(symbol->text) + 1];
#else
Expand Down Expand Up @@ -518,7 +519,7 @@ int ps_plot(struct zint_symbol *symbol) {
}
fprintf(feps, "matrix currentmatrix\n");
fprintf(feps, "/Helvetica findfont\n");
fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
fprintf(feps, "%.2f scalefont setfont\n", (11.0 / 8.0) * fontsize);
textpos = 17;
fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", (textpos + xoffset) * scaler, default_text_posn);
fprintf(feps, " (%s) stringwidth\n", textpart);
Expand All @@ -532,7 +533,7 @@ int ps_plot(struct zint_symbol *symbol) {
textpart[4] = '\0';
fprintf(feps, "matrix currentmatrix\n");
fprintf(feps, "/Helvetica findfont\n");
fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
fprintf(feps, "%.2f scalefont setfont\n", (11.0 / 8.0) * fontsize);
textpos = 50;
fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", (textpos + xoffset) * scaler, default_text_posn);
fprintf(feps, " (%s) stringwidth\n", textpart);
Expand All @@ -545,7 +546,7 @@ int ps_plot(struct zint_symbol *symbol) {
case 2:
fprintf(feps, "matrix currentmatrix\n");
fprintf(feps, "/Helvetica findfont\n");
fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
fprintf(feps, "%.2f scalefont setfont\n", (11.0 / 8.0) * fontsize);
textpos = xoffset + 86;
fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", textpos * scaler, addon_text_posn * scaler);
fprintf(feps, " (%s) stringwidth\n", addon);
Expand All @@ -557,7 +558,7 @@ int ps_plot(struct zint_symbol *symbol) {
case 5:
fprintf(feps, "matrix currentmatrix\n");
fprintf(feps, "/Helvetica findfont\n");
fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
fprintf(feps, "%.2f scalefont setfont\n", (11.0 / 8.0) * fontsize);
textpos = xoffset + 100;
fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", textpos * scaler, addon_text_posn * scaler);
fprintf(feps, " (%s) stringwidth\n", addon);
Expand Down Expand Up @@ -595,7 +596,7 @@ int ps_plot(struct zint_symbol *symbol) {
}
fprintf(feps, "matrix currentmatrix\n");
fprintf(feps, "/Helvetica findfont\n");
fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
fprintf(feps, "%.2f scalefont setfont\n", (11.0 / 8.0) * fontsize);
textpos = -7;
fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", (textpos + xoffset) * scaler, default_text_posn);
fprintf(feps, " (%s) stringwidth\n", textpart);
Expand All @@ -609,7 +610,7 @@ int ps_plot(struct zint_symbol *symbol) {
textpart[6] = '\0';
fprintf(feps, "matrix currentmatrix\n");
fprintf(feps, "/Helvetica findfont\n");
fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
fprintf(feps, "%.2f scalefont setfont\n", (11.0 / 8.0) * fontsize);
textpos = 24;
fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", (textpos + xoffset) * scaler, default_text_posn);
fprintf(feps, " (%s) stringwidth\n", textpart);
Expand All @@ -623,7 +624,7 @@ int ps_plot(struct zint_symbol *symbol) {
textpart[6] = '\0';
fprintf(feps, "matrix currentmatrix\n");
fprintf(feps, "/Helvetica findfont\n");
fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
fprintf(feps, "%.2f scalefont setfont\n", (11.0 / 8.0) * fontsize);
textpos = 71;
fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", (textpos + xoffset) * scaler, default_text_posn);
fprintf(feps, " (%s) stringwidth\n", textpart);
Expand All @@ -636,7 +637,7 @@ int ps_plot(struct zint_symbol *symbol) {
case 2:
fprintf(feps, "matrix currentmatrix\n");
fprintf(feps, "/Helvetica findfont\n");
fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
fprintf(feps, "%.2f scalefont setfont\n", (11.0 / 8.0) * fontsize);
textpos = xoffset + 114;
fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", textpos * scaler, addon_text_posn * scaler);
fprintf(feps, " (%s) stringwidth\n", addon);
Expand All @@ -648,7 +649,7 @@ int ps_plot(struct zint_symbol *symbol) {
case 5:
fprintf(feps, "matrix currentmatrix\n");
fprintf(feps, "/Helvetica findfont\n");
fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
fprintf(feps, "%.2f scalefont setfont\n", (11.0 / 8.0) * fontsize);
textpos = xoffset + 128;
fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", textpos * scaler, addon_text_posn * scaler);
fprintf(feps, " (%s) stringwidth\n", addon);
Expand Down Expand Up @@ -719,7 +720,7 @@ int ps_plot(struct zint_symbol *symbol) {
}
fprintf(feps, "matrix currentmatrix\n");
fprintf(feps, "/Helvetica findfont\n");
fprintf(feps, "%.2f scalefont setfont\n", 8.0 * scaler);
fprintf(feps, "%.2f scalefont setfont\n", fontsize);
textpos = -5;
fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", (textpos + xoffset) * scaler, default_text_posn);
fprintf(feps, " (%s) stringwidth\n", textpart);
Expand All @@ -733,7 +734,7 @@ int ps_plot(struct zint_symbol *symbol) {
textpart[5] = '\0';
fprintf(feps, "matrix currentmatrix\n");
fprintf(feps, "/Helvetica findfont\n");
fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
fprintf(feps, "%.2f scalefont setfont\n", (11.0 / 8.0) * fontsize);
textpos = 27;
fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", (textpos + xoffset) * scaler, default_text_posn);
fprintf(feps, " (%s) stringwidth\n", textpart);
Expand All @@ -747,7 +748,7 @@ int ps_plot(struct zint_symbol *symbol) {
textpart[6] = '\0';
fprintf(feps, "matrix currentmatrix\n");
fprintf(feps, "/Helvetica findfont\n");
fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
fprintf(feps, "%.2f scalefont setfont\n", (11.0 / 8.0) * fontsize);
textpos = 68;
fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", (textpos + xoffset) * scaler, default_text_posn);
fprintf(feps, " (%s) stringwidth\n", textpart);
Expand All @@ -759,7 +760,7 @@ int ps_plot(struct zint_symbol *symbol) {
textpart[1] = '\0';
fprintf(feps, "matrix currentmatrix\n");
fprintf(feps, "/Helvetica findfont\n");
fprintf(feps, "%.2f scalefont setfont\n", 8.0 * scaler);
fprintf(feps, "%.2f scalefont setfont\n", fontsize);
textpos = 100;
fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", (textpos + xoffset) * scaler, default_text_posn);
fprintf(feps, " (%s) stringwidth\n", textpart);
Expand All @@ -772,7 +773,7 @@ int ps_plot(struct zint_symbol *symbol) {
case 2:
fprintf(feps, "matrix currentmatrix\n");
fprintf(feps, "/Helvetica findfont\n");
fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
fprintf(feps, "%.2f scalefont setfont\n", (11.0 / 8.0) * fontsize);
textpos = xoffset + 116;
fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", textpos * scaler, addon_text_posn * scaler);
fprintf(feps, " (%s) stringwidth\n", addon);
Expand All @@ -784,7 +785,7 @@ int ps_plot(struct zint_symbol *symbol) {
case 5:
fprintf(feps, "matrix currentmatrix\n");
fprintf(feps, "/Helvetica findfont\n");
fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
fprintf(feps, "%.2f scalefont setfont\n", (11.0 / 8.0) * fontsize);
textpos = xoffset + 130;
fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", textpos * scaler, addon_text_posn * scaler);
fprintf(feps, " (%s) stringwidth\n", addon);
Expand Down Expand Up @@ -817,7 +818,7 @@ int ps_plot(struct zint_symbol *symbol) {
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
fprintf(feps, "matrix currentmatrix\n");
fprintf(feps, "/Helvetica findfont\n");
fprintf(feps, "%.2f scalefont setfont\n", 8.0 * scaler);
fprintf(feps, "%.2f scalefont setfont\n", fontsize);
textpos = -5;
fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", (textpos + xoffset) * scaler, default_text_posn);
fprintf(feps, " (%s) stringwidth\n", textpart);
Expand All @@ -831,7 +832,7 @@ int ps_plot(struct zint_symbol *symbol) {
textpart[6] = '\0';
fprintf(feps, "matrix currentmatrix\n");
fprintf(feps, "/Helvetica findfont\n");
fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
fprintf(feps, "%.2f scalefont setfont\n", (11.0 / 8.0) * fontsize);
textpos = 24;
fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", (textpos + xoffset) * scaler, default_text_posn);
fprintf(feps, " (%s) stringwidth\n", textpart);
Expand All @@ -843,7 +844,7 @@ int ps_plot(struct zint_symbol *symbol) {
textpart[1] = '\0';
fprintf(feps, "matrix currentmatrix\n");
fprintf(feps, "/Helvetica findfont\n");
fprintf(feps, "%.2f scalefont setfont\n", 8.0 * scaler);
fprintf(feps, "%.2f scalefont setfont\n", fontsize);
textpos = 55;
fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", (textpos + xoffset) * scaler, default_text_posn);
fprintf(feps, " (%s) stringwidth\n", textpart);
Expand All @@ -856,7 +857,7 @@ int ps_plot(struct zint_symbol *symbol) {
case 2:
fprintf(feps, "matrix currentmatrix\n");
fprintf(feps, "/Helvetica findfont\n");
fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
fprintf(feps, "%.2f scalefont setfont\n", (11.0 / 8.0) * fontsize);
textpos = xoffset + 70;
fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", textpos * scaler, addon_text_posn * scaler);
fprintf(feps, " (%s) stringwidth\n", addon);
Expand All @@ -868,7 +869,7 @@ int ps_plot(struct zint_symbol *symbol) {
case 5:
fprintf(feps, "matrix currentmatrix\n");
fprintf(feps, "/Helvetica findfont\n");
fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
fprintf(feps, "%.2f scalefont setfont\n", (11.0 / 8.0) * fontsize);
textpos = xoffset + 84;
fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", textpos * scaler, addon_text_posn * scaler);
fprintf(feps, " (%s) stringwidth\n", addon);
Expand Down Expand Up @@ -947,7 +948,7 @@ int ps_plot(struct zint_symbol *symbol) {
}
fprintf(feps, "matrix currentmatrix\n");
fprintf(feps, "/Helvetica findfont\n");
fprintf(feps, "%.2f scalefont setfont\n", 8.0 * scaler);
fprintf(feps, "%.2f scalefont setfont\n", fontsize);
textpos = symbol->width / 2.0;
fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", (textpos + xoffset) * scaler, default_text_posn);
fprintf(feps, " (%s) stringwidth\n", local_text);
Expand Down
Loading

0 comments on commit 78d85bd

Please sign in to comment.