/var/www/hkosl.com/oneMotorChunHing_delete20240201/html/html/bcclass/BCGothercode.barcode.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/**
 * BCGothercode.barcode.php
 *--------------------------------------------------------------------
 *
 * Sub-Class - othercode
 *
 * Other Codes
 * Starting with a bar and altern to space, bar, ...
 * 0 is the smallest
 *
 *--------------------------------------------------------------------
 * Revision History
 * v2.0.0    23 apr    2008    Jean-Sébastien Goupil    New Version Update
 * v1.2.3b    2  jan    2006    Jean-Sébastien Goupil    Correct error if $textfont was empty
 * v1.2.1    27 jun    2005    Jean-Sébastien Goupil    Font support added
 * V1.00    17 jun    2004    Jean-Sebastien Goupil
 *--------------------------------------------------------------------
 * $Id: BCGothercode.barcode.php,v 1.10 2009/11/09 04:08:41 jsgoupil Exp $
 *--------------------------------------------------------------------
 * Copyright (C) Jean-Sebastien Goupil
 * http://www.barcodephp.com
 */
include_once('BCGBarcode1D.php');

// Function str_split is not available for PHP4. So we emulate it here.
if (!function_exists('str_split')) {
    function 
str_split($string$split_length 1) {
        
$array explode("\r\n"chunk_split($string$split_length));
        
array_pop($array);
        return 
$array;
    }
}

class 
BCGothercode extends BCGBarcode1D {
    
/**
     * Constructor
     */
    
public function __construct() {
        
parent::__construct();
    }

    
/**
     * Draws the barcode
     *
     * @param resource $im
     */
    
public function draw(&$im) {
        
$this->drawChar($im$this->texttrue);
        
$this->drawText($im);
    }

    public function 
getLabel() {
        
$label $this->label;
        if(
$this->label === BCGBarcode1D::AUTO_LABEL) {
            
$label '';
        }

        return 
$label;
    }

    
/**
     * Returns the maximal size of a barcode
     *
     * @return int[]
     */
    
public function getMaxSize() {
        
$p parent::getMaxSize();

        
$array str_split($this->text1);
        
$textlength = (array_sum($array) + count($array)) * $this->scale;

        return array(
$p[0] + $textlength$p[1]);
    }

    
/**
     * Overloaded method for drawing special label
     *
     * @param resource $im
     */
    
protected function drawText($im) {
        if(
$this->label !== BCGBarcode1D::AUTO_LABEL && $this->label !== '') {
            
$pA $this->getMaxSize();
            
$pB BCGBarcode1D::getMaxSize();
            
$w =  $pA[0] - $pB[0];

            if(
$this->textfont instanceof BCGFont) {
                
$textfont = clone $this->textfont;
                
$textfont->setText($this->label);

                
$xPosition = ($w 2) - $textfont->getWidth() / $this->offsetX $this->scale;
                
$yPosition $this->thickness $this->scale $textfont->getHeight() - $textfont->getUnderBaseline() + BCGBarcode1D::SIZE_SPACING_FONT $this->offsetY $this->scale;

                
$text_color $this->colorFg->allocate($im);
                
$textfont->draw($im$text_color$xPosition$yPosition);
            } elseif(
$this->textfont !== 0) {
                
$xPosition = ($w 2) - (strlen($this->label) * imagefontwidth($this->textfont)) / $this->offsetX $this->scale;
                
$yPosition $this->thickness $this->scale $this->offsetY $this->scale BCGBarcode1D::SIZE_SPACING_FONT;

                
$text_color $this->colorFg->allocate($im);
                
imagestring($im$this->textfont$xPosition$yPosition$this->label$text_color);
            }
        }
    }
};
?>