mirror of
https://git.code.sf.net/p/zint/code
synced 2025-05-09 13:41:59 -04:00
- 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
This commit is contained in:
parent
6393813cff
commit
c8033695d9
127 changed files with 4032 additions and 1248 deletions
|
@ -16,9 +16,15 @@
|
|||
***************************************************************************/
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
|
||||
/*
|
||||
* For version, see "../backend/zintconfig.h"
|
||||
* For documentation, see "../docs/manual.txt"
|
||||
*/
|
||||
|
||||
#ifndef QZINT_H
|
||||
#define QZINT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QColor>
|
||||
#include <QPainter>
|
||||
#include "zint.h"
|
||||
|
@ -29,148 +35,200 @@ namespace Zint
|
|||
/* QString version of `struct zint_seg` */
|
||||
class QZintSeg {
|
||||
public:
|
||||
QString m_text;
|
||||
int m_eci;
|
||||
QString m_text; // `seg->source` and `seg->length`
|
||||
int m_eci; // `seg->eci`
|
||||
|
||||
QZintSeg();
|
||||
QZintSeg(const QString& text, const int ECIIndex = 0); // `ECIIndex` is comboBox index (not ECI value)
|
||||
};
|
||||
|
||||
struct QZintXdimDpVars; // Forward reference to Printing Scale settings, see end
|
||||
|
||||
/* Interface */
|
||||
class QZint : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum AspectRatioMode{ IgnoreAspectRatio = 0, KeepAspectRatio = 1, CenterBarCode = 2 }; /* Legacy - not used */
|
||||
/* Legacy - not used */
|
||||
enum AspectRatioMode{ IgnoreAspectRatio = 0, KeepAspectRatio = 1, CenterBarCode = 2 };
|
||||
|
||||
public:
|
||||
QZint();
|
||||
~QZint();
|
||||
|
||||
int symbol() const; /* Symbology */
|
||||
/* Symbology to use (see BARCODE_XXX) */
|
||||
int symbol() const; // `symbol->symbology`
|
||||
void setSymbol(int symbol);
|
||||
|
||||
int inputMode() const;
|
||||
/* Input data encoding. Default UNICODE_MODE */
|
||||
int inputMode() const; // `symbol->input_mode`
|
||||
void setInputMode(int input_mode);
|
||||
|
||||
/* Note text/eci and segs are mutally exclusive */
|
||||
|
||||
/* Input data (segment 0 text) */
|
||||
QString text() const;
|
||||
void setText(const QString& text); // Clears segs
|
||||
/* Set input data. Note: clears segs */
|
||||
void setText(const QString& text);
|
||||
|
||||
/* Input segments. */
|
||||
std::vector<QZintSeg> segs() const;
|
||||
void setSegs(const std::vector<QZintSeg>& segs); // Clears text and sets eci
|
||||
/* Set segments. Note: clears text and sets eci */
|
||||
void setSegs(const std::vector<QZintSeg>& segs);
|
||||
|
||||
QString primaryMessage() const;
|
||||
/* Primary message (Maxicode, Composite) */
|
||||
QString primaryMessage() const; // `symbol->primary`
|
||||
void setPrimaryMessage(const QString& primaryMessage);
|
||||
|
||||
float height() const;
|
||||
/* Symbol height in X-dimensions */
|
||||
float height() const; // `symbol->height`
|
||||
void setHeight(float height);
|
||||
|
||||
int option1() const;
|
||||
/* Symbol-specific options (see "../docs/manual.txt") */
|
||||
int option1() const; // `symbol->option_1`
|
||||
void setOption1(int option_1);
|
||||
|
||||
int option2() const;
|
||||
/* Symbol-specific options */
|
||||
int option2() const; // `symbol->option_2`
|
||||
void setOption2(int option);
|
||||
|
||||
int option3() const;
|
||||
/* Symbol-specific options */
|
||||
int option3() const; // `symbol->option_3`
|
||||
void setOption3(int option);
|
||||
|
||||
float scale() const;
|
||||
/* Scale factor when printing barcode, i.e. adjusts X-dimension */
|
||||
float scale() const; // `symbol->scale`
|
||||
void setScale(float scale);
|
||||
|
||||
bool dotty() const;
|
||||
/* Resolution of output in dots per mm (BMP/EMF/PCX/PNG/TIF only) */
|
||||
float dpmm() const; // `symbol->dpmm`
|
||||
void setDPMM(float dpmm);
|
||||
|
||||
/* Dotty mode */
|
||||
bool dotty() const; // `symbol->input_mode | BARCODE_DOTTY_MODE`
|
||||
void setDotty(bool botty);
|
||||
|
||||
float dotSize() const;
|
||||
/* Size of dots used in BARCODE_DOTTY_MODE */
|
||||
float dotSize() const; // `symbol->dot_size`
|
||||
void setDotSize(float dot_size);
|
||||
|
||||
float guardDescent() const;
|
||||
/* Height in X-dimensions that EAN/UPC guard bars descend */
|
||||
float guardDescent() const; // `symbol->guard_descent`
|
||||
void setGuardDescent(float guardDescent);
|
||||
|
||||
int structAppCount() const;
|
||||
int structAppIndex() const;
|
||||
QString structAppID() const;
|
||||
/* Structured Append info */
|
||||
int structAppCount() const; // `symbol->structapp.count`
|
||||
int structAppIndex() const; // `symbol->structapp.index`
|
||||
QString structAppID() const; // `symbol->structapp.id`
|
||||
void setStructApp(const int count, const int index, const QString& id);
|
||||
void clearStructApp();
|
||||
|
||||
QColor fgColor() const;
|
||||
/* Foreground colour */
|
||||
QColor fgColor() const; // `symbol->fgcolour`
|
||||
void setFgColor(const QColor& fgColor);
|
||||
|
||||
QColor bgColor() const;
|
||||
/* Background colour */
|
||||
QColor bgColor() const; // `symbol->bgcolour`
|
||||
void setBgColor(const QColor& bgColor);
|
||||
|
||||
bool cmyk() const;
|
||||
/* Use CMYK colour space (Encapsulated PostScript and TIF) */
|
||||
bool cmyk() const; // `symbol->output_options | CMYK_COLOUR`
|
||||
void setCMYK(bool cmyk);
|
||||
|
||||
int borderType() const;
|
||||
/* Type of border above/below/around barcode */
|
||||
int borderType() const; // `symbol->output_options | BARCODE_BIND | BARCODE_BOX | BARCODE_BIND_TOP`
|
||||
void setBorderType(int borderTypeIndex);
|
||||
|
||||
int borderWidth() const;
|
||||
/* Size of border in X-dimensions */
|
||||
int borderWidth() const; // `symbol->border_width`
|
||||
void setBorderWidth(int borderWidth);
|
||||
|
||||
int whitespace() const;
|
||||
/* Width in X-dimensions of whitespace to left & right of barcode */
|
||||
int whitespace() const; // `symbol->whitespace_width`
|
||||
void setWhitespace(int whitespace);
|
||||
|
||||
int vWhitespace() const;
|
||||
/* Height in X-dimensions of whitespace above & below the barcode */
|
||||
int vWhitespace() const; // `symbol->whitespace_height`
|
||||
void setVWhitespace(int vWhitespace);
|
||||
|
||||
int fontSetting() const;
|
||||
/* Type of font to use i.e. normal, small, bold or (vector only) small bold */
|
||||
int fontSetting() const; // `symbol->output_options | SMALL_TEXT | BOLD_TEXT`
|
||||
void setFontSetting(int fontSettingIndex); // Sets from comboBox index
|
||||
void setFontSettingValue(int fontSetting); // Sets literal value
|
||||
|
||||
bool showText() const;
|
||||
/* Show (true) or hide (false) Human Readable Text */
|
||||
bool showText() const; // `symbol->show_hrt`
|
||||
void setShowText(bool showText);
|
||||
|
||||
bool gsSep() const;
|
||||
/* Set to true to use GS (Group Separator) instead of FNC1 as GS1 separator (Data Matrix) */
|
||||
bool gsSep() const; // `symbol->output_options | GS1_GS_SEPARATOR`
|
||||
void setGSSep(bool gsSep);
|
||||
|
||||
bool quietZones() const;
|
||||
/* Add compliant quiet zones (additional to any specified whitespace)
|
||||
Note: CODE16K, CODE49, CODABLOCKF, ITF14, EAN/UPC have default quiet zones */
|
||||
bool quietZones() const; // `symbol->output_options | BARCODE_QUIET_ZONES`
|
||||
void setQuietZones(bool quietZones);
|
||||
|
||||
bool noQuietZones() const;
|
||||
/* Disable quiet zones, notably those with defaults as listed above */
|
||||
bool noQuietZones() const; // `symbol->output_options | BARCODE_NO_QUIET_ZONES`
|
||||
void setNoQuietZones(bool noQuietZones);
|
||||
|
||||
bool compliantHeight() const;
|
||||
/* Warn if height not compliant and use standard height (if any) as default */
|
||||
bool compliantHeight() const; // `symbol->output_options | COMPLIANT_HEIGHT`
|
||||
void setCompliantHeight(bool compliantHeight);
|
||||
|
||||
/* Rotate barcode by angle (degrees 0, 90, 180 and 270) */
|
||||
int rotateAngle() const;
|
||||
void setRotateAngle(int rotateIndex); // Sets from comboBox index
|
||||
void setRotateAngleValue(int rotateAngle); // Sets literal value
|
||||
|
||||
int eci() const;
|
||||
/* Extended Channel Interpretation (segment 0 eci) */
|
||||
int eci() const; // `symbol->eci`
|
||||
void setECI(int ECIIndex); // Sets from comboBox index
|
||||
void setECIValue(int eci); // Sets literal value
|
||||
|
||||
bool gs1Parens() const;
|
||||
/* Process parentheses as GS1 AI delimiters (instead of square brackets) */
|
||||
bool gs1Parens() const; // `symbol->input_mode | GS1PARENS_MODE`
|
||||
void setGS1Parens(bool gs1Parens);
|
||||
|
||||
bool gs1NoCheck() const;
|
||||
/* Do not check validity of GS1 data (except that printable ASCII only) */
|
||||
bool gs1NoCheck() const; // `symbol->input_mode | GS1NOCHECK_MODE`
|
||||
void setGS1NoCheck(bool gs1NoCheck);
|
||||
|
||||
bool readerInit() const;
|
||||
/* Reader Initialisation (Programming) */
|
||||
bool readerInit() const; // `symbol->output_options | READER_INIT`
|
||||
void setReaderInit(bool readerInit);
|
||||
|
||||
int warnLevel() const;
|
||||
/* Affects error/warning value returned by Zint API (see `getError()` below) */
|
||||
int warnLevel() const; // `symbol->warn_level`
|
||||
void setWarnLevel(int warnLevel);
|
||||
|
||||
bool debug() const;
|
||||
/* Debugging flags */
|
||||
bool debug() const; // `symbol->debug`
|
||||
void setDebug(bool debug);
|
||||
|
||||
|
||||
/* Symbol output info set by Zint on successful `render()` */
|
||||
int encodedWidth() const; // Read-only, encoded width (no. of modules encoded)
|
||||
int encodedRows() const; // Read-only, no. of rows encoded
|
||||
float vectorWidth() const; // Read-only, scaled width
|
||||
float vectorHeight() const; // Read-only, scaled height
|
||||
|
||||
|
||||
/* Legacy property getters/setters */
|
||||
void setWidth(int width); /* option_1 */
|
||||
void setWidth(int width); /* `symbol->option_1` */
|
||||
int width() const;
|
||||
void setSecurityLevel(int securityLevel); /* option_2 */
|
||||
void setSecurityLevel(int securityLevel); /* `symbol->option_2` */
|
||||
int securityLevel() const;
|
||||
void setPdf417CodeWords(int pdf417CodeWords); /* No-op */
|
||||
int pdf417CodeWords() const;
|
||||
void setHideText(bool hide); /* setShowText(!hide) */
|
||||
void setTargetSize(int width, int height);
|
||||
QString error_message() const; /* Same as lastError() */
|
||||
void setHideText(bool hide); /* `setShowText(!hide)` */
|
||||
void setTargetSize(int width, int height); /* No-op */
|
||||
QString error_message() const; /* Same as `lastError()` */
|
||||
|
||||
/* Test capabilities - ZBarcode_Cap() */
|
||||
|
||||
/* Test capabilities - `ZBarcode_Cap()` */
|
||||
bool hasHRT(int symbology = 0) const;
|
||||
bool isStackable(int symbology = 0) const;
|
||||
bool isExtendable(int symbology = 0) const;
|
||||
|
@ -186,20 +244,56 @@ public:
|
|||
bool supportsStructApp(int symbology = 0) const;
|
||||
bool hasCompliantHeight(int symbology = 0) const;
|
||||
|
||||
/* Whether takes GS1 AI-delimited data */
|
||||
bool takesGS1AIData(int symbology = 0) const;
|
||||
|
||||
|
||||
/* Error or warning returned by Zint on `render()` or `save_to_file()` */
|
||||
int getError() const;
|
||||
|
||||
const QString& lastError() const;
|
||||
bool hasErrors() const;
|
||||
/* Error message returned by Zint on `render()` or `save_to_file()` */
|
||||
const QString& lastError() const; // `symbol->errtxt`
|
||||
|
||||
bool save_to_file(const QString& filename);
|
||||
/* Whether `lastError()` set */
|
||||
bool hasErrors() const; // `symbol->errtxt`
|
||||
|
||||
/* Note: legacy argument `mode` is not used */
|
||||
|
||||
/* Encode and print barcode to file `filename`. Only sets `getError()` on error, not on warning */
|
||||
bool save_to_file(const QString& filename); // `ZBarcode_Print()`
|
||||
|
||||
/* Encode and display barcode in `paintRect` using `painter`.
|
||||
Note: legacy argument `mode` is not used */
|
||||
void render(QPainter& painter, const QRectF& paintRect, AspectRatioMode mode = IgnoreAspectRatio);
|
||||
|
||||
/* Whether Zint library "libzint" built with PNG support or not (`ZBarcode_NoPng()`) */
|
||||
bool noPng() const;
|
||||
|
||||
int getVersion() const;
|
||||
/* Returns the default X-dimension (`ZBarcode_Default_Xdim()`).
|
||||
If `symbology` non-zero then used instead of `symbol()` */
|
||||
float defaultXdim(int symbology = 0) const;
|
||||
|
||||
/* Returns the scale to use for X-dimension `x_dim_mm` at `dpmm` for `filetype`.
|
||||
If `symbology` non-zero then used instead of `symbol()` */
|
||||
float getScaleFromXdimDp(float x_dim_mm, float dpmm, const QString& fileType, int symbology = 0) const;
|
||||
// `ZBarcode_Scale_Xdim()`
|
||||
|
||||
/* Reverse of `getScaleFromXdimDp()` above, returning the X-dimension or dot density given the scale `scale`.
|
||||
If `symbology` non-zero then used instead of `symbol()` */
|
||||
float getXdimDpFromScale(float scale, float x_dim_mm_or_dpmm, const QString& fileType, int symbology = 0) const;
|
||||
// `ZBarcode_XdimDp_From_Scale()`
|
||||
|
||||
/* Set `width_x_dim` and `height_x_dim` with estimated size of barcode based on X-dimension `x_dim`. To be called
|
||||
after a successful `render()`. Returns false if `scale()` zero or render is in error, otherwise true */
|
||||
bool getWidthHeightXdim(float x_dim, float &width_x_dim, float &height_x_dim) const;
|
||||
|
||||
|
||||
/* Return the BARCODE_XXX name of `symbology` */
|
||||
static QString barcodeName(const int symbology); // `ZBarcode_BarcodeName()`
|
||||
|
||||
/* Whether Zint library "libzint" built with PNG support or not */
|
||||
static bool noPng(); // `ZBarcode_NoPng()`
|
||||
|
||||
/* Version of Zint library "libzint" linked to */
|
||||
static int getVersion(); // `ZBarcode_Version()`
|
||||
|
||||
|
||||
/* Translate settings into Command Line equivalent. Set `win` to use Windows escaping of data.
|
||||
If `autoHeight` set then `--height=` option will not be emitted.
|
||||
|
@ -207,18 +301,20 @@ public:
|
|||
height */
|
||||
QString getAsCLI(const bool win, const bool longOptOnly = false, const bool barcodeNames = false,
|
||||
const bool noEXE = false, const bool autoHeight = false, const float heightPerRow = 0.0f,
|
||||
const QString& outfile = "") const;
|
||||
const QString& outfile = "", const QZintXdimDpVars *xdimdpVars = nullptr) const;
|
||||
|
||||
signals:
|
||||
void encoded();
|
||||
void errored();
|
||||
void encoded(); // Emitted on successful `render()`
|
||||
void errored(); // Emitted if an error (not warning) occurred on `render()`
|
||||
|
||||
private:
|
||||
void resetSymbol();
|
||||
void encode();
|
||||
bool resetSymbol(); // Reset the symbol structure for encoding using member fields
|
||||
void encode(); // `ZBarcode_Encode_and_Buffer_Vector()` or `ZBarcode_Encode_Segs_and_Buffer_Vector()`
|
||||
|
||||
/* Helper to convert `m_segs` to `struct zint_seg[]` */
|
||||
int convertSegs(struct zint_seg segs[], std::vector<QByteArray>& bstrs);
|
||||
|
||||
/* Convert `zint_vector_rect->colour` to Qt color */
|
||||
static Qt::GlobalColor colourToQtColor(int colour);
|
||||
|
||||
/* `getAsCLI()` helpers */
|
||||
|
@ -232,6 +328,8 @@ private:
|
|||
static void arg_float(QString& cmd, const char *const opt, const float val, const bool allowZero = false);
|
||||
static void arg_structapp(QString& cmd, const char *const opt, const int count, const int index,
|
||||
const QString& id, const bool win);
|
||||
static void arg_scalexdimdp(QString& cmd, const char *const opt, const float scale, const float dpmm,
|
||||
const int symbol, const QZintXdimDpVars *xdimdpVars);
|
||||
|
||||
private:
|
||||
zint_symbol *m_zintSymbol;
|
||||
|
@ -244,6 +342,7 @@ private:
|
|||
int m_option_1;
|
||||
int m_option_2;
|
||||
int m_option_3;
|
||||
float m_dpmm;
|
||||
float m_scale;
|
||||
bool m_dotty;
|
||||
float m_dot_size;
|
||||
|
@ -271,6 +370,8 @@ private:
|
|||
bool m_debug;
|
||||
int m_encodedWidth;
|
||||
int m_encodedRows;
|
||||
float m_vectorWidth;
|
||||
float m_vectorHeight;
|
||||
QString m_lastError;
|
||||
int m_error;
|
||||
|
||||
|
@ -278,6 +379,21 @@ private:
|
|||
int target_size_vert; /* Legacy */
|
||||
};
|
||||
|
||||
/* Printing Scale settings */
|
||||
struct QZintXdimDpVars {
|
||||
double x_dim = 0.0; // X-dimension in `x_dim_units`
|
||||
int x_dim_units = 0; // 0 for mm, 1 for inches
|
||||
int resolution = 0; // Dot density in `resolution_units`
|
||||
int resolution_units = 0; // 0 for dpmm, 1 for dpi
|
||||
int filetype = 0; // For non-MaxiCode, 0 for GIF (raster), 1 for SVG (vector)
|
||||
int filetype_maxicode = 0; // For MaxiCode only, 0 for GIF (raster), 1 for SVG (vector), 2 for EMF
|
||||
int set = 0; // 1 if explicitly set, 0 if just defaults (in which case the struct isn't applicable to `dpmm()`)
|
||||
|
||||
/* Helper to return "GIF"/"SVG"(/"EMF") if `msg` false, "raster"/"vector"(/"EMF") otherwise
|
||||
(EMF only if `symbol` is MaxiCode) */
|
||||
static const char *getFileType(int symbol, const struct QZintXdimDpVars *vars, bool msg = false);
|
||||
};
|
||||
|
||||
} /* namespace Zint */
|
||||
|
||||
/* vim: set ts=4 sw=4 et : */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue