BarcodeObject::DrawChar()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 4
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
//============================================================+
3
// File name   : barcode.php
4
// Begin       : 2002-07-31
5
// Last Update : 2005-01-02
6
// Author      : Karim Mribti [[email protected]]
7
// Version     : 1.1 [0.0.8a (original code)]
8
// License     : GNU LGPL (Lesser General Public License) 2.1
9
//               http://www.gnu.org/copyleft/lesser.txt
10
// Source Code : http://www.mribti.com/barcode/
11
//
12
// Description : Generic Barcode Render Class for PHP using
13
//               the GD graphics library.
14
//
15
// NOTE:
16
// This version contains changes by Nicola Asuni:
17
//  - porting to PHP4
18
//  - code style and formatting
19
//  - automatic php documentation in PhpDocumentor Style
20
//    (www.phpdoc.org)
21
//  - minor bug fixing
22
//  - $mCharSet and $mChars variables were added here
23
//============================================================+
24
25
/**
26
 * Barcode Render Class for PHP using the GD graphics library.
27
 * @author Karim Mribti, Nicola Asuni
28
 * @name BarcodeObject
29
 * @package com.tecnick.tcpdf
30
 * @version 0.0.8a 2001-04-01 (original code)
31
 * @since 2001-03-25
32
 * @license http://www.gnu.org/copyleft/lesser.html LGPL
33
 */
34
35
// Styles
36
// Global
37
38
/**
39
 * option: generate barcode border
40
 */
41
define("BCS_BORDER", 1);
42
43
/**
44
 * option: use transparent background
45
 */
46
define("BCS_TRANSPARENT", 2);
47
48
/**
49
 * option: center barcode
50
 */
51
define("BCS_ALIGN_CENTER", 4);
52
53
/**
54
 * option: align left
55
 */
56
define("BCS_ALIGN_LEFT", 8);
57
58
/**
59
 * option: align right
60
 */
61
define("BCS_ALIGN_RIGHT", 16);
62
63
/**
64
 * option: generate JPEG image
65
 */
66
define("BCS_IMAGE_JPEG", 32);
67
68
/**
69
 * option: generate PNG image
70
 */
71
define("BCS_IMAGE_PNG", 64);
72
73
/**
74
 * option: draw text
75
 */
76
define("BCS_DRAW_TEXT", 128);
77
78
/**
79
 * option: stretch text
80
 */
81
define("BCS_STRETCH_TEXT", 256);
82
83
/**
84
 * option: reverse color
85
 */
86
define("BCS_REVERSE_COLOR", 512);
87
88
/**
89
 * option: draw check
90
 * (only for I25 code)
91
 */
92
define("BCS_I25_DRAW_CHECK", 2048);
93
94
/**
95
 * set default background color
96
 */
97
define("BCD_DEFAULT_BACKGROUND_COLOR", 0xFFFFFF);
98
99
/**
100
 * set default foreground color
101
 */
102
define("BCD_DEFAULT_FOREGROUND_COLOR", 0x000000);
103
104
/**
105
 * set default style options
106
 */
107
define("BCD_DEFAULT_STYLE", BCS_BORDER | BCS_ALIGN_CENTER | BCS_IMAGE_PNG);
108
109
/**
110
 * set default width
111
 */
112
define("BCD_DEFAULT_WIDTH", 460);
113
114
/**
115
 * set default height
116
 */
117
define("BCD_DEFAULT_HEIGHT", 120);
118
119
/**
120
 * set default font
121
 */
122
define("BCD_DEFAULT_FONT", 5);
123
124
/**
125
 * st default horizontal resolution
126
 */
127
define("BCD_DEFAULT_XRES", 2);
128
129
// Margins
130
131
/**
132
 * set default margin
133
 */
134
define("BCD_DEFAULT_MAR_Y1", 0);
135
136
/**
137
 * set default margin
138
 */
139
define("BCD_DEFAULT_MAR_Y2", 0);
140
141
/**
142
 * set default text offset
143
 */
144
define("BCD_DEFAULT_TEXT_OFFSET", 2);
145
146
// For the I25 Only
147
148
/**
149
 * narrow bar option
150
 * (only for I25 code)
151
 */
152
define("BCD_I25_NARROW_BAR", 1);
153
154
/**
155
 * wide bar option
156
 * (only for I25 code)
157
 */
158
define("BCD_I25_WIDE_BAR", 2);
159
160
// For the C39 Only
161
162
/**
163
 * narrow bar option
164
 * (only for c39 code)
165
 */
166
define("BCD_C39_NARROW_BAR", 1);
167
168
/**
169
 * wide bar option
170
 * (only for c39 code)
171
 */
172
define("BCD_C39_WIDE_BAR", 2);
173
174
// For Code 128
175
176
/**
177
 * set type 1 bar
178
 * (only for c128 code)
179
 */
180
define("BCD_C128_BAR_1", 1);
181
182
/**
183
 * set type 2 bar
184
 * (only for c128 code)
185
 */
186
define("BCD_C128_BAR_2", 2);
187
188
/**
189
 * set type 3 bar
190
 * (only for c128 code)
191
 */
192
define("BCD_C128_BAR_3", 3);
193
194
/**
195
 * set type 4 bar
196
 * (only for c128 code)
197
 */
198
define("BCD_C128_BAR_4", 4);
199
200
/**
201
 * Barcode Render Class for PHP using the GD graphics library.
202
 * @author Karim Mribti, Nicola Asuni
203
 * @name BarcodeObject
204
 * @package com.tecnick.tcpdf
205
 * @version 0.0.8a 2001-04-01 (original code)
206
 * @since 2001-03-25
207
 * @license http://www.gnu.org/copyleft/lesser.html LGPL
208
 */
209
class BarcodeObject {
210
	/**
211
	 * @var Image width in pixels.
212
	 * @access protected
213
	 */
214
	var $mWidth;
215
	
216
	/**
217
	 * @var Image height in pixels.
218
	 * @access protected
219
	 */
220
	var $mHeight;
221
	
222
	/**
223
	 * @var Numeric code for Barcode style.
224
	 * @access protected
225
	 */
226
	var $mStyle;
227
	
228
	/**
229
	 * @var Background color.
230
	 * @access protected
231
	 */
232
	var $mBgcolor;
233
	
234
	/**
235
	 * @var Brush color.
236
	 * @access protected
237
	 */
238
	var $mBrush;
239
	
240
	/**
241
	 * @var Image object.
242
	 * @access protected
243
	 */
244
	var $mImg;
245
	
246
	/**
247
	 * @var Numeric code for character font.
248
	 * @access protected
249
	 */
250
	var $mFont;
251
	
252
	/**
253
	 * @var Error message.
254
	 * @access protected
255
	 */
256
	var $mError;
257
	
258
	/**
259
	 * @var Character Set.
260
	 * @access protected
261
	 */
262
	var $mCharSet;
263
	
264
	/**
265
	 * @var Allowed symbols.
266
	 * @access protected
267
	 */
268
	var $mChars;
269
270
	/**
271
	 * Class Constructor.
272
	 * @param int $Width Image width in pixels.
273
	 * @param int $Height Image height in pixels. 
274
	 * @param int $Style Barcode style.
275
	 */
276
	function BarcodeObject($Width=BCD_DEFAULT_WIDTH, $Height=BCD_DEFAULT_HEIGHT, $Style=BCD_DEFAULT_STYLE) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
277
		$this->mWidth = $Width;
0 ignored issues
show
Documentation Bug introduced by
It seems like $Width of type integer is incompatible with the declared type object<Image> of property $mWidth.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
278
		$this->mHeight = $Height;
0 ignored issues
show
Documentation Bug introduced by
It seems like $Height of type integer is incompatible with the declared type object<Image> of property $mHeight.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
279
		$this->mStyle = $Style;
0 ignored issues
show
Documentation Bug introduced by
It seems like $Style of type integer is incompatible with the declared type object<Numeric> of property $mStyle.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
280
		$this->mFont = BCD_DEFAULT_FONT;
0 ignored issues
show
Documentation Bug introduced by
It seems like BCD_DEFAULT_FONT of type integer is incompatible with the declared type object<Numeric> of property $mFont.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
281
		$this->mImg = ImageCreate($this->mWidth, $this->mHeight);
0 ignored issues
show
Documentation Bug introduced by
It seems like ImageCreate($this->mWidth, $this->mHeight) of type resource is incompatible with the declared type object<Image> of property $mImg.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
282
		$dbColor = $this->mStyle & BCS_REVERSE_COLOR ? BCD_DEFAULT_FOREGROUND_COLOR : BCD_DEFAULT_BACKGROUND_COLOR;
283
		$dfColor = $this->mStyle & BCS_REVERSE_COLOR ? BCD_DEFAULT_BACKGROUND_COLOR : BCD_DEFAULT_FOREGROUND_COLOR;
284
		$this->mBgcolor = ImageColorAllocate($this->mImg, ($dbColor & 0xFF0000) >> 16,
0 ignored issues
show
Documentation Bug introduced by
It seems like ImageColorAllocate($this...) >> 8, $dbColor & 255) of type integer is incompatible with the declared type object<Background> of property $mBgcolor.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
285
		($dbColor & 0x00FF00) >> 8, $dbColor & 0x0000FF);
286
		$this->mBrush = ImageColorAllocate($this->mImg, ($dfColor & 0xFF0000) >> 16,
0 ignored issues
show
Documentation Bug introduced by
It seems like ImageColorAllocate($this...) >> 8, $dfColor & 255) of type integer is incompatible with the declared type object<Brush> of property $mBrush.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
287
		($dfColor & 0x00FF00) >> 8, $dfColor & 0x0000FF);
288
		if (!($this->mStyle & BCS_TRANSPARENT)) {
289
			ImageFill($this->mImg, $this->mWidth, $this->mHeight, $this->mBgcolor);
290
		}
291
	}
292
293
	/**
294
	 * Returns the image object.
295
	 * @return object image.
296
	 * @author Nicola Asuni
297
	 * @since 1.5.2
298
	 */
299
	function getImage() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
300
		return $this->mImg;
301
	}
302
	
303
	/**
304
	 * Abstract method used to draw the barcode image.
305
	 * @param int $xres Horizontal resolution.
306
	 */
307
	function DrawObject($xres)	{
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
308
		/* there is not implementation neded, is simply the asbsract function. */
309
		return false;
310
	}
311
	
312
	/**
313
	 * Draws the barcode border.
314
	 * @access protected
315
	 */
316
	function DrawBorder() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
317
		ImageRectangle($this->mImg, 0, 0, $this->mWidth-1, $this->mHeight-1, $this->mBrush);
318
	}
319
	
320
	/**
321
	 * Draws the alphanumeric code.
322
	 * @param int $Font Font type.
323
	 * @param int $xPos Horiziontal position.
324
	 * @param int $yPos Vertical position.
325
	 * @param int $Char Alphanumeric code to write.
326
	 * @access protected
327
	 */
328
	function DrawChar($Font, $xPos, $yPos, $Char) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
329
		ImageString($this->mImg,$Font,$xPos,$yPos,$Char,$this->mBrush);
330
	}
331
	
332
	/**
333
	 * Draws a character string.
334
	 * @param int $Font Font type.
335
	 * @param int $xPos Horiziontal position.
336
	 * @param int $yPos Vertical position.
337
	 * @param int $Char string to write.
338
	 * @access protected
339
	 */
340
	function DrawText($Font, $xPos, $yPos, $Char) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
341
		ImageString($this->mImg,$Font,$xPos,$yPos,$Char,$this->mBrush);
342
	}
343
344
	/**
345
	 * Draws a single barcode bar.
346
	 * @param int $xPos Horiziontal position.
347
	 * @param int $yPos Vertical position.
348
	 * @param int $xSize Horizontal size.
349
     * @param int $xSize Vertical size.
350
     * @return bool trur in case of success, false otherwise.
351
     * @access protected
352
	 */
353
	function DrawSingleBar($xPos, $yPos, $xSize, $ySize) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
354
		if ($xPos>=0 && $xPos<=$this->mWidth && ($xPos+$xSize)<=$this->mWidth &&
355
		$yPos>=0 && $yPos<=$this->mHeight && ($yPos+$ySize)<=$this->mHeight) {
356
			for ($i=0;$i<$xSize;$i++) {
357
				ImageLine($this->mImg, $xPos+$i, $yPos, $xPos+$i, $yPos+$ySize, $this->mBrush);
358
			}
359
			return true;
360
		}
361
		return false;
362
	}
363
	
364
	/**
365
	 * Returns the current error message.
366
	 * @return string error message.
0 ignored issues
show
Documentation introduced by
Should the return type not be Error?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
367
	 */
368
	function GetError() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
369
		return $this->mError;
370
	}
371
	
372
	/**
373
	 * Returns the font height.
374
	 * @param int $font font type.
375
	 * @return int font height.
376
	 */
377
	function GetFontHeight($font) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
378
		return ImageFontHeight($font);
379
	}
380
	
381
	/**
382
	 * Returns the font width.
383
	 * @param int $font font type.
384
	 * @return int font width.
385
	 */
386
	function GetFontWidth($font) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
387
		return ImageFontWidth($font);
388
	}
389
	
390
	/**
391
	 * Set font type.
392
	 * @param int $font font type.
393
	 */
394
	function SetFont($font) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
395
		$this->mFont = $font;
0 ignored issues
show
Documentation Bug introduced by
It seems like $font of type integer is incompatible with the declared type object<Numeric> of property $mFont.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
396
	}
397
	
398
	/**
399
	 * Returns barcode style.
400
	 * @return int barcode style.
0 ignored issues
show
Documentation introduced by
Should the return type not be Numeric?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
401
	 */
402
	function GetStyle() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
403
		return $this->mStyle;
404
	}
405
406
	/**
407
	 * Set barcode style.
408
	 * @param int $Style barcode style.
409
	 */
410
	function SetStyle ($Style) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
411
		$this->mStyle = $Style;
0 ignored issues
show
Documentation Bug introduced by
It seems like $Style of type integer is incompatible with the declared type object<Numeric> of property $mStyle.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
412
	}
413
414
	/**
415
	 * Flush the barcode image.
416
	 */
417
	function FlushObject() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
418
		if (($this->mStyle & BCS_BORDER)) {
419
			$this->DrawBorder();
420
		}
421
		if ($this->mStyle & BCS_IMAGE_PNG) {
422
			Header("Content-Type: image/png");
423
			ImagePng($this->mImg);
424
		} else if ($this->mStyle & BCS_IMAGE_JPEG) {
425
			Header("Content-Type: image/jpeg");
426
			ImageJpeg($this->mImg);
427
		}
428
	}
429
	
430
	/**
431
	 * Destroy the barcode image.
432
	 */
433
	function DestroyObject() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
434
		ImageDestroy($this->mImg);
435
	}
436
}
437
438
//============================================================+
439
// END OF FILE
440
//============================================================+
441
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...