source: trunk/client/inc/hpdf403/_tcpdf_5.0.002/2dbarcodes.php@ 418

Last change on this file since 418 was 349, checked in by roby, 4 years ago
File size: 5.8 KB
Line 
1<?php
2//============================================================+
3// File name : 2dbarcodes.php
4// Begin : 2009-04-07
5// Last Update : 2010-04-30
6// Version : 1.0.003
7// License : GNU LGPL (http://www.gnu.org/copyleft/lesser.html)
8// ----------------------------------------------------------------------------
9// Copyright (C) 2008-2009 Nicola Asuni - Tecnick.com S.r.l.
10//
11// This program is free software: you can redistribute it and/or modify
12// it under the terms of the GNU Lesser General Public License as published by
13// the Free Software Foundation, either version 2.1 of the License, or
14// (at your option) any later version.
15//
16// This program is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU Lesser General Public License for more details.
20//
21// You should have received a copy of the GNU Lesser General Public License
22// along with this program. If not, see <http://www.gnu.org/licenses/>.
23//
24// See LICENSE.TXT file for more information.
25// ----------------------------------------------------------------------------
26//
27// Description : PHP class to creates array representations for
28// 2D barcodes to be used with TCPDF.
29//
30// Author: Nicola Asuni
31//
32// (c) Copyright:
33// Nicola Asuni
34// Tecnick.com S.r.l.
35// Via della Pace, 11
36// 09044 Quartucciu (CA)
37// ITALY
38// www.tecnick.com
39// info@tecnick.com
40//============================================================+
41
42/**
43 * PHP class to creates array representations for 2D barcodes to be used with TCPDF.
44 * @package com.tecnick.tcpdf
45 * @abstract Functions for generating string representation of 2D barcodes.
46 * @author Nicola Asuni
47 * @copyright 2008-2009 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
48 * @link http://www.tcpdf.org
49 * @license http://www.gnu.org/copyleft/lesser.html LGPL
50 * @version 1.0.003
51 */
52
53 /**
54 * PHP class to creates array representations for 2D barcodes to be used with TCPDF (http://www.tcpdf.org).<br>
55 * @name TCPDFBarcode
56 * @package com.tecnick.tcpdf
57 * @version 1.0.003
58 * @author Nicola Asuni
59 * @link http://www.tcpdf.org
60 * @license http://www.gnu.org/copyleft/lesser.html LGPL
61 */
62class TCPDF2DBarcode {
63
64 /**
65 * @var array representation of barcode.
66 * @access protected
67 */
68 protected $barcode_array = false;
69
70 /**
71 * This is the class constructor.
72 * Return an array representations for 2D barcodes:<ul>
73 * <li>$arrcode['code'] code to be printed on text label</li>
74 * <li>$arrcode['num_rows'] required number of rows</li>
75 * <li>$arrcode['num_cols'] required number of columns</li>
76 * <li>$arrcode['bcode'][$r][$c] value of the cell is $r row and $c column (0 = transparent, 1 = black)</li></ul>
77 * @param string $code code to print
78 * @param string $type type of barcode: <ul>li>RAW: raw mode - comma-separad list of array rows</li><li>RAW2: raw mode - array rows are surrounded by square parenthesis.</li><li>QRCODE : QR-CODE Low error correction</li><li>QRCODE,L : QR-CODE Low error correction</li><li>QRCODE,M : QR-CODE Medium error correction</li><li>QRCODE,Q : QR-CODE Better error correction</li><li>QRCODE,H : QR-CODE Best error correction</li></ul>
79 */
80 public function __construct($code, $type) {
81 $this->setBarcode($code, $type);
82 }
83
84 /**
85 * Return an array representations of barcode.
86 * @return array
87 */
88 public function getBarcodeArray() {
89 return $this->barcode_array;
90 }
91
92 /**
93 * Set the barcode.
94 * @param string $code code to print
95 * @param string $type type of barcode: <ul><li>RAW: raw mode - comma-separad list of array rows</li><li>RAW2: raw mode - array rows are surrounded by square parenthesis.</li><li>QRCODE : QR-CODE Low error correction</li><li>QRCODE,L : QR-CODE Low error correction</li><li>QRCODE,M : QR-CODE Medium error correction</li><li>QRCODE,Q : QR-CODE Better error correction</li><li>QRCODE,H : QR-CODE Best error correction</li></ul>
96 * @return array
97 */
98 public function setBarcode($code, $type) {
99 $mode = explode(',', $type);
100 $qrtype = strtoupper($mode[0]);
101 switch ($qrtype) {
102 case 'QRCODE': { // QR-CODE
103 require_once(dirname(__FILE__).'/qrcode.php');
104 if (!isset($mode[1]) OR (!in_array($mode[1],array('L','M','Q','H')))) {
105 $mode[1] = 'L'; // Ddefault: Low error correction
106 }
107 $qrcode = new QRcode($code, strtoupper($mode[1]));
108 $this->barcode_array = $qrcode->getBarcodeArray();
109 break;
110 }
111 case 'RAW':
112 case 'RAW2': { // RAW MODE
113 // remove spaces
114 $code = preg_replace('/[\s]*/si', '', $code);
115 if (strlen($code) < 3) {
116 break;
117 }
118 if ($qrtype == 'RAW') {
119 // comma-separated rows
120 $rows = explode(',', $code);
121 } else {
122 // rows enclosed in square parethesis
123 $code = substr($code, 1, -1);
124 $rows = explode('][', $code);
125 }
126 $this->barcode_array['num_rows'] = count($rows);
127 $this->barcode_array['num_cols'] = strlen($rows[0]);
128 $this->barcode_array['bcode'] = array();
129 foreach ($rows as $r) {
130 $this->barcode_array['bcode'][] = str_split($r, 1);
131 }
132 break;
133 }
134 case 'TEST': { // TEST MODE
135 $this->barcode_array['num_rows'] = 5;
136 $this->barcode_array['num_cols'] = 15;
137 $this->barcode_array['bcode'] = array(
138 array(1,1,1,0,1,1,1,0,1,1,1,0,1,1,1),
139 array(0,1,0,0,1,0,0,0,1,0,0,0,0,1,0),
140 array(0,1,0,0,1,1,0,0,1,1,1,0,0,1,0),
141 array(0,1,0,0,1,0,0,0,0,0,1,0,0,1,0),
142 array(0,1,0,0,1,1,1,0,1,1,1,0,0,1,0));
143 break;
144 }
145 default: {
146 $this->barcode_array = false;
147 }
148 }
149 }
150} // end of class
151
152//============================================================+
153// END OF FILE
154//============================================================+
155?>
Note: See TracBrowser for help on using the repository browser.