30
1
mirror of https://github.com/vdm-io/tcpdf.git synced 2024-06-05 23:30:47 +00:00
This commit is contained in:
nicolaasuni 2011-05-31 16:35:47 +02:00
parent ac96cada85
commit d4087a9aca
5 changed files with 141 additions and 20 deletions

View File

@ -1,13 +1,13 @@
<?php
//============================================================+
// File name : 2dbarcodes.php
// Version : 1.0.007
// Version : 1.0.008
// Begin : 2009-04-07
// Last Update : 2010-12-16
// Last Update : 2011-05-31
// Author : Nicola Asuni - Tecnick.com S.r.l - Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
// License : GNU-LGPL v3 (http://www.gnu.org/copyleft/lesser.html)
// -------------------------------------------------------------------
// Copyright (C) 2009-2010 Nicola Asuni - Tecnick.com S.r.l.
// Copyright (C) 2009-2011 Nicola Asuni - Tecnick.com S.r.l.
//
// This file is part of TCPDF software library.
//
@ -37,14 +37,14 @@
* PHP class to creates array representations for 2D barcodes to be used with TCPDF.
* @package com.tecnick.tcpdf
* @author Nicola Asuni
* @version 1.0.007
* @version 1.0.008
*/
/**
* @class TCPDF2DBarcode
* PHP class to creates array representations for 2D barcodes to be used with TCPDF (http://www.tcpdf.org).
* @package com.tecnick.tcpdf
* @version 1.0.007
* @version 1.0.008
* @author Nicola Asuni
*/
class TCPDF2DBarcode {
@ -77,6 +77,63 @@ class TCPDF2DBarcode {
return $this->barcode_array;
}
/**
* Send barcode as SVG image object to the standard output.
* @param $w (int) Width of a single rectangle element in user units.
* @param $h (int) Height of a single rectangle element in user units.
* @param $color (string) Foreground color (in SVG format) for bar elements (background is transparent).
* @public
*/
public function getBarcodeSVG($w=2, $h=3, $color='black') {
// send XML headers
$code = $this->getBarcodeSVGcode($w, $h, $color);
header('Content-Type: application/svg+xml');
header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
header('Pragma: public');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
//header('Content-Length: '.strlen($code));
header('Content-Disposition: inline; filename="'.md5($code).'.svg";');
echo $code;
}
/**
* Return a SVG string representation of barcode.
* @param $w (int) Width of a single rectangle element in user units.
* @param $h (int) Height of a single rectangle element in user units.
* @param $color (string) Foreground color (in SVG format) for bar elements (background is transparent).
* @return string SVG code.
* @public
*/
public function getBarcodeSVGcode($w=3, $h=3, $color='black') {
// replace table for special characters
$repstr = array("\0" => '', '&' => '&amp;', '<' => '&lt;', '>' => '&gt;');
$svg = '<'.'?'.'xml version="1.0" standalone="no"'.'?'.'>'."\n";
$svg .= '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'."\n";
$svg .= '<svg width="'.round(($this->barcode_array['num_cols'] * $w), 3).'" height="'.round(($this->barcode_array['num_rows'] * $h), 3).'" version="1.1" xmlns="http://www.w3.org/2000/svg">'."\n";
$svg .= "\t".'<desc>'.strtr($this->barcode_array['code'], $repstr).'</desc>'."\n";
$svg .= "\t".'<g id="elements" fill="'.$color.'" stroke="none">'."\n";
// print barcode elements
$xstart = 0;
$y = 0;
// for each row
for ($r = 0; $r < $this->barcode_array['num_rows']; ++$r) {
$x = $xstart;
// for each column
for ($c = 0; $c < $this->barcode_array['num_cols']; ++$c) {
if ($this->barcode_array['bcode'][$r][$c] == 1) {
// draw a single barcode cell
$svg .= "\t\t".'<rect x="'.$x.'" y="'.$y.'" width="'.$w.'" height="'.$h.'" />'."\n";
}
$x += $w;
}
$y += $h;
}
$svg .= "\t".'</g>'."\n";
$svg .= '</svg>'."\n";
return $svg;
}
/**
* Set the barcode.
* @param $code (string) code to print
@ -94,6 +151,7 @@ class TCPDF2DBarcode {
}
$qrcode = new QRcode($code, strtoupper($mode[1]));
$this->barcode_array = $qrcode->getBarcodeArray();
$this->barcode_array['code'] = $code;
break;
}
case 'PDF417': { // PDF417 (ISO/IEC 15438:2006)
@ -124,6 +182,7 @@ class TCPDF2DBarcode {
}
$qrcode = new PDF417($code, $ecl, $aspectratio, $macro);
$this->barcode_array = $qrcode->getBarcodeArray();
$this->barcode_array['code'] = $code;
break;
}
case 'RAW':
@ -147,6 +206,7 @@ class TCPDF2DBarcode {
foreach ($rows as $r) {
$this->barcode_array['bcode'][] = str_split($r, 1);
}
$this->barcode_array['code'] = $code;
break;
}
case 'TEST': { // TEST MODE
@ -158,6 +218,7 @@ class TCPDF2DBarcode {
array(0,1,0,0,1,1,0,0,1,1,1,0,0,1,0),
array(0,1,0,0,1,0,0,0,0,0,1,0,0,1,0),
array(0,1,0,0,1,1,1,0,1,1,1,0,0,1,0));
$this->barcode_array['code'] = $code;
break;
}
default: {

View File

@ -1,3 +1,7 @@
5.9.085 (2011-05-31)
- TCPDFBarcode class (barcodes.php) now includes getBarcodeSVG() and getBarcodeSVGcode() methods to get SVG image representation of the barcode.
- TCPDF2DBarcode class (2dbarcodes.php) now includes getBarcodeSVG() and getBarcodeSVGcode() methods to get SVG image representation of the barcode.
5.9.084 (2011-05-29)
- Font files were updated.
- The file fonts/utils/makeallttffonts.php was updated.

View File

@ -8,8 +8,8 @@ http://sourceforge.net/donate/index.php?group_id=128076
------------------------------------------------------------
Name: TCPDF
Version: 5.9.084
Release date: 2011-05-29
Version: 5.9.085
Release date: 2011-05-31
Author: Nicola Asuni
Copyright (c) 2002-2011:

View File

@ -1,9 +1,9 @@
<?php
//============================================================+
// File name : barcodes.php
// Version : 1.0.015
// Version : 1.0.016
// Begin : 2008-06-09
// Last Update : 2011-05-12
// Last Update : 2011-05-31
// Author : Nicola Asuni - Tecnick.com S.r.l - Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
// License : GNU-LGPL v3 (http://www.gnu.org/copyleft/lesser.html)
// -------------------------------------------------------------------
@ -37,14 +37,14 @@
* PHP class to creates array representations for common 1D barcodes to be used with TCPDF.
* @package com.tecnick.tcpdf
* @author Nicola Asuni
* @version 1.0.015
* @version 1.0.016
*/
/**
* @class TCPDFBarcode
* PHP class to creates array representations for common 1D barcodes to be used with TCPDF (http://www.tcpdf.org).<br>
* @package com.tecnick.tcpdf
* @version 1.0.015
* @version 1.0.016
* @author Nicola Asuni
*/
class TCPDFBarcode {
@ -59,8 +59,8 @@ class TCPDFBarcode {
* This is the class constructor.
* Return an array representations for common 1D barcodes:<ul>
* <li>$arrcode['code'] code to be printed on text label</li>
* <li>$arrcode['maxh'] max bar height</li>
* <li>$arrcode['maxw'] max bar width</li>
* <li>$arrcode['maxh'] max barcode height</li>
* <li>$arrcode['maxw'] max barcode width</li>
* <li>$arrcode['bcode'][$k] single bar or space in $k position</li>
* <li>$arrcode['bcode'][$k]['t'] bar type: true = bar, false = space.</li>
* <li>$arrcode['bcode'][$k]['w'] bar width in units.</li>
@ -68,6 +68,7 @@ class TCPDFBarcode {
* <li>$arrcode['bcode'][$k]['p'] bar top position (0 = top, 1 = middle)</li></ul>
* @param $code (string) code to print
* @param $type (string) type of barcode: <ul><li>C39 : CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.</li><li>C39+ : CODE 39 with checksum</li><li>C39E : CODE 39 EXTENDED</li><li>C39E+ : CODE 39 EXTENDED + CHECKSUM</li><li>C93 : CODE 93 - USS-93</li><li>S25 : Standard 2 of 5</li><li>S25+ : Standard 2 of 5 + CHECKSUM</li><li>I25 : Interleaved 2 of 5</li><li>I25+ : Interleaved 2 of 5 + CHECKSUM</li><li>C128 : CODE 128</li><li>C128A : CODE 128 A</li><li>C128B : CODE 128 B</li><li>C128C : CODE 128 C</li><li>EAN2 : 2-Digits UPC-Based Extention</li><li>EAN5 : 5-Digits UPC-Based Extention</li><li>EAN8 : EAN 8</li><li>EAN13 : EAN 13</li><li>UPCA : UPC-A</li><li>UPCE : UPC-E</li><li>MSI : MSI (Variation of Plessey code)</li><li>MSI+ : MSI + CHECKSUM (modulo 11)</li><li>POSTNET : POSTNET</li><li>PLANET : PLANET</li><li>RMS4CC : RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)</li><li>KIX : KIX (Klant index - Customer index)</li><li>IMB: Intelligent Mail Barcode - Onecode - USPS-B-3200</li><li>CODABAR : CODABAR</li><li>CODE11 : CODE 11</li><li>PHARMA : PHARMACODE</li><li>PHARMA2T : PHARMACODE TWO-TRACKS</li></ul>
* @public
*/
public function __construct($code, $type) {
$this->setBarcode($code, $type);
@ -76,16 +77,71 @@ class TCPDFBarcode {
/**
* Return an array representations of barcode.
* @return array
* @public
*/
public function getBarcodeArray() {
return $this->barcode_array;
}
/**
* Send barcode as SVG image object to the standard output.
* @param $w (int) Minimum width of a single bar in user units.
* @param $h (int) Height of barcode in user units.
* @param $color (string) Foreground color (in SVG format) for bar elements (background is transparent).
* @public
*/
public function getBarcodeSVG($w=2, $h=30, $color='black') {
// send XML headers
$code = $this->getBarcodeSVGcode($w, $h, $color);
header('Content-Type: application/svg+xml');
header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
header('Pragma: public');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
//header('Content-Length: '.strlen($code));
header('Content-Disposition: inline; filename="'.md5($code).'.svg";');
echo $code;
}
/**
* Return a SVG string representation of barcode.
* @param $w (int) Minimum width of a single bar in user units.
* @param $h (int) Height of barcode in user units.
* @param $color (string) Foreground color (in SVG format) for bar elements (background is transparent).
* @return string SVG code.
* @public
*/
public function getBarcodeSVGcode($w=2, $h=30, $color='black') {
// replace table for special characters
$repstr = array("\0" => '', '&' => '&amp;', '<' => '&lt;', '>' => '&gt;');
$svg = '<'.'?'.'xml version="1.0" standalone="no"'.'?'.'>'."\n";
$svg .= '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'."\n";
$svg .= '<svg width="'.round(($this->barcode_array['maxw'] * $w), 3).'" height="'.$h.'" version="1.1" xmlns="http://www.w3.org/2000/svg">'."\n";
$svg .= "\t".'<desc>'.strtr($this->barcode_array['code'], $repstr).'</desc>'."\n";
$svg .= "\t".'<g id="bars" fill="'.$color.'" stroke="none">'."\n";
// print bars
$x = 0;
foreach ($this->barcode_array['bcode'] as $k => $v) {
$bw = round(($v['w'] * $w), 3);
$bh = round(($v['h'] * $h / $this->barcode_array['maxh']), 3);
if ($v['t']) {
$y = round(($v['p'] * $h / $this->barcode_array['maxh']), 3);
// draw a vertical bar
$svg .= "\t\t".'<rect x="'.$x.'" y="'.$y.'" width="'.$bw.'" height="'.$bh.'" />'."\n";
}
$x += $bw;
}
$svg .= "\t".'</g>'."\n";
$svg .= '</svg>'."\n";
return $svg;
}
/**
* Set the barcode.
* @param $code (string) code to print
* @param $type (string) type of barcode: <ul><li>C39 : CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.</li><li>C39+ : CODE 39 with checksum</li><li>C39E : CODE 39 EXTENDED</li><li>C39E+ : CODE 39 EXTENDED + CHECKSUM</li><li>C93 : CODE 93 - USS-93</li><li>S25 : Standard 2 of 5</li><li>S25+ : Standard 2 of 5 + CHECKSUM</li><li>I25 : Interleaved 2 of 5</li><li>I25+ : Interleaved 2 of 5 + CHECKSUM</li><li>C128 : CODE 128</li><li>C128A : CODE 128 A</li><li>C128B : CODE 128 B</li><li>C128C : CODE 128 C</li><li>EAN2 : 2-Digits UPC-Based Extention</li><li>EAN5 : 5-Digits UPC-Based Extention</li><li>EAN8 : EAN 8</li><li>EAN13 : EAN 13</li><li>UPCA : UPC-A</li><li>UPCE : UPC-E</li><li>MSI : MSI (Variation of Plessey code)</li><li>MSI+ : MSI + CHECKSUM (modulo 11)</li><li>POSTNET : POSTNET</li><li>PLANET : PLANET</li><li>RMS4CC : RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)</li><li>KIX : KIX (Klant index - Customer index)</li><li>IMB: Intelligent Mail Barcode - Onecode - USPS-B-3200</li><li>CODABAR : CODABAR</li><li>CODE11 : CODE 11</li><li>PHARMA : PHARMACODE</li><li>PHARMA2T : PHARMACODE TWO-TRACKS</li></ul>
* @return array
* @return array barcode array
* @public
*/
public function setBarcode($code, $type) {
switch (strtoupper($type)) {

View File

@ -1,9 +1,9 @@
<?php
//============================================================+
// File name : tcpdf.php
// Version : 5.9.084
// Version : 5.9.085
// Begin : 2002-08-03
// Last Update : 2011-05-29
// Last Update : 2011-05-31
// Author : Nicola Asuni - Tecnick.com S.r.l - Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
// License : http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT GNU-LGPLv3 + YOU CAN'T REMOVE ANY TCPDF COPYRIGHT NOTICE OR LINK FROM THE GENERATED PDF DOCUMENTS.
// -------------------------------------------------------------------
@ -134,7 +134,7 @@
* Tools to encode your unicode fonts are on fonts/utils directory.</p>
* @package com.tecnick.tcpdf
* @author Nicola Asuni
* @version 5.9.084
* @version 5.9.085
*/
// Main configuration file. Define the K_TCPDF_EXTERNAL_CONFIG constant to skip this file.
@ -146,7 +146,7 @@ require_once(dirname(__FILE__).'/config/tcpdf_config.php');
* TCPDF project (http://www.tcpdf.org) has been originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org), but now is almost entirely rewritten.<br>
* @package com.tecnick.tcpdf
* @brief PHP class for generating PDF documents without requiring external extensions.
* @version 5.9.084
* @version 5.9.085
* @author Nicola Asuni - info@tecnick.com
*/
class TCPDF {
@ -157,7 +157,7 @@ class TCPDF {
* Current TCPDF version.
* @private
*/
private $tcpdf_version = '5.9.084';
private $tcpdf_version = '5.9.085';
// Protected properties
@ -25152,7 +25152,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value:
xml_set_character_data_handler($this->parser, 'segSVGContentHandler');
// start parsing an XML document
if (!xml_parse($this->parser, $svgdata)) {
$error_message = sprintf("SVG Error: %s at line %d", xml_error_string(xml_get_error_code($this->parser)), xml_get_current_line_number($this->parser));
$error_message = sprintf('SVG Error: %s at line %d', xml_error_string(xml_get_error_code($this->parser)), xml_get_current_line_number($this->parser));
$this->Error($error_message);
}
// free this XML parser