2016-07-20 10:02:39 +12:00
|
|
|
/* raster.c - Handles output to raster files */
|
|
|
|
|
|
|
|
/*
|
|
|
|
libzint - the open source barcode library
|
2020-04-04 07:40:59 +13:00
|
|
|
Copyright (C) 2009 - 2020 Robin Stuart <rstuart114@gmail.com>
|
2016-07-20 10:02:39 +12:00
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
|
2017-10-24 08:37:52 +13:00
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
2016-07-20 10:02:39 +12:00
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
2017-10-24 08:37:52 +13:00
|
|
|
documentation and/or other materials provided with the distribution.
|
2016-07-20 10:02:39 +12:00
|
|
|
3. Neither the name of the project nor the names of its contributors
|
|
|
|
may be used to endorse or promote products derived from this software
|
2017-10-24 08:37:52 +13:00
|
|
|
without specific prior written permission.
|
2016-07-20 10:02:39 +12:00
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
|
|
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
2017-10-24 08:37:52 +13:00
|
|
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
2016-07-20 10:02:39 +12:00
|
|
|
SUCH DAMAGE.
|
|
|
|
*/
|
2019-11-12 10:38:21 +13:00
|
|
|
/* vim: set ts=4 sw=4 et : */
|
2016-07-20 10:02:39 +12:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <io.h>
|
|
|
|
#endif
|
|
|
|
#include <string.h>
|
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
2017-10-24 08:37:52 +13:00
|
|
|
#include <malloc.h>
|
2016-07-20 10:02:39 +12:00
|
|
|
#endif /* _MSC_VER */
|
|
|
|
|
2016-08-09 10:18:55 +12:00
|
|
|
#include "font.h" /* Font for human readable text */
|
2016-07-20 10:02:39 +12:00
|
|
|
|
2016-10-28 05:50:10 +13:00
|
|
|
#define SSET "0123456789ABCDEF"
|
|
|
|
|
2020-01-07 09:01:48 +13:00
|
|
|
#define DEFAULT_INK '1'
|
|
|
|
#define DEFAULT_PAPER '0'
|
|
|
|
|
2016-07-20 10:02:39 +12:00
|
|
|
#ifndef NO_PNG
|
2019-12-19 13:37:55 +13:00
|
|
|
INTERNAL int png_pixel_plot(struct zint_symbol *symbol, char *pixelbuf);
|
2016-07-20 10:02:39 +12:00
|
|
|
#endif /* NO_PNG */
|
2019-12-19 13:37:55 +13:00
|
|
|
INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, char *pixelbuf);
|
|
|
|
INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, char *pixelbuf);
|
|
|
|
INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, char *pixelbuf);
|
|
|
|
INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, char *pixelbuf);
|
2016-07-20 10:02:39 +12:00
|
|
|
|
2020-01-07 09:01:48 +13:00
|
|
|
static const char ultra_colour[] = "WCBMRYGK";
|
|
|
|
|
2019-12-19 13:37:55 +13:00
|
|
|
static void buffer_plot(struct zint_symbol *symbol, char *pixelbuf) {
|
2016-10-02 22:45:47 +13:00
|
|
|
/* Place pixelbuffer into symbol */
|
|
|
|
int fgred, fggrn, fgblu, bgred, bggrn, bgblu;
|
|
|
|
int row, column, i;
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2020-03-30 01:42:33 +13:00
|
|
|
symbol->bitmap = (unsigned char *) malloc(symbol->bitmap_width * symbol->bitmap_height * 3);
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2016-10-02 22:45:47 +13:00
|
|
|
fgred = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]);
|
|
|
|
fggrn = (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]);
|
|
|
|
fgblu = (16 * ctoi(symbol->fgcolour[4])) + ctoi(symbol->fgcolour[5]);
|
|
|
|
bgred = (16 * ctoi(symbol->bgcolour[0])) + ctoi(symbol->bgcolour[1]);
|
|
|
|
bggrn = (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]);
|
|
|
|
bgblu = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]);
|
2020-03-30 01:42:33 +13:00
|
|
|
|
2016-10-02 22:45:47 +13:00
|
|
|
for (row = 0; row < symbol->bitmap_height; row++) {
|
|
|
|
for (column = 0; column < symbol->bitmap_width; column++) {
|
|
|
|
i = ((row * symbol->bitmap_width) + column) * 3;
|
2016-10-15 04:08:03 +13:00
|
|
|
switch (*(pixelbuf + (symbol->bitmap_width * row) + column)) {
|
2020-01-07 09:01:48 +13:00
|
|
|
case 'W': // White
|
|
|
|
symbol->bitmap[i] = 255;
|
|
|
|
symbol->bitmap[i + 1] = 255;
|
|
|
|
symbol->bitmap[i + 2] = 255;
|
|
|
|
break;
|
|
|
|
case 'C': // Cyan
|
|
|
|
symbol->bitmap[i] = 0;
|
|
|
|
symbol->bitmap[i + 1] = 255;
|
|
|
|
symbol->bitmap[i + 2] = 255;
|
|
|
|
break;
|
|
|
|
case 'B': // Blue
|
|
|
|
symbol->bitmap[i] = 0;
|
|
|
|
symbol->bitmap[i + 1] = 0;
|
|
|
|
symbol->bitmap[i + 2] = 255;
|
|
|
|
break;
|
|
|
|
case 'M': // Magenta
|
|
|
|
symbol->bitmap[i] = 255;
|
|
|
|
symbol->bitmap[i + 1] = 0;
|
|
|
|
symbol->bitmap[i + 2] = 255;
|
|
|
|
break;
|
|
|
|
case 'R': // Red
|
|
|
|
symbol->bitmap[i] = 255;
|
|
|
|
symbol->bitmap[i + 1] = 0;
|
|
|
|
symbol->bitmap[i + 2] = 0;
|
|
|
|
break;
|
|
|
|
case 'Y': // Yellow
|
|
|
|
symbol->bitmap[i] = 255;
|
|
|
|
symbol->bitmap[i + 1] = 255;
|
|
|
|
symbol->bitmap[i + 2] = 0;
|
|
|
|
break;
|
|
|
|
case 'G': // Green
|
|
|
|
symbol->bitmap[i] = 0;
|
|
|
|
symbol->bitmap[i + 1] = 255;
|
|
|
|
symbol->bitmap[i + 2] = 0;
|
|
|
|
break;
|
|
|
|
case 'K': // Black
|
|
|
|
symbol->bitmap[i] = 0;
|
|
|
|
symbol->bitmap[i + 1] = 0;
|
|
|
|
symbol->bitmap[i + 2] = 0;
|
|
|
|
break;
|
|
|
|
case DEFAULT_INK:
|
2016-10-02 22:45:47 +13:00
|
|
|
symbol->bitmap[i] = fgred;
|
|
|
|
symbol->bitmap[i + 1] = fggrn;
|
|
|
|
symbol->bitmap[i + 2] = fgblu;
|
|
|
|
break;
|
2020-01-07 09:01:48 +13:00
|
|
|
default: // DEFAULT_PAPER
|
2016-10-02 22:45:47 +13:00
|
|
|
symbol->bitmap[i] = bgred;
|
|
|
|
symbol->bitmap[i + 1] = bggrn;
|
|
|
|
symbol->bitmap[i + 2] = bgblu;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-19 13:37:55 +13:00
|
|
|
static int save_raster_image_to_file(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle, int image_type) {
|
2016-07-20 10:02:39 +12:00
|
|
|
int error_number;
|
2016-09-11 19:42:31 +12:00
|
|
|
int row, column;
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2016-10-28 05:50:10 +13:00
|
|
|
char *rotated_pixbuf;
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2016-10-28 05:50:10 +13:00
|
|
|
if (!(rotated_pixbuf = (char *) malloc(image_width * image_height))) {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "650: Insufficient memory for pixel buffer");
|
2016-10-28 05:50:10 +13:00
|
|
|
return ZINT_ERROR_ENCODING_PROBLEM;
|
|
|
|
}
|
2016-07-20 10:02:39 +12:00
|
|
|
|
2016-09-11 19:42:31 +12:00
|
|
|
switch (rotate_angle) {
|
|
|
|
case 0:
|
|
|
|
case 180:
|
|
|
|
symbol->bitmap_width = image_width;
|
|
|
|
symbol->bitmap_height = image_height;
|
|
|
|
break;
|
|
|
|
case 90:
|
|
|
|
case 270:
|
|
|
|
symbol->bitmap_width = image_height;
|
|
|
|
symbol->bitmap_height = image_width;
|
|
|
|
break;
|
|
|
|
}
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2016-09-11 19:42:31 +12:00
|
|
|
/* sort out colour options */
|
|
|
|
to_upper((unsigned char*) symbol->fgcolour);
|
|
|
|
to_upper((unsigned char*) symbol->bgcolour);
|
|
|
|
|
|
|
|
if (strlen(symbol->fgcolour) != 6) {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "651: Malformed foreground colour target");
|
2017-06-29 07:46:29 +12:00
|
|
|
free(rotated_pixbuf);
|
2016-09-11 19:42:31 +12:00
|
|
|
return ZINT_ERROR_INVALID_OPTION;
|
|
|
|
}
|
|
|
|
if (strlen(symbol->bgcolour) != 6) {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "652: Malformed background colour target");
|
2017-06-29 07:46:29 +12:00
|
|
|
free(rotated_pixbuf);
|
2016-09-11 19:42:31 +12:00
|
|
|
return ZINT_ERROR_INVALID_OPTION;
|
|
|
|
}
|
|
|
|
error_number = is_sane(SSET, (unsigned char*) symbol->fgcolour, strlen(symbol->fgcolour));
|
|
|
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "653: Malformed foreground colour target");
|
2017-06-29 07:46:29 +12:00
|
|
|
free(rotated_pixbuf);
|
2016-09-11 19:42:31 +12:00
|
|
|
return ZINT_ERROR_INVALID_OPTION;
|
|
|
|
}
|
|
|
|
error_number = is_sane(SSET, (unsigned char*) symbol->bgcolour, strlen(symbol->fgcolour));
|
|
|
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "654: Malformed background colour target");
|
2017-06-29 07:46:29 +12:00
|
|
|
free(rotated_pixbuf);
|
2016-09-11 19:42:31 +12:00
|
|
|
return ZINT_ERROR_INVALID_OPTION;
|
|
|
|
}
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2016-09-11 19:42:31 +12:00
|
|
|
/* Rotate image before plotting */
|
|
|
|
switch (rotate_angle) {
|
|
|
|
case 0: /* Plot the right way up */
|
|
|
|
for (row = 0; row < image_height; row++) {
|
|
|
|
for (column = 0; column < image_width; column++) {
|
|
|
|
rotated_pixbuf[(row * image_width) + column] =
|
2016-10-28 05:50:10 +13:00
|
|
|
pixelbuf[(image_width * row) + column];
|
2016-09-11 19:42:31 +12:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 90: /* Plot 90 degrees clockwise */
|
|
|
|
for (row = 0; row < image_width; row++) {
|
|
|
|
for (column = 0; column < image_height; column++) {
|
|
|
|
rotated_pixbuf[(row * image_height) + column] =
|
|
|
|
*(pixelbuf + (image_width * (image_height - column - 1)) + row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 180: /* Plot upside down */
|
|
|
|
for (row = 0; row < image_height; row++) {
|
|
|
|
for (column = 0; column < image_width; column++) {
|
|
|
|
rotated_pixbuf[(row * image_width) + column] =
|
|
|
|
*(pixelbuf + (image_width * (image_height - row - 1)) + (image_width - column - 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 270: /* Plot 90 degrees anti-clockwise */
|
|
|
|
for (row = 0; row < image_width; row++) {
|
|
|
|
for (column = 0; column < image_height; column++) {
|
|
|
|
rotated_pixbuf[(row * image_height) + column] =
|
|
|
|
*(pixelbuf + (image_width * column) + (image_width - row - 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2016-08-09 10:18:55 +12:00
|
|
|
switch (image_type) {
|
2016-10-02 22:45:47 +13:00
|
|
|
case OUT_BUFFER:
|
|
|
|
buffer_plot(symbol, rotated_pixbuf);
|
|
|
|
error_number = 0;
|
|
|
|
break;
|
2016-07-24 02:08:55 +12:00
|
|
|
case OUT_PNG_FILE:
|
2016-07-20 10:02:39 +12:00
|
|
|
#ifndef NO_PNG
|
2016-09-11 19:42:31 +12:00
|
|
|
error_number = png_pixel_plot(symbol, rotated_pixbuf);
|
2016-07-20 10:02:39 +12:00
|
|
|
#else
|
2017-06-29 07:46:29 +12:00
|
|
|
free(rotated_pixbuf);
|
2016-07-24 02:08:55 +12:00
|
|
|
return ZINT_ERROR_INVALID_OPTION;
|
2016-07-20 10:02:39 +12:00
|
|
|
#endif
|
2016-07-24 02:08:55 +12:00
|
|
|
break;
|
|
|
|
case OUT_PCX_FILE:
|
2016-09-11 19:42:31 +12:00
|
|
|
error_number = pcx_pixel_plot(symbol, rotated_pixbuf);
|
2016-08-09 10:18:55 +12:00
|
|
|
break;
|
|
|
|
case OUT_GIF_FILE:
|
2016-09-11 19:42:31 +12:00
|
|
|
error_number = gif_pixel_plot(symbol, rotated_pixbuf);
|
2016-07-24 02:08:55 +12:00
|
|
|
break;
|
2016-12-31 09:25:58 +13:00
|
|
|
case OUT_TIF_FILE:
|
|
|
|
error_number = tif_pixel_plot(symbol, rotated_pixbuf);
|
|
|
|
break;
|
2016-07-24 02:08:55 +12:00
|
|
|
default:
|
2016-09-11 19:42:31 +12:00
|
|
|
error_number = bmp_pixel_plot(symbol, rotated_pixbuf);
|
2016-07-24 02:08:55 +12:00
|
|
|
break;
|
2016-07-20 10:02:39 +12:00
|
|
|
}
|
|
|
|
|
2016-10-28 05:50:10 +13:00
|
|
|
free(rotated_pixbuf);
|
2016-07-20 10:02:39 +12:00
|
|
|
return error_number;
|
|
|
|
}
|
|
|
|
|
2020-04-07 04:05:22 +12:00
|
|
|
static void draw_bar(char *pixelbuf, int xpos, int xlen, int ypos, int ylen, int image_width, int image_height, char fill) {
|
2016-07-20 10:02:39 +12:00
|
|
|
/* Draw a rectangle */
|
|
|
|
int i, j, png_ypos;
|
|
|
|
|
|
|
|
png_ypos = image_height - ypos - ylen;
|
|
|
|
/* This fudge is needed because EPS measures height from the bottom up but
|
|
|
|
PNG measures y position from the top down */
|
|
|
|
|
|
|
|
for (i = (xpos); i < (xpos + xlen); i++) {
|
|
|
|
for (j = (png_ypos); j < (png_ypos + ylen); j++) {
|
2020-01-07 09:01:48 +13:00
|
|
|
*(pixelbuf + (image_width * j) + i) = fill;
|
2016-07-20 10:02:39 +12:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-19 13:37:55 +13:00
|
|
|
static void draw_circle(char *pixelbuf, int image_width, int image_height, int x0, int y0, float radius, char fill) {
|
2016-09-13 08:47:40 +12:00
|
|
|
int x, y;
|
2016-09-19 01:09:58 +12:00
|
|
|
int radius_i = (int) radius;
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2016-09-19 01:09:58 +12:00
|
|
|
for (y = -radius_i; y <= radius_i; y++) {
|
|
|
|
for (x = -radius_i; x <= radius_i; x++) {
|
|
|
|
if ((x * x) + (y * y) <= (radius_i * radius_i)) {
|
2016-09-13 08:47:40 +12:00
|
|
|
if ((y + y0 >= 0) && (y + y0 < image_height)
|
|
|
|
&& (x + x0 >= 0) && (x + x0 < image_width)) {
|
|
|
|
*(pixelbuf + ((y + y0) * image_width) + (x + x0)) = fill;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-19 13:37:55 +13:00
|
|
|
static void draw_bullseye(char *pixelbuf, int image_width, int image_height, int xoffset, int yoffset, int scaler) {
|
2019-09-02 22:05:08 +12:00
|
|
|
/* Central bullseye in Maxicode symbols */
|
2019-09-02 21:26:30 +12:00
|
|
|
float x = 14.5 * scaler;
|
|
|
|
float y = 15.0 * scaler;
|
|
|
|
if(scaler < 10) {
|
|
|
|
x = 16.0 * scaler;
|
|
|
|
y = 16.5 * scaler;
|
|
|
|
}
|
2020-01-07 09:01:48 +13:00
|
|
|
|
|
|
|
draw_circle(pixelbuf, image_width, image_height, x + xoffset, y + yoffset, (4.571 * scaler) + 1, DEFAULT_INK);
|
|
|
|
draw_circle(pixelbuf, image_width, image_height, x + xoffset, y + yoffset, (3.779 * scaler) + 1, DEFAULT_PAPER);
|
|
|
|
draw_circle(pixelbuf, image_width, image_height, x + xoffset, y + yoffset, (2.988 * scaler) + 1, DEFAULT_INK);
|
|
|
|
draw_circle(pixelbuf, image_width, image_height, x + xoffset, y + yoffset, (2.196 * scaler) + 1, DEFAULT_PAPER);
|
|
|
|
draw_circle(pixelbuf, image_width, image_height, x + xoffset, y + yoffset, (1.394 * scaler) + 1, DEFAULT_INK);
|
|
|
|
draw_circle(pixelbuf, image_width, image_height, x + xoffset, y + yoffset, (0.602 * scaler) + 1, DEFAULT_PAPER);
|
2016-07-20 10:02:39 +12:00
|
|
|
}
|
|
|
|
|
2019-12-19 13:37:55 +13:00
|
|
|
static void draw_hexagon(char *pixelbuf, int image_width, char *scaled_hexagon, int hexagon_size, int xposn, int yposn) {
|
2016-07-20 10:02:39 +12:00
|
|
|
/* Put a hexagon into the pixel buffer */
|
|
|
|
int i, j;
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2016-10-28 05:50:10 +13:00
|
|
|
for (i = 0; i < hexagon_size; i++) {
|
|
|
|
for (j = 0; j < hexagon_size; j++) {
|
2020-01-07 09:01:48 +13:00
|
|
|
if (scaled_hexagon[(i * hexagon_size) + j] == DEFAULT_INK) {
|
|
|
|
*(pixelbuf + (image_width * i) + (image_width * yposn) + xposn + j) = DEFAULT_INK;
|
2016-07-20 10:02:39 +12:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-19 13:37:55 +13:00
|
|
|
static void draw_letter(char *pixelbuf, unsigned char letter, int xposn, int yposn, int textflags, int image_width, int image_height) {
|
2016-07-20 10:02:39 +12:00
|
|
|
/* Put a letter into a position */
|
2017-09-11 03:03:09 +12:00
|
|
|
int skip;
|
2016-07-20 10:02:39 +12:00
|
|
|
|
|
|
|
skip = 0;
|
|
|
|
|
|
|
|
if (letter < 33) {
|
|
|
|
skip = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((letter > 127) && (letter < 161)) {
|
|
|
|
skip = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xposn < 0 || yposn < 0) {
|
|
|
|
skip = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (skip == 0) {
|
2017-09-11 03:03:09 +12:00
|
|
|
int glyph_no;
|
2017-10-24 08:34:31 +13:00
|
|
|
int x, y;
|
2016-07-20 10:02:39 +12:00
|
|
|
if (letter > 128) {
|
|
|
|
glyph_no = letter - 66;
|
|
|
|
} else {
|
|
|
|
glyph_no = letter - 33;
|
|
|
|
}
|
2016-08-09 10:18:55 +12:00
|
|
|
|
|
|
|
|
2016-07-20 10:02:39 +12:00
|
|
|
switch (textflags) {
|
2017-09-11 03:03:09 +12:00
|
|
|
int max_x, max_y;
|
2016-08-09 10:18:55 +12:00
|
|
|
case 1: // small font 5x9
|
|
|
|
max_x = 5;
|
|
|
|
max_y = 9;
|
2016-07-20 10:02:39 +12:00
|
|
|
|
2016-08-09 10:18:55 +12:00
|
|
|
if (xposn + max_x >= image_width) {
|
|
|
|
max_x = image_width - xposn - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (yposn + max_y >= image_height) {
|
|
|
|
max_y = image_height - yposn - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (y = 0; y < max_y; y++) {
|
|
|
|
for (x = 0; x < max_x; x++) {
|
|
|
|
if (small_font[(glyph_no * 9) + y] & (0x10 >> x)) {
|
2020-01-07 09:01:48 +13:00
|
|
|
*(pixelbuf + (y * image_width) + (yposn * image_width) + xposn + x) = DEFAULT_INK;
|
2016-08-09 10:18:55 +12:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: // bold font -> twice the regular font
|
|
|
|
{
|
|
|
|
char * linePtr;
|
|
|
|
max_x = 7;
|
|
|
|
max_y = 14;
|
2016-07-20 10:02:39 +12:00
|
|
|
|
2016-08-09 10:18:55 +12:00
|
|
|
if (xposn + max_x + 1 >= image_width) {
|
|
|
|
max_x = image_width - xposn - 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (yposn + max_y >= image_height) {
|
|
|
|
max_y = image_height - yposn - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
linePtr = pixelbuf + (yposn * image_width) + xposn + 1;
|
|
|
|
for (y = 0; y < max_y; y++) {
|
|
|
|
char * pixelPtr = linePtr;
|
|
|
|
int extra_dot = 0;
|
|
|
|
for (x = 0; x < 7; x++) {
|
|
|
|
if (ascii_font[(glyph_no * 14) + y] & (0x40 >> x)) {
|
2020-01-07 09:01:48 +13:00
|
|
|
*pixelPtr = DEFAULT_INK;
|
2016-08-09 10:18:55 +12:00
|
|
|
extra_dot = 1;
|
|
|
|
} else {
|
|
|
|
if (extra_dot) {
|
2020-01-07 09:01:48 +13:00
|
|
|
*pixelPtr = DEFAULT_INK;
|
2016-08-09 10:18:55 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
extra_dot = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
++pixelPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (extra_dot) {
|
2020-01-07 09:01:48 +13:00
|
|
|
*pixelPtr = DEFAULT_INK;
|
2016-08-09 10:18:55 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
linePtr += image_width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: // regular font 7x15
|
|
|
|
max_x = 7;
|
|
|
|
max_y = 14;
|
2016-07-20 10:02:39 +12:00
|
|
|
|
2016-08-09 10:18:55 +12:00
|
|
|
if (xposn + max_x >= image_width) {
|
|
|
|
max_x = image_width - xposn - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (yposn + max_y >= image_height) {
|
|
|
|
max_y = image_height - yposn - 1;
|
|
|
|
}
|
2016-07-20 10:02:39 +12:00
|
|
|
|
2016-08-09 10:18:55 +12:00
|
|
|
for (y = 0; y < max_y; y++) {
|
|
|
|
for (x = 0; x < 7; x++) {
|
|
|
|
if (ascii_font[(glyph_no * 14) + y] & (0x40 >> x)) {
|
2020-01-07 09:01:48 +13:00
|
|
|
*(pixelbuf + (y * image_width) + (yposn * image_width) + xposn + x) = DEFAULT_INK;
|
2016-08-09 10:18:55 +12:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2016-07-20 10:02:39 +12:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Plot a string into the pixel buffer */
|
2019-12-19 13:37:55 +13:00
|
|
|
static void draw_string(char *pixbuf, char input_string[], int xposn, int yposn, int textflags, int image_width, int image_height) {
|
2016-07-20 10:02:39 +12:00
|
|
|
int i, string_length, string_left_hand, letter_width = 7;
|
|
|
|
|
|
|
|
switch (textflags) {
|
2016-08-09 10:18:55 +12:00
|
|
|
case 1: // small font 5x9
|
|
|
|
letter_width = 5;
|
|
|
|
break;
|
2016-07-20 10:02:39 +12:00
|
|
|
|
2016-08-09 10:18:55 +12:00
|
|
|
case 2: // bold font -> width of the regular font + 1 extra dot + 1 extra space
|
|
|
|
letter_width = 9;
|
|
|
|
break;
|
2016-07-20 10:02:39 +12:00
|
|
|
|
2016-08-09 10:18:55 +12:00
|
|
|
default: // regular font 7x15
|
|
|
|
letter_width = 7;
|
|
|
|
break;
|
2016-07-20 10:02:39 +12:00
|
|
|
}
|
2016-08-09 10:18:55 +12:00
|
|
|
|
2016-07-20 10:02:39 +12:00
|
|
|
string_length = strlen(input_string);
|
|
|
|
string_left_hand = xposn - ((letter_width * string_length) / 2);
|
|
|
|
|
|
|
|
for (i = 0; i < string_length; i++) {
|
|
|
|
draw_letter(pixbuf, input_string[i], string_left_hand + (i * letter_width), yposn, textflags, image_width, image_height);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-12-19 13:37:55 +13:00
|
|
|
static void plot_hexline(char *scaled_hexagon, int hexagon_size, float start_x, float start_y, float end_x, float end_y) {
|
2016-10-28 05:50:10 +13:00
|
|
|
/* Draw a straight line from start to end */
|
|
|
|
int i;
|
|
|
|
float inc_x, inc_y;
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2016-10-28 05:50:10 +13:00
|
|
|
inc_x = (end_x - start_x) / hexagon_size;
|
|
|
|
inc_y = (end_y - start_y) / hexagon_size;
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2016-10-28 05:50:10 +13:00
|
|
|
for (i = 0; i < hexagon_size; i++) {
|
2017-09-11 03:03:09 +12:00
|
|
|
float this_x = start_x + ((float)i * inc_x);
|
|
|
|
float this_y = start_y + ((float)i * inc_y);
|
2016-10-28 05:50:10 +13:00
|
|
|
if (((this_x >= 0) && (this_x < hexagon_size)) && ((this_y >= 0) && (this_y < hexagon_size))) {
|
2020-01-07 09:01:48 +13:00
|
|
|
scaled_hexagon[(hexagon_size * (int)this_y) + (int)this_x] = DEFAULT_INK;
|
2016-10-28 05:50:10 +13:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-19 13:37:55 +13:00
|
|
|
static void plot_hexagon(char *scaled_hexagon, int hexagon_size) {
|
2016-10-28 05:50:10 +13:00
|
|
|
/* Create a hexagon shape and fill it */
|
|
|
|
int line, i;
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2016-10-28 05:50:10 +13:00
|
|
|
float x_offset[6];
|
|
|
|
float y_offset[6];
|
|
|
|
float start_x, start_y;
|
|
|
|
float end_x, end_y;
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2016-10-28 05:50:10 +13:00
|
|
|
x_offset[0] = 0.0;
|
|
|
|
x_offset[1] = 0.86;
|
|
|
|
x_offset[2] = 0.86;
|
|
|
|
x_offset[3] = 0.0;
|
|
|
|
x_offset[4] = -0.86;
|
|
|
|
x_offset[5] = -0.86;
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2016-10-28 05:50:10 +13:00
|
|
|
y_offset[0] = 1.0;
|
|
|
|
y_offset[1] = 0.5;
|
|
|
|
y_offset[2] = -0.5;
|
|
|
|
y_offset[3] = -1.0;
|
|
|
|
y_offset[4] = -0.5;
|
|
|
|
y_offset[5] = 0.5;
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2016-10-28 05:50:10 +13:00
|
|
|
/* Plot hexagon outline */
|
|
|
|
for (line = 0; line < 5; line++) {
|
|
|
|
start_x = ((float)hexagon_size / 2.0) + (((float)hexagon_size / 2.0) * x_offset[line]);
|
|
|
|
start_y = ((float)hexagon_size / 2.0) + (((float)hexagon_size / 2.0) * y_offset[line]);
|
|
|
|
end_x = ((float)hexagon_size / 2.0) + (((float)hexagon_size / 2.0) * x_offset[line + 1]);
|
|
|
|
end_y = ((float)hexagon_size / 2.0) + (((float)hexagon_size / 2.0) * y_offset[line + 1]);
|
|
|
|
plot_hexline(scaled_hexagon, hexagon_size, start_x, start_y, end_x, end_y);
|
|
|
|
}
|
|
|
|
start_x = ((float)hexagon_size / 2.0) + (((float)hexagon_size / 2.0) * x_offset[line]);
|
|
|
|
start_y = ((float)hexagon_size / 2.0) + (((float)hexagon_size / 2.0) * y_offset[line]);
|
|
|
|
end_x = ((float)hexagon_size / 2.0) + (((float)hexagon_size / 2.0) * x_offset[0]);
|
|
|
|
end_y = ((float)hexagon_size / 2.0) + (((float)hexagon_size / 2.0) * y_offset[0]);
|
|
|
|
plot_hexline(scaled_hexagon, hexagon_size, start_x, start_y, end_x, end_y);
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2016-10-28 05:50:10 +13:00
|
|
|
/* Fill hexagon */
|
|
|
|
for (line = 0; line < hexagon_size; line++) {
|
2020-01-07 09:01:48 +13:00
|
|
|
char ink = DEFAULT_PAPER;
|
2016-10-28 05:50:10 +13:00
|
|
|
for (i = 0; i < hexagon_size; i++) {
|
2020-01-07 09:01:48 +13:00
|
|
|
if (scaled_hexagon[(hexagon_size * line) + i] == DEFAULT_INK) {
|
2016-10-28 05:50:10 +13:00
|
|
|
if (i < (hexagon_size / 2)) {
|
2020-01-07 09:01:48 +13:00
|
|
|
ink = DEFAULT_INK;
|
2016-10-28 05:50:10 +13:00
|
|
|
} else {
|
2020-01-07 09:01:48 +13:00
|
|
|
ink = DEFAULT_PAPER;
|
2016-10-28 05:50:10 +13:00
|
|
|
}
|
|
|
|
}
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2020-01-07 09:01:48 +13:00
|
|
|
if (ink == DEFAULT_INK) {
|
2016-10-28 05:50:10 +13:00
|
|
|
scaled_hexagon[(hexagon_size * line) + i] = ink;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-19 13:37:55 +13:00
|
|
|
static int plot_raster_maxicode(struct zint_symbol *symbol, int rotate_angle, int data_type) {
|
2016-10-28 05:50:10 +13:00
|
|
|
/* Plot a MaxiCode symbol with hexagons and bullseye */
|
2017-09-11 03:03:09 +12:00
|
|
|
int i, row, column, xposn;
|
2016-07-20 10:02:39 +12:00
|
|
|
int image_height, image_width;
|
|
|
|
char *pixelbuf;
|
|
|
|
int error_number;
|
|
|
|
int xoffset, yoffset;
|
2016-08-09 10:18:55 +12:00
|
|
|
float scaler = symbol->scale;
|
2016-10-28 05:50:10 +13:00
|
|
|
char *scaled_hexagon;
|
|
|
|
int hexagon_size;
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2016-07-20 10:02:39 +12:00
|
|
|
xoffset = symbol->border_width + symbol->whitespace_width;
|
|
|
|
yoffset = symbol->border_width;
|
2016-10-28 05:50:10 +13:00
|
|
|
image_width = (300 + (2 * xoffset * 2)) * scaler;
|
|
|
|
image_height = (300 + (2 * yoffset * 2)) * scaler;
|
2016-07-20 10:02:39 +12:00
|
|
|
|
|
|
|
if (!(pixelbuf = (char *) malloc(image_width * image_height))) {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "655: Insufficient memory for pixel buffer");
|
2016-07-20 10:02:39 +12:00
|
|
|
return ZINT_ERROR_ENCODING_PROBLEM;
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < (image_width * image_height); i++) {
|
2020-01-07 09:01:48 +13:00
|
|
|
*(pixelbuf + i) = DEFAULT_PAPER;
|
2016-07-20 10:02:39 +12:00
|
|
|
}
|
|
|
|
}
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2019-03-17 04:47:08 +13:00
|
|
|
hexagon_size = (int)(scaler * 10);
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2016-10-28 05:50:10 +13:00
|
|
|
if (!(scaled_hexagon = (char *) malloc(hexagon_size * hexagon_size))) {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "656: Insufficient memory for pixel buffer");
|
2017-06-29 07:46:29 +12:00
|
|
|
free(pixelbuf);
|
2016-10-28 05:50:10 +13:00
|
|
|
return ZINT_ERROR_ENCODING_PROBLEM;
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < (hexagon_size * hexagon_size); i++) {
|
2020-01-07 09:01:48 +13:00
|
|
|
*(scaled_hexagon + i) = DEFAULT_PAPER;
|
2016-10-28 05:50:10 +13:00
|
|
|
}
|
|
|
|
}
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2016-10-28 05:50:10 +13:00
|
|
|
plot_hexagon(scaled_hexagon, hexagon_size);
|
2016-07-20 10:02:39 +12:00
|
|
|
|
|
|
|
for (row = 0; row < symbol->rows; row++) {
|
2017-09-11 03:03:09 +12:00
|
|
|
int yposn = row * 9;
|
2016-07-20 10:02:39 +12:00
|
|
|
for (column = 0; column < symbol->width; column++) {
|
|
|
|
xposn = column * 10;
|
|
|
|
if (module_is_set(symbol, row, column)) {
|
|
|
|
if (row & 1) {
|
|
|
|
/* Odd (reduced) row */
|
|
|
|
xposn += 5;
|
2016-10-28 05:50:10 +13:00
|
|
|
draw_hexagon(pixelbuf, image_width, scaled_hexagon, hexagon_size, (xposn + (2 * xoffset)) * scaler, (yposn + (2 * yoffset)) * scaler);
|
2016-07-20 10:02:39 +12:00
|
|
|
} else {
|
|
|
|
/* Even (full) row */
|
2016-10-28 05:50:10 +13:00
|
|
|
draw_hexagon(pixelbuf, image_width, scaled_hexagon, hexagon_size, (xposn + (2 * xoffset)) * scaler, (yposn + (2 * yoffset)) * scaler);
|
2016-07-20 10:02:39 +12:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2019-09-02 22:05:08 +12:00
|
|
|
draw_bullseye(pixelbuf, image_width, image_height, (2.0 * xoffset), (2.0 * yoffset), scaler * 10);
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2017-10-09 23:17:11 +13:00
|
|
|
// Virtual hexagon
|
|
|
|
//draw_hexagon(pixelbuf, image_width, scaled_hexagon, hexagon_size, ((14 * 10) + (2 * xoffset)) * scaler, ((16 * 9) + (2 * yoffset)) * scaler);
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2016-08-27 02:13:40 +12:00
|
|
|
if ((symbol->output_options & BARCODE_BOX) || (symbol->output_options & BARCODE_BIND)) {
|
2016-07-20 10:02:39 +12:00
|
|
|
/* boundary bars */
|
2020-01-07 09:01:48 +13:00
|
|
|
draw_bar(pixelbuf, 0, image_width, 0, symbol->border_width * 2, image_width, image_height, DEFAULT_INK);
|
|
|
|
draw_bar(pixelbuf, 0, image_width, 300 + (symbol->border_width * 2), symbol->border_width * 2, image_width, image_height, DEFAULT_INK);
|
2016-07-20 10:02:39 +12:00
|
|
|
}
|
|
|
|
|
2016-08-27 02:13:40 +12:00
|
|
|
if (symbol->output_options & BARCODE_BOX) {
|
2016-07-20 10:02:39 +12:00
|
|
|
/* side bars */
|
2020-01-07 09:01:48 +13:00
|
|
|
draw_bar(pixelbuf, 0, symbol->border_width * 2, 0, image_height, image_width, image_height, DEFAULT_INK);
|
|
|
|
draw_bar(pixelbuf, 300 + ((symbol->border_width + symbol->whitespace_width + symbol->whitespace_width) * 2), symbol->border_width * 2, 0, image_height, image_width, image_height, DEFAULT_INK);
|
2016-07-20 10:02:39 +12:00
|
|
|
}
|
|
|
|
|
2016-10-28 05:50:10 +13:00
|
|
|
error_number = save_raster_image_to_file(symbol, image_height, image_width, pixelbuf, rotate_angle, data_type);
|
|
|
|
free(scaled_hexagon);
|
2016-07-20 10:02:39 +12:00
|
|
|
free(pixelbuf);
|
|
|
|
return error_number;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert UTF-8 to Latin1 Codepage for the interpretation line */
|
2019-12-19 13:37:55 +13:00
|
|
|
static void to_latin1(unsigned char source[], unsigned char preprocessed[]) {
|
2016-07-20 10:02:39 +12:00
|
|
|
int j, i, input_length;
|
|
|
|
|
|
|
|
input_length = ustrlen(source);
|
|
|
|
|
|
|
|
j = 0;
|
|
|
|
i = 0;
|
|
|
|
while (i < input_length) {
|
|
|
|
switch (source[i]) {
|
|
|
|
case 0xC2:
|
|
|
|
/* UTF-8 C2xxh */
|
|
|
|
/* Character range: C280h (latin: 80h) to C2BFh (latin: BFh) */
|
|
|
|
i++;
|
|
|
|
preprocessed[j] = source[i];
|
|
|
|
j++;
|
|
|
|
break;
|
|
|
|
case 0xC3:
|
|
|
|
/* UTF-8 C3xx */
|
|
|
|
/* Character range: C380h (latin: C0h) to C3BFh (latin: FFh) */
|
|
|
|
i++;
|
|
|
|
preprocessed[j] = source[i] + 64;
|
|
|
|
j++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Process ASCII (< 80h), all other unicode points are ignored */
|
|
|
|
if (source[i] < 128) {
|
|
|
|
preprocessed[j] = source[i];
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
preprocessed[j] = '\0';
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-19 13:37:55 +13:00
|
|
|
static int plot_raster_dotty(struct zint_symbol *symbol, int rotate_angle, int data_type) {
|
2016-08-09 10:18:55 +12:00
|
|
|
float scaler = 2 * symbol->scale;
|
|
|
|
char *scaled_pixelbuf;
|
|
|
|
int r, i;
|
|
|
|
int scale_width, scale_height;
|
|
|
|
int error_number = 0;
|
|
|
|
int xoffset, yoffset, image_width, image_height;
|
|
|
|
|
|
|
|
symbol->height = symbol->rows; // This is true because only 2d matrix symbols are processed here
|
|
|
|
|
|
|
|
xoffset = symbol->border_width + symbol->whitespace_width;
|
|
|
|
yoffset = symbol->border_width;
|
|
|
|
image_width = symbol->width + xoffset + xoffset;
|
|
|
|
image_height = symbol->height + yoffset + yoffset;
|
|
|
|
|
|
|
|
if (scaler < 2.0) {
|
|
|
|
scaler = 2.0;
|
|
|
|
}
|
|
|
|
scale_width = (image_width * scaler) + 1;
|
|
|
|
scale_height = (image_height * scaler) + 1;
|
|
|
|
|
|
|
|
/* Apply scale options by creating another pixel buffer */
|
|
|
|
if (!(scaled_pixelbuf = (char *) malloc(scale_width * scale_height))) {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "657: Insufficient memory for pixel buffer");
|
2016-08-09 10:18:55 +12:00
|
|
|
return ZINT_ERROR_ENCODING_PROBLEM;
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < (scale_width * scale_height); i++) {
|
2020-01-07 09:01:48 +13:00
|
|
|
*(scaled_pixelbuf + i) = DEFAULT_PAPER;
|
2016-08-09 10:18:55 +12:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Plot the body of the symbol to the pixel buffer */
|
|
|
|
for (r = 0; r < symbol->rows; r++) {
|
|
|
|
for (i = 0; i < symbol->width; i++) {
|
|
|
|
if (module_is_set(symbol, r, i)) {
|
|
|
|
draw_circle(scaled_pixelbuf, scale_width, scale_height,
|
|
|
|
(int) ((i + xoffset) * scaler) + (scaler / 2.0),
|
|
|
|
(int) ((r + yoffset) * scaler) + (scaler / 2.0),
|
2016-09-19 01:09:58 +12:00
|
|
|
(symbol->dot_size / 2.0) * scaler,
|
2020-01-07 09:01:48 +13:00
|
|
|
DEFAULT_INK);
|
2016-08-09 10:18:55 +12:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
error_number = save_raster_image_to_file(symbol, scale_height, scale_width, scaled_pixelbuf, rotate_angle, data_type);
|
|
|
|
free(scaled_pixelbuf);
|
|
|
|
|
|
|
|
return error_number;
|
|
|
|
}
|
|
|
|
|
2019-12-19 13:37:55 +13:00
|
|
|
static int plot_raster_default(struct zint_symbol *symbol, int rotate_angle, int data_type) {
|
2016-07-20 10:02:39 +12:00
|
|
|
int textdone, main_width, comp_offset, large_bar_count;
|
|
|
|
char textpart[10], addon[6];
|
|
|
|
float addon_text_posn, preset_height, large_bar_height;
|
|
|
|
int i, r, textoffset, yoffset, xoffset, latch, image_width, image_height;
|
|
|
|
char *pixelbuf;
|
|
|
|
int addon_latch = 0, textflags = 0;
|
2017-09-11 03:03:09 +12:00
|
|
|
int block_width, textpos;
|
2016-07-20 10:02:39 +12:00
|
|
|
float row_height, row_posn;
|
|
|
|
int error_number;
|
|
|
|
int default_text_posn;
|
|
|
|
int next_yposn;
|
2016-08-09 10:18:55 +12:00
|
|
|
float scaler = symbol->scale;
|
|
|
|
char *scaled_pixelbuf;
|
|
|
|
int horiz, vert;
|
|
|
|
int scale_width, scale_height;
|
2016-07-20 10:02:39 +12:00
|
|
|
#ifndef _MSC_VER
|
|
|
|
unsigned char local_text[ustrlen(symbol->text) + 1];
|
|
|
|
#else
|
|
|
|
unsigned char* local_text = (unsigned char*) _alloca(ustrlen(symbol->text) + 1);
|
|
|
|
#endif
|
|
|
|
|
2020-04-29 09:19:32 +12:00
|
|
|
memset(local_text, 0, ustrlen(symbol->text) + 1);
|
2016-07-20 10:02:39 +12:00
|
|
|
if (symbol->show_hrt != 0) {
|
|
|
|
/* Copy text from symbol */
|
|
|
|
to_latin1(symbol->text, local_text);
|
|
|
|
} else {
|
|
|
|
/* No text needed */
|
2019-11-12 10:38:21 +13:00
|
|
|
if (is_extendable(symbol->symbology)) {
|
|
|
|
/* For these symbols use dummy text to ensure formatting is done
|
|
|
|
* properly even if no text is required */
|
2020-04-04 07:40:59 +13:00
|
|
|
for (i = 0; i < (int) ustrlen(symbol->text); i++) {
|
2019-11-12 10:38:21 +13:00
|
|
|
if (symbol->text[i] == '+') {
|
|
|
|
local_text[i] = '+';
|
|
|
|
} else {
|
|
|
|
local_text[i] = ' ';
|
2016-07-20 10:02:39 +12:00
|
|
|
}
|
2019-11-12 10:38:21 +13:00
|
|
|
}
|
2020-04-29 09:19:32 +12:00
|
|
|
local_text[ustrlen(symbol->text)] = '\0';
|
2019-11-12 10:38:21 +13:00
|
|
|
} else {
|
|
|
|
/* For everything else, just remove the text */
|
|
|
|
local_text[0] = '\0';
|
2016-07-20 10:02:39 +12:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
textdone = 0;
|
|
|
|
main_width = symbol->width;
|
|
|
|
comp_offset = 0;
|
|
|
|
addon_text_posn = 0.0;
|
|
|
|
row_height = 0;
|
|
|
|
if (symbol->output_options & SMALL_TEXT) {
|
|
|
|
textflags = 1;
|
2016-08-09 10:18:55 +12:00
|
|
|
} else if (symbol->output_options & BOLD_TEXT) {
|
2016-07-20 10:02:39 +12:00
|
|
|
textflags = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (symbol->height == 0) {
|
|
|
|
symbol->height = 50;
|
|
|
|
}
|
|
|
|
|
|
|
|
large_bar_count = 0;
|
|
|
|
preset_height = 0.0;
|
|
|
|
for (i = 0; i < symbol->rows; i++) {
|
|
|
|
preset_height += symbol->row_height[i];
|
|
|
|
if (symbol->row_height[i] == 0) {
|
|
|
|
large_bar_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (large_bar_count == 0) {
|
|
|
|
symbol->height = preset_height;
|
|
|
|
large_bar_height = 10;
|
|
|
|
} else {
|
|
|
|
large_bar_height = (symbol->height - preset_height) / large_bar_count;
|
|
|
|
}
|
|
|
|
|
2019-11-12 10:38:21 +13:00
|
|
|
if (is_composite(symbol->symbology)) {
|
|
|
|
while (!(module_is_set(symbol, symbol->rows - 1, comp_offset))) {
|
|
|
|
comp_offset++;
|
|
|
|
}
|
2016-07-20 10:02:39 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Certain symbols need whitespace otherwise characters get chopped off the sides */
|
2019-11-12 10:38:21 +13:00
|
|
|
if ((symbol->symbology == BARCODE_EANX) || (symbol->symbology == BARCODE_EANX_CHK)
|
|
|
|
|| (symbol->symbology == BARCODE_EANX_CC) || (symbol->symbology == BARCODE_ISBNX)) {
|
2016-07-20 10:02:39 +12:00
|
|
|
switch (ustrlen(local_text)) {
|
|
|
|
case 13: /* EAN 13 */
|
|
|
|
case 16:
|
|
|
|
case 19:
|
|
|
|
if (symbol->whitespace_width == 0) {
|
|
|
|
symbol->whitespace_width = 10;
|
|
|
|
}
|
|
|
|
main_width = 96 + comp_offset;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
main_width = 68 + comp_offset;
|
|
|
|
}
|
2019-11-12 10:38:21 +13:00
|
|
|
} else if ((symbol->symbology == BARCODE_UPCA) || (symbol->symbology == BARCODE_UPCA_CHK)
|
|
|
|
|| (symbol->symbology == BARCODE_UPCA_CC)) {
|
2016-07-20 10:02:39 +12:00
|
|
|
if (symbol->whitespace_width == 0) {
|
|
|
|
symbol->whitespace_width = 10;
|
|
|
|
}
|
2019-11-12 10:38:21 +13:00
|
|
|
main_width = 96 + comp_offset;
|
|
|
|
} else if ((symbol->symbology == BARCODE_UPCE) || (symbol->symbology == BARCODE_UPCE_CHK)
|
|
|
|
|| (symbol->symbology == BARCODE_UPCE_CC)) {
|
2016-07-20 10:02:39 +12:00
|
|
|
if (symbol->whitespace_width == 0) {
|
|
|
|
symbol->whitespace_width = 10;
|
|
|
|
}
|
2019-11-12 10:38:21 +13:00
|
|
|
main_width = 51 + comp_offset;
|
2016-07-20 10:02:39 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
latch = 0;
|
|
|
|
r = 0;
|
|
|
|
/* Isolate add-on text */
|
|
|
|
if (is_extendable(symbol->symbology)) {
|
2020-04-04 07:40:59 +13:00
|
|
|
for (i = 0; i < (int) ustrlen(local_text); i++) {
|
2016-07-20 10:02:39 +12:00
|
|
|
if (latch == 1) {
|
|
|
|
addon[r] = local_text[i];
|
|
|
|
r++;
|
|
|
|
}
|
|
|
|
if (symbol->text[i] == '+') {
|
|
|
|
latch = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
addon[r] = '\0';
|
|
|
|
|
|
|
|
if (ustrlen(local_text) != 0) {
|
|
|
|
textoffset = 9;
|
|
|
|
} else {
|
|
|
|
textoffset = 0;
|
|
|
|
}
|
2016-08-09 10:18:55 +12:00
|
|
|
|
2016-07-20 10:02:39 +12:00
|
|
|
xoffset = symbol->border_width + symbol->whitespace_width;
|
|
|
|
yoffset = symbol->border_width;
|
|
|
|
image_width = 2 * (symbol->width + xoffset + xoffset);
|
|
|
|
image_height = 2 * (symbol->height + textoffset + yoffset + yoffset);
|
|
|
|
|
|
|
|
if (!(pixelbuf = (char *) malloc(image_width * image_height))) {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "658: Insufficient memory for pixel buffer");
|
2016-07-20 10:02:39 +12:00
|
|
|
return ZINT_ERROR_ENCODING_PROBLEM;
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < (image_width * image_height); i++) {
|
2020-01-07 09:01:48 +13:00
|
|
|
*(pixelbuf + i) = DEFAULT_PAPER;
|
2016-07-20 10:02:39 +12:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-27 02:13:40 +12:00
|
|
|
if ((symbol->output_options & BARCODE_BOX) || (symbol->output_options & BARCODE_BIND)) {
|
2016-07-20 10:02:39 +12:00
|
|
|
default_text_posn = image_height - 17;
|
|
|
|
} else {
|
|
|
|
default_text_posn = image_height - 17 - symbol->border_width - symbol->border_width;
|
|
|
|
}
|
|
|
|
|
|
|
|
row_posn = textoffset + yoffset;
|
|
|
|
next_yposn = textoffset + yoffset;
|
|
|
|
row_height = 0;
|
|
|
|
|
|
|
|
/* Plot the body of the symbol to the pixel buffer */
|
|
|
|
for (r = 0; r < symbol->rows; r++) {
|
2017-10-24 08:34:31 +13:00
|
|
|
int plot_yposn;
|
|
|
|
int plot_height;
|
2017-09-11 03:03:09 +12:00
|
|
|
int this_row = symbol->rows - r - 1; /* invert r otherwise plots upside down */
|
2020-01-07 09:01:48 +13:00
|
|
|
int module_fill;
|
2016-07-20 10:02:39 +12:00
|
|
|
row_posn += row_height;
|
2017-10-17 06:26:54 +13:00
|
|
|
plot_yposn = next_yposn;
|
2016-07-20 10:02:39 +12:00
|
|
|
if (symbol->row_height[this_row] == 0) {
|
|
|
|
row_height = large_bar_height;
|
|
|
|
} else {
|
|
|
|
row_height = symbol->row_height[this_row];
|
|
|
|
}
|
|
|
|
next_yposn = (int) (row_posn + row_height);
|
2017-10-17 06:26:54 +13:00
|
|
|
plot_height = next_yposn - plot_yposn;
|
2016-07-20 10:02:39 +12:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
do {
|
2020-01-07 09:01:48 +13:00
|
|
|
module_fill = module_is_set(symbol, this_row, i);
|
2016-07-20 10:02:39 +12:00
|
|
|
block_width = 0;
|
|
|
|
do {
|
|
|
|
block_width++;
|
2019-12-19 13:59:51 +13:00
|
|
|
} while ((i + block_width < symbol->width) && module_is_set(symbol, this_row, i + block_width) == module_is_set(symbol, this_row, i));
|
2020-04-07 04:05:22 +12:00
|
|
|
|
2016-07-20 10:02:39 +12:00
|
|
|
if ((addon_latch == 0) && (r == 0) && (i > main_width)) {
|
|
|
|
plot_height = (int) (row_height - 5.0);
|
|
|
|
plot_yposn = (int) (row_posn - 5.0);
|
|
|
|
addon_text_posn = row_posn + row_height - 8.0;
|
|
|
|
addon_latch = 1;
|
|
|
|
}
|
2020-01-07 09:01:48 +13:00
|
|
|
if (module_fill) {
|
2016-07-20 10:02:39 +12:00
|
|
|
/* a bar */
|
2020-01-07 09:01:48 +13:00
|
|
|
if (symbol->symbology == BARCODE_ULTRA) {
|
|
|
|
draw_bar(pixelbuf, (i + xoffset) * 2, block_width * 2, plot_yposn * 2, plot_height * 2, image_width, image_height, ultra_colour[module_fill]);
|
|
|
|
} else {
|
|
|
|
draw_bar(pixelbuf, (i + xoffset) * 2, block_width * 2, plot_yposn * 2, plot_height * 2, image_width, image_height, DEFAULT_INK);
|
|
|
|
}
|
2016-07-20 10:02:39 +12:00
|
|
|
}
|
|
|
|
i += block_width;
|
|
|
|
|
|
|
|
} while (i < symbol->width);
|
|
|
|
}
|
|
|
|
|
|
|
|
xoffset += comp_offset;
|
|
|
|
|
2019-11-12 10:38:21 +13:00
|
|
|
if ((symbol->symbology == BARCODE_EANX) || (symbol->symbology == BARCODE_EANX_CHK)
|
|
|
|
|| (symbol->symbology == BARCODE_EANX_CC) || (symbol->symbology == BARCODE_ISBNX)) {
|
2016-07-20 10:02:39 +12:00
|
|
|
/* guard bar extensions and text formatting for EAN8 and EAN13 */
|
|
|
|
switch (ustrlen(local_text)) {
|
|
|
|
case 8: /* EAN-8 */
|
|
|
|
case 11:
|
|
|
|
case 14:
|
2020-01-07 09:01:48 +13:00
|
|
|
draw_bar(pixelbuf, (0 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height, DEFAULT_INK);
|
|
|
|
draw_bar(pixelbuf, (2 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height, DEFAULT_INK);
|
|
|
|
draw_bar(pixelbuf, (32 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height, DEFAULT_INK);
|
|
|
|
draw_bar(pixelbuf, (34 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height, DEFAULT_INK);
|
|
|
|
draw_bar(pixelbuf, (64 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height, DEFAULT_INK);
|
|
|
|
draw_bar(pixelbuf, (66 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height, DEFAULT_INK);
|
2016-07-20 10:02:39 +12:00
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
textpart[i] = local_text[i];
|
|
|
|
}
|
|
|
|
textpart[4] = '\0';
|
|
|
|
textpos = 2 * (17 + xoffset);
|
|
|
|
|
|
|
|
draw_string(pixelbuf, textpart, textpos, default_text_posn, textflags, image_width, image_height);
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
textpart[i] = local_text[i + 4];
|
|
|
|
}
|
|
|
|
textpart[4] = '\0';
|
|
|
|
textpos = 2 * (50 + xoffset);
|
|
|
|
draw_string(pixelbuf, textpart, textpos, default_text_posn, textflags, image_width, image_height);
|
|
|
|
textdone = 1;
|
|
|
|
switch (strlen(addon)) {
|
|
|
|
case 2:
|
|
|
|
textpos = 2 * (xoffset + 86);
|
|
|
|
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, textflags, image_width, image_height);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
textpos = 2 * (xoffset + 100);
|
|
|
|
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, textflags, image_width, image_height);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case 13: /* EAN 13 */
|
|
|
|
case 16:
|
|
|
|
case 19:
|
2020-01-07 09:01:48 +13:00
|
|
|
draw_bar(pixelbuf, (0 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height, DEFAULT_INK);
|
|
|
|
draw_bar(pixelbuf, (2 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height, DEFAULT_INK);
|
|
|
|
draw_bar(pixelbuf, (46 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height, DEFAULT_INK);
|
|
|
|
draw_bar(pixelbuf, (48 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height, DEFAULT_INK);
|
|
|
|
draw_bar(pixelbuf, (92 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height, DEFAULT_INK);
|
|
|
|
draw_bar(pixelbuf, (94 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height, DEFAULT_INK);
|
2016-07-20 10:02:39 +12:00
|
|
|
|
|
|
|
textpart[0] = local_text[0];
|
|
|
|
textpart[1] = '\0';
|
|
|
|
textpos = 2 * (-7 + xoffset);
|
|
|
|
draw_string(pixelbuf, textpart, textpos, default_text_posn, textflags, image_width, image_height);
|
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
textpart[i] = local_text[i + 1];
|
|
|
|
}
|
|
|
|
textpart[6] = '\0';
|
|
|
|
textpos = 2 * (24 + xoffset);
|
|
|
|
draw_string(pixelbuf, textpart, textpos, default_text_posn, textflags, image_width, image_height);
|
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
textpart[i] = local_text[i + 7];
|
|
|
|
}
|
|
|
|
textpart[6] = '\0';
|
|
|
|
textpos = 2 * (71 + xoffset);
|
|
|
|
draw_string(pixelbuf, textpart, textpos, default_text_posn, textflags, image_width, image_height);
|
|
|
|
textdone = 1;
|
|
|
|
switch (strlen(addon)) {
|
|
|
|
case 2:
|
|
|
|
textpos = 2 * (xoffset + 114);
|
|
|
|
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, textflags, image_width, image_height);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
textpos = 2 * (xoffset + 128);
|
|
|
|
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, textflags, image_width, image_height);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-11-12 10:38:21 +13:00
|
|
|
} else if ((symbol->symbology == BARCODE_UPCA) || (symbol->symbology == BARCODE_UPCA_CHK)
|
|
|
|
|| (symbol->symbology == BARCODE_UPCA_CC)) {
|
2016-07-20 10:02:39 +12:00
|
|
|
/* guard bar extensions and text formatting for UPCA */
|
|
|
|
latch = 1;
|
|
|
|
|
|
|
|
i = 0 + comp_offset;
|
|
|
|
do {
|
|
|
|
block_width = 0;
|
|
|
|
do {
|
|
|
|
block_width++;
|
2019-12-19 13:59:51 +13:00
|
|
|
} while ((i + block_width < symbol->width) && module_is_set(symbol, symbol->rows - 1, i + block_width) == module_is_set(symbol, symbol->rows - 1, i));
|
2016-07-20 10:02:39 +12:00
|
|
|
if (latch == 1) {
|
|
|
|
/* a bar */
|
2020-01-07 09:01:48 +13:00
|
|
|
draw_bar(pixelbuf, (i + xoffset - comp_offset) * 2, block_width * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height, DEFAULT_INK);
|
2016-07-20 10:02:39 +12:00
|
|
|
latch = 0;
|
|
|
|
} else {
|
|
|
|
/* a space */
|
|
|
|
latch = 1;
|
|
|
|
}
|
|
|
|
i += block_width;
|
|
|
|
} while (i < 11 + comp_offset);
|
2020-01-07 09:01:48 +13:00
|
|
|
draw_bar(pixelbuf, (46 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height, DEFAULT_INK);
|
|
|
|
draw_bar(pixelbuf, (48 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height, DEFAULT_INK);
|
2016-07-20 10:02:39 +12:00
|
|
|
latch = 1;
|
|
|
|
i = 85 + comp_offset;
|
|
|
|
do {
|
|
|
|
block_width = 0;
|
|
|
|
do {
|
|
|
|
block_width++;
|
2019-12-19 13:59:51 +13:00
|
|
|
} while ((i + block_width < symbol->width) && module_is_set(symbol, symbol->rows - 1, i + block_width) == module_is_set(symbol, symbol->rows - 1, i));
|
2016-07-20 10:02:39 +12:00
|
|
|
if (latch == 1) {
|
|
|
|
/* a bar */
|
2020-01-07 09:01:48 +13:00
|
|
|
draw_bar(pixelbuf, (i + xoffset - comp_offset) * 2, block_width * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height, DEFAULT_INK);
|
2016-07-20 10:02:39 +12:00
|
|
|
latch = 0;
|
|
|
|
} else {
|
|
|
|
/* a space */
|
|
|
|
latch = 1;
|
|
|
|
}
|
|
|
|
i += block_width;
|
|
|
|
} while (i < 96 + comp_offset);
|
|
|
|
textpart[0] = local_text[0];
|
|
|
|
textpart[1] = '\0';
|
|
|
|
textpos = 2 * (-5 + xoffset);
|
|
|
|
draw_string(pixelbuf, textpart, textpos, default_text_posn, textflags, image_width, image_height);
|
|
|
|
for (i = 0; i < 5; i++) {
|
|
|
|
textpart[i] = local_text[i + 1];
|
|
|
|
}
|
|
|
|
textpart[5] = '\0';
|
|
|
|
textpos = 2 * (27 + xoffset);
|
|
|
|
draw_string(pixelbuf, textpart, textpos, default_text_posn, textflags, image_width, image_height);
|
|
|
|
for (i = 0; i < 5; i++) {
|
|
|
|
textpart[i] = local_text[i + 6];
|
|
|
|
}
|
|
|
|
textpart[6] = '\0';
|
|
|
|
textpos = 2 * (68 + xoffset);
|
|
|
|
draw_string(pixelbuf, textpart, textpos, default_text_posn, textflags, image_width, image_height);
|
|
|
|
textpart[0] = local_text[11];
|
|
|
|
textpart[1] = '\0';
|
|
|
|
textpos = 2 * (100 + xoffset);
|
|
|
|
draw_string(pixelbuf, textpart, textpos, default_text_posn, textflags, image_width, image_height);
|
|
|
|
textdone = 1;
|
|
|
|
switch (strlen(addon)) {
|
|
|
|
case 2:
|
|
|
|
textpos = 2 * (xoffset + 116);
|
|
|
|
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, textflags, image_width, image_height);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
textpos = 2 * (xoffset + 130);
|
|
|
|
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, textflags, image_width, image_height);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-11-12 10:38:21 +13:00
|
|
|
} else if ((symbol->symbology == BARCODE_UPCE) || (symbol->symbology == BARCODE_UPCE_CHK)
|
|
|
|
|| (symbol->symbology == BARCODE_UPCE_CC)) {
|
2016-07-20 10:02:39 +12:00
|
|
|
/* guard bar extensions and text formatting for UPCE */
|
2020-01-07 09:01:48 +13:00
|
|
|
draw_bar(pixelbuf, (0 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height, DEFAULT_INK);
|
|
|
|
draw_bar(pixelbuf, (2 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height, DEFAULT_INK);
|
|
|
|
draw_bar(pixelbuf, (46 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height, DEFAULT_INK);
|
|
|
|
draw_bar(pixelbuf, (48 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height, DEFAULT_INK);
|
|
|
|
draw_bar(pixelbuf, (50 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height, DEFAULT_INK);
|
2016-07-20 10:02:39 +12:00
|
|
|
|
|
|
|
textpart[0] = local_text[0];
|
|
|
|
textpart[1] = '\0';
|
|
|
|
textpos = 2 * (-5 + xoffset);
|
|
|
|
draw_string(pixelbuf, textpart, textpos, default_text_posn, textflags, image_width, image_height);
|
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
textpart[i] = local_text[i + 1];
|
|
|
|
}
|
|
|
|
textpart[6] = '\0';
|
|
|
|
textpos = 2 * (24 + xoffset);
|
|
|
|
draw_string(pixelbuf, textpart, textpos, default_text_posn, textflags, image_width, image_height);
|
|
|
|
textpart[0] = local_text[7];
|
|
|
|
textpart[1] = '\0';
|
|
|
|
textpos = 2 * (55 + xoffset);
|
|
|
|
draw_string(pixelbuf, textpart, textpos, default_text_posn, textflags, image_width, image_height);
|
|
|
|
textdone = 1;
|
|
|
|
switch (strlen(addon)) {
|
|
|
|
case 2:
|
|
|
|
textpos = 2 * (xoffset + 70);
|
|
|
|
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, textflags, image_width, image_height);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
textpos = 2 * (xoffset + 84);
|
|
|
|
draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, textflags, image_width, image_height);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
xoffset -= comp_offset;
|
|
|
|
|
|
|
|
/* Put boundary bars or box around symbol */
|
2016-08-27 02:13:40 +12:00
|
|
|
if ((symbol->output_options & BARCODE_BOX) || (symbol->output_options & BARCODE_BIND)) {
|
2016-07-20 10:02:39 +12:00
|
|
|
/* boundary bars */
|
2016-09-13 08:47:40 +12:00
|
|
|
if (symbol->symbology != BARCODE_CODABLOCKF) {
|
2020-01-07 09:01:48 +13:00
|
|
|
draw_bar(pixelbuf, 0, (symbol->width + xoffset + xoffset) * 2, textoffset * 2, symbol->border_width * 2, image_width, image_height, DEFAULT_INK);
|
|
|
|
draw_bar(pixelbuf, 0, (symbol->width + xoffset + xoffset) * 2, (textoffset + symbol->height + symbol->border_width) * 2, symbol->border_width * 2, image_width, image_height, DEFAULT_INK);
|
2016-09-13 08:47:40 +12:00
|
|
|
} else {
|
2020-01-07 09:01:48 +13:00
|
|
|
draw_bar(pixelbuf, xoffset * 2, symbol->width * 2, textoffset * 2, symbol->border_width * 2, image_width, image_height, DEFAULT_INK);
|
|
|
|
draw_bar(pixelbuf, xoffset * 2, symbol->width * 2, (textoffset + symbol->height + symbol->border_width) * 2, symbol->border_width * 2, image_width, image_height, DEFAULT_INK);
|
2016-09-13 08:47:40 +12:00
|
|
|
}
|
2016-07-20 10:02:39 +12:00
|
|
|
if ((symbol->output_options & BARCODE_BIND) != 0) {
|
|
|
|
if ((symbol->rows > 1) && (is_stackable(symbol->symbology) == 1)) {
|
|
|
|
/* row binding */
|
2016-09-13 08:47:40 +12:00
|
|
|
if (symbol->symbology != BARCODE_CODABLOCKF) {
|
|
|
|
for (r = 1; r < symbol->rows; r++) {
|
2020-01-07 09:01:48 +13:00
|
|
|
draw_bar(pixelbuf, xoffset * 2, symbol->width * 2, ((r * row_height) + textoffset + yoffset - 1) * 2, 2 * 2, image_width, image_height, DEFAULT_INK);
|
2016-09-13 08:47:40 +12:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (r = 1; r < symbol->rows; r++) {
|
2020-04-04 07:40:59 +13:00
|
|
|
/* Avoid 11-module start and stop chars */
|
2020-04-07 04:05:22 +12:00
|
|
|
draw_bar(pixelbuf, (xoffset + 11) * 2 , (symbol->width - 22) * 2, ((r * row_height) + textoffset + yoffset - 1) * 2, 2 * 2, image_width, image_height, DEFAULT_INK);
|
2016-09-13 08:47:40 +12:00
|
|
|
}
|
2016-07-20 10:02:39 +12:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-27 02:13:40 +12:00
|
|
|
if (symbol->output_options & BARCODE_BOX) {
|
2016-07-20 10:02:39 +12:00
|
|
|
/* side bars */
|
2020-01-07 09:01:48 +13:00
|
|
|
draw_bar(pixelbuf, 0, symbol->border_width * 2, textoffset * 2, (symbol->height + (2 * symbol->border_width)) * 2, image_width, image_height, DEFAULT_INK);
|
|
|
|
draw_bar(pixelbuf, (symbol->width + xoffset + xoffset - symbol->border_width) * 2, symbol->border_width * 2, textoffset * 2, (symbol->height + (2 * symbol->border_width)) * 2, image_width, image_height, DEFAULT_INK);
|
2016-07-20 10:02:39 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Put the human readable text at the bottom */
|
|
|
|
if ((textdone == 0) && (ustrlen(local_text) != 0)) {
|
|
|
|
textpos = (image_width / 2);
|
|
|
|
draw_string(pixelbuf, (char*) local_text, textpos, default_text_posn, textflags, image_width, image_height);
|
|
|
|
}
|
|
|
|
|
2016-08-09 10:18:55 +12:00
|
|
|
|
|
|
|
if (scaler == 0) {
|
|
|
|
scaler = 0.5;
|
|
|
|
}
|
|
|
|
scale_width = image_width * scaler;
|
|
|
|
scale_height = image_height * scaler;
|
|
|
|
|
|
|
|
/* Apply scale options by creating another pixel buffer */
|
|
|
|
if (!(scaled_pixelbuf = (char *) malloc(scale_width * scale_height))) {
|
2016-09-04 05:45:09 +12:00
|
|
|
free(pixelbuf);
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "659: Insufficient memory for pixel buffer");
|
2016-08-09 10:18:55 +12:00
|
|
|
return ZINT_ERROR_ENCODING_PROBLEM;
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < (scale_width * scale_height); i++) {
|
2020-01-07 09:01:48 +13:00
|
|
|
*(scaled_pixelbuf + i) = DEFAULT_PAPER;
|
2016-08-09 10:18:55 +12:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (vert = 0; vert < scale_height; vert++) {
|
|
|
|
for (horiz = 0; horiz < scale_width; horiz++) {
|
|
|
|
*(scaled_pixelbuf + (vert * scale_width) + horiz) = *(pixelbuf + ((int) (vert / scaler) * image_width) + (int) (horiz / scaler));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
error_number = save_raster_image_to_file(symbol, scale_height, scale_width, scaled_pixelbuf, rotate_angle, data_type);
|
|
|
|
free(scaled_pixelbuf);
|
2016-07-20 10:02:39 +12:00
|
|
|
free(pixelbuf);
|
|
|
|
return error_number;
|
|
|
|
}
|
|
|
|
|
2019-12-19 13:37:55 +13:00
|
|
|
INTERNAL int plot_raster(struct zint_symbol *symbol, int rotate_angle, int file_type) {
|
2016-07-20 10:02:39 +12:00
|
|
|
int error;
|
|
|
|
|
|
|
|
#ifdef NO_PNG
|
2020-04-08 04:39:02 +12:00
|
|
|
if (file_type == OUT_PNG_FILE) {
|
|
|
|
strcpy(symbol->errtxt, "660: PNG format disabled on compile time");
|
2016-07-20 10:02:39 +12:00
|
|
|
return ZINT_ERROR_INVALID_OPTION;
|
|
|
|
}
|
2017-10-24 08:37:52 +13:00
|
|
|
#endif /* NO_PNG */
|
2016-08-09 10:18:55 +12:00
|
|
|
|
2016-08-27 02:13:40 +12:00
|
|
|
if (symbol->output_options & BARCODE_DOTTY_MODE) {
|
2016-08-09 10:18:55 +12:00
|
|
|
error = plot_raster_dotty(symbol, rotate_angle, file_type);
|
2016-07-20 10:02:39 +12:00
|
|
|
} else {
|
2016-08-09 10:18:55 +12:00
|
|
|
if (symbol->symbology == BARCODE_MAXICODE) {
|
|
|
|
error = plot_raster_maxicode(symbol, rotate_angle, file_type);
|
|
|
|
} else {
|
|
|
|
error = plot_raster_default(symbol, rotate_angle, file_type);
|
|
|
|
}
|
2016-07-20 10:02:39 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|