Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/zint/backend_qt/qzint.h @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 /*************************************************************************** | |
| 2 * Copyright (C) 2008 by BogDan Vatra * | |
| 3 * bogdan@licentia.eu * | |
| 4 * Copyright (C) 2010-2023 Robin Stuart * | |
| 5 * * | |
| 6 * This program is free software: you can redistribute it and/or modify * | |
| 7 * it under the terms of the GNU General Public License as published by * | |
| 8 * the Free Software Foundation, either version 3 of the License, or * | |
| 9 * (at your option) any later version. * | |
| 10 * This program is distributed in the hope that it will be useful, * | |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
| 13 * GNU General Public License for more details. * | |
| 14 * You should have received a copy of the GNU General Public License * | |
| 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. * | |
| 16 ***************************************************************************/ | |
| 17 /* SPDX-License-Identifier: GPL-3.0-or-later */ | |
| 18 | |
| 19 /* | |
| 20 * For version, see "../backend/zintconfig.h" | |
| 21 * For documentation, see "../docs/manual.txt" | |
| 22 */ | |
| 23 | |
| 24 #ifndef QZINT_H | |
| 25 #define QZINT_H | |
| 26 | |
| 27 #include <QObject> | |
| 28 #include <QColor> | |
| 29 #include <QPainter> | |
| 30 #include "zint.h" | |
| 31 | |
| 32 namespace Zint | |
| 33 { | |
| 34 | |
| 35 /* QString version of `struct zint_seg` */ | |
| 36 class QZintSeg { | |
| 37 public: | |
| 38 QString m_text; // `seg->source` and `seg->length` | |
| 39 int m_eci; // `seg->eci` | |
| 40 | |
| 41 QZintSeg(); | |
| 42 QZintSeg(const QString& text, const int ECIIndex = 0); // `ECIIndex` is comboBox index (not ECI value) | |
| 43 }; | |
| 44 | |
| 45 struct QZintXdimDpVars; // Forward reference to Printing Scale settings, see end | |
| 46 | |
| 47 /* Interface */ | |
| 48 class QZint : public QObject | |
| 49 { | |
| 50 Q_OBJECT | |
| 51 | |
| 52 public: | |
| 53 /* Legacy - not used */ | |
| 54 enum AspectRatioMode{ IgnoreAspectRatio = 0, KeepAspectRatio = 1, CenterBarCode = 2 }; | |
| 55 | |
| 56 public: | |
| 57 QZint(); | |
| 58 ~QZint(); | |
| 59 | |
| 60 /* Symbology to use (see BARCODE_XXX) */ | |
| 61 int symbol() const; // `symbol->symbology` | |
| 62 void setSymbol(int symbol); | |
| 63 | |
| 64 /* Input data encoding. Default UNICODE_MODE */ | |
| 65 int inputMode() const; // `symbol->input_mode` | |
| 66 void setInputMode(int input_mode); | |
| 67 | |
| 68 /* Note text/eci and segs are mutally exclusive */ | |
| 69 | |
| 70 /* Input data (segment 0 text) */ | |
| 71 QString text() const; | |
| 72 /* Set input data. Note: clears segs */ | |
| 73 void setText(const QString& text); | |
| 74 | |
| 75 /* Input segments. */ | |
| 76 std::vector<QZintSeg> segs() const; | |
| 77 /* Set segments. Note: clears text and sets eci */ | |
| 78 void setSegs(const std::vector<QZintSeg>& segs); | |
| 79 | |
| 80 /* Primary message (Maxicode, Composite) */ | |
| 81 QString primaryMessage() const; // `symbol->primary` | |
| 82 void setPrimaryMessage(const QString& primaryMessage); | |
| 83 | |
| 84 /* Symbol height in X-dimensions */ | |
| 85 float height() const; // `symbol->height` | |
| 86 void setHeight(float height); | |
| 87 | |
| 88 /* Symbol-specific options (see "../docs/manual.txt") */ | |
| 89 int option1() const; // `symbol->option_1` | |
| 90 void setOption1(int option_1); | |
| 91 | |
| 92 /* Symbol-specific options */ | |
| 93 int option2() const; // `symbol->option_2` | |
| 94 void setOption2(int option); | |
| 95 | |
| 96 /* Symbol-specific options */ | |
| 97 int option3() const; // `symbol->option_3` | |
| 98 void setOption3(int option); | |
| 99 | |
| 100 /* Scale factor when printing barcode, i.e. adjusts X-dimension */ | |
| 101 float scale() const; // `symbol->scale` | |
| 102 void setScale(float scale); | |
| 103 | |
| 104 /* Resolution of output in dots per mm (BMP/EMF/PCX/PNG/TIF only) */ | |
| 105 float dpmm() const; // `symbol->dpmm` | |
| 106 void setDPMM(float dpmm); | |
| 107 | |
| 108 /* Dotty mode */ | |
| 109 bool dotty() const; // `symbol->input_mode | BARCODE_DOTTY_MODE` | |
| 110 void setDotty(bool botty); | |
| 111 | |
| 112 /* Size of dots used in BARCODE_DOTTY_MODE */ | |
| 113 float dotSize() const; // `symbol->dot_size` | |
| 114 void setDotSize(float dot_size); | |
| 115 | |
| 116 /* Height in X-dimensions that EAN/UPC guard bars descend */ | |
| 117 float guardDescent() const; // `symbol->guard_descent` | |
| 118 void setGuardDescent(float guardDescent); | |
| 119 | |
| 120 /* Structured Append info */ | |
| 121 int structAppCount() const; // `symbol->structapp.count` | |
| 122 int structAppIndex() const; // `symbol->structapp.index` | |
| 123 QString structAppID() const; // `symbol->structapp.id` | |
| 124 void setStructApp(const int count, const int index, const QString& id); | |
| 125 void clearStructApp(); | |
| 126 | |
| 127 /* Foreground colour (may be RGB(A) hex string or CMYK decimal "C,M,Y,K" percentage string) */ | |
| 128 QString fgStr() const; // `symbol->fgcolour` | |
| 129 bool setFgStr(const QString& fgStr); // Returns false if not valid colour string | |
| 130 | |
| 131 /* Foreground colour as QColor */ | |
| 132 QColor fgColor() const; // `symbol->fgcolour` | |
| 133 void setFgColor(const QColor& fgColor); | |
| 134 | |
| 135 /* Background colour (may be RGB(A) hex string or CMYK decimal "C,M,Y,K" percentage string) */ | |
| 136 QString bgStr() const; // `symbol->bgcolour` | |
| 137 bool setBgStr(const QString& bgStr); // Returns false if not valid colour string | |
| 138 | |
| 139 /* Background colour as QColor */ | |
| 140 QColor bgColor() const; // `symbol->bgcolour` | |
| 141 void setBgColor(const QColor& bgColor); | |
| 142 | |
| 143 /* Use CMYK colour space (Encapsulated PostScript and TIF) */ | |
| 144 bool cmyk() const; // `symbol->output_options | CMYK_COLOUR` | |
| 145 void setCMYK(bool cmyk); | |
| 146 | |
| 147 /* Type of border above/below/around barcode */ | |
| 148 int borderType() const; // `symbol->output_options | BARCODE_BIND | BARCODE_BOX | BARCODE_BIND_TOP` | |
| 149 void setBorderType(int borderTypeIndex); | |
| 150 | |
| 151 /* Size of border in X-dimensions */ | |
| 152 int borderWidth() const; // `symbol->border_width` | |
| 153 void setBorderWidth(int borderWidth); | |
| 154 | |
| 155 /* Width in X-dimensions of whitespace to left & right of barcode */ | |
| 156 int whitespace() const; // `symbol->whitespace_width` | |
| 157 void setWhitespace(int whitespace); | |
| 158 | |
| 159 /* Height in X-dimensions of whitespace above & below the barcode */ | |
| 160 int vWhitespace() const; // `symbol->whitespace_height` | |
| 161 void setVWhitespace(int vWhitespace); | |
| 162 | |
| 163 /* Type of font to use i.e. normal, small, bold or (vector only) small bold */ | |
| 164 int fontSetting() const; // `symbol->output_options | SMALL_TEXT | BOLD_TEXT` | |
| 165 void setFontSetting(int fontSettingIndex); // Sets from comboBox index | |
| 166 void setFontSettingValue(int fontSetting); // Sets literal value | |
| 167 | |
| 168 /* Text gap */ | |
| 169 float textGap() const; // `symbol->text_gap` | |
| 170 void setTextGap(float textGap); | |
| 171 | |
| 172 /* Show (true) or hide (false) Human Readable Text (HRT) */ | |
| 173 bool showText() const; // `symbol->show_hrt` | |
| 174 void setShowText(bool showText); | |
| 175 | |
| 176 /* Set to true to use GS (Group Separator) instead of FNC1 as GS1 separator (Data Matrix) */ | |
| 177 bool gsSep() const; // `symbol->output_options | GS1_GS_SEPARATOR` | |
| 178 void setGSSep(bool gsSep); | |
| 179 | |
| 180 /* Add compliant quiet zones (additional to any specified whitespace) | |
| 181 Note: CODE16K, CODE49, CODABLOCKF, ITF14, EAN/UPC have default quiet zones */ | |
| 182 bool quietZones() const; // `symbol->output_options | BARCODE_QUIET_ZONES` | |
| 183 void setQuietZones(bool quietZones); | |
| 184 | |
| 185 /* Disable quiet zones, notably those with defaults as listed above */ | |
| 186 bool noQuietZones() const; // `symbol->output_options | BARCODE_NO_QUIET_ZONES` | |
| 187 void setNoQuietZones(bool noQuietZones); | |
| 188 | |
| 189 /* Warn if height not compliant and use standard height (if any) as default */ | |
| 190 bool compliantHeight() const; // `symbol->output_options | COMPLIANT_HEIGHT` | |
| 191 void setCompliantHeight(bool compliantHeight); | |
| 192 | |
| 193 /* Rotate barcode by angle (degrees 0, 90, 180 and 270) */ | |
| 194 int rotateAngle() const; | |
| 195 void setRotateAngle(int rotateIndex); // Sets from comboBox index | |
| 196 void setRotateAngleValue(int rotateAngle); // Sets literal value | |
| 197 | |
| 198 /* Extended Channel Interpretation (segment 0 eci) */ | |
| 199 int eci() const; // `symbol->eci` | |
| 200 void setECI(int ECIIndex); // Sets from comboBox index | |
| 201 void setECIValue(int eci); // Sets literal value | |
| 202 | |
| 203 /* Process parentheses as GS1 AI delimiters (instead of square brackets) */ | |
| 204 bool gs1Parens() const; // `symbol->input_mode | GS1PARENS_MODE` | |
| 205 void setGS1Parens(bool gs1Parens); | |
| 206 | |
| 207 /* Do not check validity of GS1 data (except that printable ASCII only) */ | |
| 208 bool gs1NoCheck() const; // `symbol->input_mode | GS1NOCHECK_MODE` | |
| 209 void setGS1NoCheck(bool gs1NoCheck); | |
| 210 | |
| 211 /* Reader Initialisation (Programming) */ | |
| 212 bool readerInit() const; // `symbol->output_options | READER_INIT` | |
| 213 void setReaderInit(bool readerInit); | |
| 214 | |
| 215 /* Whether to add quiet zone indicators ("<", ">") to HRT (EAN/UPC) */ | |
| 216 bool guardWhitespace() const; // `symbol->output_options | EANUPC_GUARD_WHITESPACE` | |
| 217 void setGuardWhitespace(bool guardWhitespace); | |
| 218 | |
| 219 /* Whether to embed the font in vector output - currently only for SVG output of EAN/UPC */ | |
| 220 bool embedVectorFont() const; // `symbol->output_options | EANUPC_GUARD_WHITESPACE` | |
| 221 void setEmbedVectorFont(bool embedVectorFont); | |
| 222 | |
| 223 /* Affects error/warning value returned by Zint API (see `getError()` below) */ | |
| 224 int warnLevel() const; // `symbol->warn_level` | |
| 225 void setWarnLevel(int warnLevel); | |
| 226 | |
| 227 /* Debugging flags */ | |
| 228 bool debug() const; // `symbol->debug` | |
| 229 void setDebug(bool debug); | |
| 230 | |
| 231 | |
| 232 /* Symbol output info set by Zint on successful `render()` */ | |
| 233 int encodedWidth() const; // Read-only, encoded width (no. of modules encoded) | |
| 234 int encodedRows() const; // Read-only, no. of rows encoded | |
| 235 float encodedHeight() const; // Read-only, in X-dimensions | |
| 236 float vectorWidth() const; // Read-only, scaled width | |
| 237 float vectorHeight() const; // Read-only, scaled height | |
| 238 | |
| 239 | |
| 240 /* Legacy property getters/setters */ | |
| 241 void setWidth(int width); /* `symbol->option_2` */ | |
| 242 int width() const; | |
| 243 void setSecurityLevel(int securityLevel); /* `symbol->option_1` */ | |
| 244 int securityLevel() const; | |
| 245 void setPdf417CodeWords(int pdf417CodeWords); /* No-op */ | |
| 246 int pdf417CodeWords() const; | |
| 247 void setHideText(bool hide); /* `setShowText(!hide)` */ | |
| 248 void setTargetSize(int width, int height); /* No-op */ | |
| 249 QString error_message() const; /* Same as `lastError()` */ | |
| 250 | |
| 251 | |
| 252 /* Test capabilities - `ZBarcode_Cap()` */ | |
| 253 bool hasHRT(int symbology = 0) const; | |
| 254 bool isStackable(int symbology = 0) const; | |
| 255 bool isEANUPC(int symbology = 0) const; | |
| 256 bool isExtendable(int symbology = 0) const; /* Legacy - same as `isEANUPC()` */ | |
| 257 bool isComposite(int symbology = 0) const; | |
| 258 bool supportsECI(int symbology = 0) const; | |
| 259 bool supportsGS1(int symbology = 0) const; | |
| 260 bool isDotty(int symbology = 0) const; | |
| 261 bool hasDefaultQuietZones(int symbology = 0) const; | |
| 262 bool isFixedRatio(int symbology = 0) const; | |
| 263 bool supportsReaderInit(int symbology = 0) const; | |
| 264 bool supportsFullMultibyte(int symbology = 0) const; | |
| 265 bool hasMask(int symbology = 0) const; | |
| 266 bool supportsStructApp(int symbology = 0) const; | |
| 267 bool hasCompliantHeight(int symbology = 0) const; | |
| 268 | |
| 269 /* Whether takes GS1 AI-delimited data */ | |
| 270 bool takesGS1AIData(int symbology = 0) const; | |
| 271 | |
| 272 | |
| 273 /* Error or warning returned by Zint on `render()` or `save_to_file()` */ | |
| 274 int getError() const; | |
| 275 | |
| 276 /* Error message returned by Zint on `render()` or `save_to_file()` */ | |
| 277 const QString& lastError() const; // `symbol->errtxt` | |
| 278 | |
| 279 /* Whether `lastError()` set */ | |
| 280 bool hasErrors() const; // `symbol->errtxt` | |
| 281 | |
| 282 | |
| 283 /* Encode and print barcode to file `filename`. Only sets `getError()` on error, not on warning */ | |
| 284 bool save_to_file(const QString& filename); // `ZBarcode_Print()` | |
| 285 | |
| 286 /* Encode and display barcode in `paintRect` using `painter`. | |
| 287 Note: legacy argument `mode` is not used */ | |
| 288 void render(QPainter& painter, const QRectF& paintRect, AspectRatioMode mode = IgnoreAspectRatio); | |
| 289 | |
| 290 | |
| 291 /* Returns the default X-dimension (`ZBarcode_Default_Xdim()`). | |
| 292 If `symbology` non-zero then used instead of `symbol()` */ | |
| 293 float defaultXdim(int symbology = 0) const; | |
| 294 | |
| 295 /* Returns the scale to use for X-dimension `x_dim_mm` at `dpmm` for `filetype`. | |
| 296 If `symbology` non-zero then used instead of `symbol()` */ | |
| 297 float getScaleFromXdimDp(float x_dim_mm, float dpmm, const QString& fileType, int symbology = 0) const; | |
| 298 // `ZBarcode_Scale_Xdim()` | |
| 299 | |
| 300 /* Reverse of `getScaleFromXdimDp()` above, returning the X-dimension or dot density given the scale `scale`. | |
| 301 If `symbology` non-zero then used instead of `symbol()` */ | |
| 302 float getXdimDpFromScale(float scale, float x_dim_mm_or_dpmm, const QString& fileType, int symbology = 0) const; | |
| 303 // `ZBarcode_XdimDp_From_Scale()` | |
| 304 | |
| 305 /* Set `width_x_dim` and `height_x_dim` with estimated size of barcode based on X-dimension `x_dim`. To be called | |
| 306 after a successful `render()`. Returns false if `scale()` zero or render is in error, otherwise true */ | |
| 307 bool getWidthHeightXdim(float x_dim, float &width_x_dim, float &height_x_dim) const; | |
| 308 | |
| 309 | |
| 310 /* Return the BARCODE_XXX name of `symbology` */ | |
| 311 static QString barcodeName(const int symbology); // `ZBarcode_BarcodeName()` | |
| 312 | |
| 313 /* Whether Zint library "libzint" built with PNG support or not */ | |
| 314 static bool noPng(); // `ZBarcode_NoPng()` | |
| 315 | |
| 316 /* Version of Zint library "libzint" linked to */ | |
| 317 static int getVersion(); // `ZBarcode_Version()` | |
| 318 | |
| 319 | |
| 320 /* Translate settings into Command Line equivalent. Set `win` to use Windows escaping of data. | |
| 321 If `autoHeight` set then `--height=` option will not be emitted. | |
| 322 If HEIGHTPERROW_MODE set and non-zero `heightPerRow` given then use that for height instead of internal | |
| 323 height */ | |
| 324 QString getAsCLI(const bool win, const bool longOptOnly = false, const bool barcodeNames = false, | |
| 325 const bool noEXE = false, const bool autoHeight = false, const float heightPerRow = 0.0f, | |
| 326 const QString& outfile = "", const QZintXdimDpVars *xdimdpVars = nullptr) const; | |
| 327 | |
| 328 signals: | |
| 329 void encoded(); // Emitted on successful `render()` | |
| 330 void errored(); // Emitted if an error (not warning) occurred on `render()` | |
| 331 | |
| 332 private: | |
| 333 bool resetSymbol(); // Reset the symbol structure for encoding using member fields | |
| 334 void encode(); // `ZBarcode_Encode_and_Buffer_Vector()` or `ZBarcode_Encode_Segs_and_Buffer_Vector()` | |
| 335 | |
| 336 /* Helper to convert `m_segs` to `struct zint_seg[]` */ | |
| 337 int convertSegs(struct zint_seg segs[], std::vector<QByteArray>& bstrs); | |
| 338 | |
| 339 /* Convert `zint_vector_rect->colour` to Qt color */ | |
| 340 static Qt::GlobalColor colourToQtColor(int colour); | |
| 341 | |
| 342 /* `getAsCLI()` helpers */ | |
| 343 static void arg_str(QString& cmd, const char *const opt, const QString& val); | |
| 344 static void arg_int(QString& cmd, const char *const opt, const int val, const bool allowZero = false); | |
| 345 static void arg_bool(QString& cmd, const char *const opt, const bool val); | |
| 346 static void arg_data(QString& cmd, const char *const opt, const QString& val, const bool win); | |
| 347 static void arg_seg(QString& cmd, const int seg_no, const QZintSeg& val, const bool win); | |
| 348 static void arg_data_esc(QString& cmd, const char *const opt, QString& text, const bool win); | |
| 349 static void arg_float(QString& cmd, const char *const opt, const float val, const bool allowZero = false); | |
| 350 static void arg_structapp(QString& cmd, const char *const opt, const int count, const int index, | |
| 351 const QString& id, const bool win); | |
| 352 static void arg_scalexdimdp(QString& cmd, const char *const opt, const float scale, const float dpmm, | |
| 353 const int symbol, const QZintXdimDpVars *xdimdpVars); | |
| 354 | |
| 355 private: | |
| 356 zint_symbol *m_zintSymbol; | |
| 357 int m_symbol; | |
| 358 int m_input_mode; | |
| 359 QString m_text; | |
| 360 QString m_primaryMessage; | |
| 361 std::vector<QZintSeg> m_segs; | |
| 362 float m_height; | |
| 363 int m_option_1; | |
| 364 int m_option_2; | |
| 365 int m_option_3; | |
| 366 float m_dpmm; | |
| 367 float m_scale; | |
| 368 bool m_dotty; | |
| 369 float m_dot_size; | |
| 370 float m_guardDescent; | |
| 371 float m_textGap; | |
| 372 struct zint_structapp m_structapp; | |
| 373 QString m_fgStr; | |
| 374 QString m_bgStr; | |
| 375 bool m_cmyk; | |
| 376 int m_borderType; | |
| 377 int m_borderWidth; | |
| 378 int m_whitespace; | |
| 379 int m_vwhitespace; | |
| 380 int m_fontSetting; | |
| 381 bool m_show_hrt; | |
| 382 bool m_gssep; | |
| 383 bool m_quiet_zones; | |
| 384 bool m_no_quiet_zones; | |
| 385 bool m_compliant_height; | |
| 386 int m_rotate_angle; | |
| 387 int m_eci; | |
| 388 bool m_gs1parens; | |
| 389 bool m_gs1nocheck; | |
| 390 bool m_reader_init; | |
| 391 bool m_guard_whitespace; | |
| 392 bool m_embed_vector_font; | |
| 393 int m_warn_level; | |
| 394 bool m_debug; | |
| 395 int m_encodedWidth; | |
| 396 int m_encodedRows; | |
| 397 float m_encodedHeight; | |
| 398 float m_vectorWidth; | |
| 399 float m_vectorHeight; | |
| 400 QString m_lastError; | |
| 401 int m_error; | |
| 402 | |
| 403 int target_size_horiz; /* Legacy */ | |
| 404 int target_size_vert; /* Legacy */ | |
| 405 }; | |
| 406 | |
| 407 /* Printing Scale settings */ | |
| 408 struct QZintXdimDpVars { | |
| 409 double x_dim = 0.0; // X-dimension in `x_dim_units` | |
| 410 int x_dim_units = 0; // 0 for mm, 1 for inches | |
| 411 int resolution = 0; // Dot density in `resolution_units` | |
| 412 int resolution_units = 0; // 0 for dpmm, 1 for dpi | |
| 413 int filetype = 0; // For non-MaxiCode, 0 for GIF (raster), 1 for SVG (vector) | |
| 414 int filetype_maxicode = 0; // For MaxiCode only, 0 for GIF (raster), 1 for SVG (vector), 2 for EMF | |
| 415 int set = 0; // 1 if explicitly set, 0 if just defaults (in which case the struct isn't applicable to `dpmm()`) | |
| 416 | |
| 417 /* Helper to return "GIF"/"SVG"(/"EMF") if `msg` false, "raster"/"vector"(/"EMF") otherwise | |
| 418 (EMF only if `symbol` is MaxiCode) */ | |
| 419 static const char *getFileType(int symbol, const struct QZintXdimDpVars *vars, bool msg = false); | |
| 420 }; | |
| 421 | |
| 422 } /* namespace Zint */ | |
| 423 | |
| 424 /* vim: set ts=4 sw=4 et : */ | |
| 425 #endif /* QZINT_H */ |
