2022-09-14 08:16:31 +12:00
|
|
|
/* output.h - Common routines for raster/vector */
|
|
|
|
/*
|
2020-05-22 05:22:28 +12:00
|
|
|
libzint - the open source barcode library
|
2024-01-17 14:45:45 +13:00
|
|
|
Copyright (C) 2020-2024 Robin Stuart <rstuart114@gmail.com>
|
2020-05-22 05:22:28 +12:00
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
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
|
|
|
|
without specific prior written permission.
|
|
|
|
|
|
|
|
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
|
|
|
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
SUCH DAMAGE.
|
|
|
|
*/
|
2022-09-14 08:16:31 +12:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause */
|
2020-05-22 05:22:28 +12:00
|
|
|
|
2021-11-07 13:21:02 +13:00
|
|
|
#ifndef Z_OUTPUT_H
|
|
|
|
#define Z_OUTPUT_H
|
2020-05-22 05:22:28 +12:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
- API: add new zint_symbol `dpmm` field for output resolution (BMP/
EMF/PCX/PNG/TIF only, i.e. excluding EPS, GIF & SVG)
- Add support for specifying scale by X-dimension and resolution
with new option `--scalexdimdp` for CLI/Tcl & new API function
`ZBarcode_Scale_From_XdimDp()` (+ `ZBarcode_XdimDp_From_Scale()`
& `ZBarcode_Default_Xdim()`) and new GUI popup; manual: document
- BMP/EMF/PCX/PNG/TIF: use new `dpmm` resolution field (for EMF
following Inkscape)
- backend_qt: add `dpmm()`, `vectorWidth()`, `vectorHeight()`,
`noPng()`, `getVersion()`, `takesGS1AIData()`, & `XdimDp` stuff
incl. new `QZintXdimDp` struct for passing around scale vars &
use in `getAsCLI()`; add comments
- Raise `scale` limit to 200 (from 100) to allow for large dpmm
- output: create directories & subdirectories as necessary for
output path using new function `out_fopen()` and use in BMP/EMF/
EPS/GIF/PCX/PNG/SVG/TIF
- DPLEIT/DPIDENT: format HRT according to (incomplete)
documentation, and set default height to 72X (from 50X)
- CODE128B renamed to CODE128AB as can use subsets A and/or B
- CODABAR: fix minimum height calc
- EMF: fix indexing of handles (zero-based not 1-based)
- GUI: fix symbology zap (previous technique of clearing and
re-loading settings without doing a sync no longer works);
fix UPCEAN guard descent enable
- MAILMARK: better error message if input < 14 characters
- GUI: add "Default" button for DAFT tracker ratio & enable/disable
various default buttons; use new `takesGS1AIData()` to
enable/disable GS1-specific checkboxes
- CLI: use new `validate_float()` to parse float options (7
significant digits allowed only, no scientific notation)
- DATAMATRIX/GRIDMATRIX/PDF417/QR/ULTRA: micro-optimize structapp
ID parse
- library/CLI: fiddle with static asserts (make CHAR_BIT sensitive,
supposedly)
- win32/README: update building libpng (assembly removed)
- README.linux: document incompatibility of Qt6 >= 6.3
- manual: expand Barcode Studio waffle
- test suite: change range separator to hyphen and allow multiple
excludes
2022-12-03 10:39:01 +13:00
|
|
|
#include <stdio.h> /* For FILE */
|
|
|
|
|
- `zint_symbol->fgcolour` & `bgcolour` buffer lengths extended 10
-> 16 to allow for "C,M,Y,K" comma-separated decimal percentage
strings
- API/CLI/GUI: allow foreground/background colours to be specified
as comma-separated decimal "C,M,Y,K" strings where "C", "M" etc.
are percentages (0-100) (ticket #281, 3rd point)
- output.c: new funcs `out_colour_get_rgb()` & `out_colour_get_cmyk()`
and use in bmp/emf/gif etc.
- PCX: add alpha support
- GUI: fix fg/gbcolor icon background not being reset on zap
- GUI: Rearrange some Appearance tab inputs (Border Type <-> Width,
Show Text <-> Font, Text/Font <-> Printing Scale/Size) to flow
more naturally (hopefully)
- GUI: save button "Save As..." -> "Save..." and add icon
- CLI: add --bgcolor/colour & --fgcolor/colour synonyms
2023-01-30 08:51:11 +13:00
|
|
|
/* Check colour options are good (`symbol->fgcolour`, `symbol->bgcolour`) */
|
2021-10-21 11:05:30 +13:00
|
|
|
INTERNAL int out_check_colour_options(struct zint_symbol *symbol);
|
- `zint_symbol->fgcolour` & `bgcolour` buffer lengths extended 10
-> 16 to allow for "C,M,Y,K" comma-separated decimal percentage
strings
- API/CLI/GUI: allow foreground/background colours to be specified
as comma-separated decimal "C,M,Y,K" strings where "C", "M" etc.
are percentages (0-100) (ticket #281, 3rd point)
- output.c: new funcs `out_colour_get_rgb()` & `out_colour_get_cmyk()`
and use in bmp/emf/gif etc.
- PCX: add alpha support
- GUI: fix fg/gbcolor icon background not being reset on zap
- GUI: Rearrange some Appearance tab inputs (Border Type <-> Width,
Show Text <-> Font, Text/Font <-> Printing Scale/Size) to flow
more naturally (hopefully)
- GUI: save button "Save As..." -> "Save..." and add icon
- CLI: add --bgcolor/colour & --fgcolor/colour synonyms
2023-01-30 08:51:11 +13:00
|
|
|
|
|
|
|
/* Return RGB(A) from (well-formed) colour string. Returns 0 if RGB or converted CMYK, 1 if RGBA */
|
|
|
|
INTERNAL int out_colour_get_rgb(const char *colour, unsigned char *red, unsigned char *green, unsigned char *blue,
|
|
|
|
unsigned char *alpha);
|
|
|
|
/* Return CMYK from (well-formed) colour string. Returns 0 if CMYK, 1 if converted RBG, 2 if converted RGBA */
|
|
|
|
INTERNAL int out_colour_get_cmyk(const char *colour, int *cyan, int *magenta, int *yellow, int *black,
|
|
|
|
unsigned char *rgb_alpha);
|
|
|
|
|
2023-11-20 08:39:54 +13:00
|
|
|
/* Convert internal colour chars "WCBMRYGK" to RGB */
|
|
|
|
INTERNAL int out_colour_char_to_rgb(const char ch, unsigned char *red, unsigned char *green, unsigned char *blue);
|
|
|
|
|
|
|
|
/* Set left (x), top (y), right and bottom offsets for whitespace, also right quiet zone */
|
2021-10-21 11:05:30 +13:00
|
|
|
INTERNAL void out_set_whitespace_offsets(const struct zint_symbol *symbol, const int hide_text,
|
2023-11-20 08:39:54 +13:00
|
|
|
const int comp_xoffset, float *p_xoffset, float *p_yoffset, float *p_roffset, float *p_boffset,
|
|
|
|
float *p_qz_right, const float scaler, int *p_xoffset_si, int *p_yoffset_si, int *p_roffset_si,
|
|
|
|
int *p_boffset_si, int *p_qz_right_si);
|
- `zint_symbol->fgcolour` & `bgcolour` buffer lengths extended 10
-> 16 to allow for "C,M,Y,K" comma-separated decimal percentage
strings
- API/CLI/GUI: allow foreground/background colours to be specified
as comma-separated decimal "C,M,Y,K" strings where "C", "M" etc.
are percentages (0-100) (ticket #281, 3rd point)
- output.c: new funcs `out_colour_get_rgb()` & `out_colour_get_cmyk()`
and use in bmp/emf/gif etc.
- PCX: add alpha support
- GUI: fix fg/gbcolor icon background not being reset on zap
- GUI: Rearrange some Appearance tab inputs (Border Type <-> Width,
Show Text <-> Font, Text/Font <-> Printing Scale/Size) to flow
more naturally (hopefully)
- GUI: save button "Save As..." -> "Save..." and add icon
- CLI: add --bgcolor/colour & --fgcolor/colour synonyms
2023-01-30 08:51:11 +13:00
|
|
|
|
2023-06-12 12:25:55 +12:00
|
|
|
/* Set composite offset and main width excluding add-on (for start of add-on calc) and add-on text, returning
|
2023-11-20 08:39:54 +13:00
|
|
|
EAN/UPC type */
|
2023-06-12 12:25:55 +12:00
|
|
|
INTERNAL int out_process_upcean(const struct zint_symbol *symbol, const int comp_xoffset, int *p_main_width,
|
2023-11-20 08:39:54 +13:00
|
|
|
unsigned char addon[6], int *p_addon_len, int *p_addon_gap);
|
- `zint_symbol->fgcolour` & `bgcolour` buffer lengths extended 10
-> 16 to allow for "C,M,Y,K" comma-separated decimal percentage
strings
- API/CLI/GUI: allow foreground/background colours to be specified
as comma-separated decimal "C,M,Y,K" strings where "C", "M" etc.
are percentages (0-100) (ticket #281, 3rd point)
- output.c: new funcs `out_colour_get_rgb()` & `out_colour_get_cmyk()`
and use in bmp/emf/gif etc.
- PCX: add alpha support
- GUI: fix fg/gbcolor icon background not being reset on zap
- GUI: Rearrange some Appearance tab inputs (Border Type <-> Width,
Show Text <-> Font, Text/Font <-> Printing Scale/Size) to flow
more naturally (hopefully)
- GUI: save button "Save As..." -> "Save..." and add icon
- CLI: add --bgcolor/colour & --fgcolor/colour synonyms
2023-01-30 08:51:11 +13:00
|
|
|
|
|
|
|
/* Calculate large bar height i.e. linear bars with zero row height that respond to the symbol height.
|
|
|
|
If scaler `si` non-zero (raster), then large_bar_height if non-zero or else row heights will be rounded
|
|
|
|
to nearest pixel and symbol height adjusted */
|
2023-02-11 03:44:10 +13:00
|
|
|
INTERNAL float out_large_bar_height(struct zint_symbol *symbol, const int si, int *row_heights_si,
|
|
|
|
int *symbol_height_si);
|
- `zint_symbol->fgcolour` & `bgcolour` buffer lengths extended 10
-> 16 to allow for "C,M,Y,K" comma-separated decimal percentage
strings
- API/CLI/GUI: allow foreground/background colours to be specified
as comma-separated decimal "C,M,Y,K" strings where "C", "M" etc.
are percentages (0-100) (ticket #281, 3rd point)
- output.c: new funcs `out_colour_get_rgb()` & `out_colour_get_cmyk()`
and use in bmp/emf/gif etc.
- PCX: add alpha support
- GUI: fix fg/gbcolor icon background not being reset on zap
- GUI: Rearrange some Appearance tab inputs (Border Type <-> Width,
Show Text <-> Font, Text/Font <-> Printing Scale/Size) to flow
more naturally (hopefully)
- GUI: save button "Save As..." -> "Save..." and add icon
- CLI: add --bgcolor/colour & --fgcolor/colour synonyms
2023-01-30 08:51:11 +13:00
|
|
|
|
|
|
|
/* Create output file, creating sub-directories if necessary. Returns `fopen()` FILE pointer */
|
- API: add new zint_symbol `dpmm` field for output resolution (BMP/
EMF/PCX/PNG/TIF only, i.e. excluding EPS, GIF & SVG)
- Add support for specifying scale by X-dimension and resolution
with new option `--scalexdimdp` for CLI/Tcl & new API function
`ZBarcode_Scale_From_XdimDp()` (+ `ZBarcode_XdimDp_From_Scale()`
& `ZBarcode_Default_Xdim()`) and new GUI popup; manual: document
- BMP/EMF/PCX/PNG/TIF: use new `dpmm` resolution field (for EMF
following Inkscape)
- backend_qt: add `dpmm()`, `vectorWidth()`, `vectorHeight()`,
`noPng()`, `getVersion()`, `takesGS1AIData()`, & `XdimDp` stuff
incl. new `QZintXdimDp` struct for passing around scale vars &
use in `getAsCLI()`; add comments
- Raise `scale` limit to 200 (from 100) to allow for large dpmm
- output: create directories & subdirectories as necessary for
output path using new function `out_fopen()` and use in BMP/EMF/
EPS/GIF/PCX/PNG/SVG/TIF
- DPLEIT/DPIDENT: format HRT according to (incomplete)
documentation, and set default height to 72X (from 50X)
- CODE128B renamed to CODE128AB as can use subsets A and/or B
- CODABAR: fix minimum height calc
- EMF: fix indexing of handles (zero-based not 1-based)
- GUI: fix symbology zap (previous technique of clearing and
re-loading settings without doing a sync no longer works);
fix UPCEAN guard descent enable
- MAILMARK: better error message if input < 14 characters
- GUI: add "Default" button for DAFT tracker ratio & enable/disable
various default buttons; use new `takesGS1AIData()` to
enable/disable GS1-specific checkboxes
- CLI: use new `validate_float()` to parse float options (7
significant digits allowed only, no scientific notation)
- DATAMATRIX/GRIDMATRIX/PDF417/QR/ULTRA: micro-optimize structapp
ID parse
- library/CLI: fiddle with static asserts (make CHAR_BIT sensitive,
supposedly)
- win32/README: update building libpng (assembly removed)
- README.linux: document incompatibility of Qt6 >= 6.3
- manual: expand Barcode Studio waffle
- test suite: change range separator to hyphen and allow multiple
excludes
2022-12-03 10:39:01 +13:00
|
|
|
INTERNAL FILE *out_fopen(const char filename[256], const char *mode);
|
2020-05-22 05:22:28 +12:00
|
|
|
|
2023-05-10 11:47:44 +12:00
|
|
|
#ifdef _WIN32
|
|
|
|
/* Do `fopen()` on Windows, assuming `filename` is UTF-8 encoded. Props Marcel, ticket #288 */
|
|
|
|
INTERNAL FILE *out_win_fopen(const char *filename, const char *mode);
|
|
|
|
#endif
|
|
|
|
|
2024-01-17 14:45:45 +13:00
|
|
|
/* Little-endian output */
|
|
|
|
#define out_le_u16(b, n) do { \
|
|
|
|
unsigned char *bp = (unsigned char *) &(b); \
|
|
|
|
uint16_t u16 = (uint16_t) (n); \
|
|
|
|
bp[0] = (unsigned char) (u16 & 0xFF); \
|
|
|
|
bp[1] = (unsigned char) ((u16 >> 8) & 0xFF); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define out_le_u32(b, n) do { \
|
|
|
|
unsigned char *bp = (unsigned char *) &(b); \
|
|
|
|
uint32_t u32 = (uint32_t) (n); \
|
|
|
|
bp[0] = (unsigned char) (u32 & 0xFF); \
|
|
|
|
bp[1] = (unsigned char) ((u32 >> 8) & 0xFF); \
|
|
|
|
bp[2] = (unsigned char) ((u32 >> 16) & 0xFF); \
|
|
|
|
bp[3] = (unsigned char) ((u32 >> 24) & 0xFF); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define out_le_i32(b, n) do { \
|
|
|
|
unsigned char *bp = (unsigned char *) &(b); \
|
|
|
|
int32_t i32 = (int32_t) (n); \
|
|
|
|
bp[0] = (unsigned char) (i32 & 0xFF); \
|
|
|
|
bp[1] = (unsigned char) ((i32 >> 8) & 0xFF); \
|
|
|
|
bp[2] = (unsigned char) ((i32 >> 16) & 0xFF); \
|
|
|
|
bp[3] = (unsigned char) ((i32 >> 24) & 0xFF); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define out_le_float(b, n) do { \
|
|
|
|
unsigned char *bp = (unsigned char *) &(b); \
|
2024-01-18 10:55:11 +13:00
|
|
|
float f = (float) (n); \
|
|
|
|
uint32_t *p_u32 = (uint32_t *) &f; \
|
2024-01-17 14:45:45 +13:00
|
|
|
bp[0] = (unsigned char) (*p_u32 & 0xFF); \
|
|
|
|
bp[1] = (unsigned char) ((*p_u32 >> 8) & 0xFF); \
|
|
|
|
bp[2] = (unsigned char) ((*p_u32 >> 16) & 0xFF); \
|
|
|
|
bp[3] = (unsigned char) ((*p_u32 >> 24) & 0xFF); \
|
|
|
|
} while (0)
|
|
|
|
|
2020-05-22 05:22:28 +12:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
2022-09-14 08:16:31 +12:00
|
|
|
/* vim: set ts=4 sw=4 et : */
|
2021-11-07 13:21:02 +13:00
|
|
|
#endif /* Z_OUTPUT_H */
|