<?php
+/**********************************************************************
+ Copyright (C) FrontAccounting, LLC.
+ Released under the terms of the GNU General Public License, GPL,
+ as published by the Free Software Foundation, either version 3
+ of the License, or (at your option) any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
+***********************************************************************/
/*
This class is an extension to the tcpdf class using a syntax that the original reports were written in
(the R &OS pdf.php class) - due to easily portation this wrapper class
)/x");
include_once (dirname(__FILE__).'/tcpdf.php');
+include_once (dirname(__FILE__).'/fpdi/fpdi.php');
-class Cpdf extends TCPDF {
+class Cpdf extends FPDI {
- function Cpdf($pageSize='A4', $l=array())
+ function __construct($pageSize='A4', $lang=null, $pageOrientation='P')
{
+ parent::__construct($pageOrientation, 'pt', $pageSize);//, $uni, $enc);
+ $this->SetLang($lang);
+ $this->setPrintHeader(false);
+ $this->setPrintFooter(false);
+ $this->setPDFVersion("1.3");
+ $this->setAutoPageBreak(0);
+ $this->SetLineWidth(1);
+ $this->cMargin = 0;
+ }
+ /*
+ Set lamguage for next report
+ */
+ function SetLang($code=null)
+ {
+ global $installed_languages, $dflt_lang, $path_to_root, $local_path_to_root, $GetText;
+
+ if (!$code)
+ $code = $dflt_lang;
+
+ $lang = array_search_value($code, $installed_languages, 'code');
+ $GetText->set_language($lang['code'], strtoupper($lang['encoding']));
+
+ // $local_path_to_root is set inside find_custom_file.
+ // Select extension domain if po file is provided
+ // otherwise use global translation.
+ if (file_exists($local_path_to_root.'/lang/'.$lang['code'].'/LC_MESSAGES/'.$lang['code'].'.po'))
+ $GetText->add_domain($lang['code'], $local_path_to_root . "/lang");
+ else
+ $GetText->add_domain($lang['code'], $path_to_root . "/lang", @$lang['version']);
+ // re-read translated sys names.
+ include($path_to_root.'/includes/sysnames.inc');
+
+ $l = array('a_meta_charset' => strtoupper($lang['encoding']),
+ 'a_meta_dir' => @$lang['rtl'] ? 'rtl' : 'ltr',
+ 'a_meta_language' => $code, 'w_page' => 'page');
+
if (!isset($l['a_meta_charset']))
$l = array('a_meta_charset' => 'ISO-8859-1', 'a_meta_dir' => 'ltr', 'a_meta_language' => 'en_GB', 'w_page' => 'page');
$enc = $l['a_meta_charset'];
$uni = ($enc == 'UTF-8' || $enc == 'GB2312' ? true : false);
if ($uni)
ini_set("memory_limit", "48M");
- $this->TCPDF('P', 'pt', $pageSize, $uni, $enc);
+
+ $this->isunicode = $uni;
$this->setLanguageArray($l);
- $this->setPrintHeader(false);
- $this->setPrintFooter(false);
- $this->setPDFVersion("1.3");
- $this->setAutoPageBreak(0);
- $this->AddPage();
+ if ($uni)
+ {
+ global $unicode, $unicode_mirror, $unicode_arlet, $laa_array, $diacritics;
+ include_once(dirname(__FILE__)."/unicode_data2.php");
+ }
+ $this->encoding = strtoupper($lang['encoding']);
- $this->SetLineWidth(1);
- $this->cMargin = 0;
+ $this->FontFamily = 'helvetica';
+ $this->FontStyle = '';
+ $this->FontSizePt = 12;
}
- function selectFont($fontname, $style='')
+
+ // $fontname should be a standard PDF font (like 'times', 'helvetica' or 'courier')
+ // or one that's been installed on your system. An empty string can also be used
+ // which will retain the font currently in use.
+ // $style is either:
+ // * a special case string:
+ // * bold
+ // * italic
+ // * or a case-insensitive string where each char represents a style choice
+ // and you can use more than one or none at all. Possible choices:
+ // * empty string: regular
+ // * B: bold
+ // * I: italic
+ // * U: underline
+ // * D: line trough (aka "strike through")
+ function selectFont($fontname, $style = '')
{
- if ($fontname != '')
- $fontname = basename($fontname);
+ // Parse the style - check for special cases, otherwise leave as-is
if ($style == 'italic')
- $type = 'i';
+ $style = 'i';
elseif ($style == 'bold')
- $type = 'b';
- else
- $type = '';
+ $style = 'b';
+
+ // Parse the fontname
+ if ($fontname != '')
+ $fontname = basename($fontname);
if ($fontname == '')
{
if ($this->isunicode)
default : $fontname = "freesans5"; break;
}
}
- // else use built-in adobe fonts helvetica.
+ elseif ($this->encoding === "ISO-8859-13")
+ {
+ switch ($this->l['a_meta_language'])
+ {
+ default : $fontname = "freesans13"; break;
+ }
+ }
+ // else use built-in adobe fonts helvetica.
}
- $this->SetFont($fontname, $type);
+ $this->SetFont($fontname, $style);
}
function Header1()
function newPage()
{
- TCPDF::AddPage();
+ parent::AddPage();
}
- function line($x1,$y1,$x2,$y2)
+ function line($x1,$y1,$x2,$y2, $style = array())
{
- TCPDF::line($x1, $this->h-$y1, $x2, $this->h-$y2);
+ parent::Line($x1, $this->h-$y1, $x2, $this->h-$y2, $style);
}
function rectangle($x, $y, $w, $h, $style='', $border_style=array(), $fill_color=array())
{
- TCPDF::Rect($x, $this->h-$y, $w, $h, $style, $border_style, $fill_color);
+ parent::Rect($x, $this->h-$y, $w, $h, $style, $border_style, $fill_color);
}
function addInfo($label,$value)
{
- if($label=='Title')
- {
- $this->SetTitle($value);
- }
- if ($label=='Subject')
- {
- $this->SetSubject($value);
- }
- if($label=='Creator')
- {
- // The Creator info in source is not exactly it should be ;)
- $value = str_replace( "ros.co.nz", "tcpdf.org", $value );
- $value = str_replace( "R&OS", "", $value );
- $this->SetCreator( $value );
- }
- if($label=='Author')
- {
- $this->SetAuthor($value);
+ if (in_array($label, array( 'Title', 'Subject', 'Author', 'Creator'))) {
+ $seter = "Set{$label}";
+ $this->$seter($value);
}
}
* nSeg is not allowed to be less than 2, as this will simply draw a line (and will even draw a
* pretty crappy shape at 2, as we are approximating with bezier curves.
*/
- function ellipse($x0,$y0,$r1,$r2=0,$angle=0,$nSeg=8,$astart=0,$afinish=360,$close=1,$fill=0)
- {
- TCPDF::Ellipse($x0, $y0, $r1, $r2, $angle, $astart. $afinish, ($close?'C':''), "", "", $nSeg);
- }
- function Stream()
+ function ellipse($x0,$y0,$r1,$r2=0,$angle=0,$nSeg=8,$astart=0,$afinish=360,$close=1,$fill=0, $dummy=null)
{
- TCPDF::Output('', 'I');
+ parent::Ellipse($x0, $y0, $r1, $r2, $angle, $astart. $afinish, ($close?'C':''), "", "", $nSeg);
}
- function Output()
+ function Stream($fname='')
{
- return TCPDF::Output('','S');
+ parent::Output($fname, 'I');
}
function calcTextWrap($txt, $width, $spacebreak=false)
return array($txt2, $ret);
}
- function addTextWrap($xb, $yb, $w, $h, $txt, $align='left', $border=0, $fill=0, $spacebreak=false)
+ function addTextWrap($xb, $yb, $w, $h, $txt, $align='left', $border=0, $fill=0, $link = NULL, $stretch = 1, $spacebreak=false)
{
$ret = "";
if (!$this->rtl)
$align = 'R';
elseif ($align == 'left')
$align = 'L';
+ elseif ($align == 'center')
+ $align = 'C';
+ elseif ($align == 'justify')
+ $align = 'J';
}
else
$align = 'R';
- $txt = $this->calcTextWrap($txt, $w, $spacebreak);
+
+ $txt = parent::unhtmlentities($txt);
+ // If horizontal scaling was requested, check to see if we're trying to scale
+ // too much. If so, cut back string first and then scale it.
+ $maxScaleFactor = 1.4;
+ if ($stretch == 1 || $stretch == 2)
+ $txt = $this->calcTextWrap($txt, $w * $maxScaleFactor, $spacebreak);
+ // Wrap text if stretching isn't turned on
+ else
+ $txt = $this->calcTextWrap($txt, $w, $spacebreak);
$ret = $txt[1];
$txt = $txt[0];
$this->SetXY($xb, $this->h - $yb - $h);
- $txt = TCPDF::unhtmlentities($txt);
+
if ($this->isunicode && $this->encoding != "UTF-8")
$txt = iconv($this->encoding, "UTF-8", $txt);
- $this->Cell($w, $h, $txt, $border, 0, $align, $fill);
+ $this->Cell($w, $h, $txt, $border, 0, $align, $fill, $link, $stretch);
return $ret;
}
-/**
-* sets the colour for stroke operations
-*/
- function setStrokeColor($r,$g,$b,$force=0)
- {
- TCPDF::SetDrawColor($r,$g,$b);
- }
-/**
-* this sets the line drawing style.
-* width, is the thickness of the line in user units
-* cap is the type of cap to put on the line, values can be 'butt','round','square'
-* where the diffference between 'square' and 'butt' is that 'square' projects a flat end past the
-* end of the line.
-* join can be 'miter', 'round', 'bevel'
-* dash is an array which sets the dash pattern, is a series of length values, which are the lengths of the
-* on and off dashes.
-* (2) represents 2 on, 2 off, 2 on , 2 off ...
-* (2,1) is 2 on, 1 off, 2 on, 1 off.. etc
-* phase is a modifier on the dash pattern which is used to shift the point at which the pattern starts.
-*/
- function setLineStyle($width=1,$cap='',$join='',$dash='',$phase=0)
- {
- $this->SetLineWidth($width);
- }
function Text($x, $y, $txt, $stroke=0, $clip=false)
{
- TCPDF::Text($x,$y, TCPDF::unhtmlentities($txt), $stroke, $clip);
+ parent::Text($x,$y, parent::unhtmlentities($txt), $stroke, $clip);
}
} // end of class
-?>
\ No newline at end of file