vendor/tecnickcom/tc-lib-barcode/src/Barcode.php line 99

Open in your IDE?
  1. <?php
  2. /**
  3. * Barcode.php
  4. *
  5. * @since 2015-02-21
  6. * @category Library
  7. * @package Barcode
  8. * @author Nicola Asuni <info@tecnick.com>
  9. * @copyright 2015-2023 Nicola Asuni - Tecnick.com LTD
  10. * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
  11. * @link https://github.com/tecnickcom/tc-lib-barcode
  12. *
  13. * This file is part of tc-lib-barcode software library.
  14. */
  15. namespace Com\Tecnick\Barcode;
  16. use Com\Tecnick\Barcode\Exception as BarcodeException;
  17. /**
  18. * Com\Tecnick\Barcode\Barcode
  19. *
  20. * Barcode Barcode class
  21. *
  22. * @since 2015-02-21
  23. * @category Library
  24. * @package Barcode
  25. * @author Nicola Asuni <info@tecnick.com>
  26. * @copyright 2010-2023 Nicola Asuni - Tecnick.com LTD
  27. * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
  28. * @link https://github.com/tecnickcom/tc-lib-barcode
  29. * @deprecated tc-lib-barcode 1.x is deprecated: upgrade to tecnickcom/tc-lib-barcode ^2.
  30. */
  31. class Barcode
  32. {
  33. /**
  34. * Deprecation notice message.
  35. */
  36. const DEPRECATION_NOTICE = 'tc-lib-barcode 1.x is deprecated:'
  37. . ' upgrade to tecnickcom/tc-lib-barcode ^2 (https://github.com/tecnickcom/tc-lib-barcode).';
  38. /**
  39. * Array containing the map between the barcode type and correspondent class
  40. */
  41. const TYPECLASS = array(
  42. 'C128' => 'Linear\\CodeOneTwoEight', // CODE 128
  43. 'C128A' => 'Linear\\CodeOneTwoEight\\CodeOneTwoEightA', // CODE 128 A
  44. 'C128B' => 'Linear\\CodeOneTwoEight\\CodeOneTwoEightB', // CODE 128 B
  45. 'C128C' => 'Linear\\CodeOneTwoEight\\CodeOneTwoEightC', // CODE 128 C
  46. 'C39' => 'Linear\\CodeThreeNine', // CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.
  47. 'C39+' => 'Linear\\CodeThreeNineCheck', // CODE 39 + CHECKSUM
  48. 'C39E' => 'Linear\\CodeThreeNineExt', // CODE 39 EXTENDED
  49. 'C39E+' => 'Linear\\CodeThreeNineExtCheck', // CODE 39 EXTENDED + CHECKSUM
  50. 'C93' => 'Linear\\CodeNineThree', // CODE 93 - USS-93
  51. 'CODABAR' => 'Linear\\Codabar', // CODABAR
  52. 'CODE11' => 'Linear\\CodeOneOne', // CODE 11
  53. 'EAN13' => 'Linear\\EanOneThree', // EAN 13
  54. 'EAN2' => 'Linear\\EanTwo', // EAN 2-Digits UPC-Based Extension
  55. 'EAN5' => 'Linear\\EanFive', // EAN 5-Digits UPC-Based Extension
  56. 'EAN8' => 'Linear\\EanEight', // EAN 8
  57. 'I25' => 'Linear\\InterleavedTwoOfFive', // Interleaved 2 of 5
  58. 'I25+' => 'Linear\\InterleavedTwoOfFiveCheck', // Interleaved 2 of 5 + CHECKSUM
  59. 'IMB' => 'Linear\\Imb', // IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200
  60. 'IMBPRE' => 'Linear\\ImbPre', // IMB - Intelligent Mail Barcode pre-processed
  61. 'KIX' => 'Linear\\KlantIndex', // KIX (Klant index - Customer index)
  62. 'LRAW' => 'Linear\\Raw', // 1D RAW MODE (comma-separated rows of 01 strings)
  63. 'MSI' => 'Linear\\Msi', // MSI (Variation of Plessey code)
  64. 'MSI+' => 'Linear\\MsiCheck', // MSI + CHECKSUM (modulo 11)
  65. 'PHARMA' => 'Linear\\Pharma', // PHARMACODE
  66. 'PHARMA2T' => 'Linear\\PharmaTwoTracks', // PHARMACODE TWO-TRACKS
  67. 'PLANET' => 'Linear\\Planet', // PLANET
  68. 'POSTNET' => 'Linear\\Postnet', // POSTNET
  69. 'RMS4CC' => 'Linear\\RoyalMailFourCc', // RMS4CC (Royal Mail 4-state Customer Bar Code)
  70. 'S25' => 'Linear\\StandardTwoOfFive', // Standard 2 of 5
  71. 'S25+' => 'Linear\\StandardTwoOfFiveCheck', // Standard 2 of 5 + CHECKSUM
  72. 'UPCA' => 'Linear\\UpcA', // UPC-A
  73. 'UPCE' => 'Linear\\UpcE', // UPC-E
  74. 'AZTEC' => 'Square\\Aztec', // AZTEC Code (ISO/IEC 24778:2008)
  75. 'DATAMATRIX' => 'Square\\Datamatrix', // DATAMATRIX (ISO/IEC 16022)
  76. 'PDF417' => 'Square\\PdfFourOneSeven', // PDF417 (ISO/IEC 15438:2006)
  77. 'QRCODE' => 'Square\\QrCode', // QR-CODE
  78. 'SRAW' => 'Square\\Raw', // 2D RAW MODE (comma-separated rows of 01 strings)
  79. );
  80. /**
  81. * Initialize a new barcode factory
  82. *
  83. * @deprecated tc-lib-barcode 1.x is deprecated: upgrade to tecnickcom/tc-lib-barcode ^2.
  84. */
  85. public function __construct()
  86. {
  87. // Deprecation notice, raised once per process and silenced by defining
  88. // TCLIB_BARCODE_SILENCE_DEPRECATION. The @ prevents the default handler
  89. // from printing it into the generated output.
  90. static $notice = true;
  91. if ($notice && !(defined('TCLIB_BARCODE_SILENCE_DEPRECATION') && TCLIB_BARCODE_SILENCE_DEPRECATION)) {
  92. $notice = false;
  93. @trigger_error(self::DEPRECATION_NOTICE, E_USER_DEPRECATED);
  94. }
  95. }
  96. /**
  97. * Get the list of supported Barcode types
  98. *
  99. * @return array
  100. */
  101. public function getTypes()
  102. {
  103. return array_keys(self::TYPECLASS);
  104. }
  105. /**
  106. * Get the barcode object
  107. *
  108. * @param string $type Barcode type
  109. * @param string $code Barcode content
  110. * @param int $width Barcode width in user units (excluding padding).
  111. * A negative value indicates the multiplication factor for each column.
  112. * @param int $height Barcode height in user units (excluding padding).
  113. * A negative value indicates the multiplication factor for each row.
  114. * @param string $color Foreground color in Web notation (color name, or hexadecimal code, or CSS syntax)
  115. * @param array $padding Additional padding to add around the barcode (top, right, bottom, left) in user units.
  116. * A negative value indicates the multiplication factor for each row or column.
  117. *
  118. * @return Type
  119. *
  120. * @throws BarcodeException in case of error
  121. */
  122. public function getBarcodeObj(
  123. $type,
  124. $code,
  125. $width = -1,
  126. $height = -1,
  127. $color = 'black',
  128. $padding = array(0, 0, 0, 0)
  129. ) {
  130. // extract extra parameters (if any)
  131. $params = explode(',', $type);
  132. $type = array_shift($params);
  133. if (!array_key_exists($type, self::TYPECLASS)) {
  134. throw new BarcodeException('Unsupported barcode type: ' . $type);
  135. }
  136. $bclass = '\\Com\\Tecnick\\Barcode\\Type\\' . self::TYPECLASS[$type];
  137. return new $bclass($code, $width, $height, $color, $params, $padding);
  138. }
  139. }