BarcodeObject($Width, $Height, $Style, $Value); $this->mValue = $Value; $this->oddEven = array( 0=>'OOOOOO', 1=>'OOEOEE', 2=>'OOEEOE', 3=>'OOEEEO', 4=>'OEOOEE', 5=>'OEEOOE', 6=>'OEEEOO', 7=>'OEOEOE', 8=>'OEOEEO', 9=>'OEEOEO'); $this->oddMCharSet = array( 0=>"0001101", 1=>"0011001", 2=>"0010011", 3=>"0111101", 4=>"0100011", 5=>"0110001", 6=>"0101111", 7=>"0111011", 8=>"0110111", 9=>"0001011"); $this->evenMCharSet = array( 0=>"0100111", 1=>"0110011", 2=>"0011011", 3=>"0100001", 4=>"0011101", 5=>"0111001", 6=>"0000101", 7=>"0010001", 8=>"0001001", 9=>"0010111"); $this->rightMCharSet = array( 0=>"1110010", 1=>"1100110", 2=>"1101100", 3=>"1000010", 4=>"1011100", 5=>"1001110", 6=>"1010000", 7=>"1000100", 8=>"1001000", 9=>"1110100"); } function GetSize($xres) { $len = strlen($this->mValue); if ($len == 0) { $this->mError = "Null value"; __DEBUG__("GetRealSize: null barcode value"); return false; } for ($i=0;$i<$len;$i++) { if ((ord($this->mValue[$i]) < 48) || (ord($this->mValue[$i]) > 57)) { $this->mError = "JAN is numeric only"; return false; } } if ($len != 13){ $this->mError = "The length of JAN code value must be 13"; __DEBUG__("GetSize: failed JAN requiremente"); return false; } $StartSize = BCD_JAN_LEFT_MARGIN_WIDTH + BCD_JAN_EDGE_GUARD_BAR_WIDTH; $StopSize = BCD_JAN_RIGHT_MARGIN_WIDTH + BCD_JAN_EDGE_GUARD_BAR_WIDTH; $cPos = 0; $sPos = 0; do { $sPos += 7 * $xres; $cPos++; } while ($cPos < $len); return $sPos + $StarSize + $StopSize + BCD_JAN_CENTER_GUARD_BAR_WIDTH; } function DrawStart($DrawPos, $yPos, $ySize, $xres) { $DrawPos += BCD_JAN_LEFT_MARGIN_WIDTH; $this->DrawSingleBar($DrawPos, $yPos, BCD_JAN_BAR_WIDTH * $xres, $ySize + min($ySize * 0.2, 16)); $DrawPos += BCD_JAN_BAR_WIDTH * $xres; $DrawPos += BCD_JAN_BAR_WIDTH * $xres; $this->DrawSingleBar($DrawPos, $yPos, BCD_JAN_BAR_WIDTH * $xres, $ySize + min($ySize * 0.2, 16)); $DrawPos += BCD_JAN_BAR_WIDTH * $xres; return $DrawPos; } function DrawStop($DrawPos, $yPos, $ySize, $xres) { $this->DrawSingleBar($DrawPos, $yPos, BCD_JAN_BAR_WIDTH * $xres, $ySize + min($ySize * 0.2, 16)); $DrawPos += BCD_JAN_BAR_WIDTH * $xres; $DrawPos += BCD_JAN_BAR_WIDTH * $xres; $this->DrawSingleBar($DrawPos, $yPos, BCD_JAN_BAR_WIDTH * $xres, $ySize + min($ySize * 0.2, 16)); $DrawPos += BCD_JAN_RIGHT_MARGIN_WIDTH; return $DrawPos; } function DrawObject ($xres) { $len = strlen($this->mValue); if(($size = $this->GetSize($xres))==0){ __DEBUG__("GetSize: failed"); return FALSE; } if ($this->mStyle & BCS_DRAW_TEXT) $ysize = $this->mHeight - BCD_DEFAULT_MAR_Y1 - BCD_DEFAULT_MAR_Y2 - $this->GetFontHeight($this->mFont); else $ysize = $this->mHeight - BCD_DEFAULT_MAR_Y1 - BCD_DEFAULT_MAR_Y2; if ($this->mStyle & BCS_ALIGN_CENTER) $sPos = (integer)(($this->mWidth - $size ) / 2); else if ($this->mStyle & BCS_ALIGN_RIGHT) $sPos = $this->mWidth - $size; else $sPos = 0; if ($this->mStyle & BCS_DRAW_TEXT) { if ($this->mStyle & BCS_STRETCH_TEXT) { /* Stretch */ for ($i=0;$i<$len;$i++) { $this->DrawChar($this->mFont, $sPos+BCD_JAN_BAR_WIDTH*$xres+($size/$len)*$i, $ysize + BCD_DEFAULT_MAR_Y1 + BCD_DEFAULT_TEXT_OFFSET , $this->mValue[$i]); } }else {/* Center */ $text_width = $this->GetFontWidth($this->mFont) * strlen($this->mValue); $this->DrawText($this->mFont, $sPos+(($size-$text_width)/2)+(BCD_JAN_BAR_WIDTH*$xres), $ysize + BCD_DEFAULT_MAR_Y1 + BCD_DEFAULT_TEXT_OFFSET, $this->mValue); } } $oe = $this->oddEven[$this->mValue[0]]; $DrawPos = $this->DrawStart($sPos, BCD_DEFAULT_MAR_Y1 , $ysize, $xres); for($cPos = 1; $cPos < 7; $cPos++){ $c = (int)$this->mValue[$cPos]; $pattern = ($oe[$cPos - 1] == 'O')?($this->oddMCharSet[$c]):($this->evenMCharSet[$c]); for($i = 0; $i < 7; $i++){ if($pattern{$i} == '1') $this->DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, $xres, $ysize); $DrawPos += BCD_JAN_BAR_WIDTH * $xres; } } $DrawPos += BCD_JAN_BAR_WIDTH * $xres; $this->DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, $xres, $ysize + min($ysize * 0.2, 16)); $DrawPos += BCD_JAN_BAR_WIDTH * $xres; $DrawPos += BCD_JAN_BAR_WIDTH * $xres; $this->DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, $xres, $ysize + min($ysize * 0.2, 16)); $DrawPos += BCD_JAN_BAR_WIDTH * $xres; $DrawPos += BCD_JAN_BAR_WIDTH * $xres; for($cPos = 7; $cPos < 13; $cPos++){ $c = (int)$this->mValue[$cPos]; $pattern = $this->rightMCharSet[$c];//right side is even only for($i = 0; $i < 7; $i++){ if($pattern{$i} == '1') $this->DrawSingleBar($DrawPos, BCD_DEFAULT_MAR_Y1, $xres, $ysize); $DrawPos += BCD_JAN_BAR_WIDTH * $xres; } } $DrawPos = $this->DrawStop($DrawPos, BCD_DEFAULT_MAR_Y1 , $ysize, $xres); return TRUE; } } ?>