From a62a8bbbfb1a658badfa866fbb8887fe26550afe Mon Sep 17 00:00:00 2001 From: dave Date: Mon, 10 Dec 2007 21:28:17 +0000 Subject: [PATCH] - Add a bold font option to pdf generation --- lpdf.php | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/lpdf.php b/lpdf.php index 029bca7..9ea58b0 100644 --- a/lpdf.php +++ b/lpdf.php @@ -56,6 +56,9 @@ class lpdf var $currentFontSize=12; + var $normalfont; + var $boldfont; + function loc($inch) { return $inch*72; @@ -145,7 +148,18 @@ class lpdf pdf_set_value($this->pdf,"leading",$leading); } - function addText($text,$align="left") + function setFontBold() + { + pdf_setfont($this->pdf, $this->boldfont, $this->currentFontSize); + } + + function setFontNormal() + { + pdf_setfont($this->pdf, $this->normalfont, $this->currentFontSize); + } + + + function addText($text,$align="left", $xloc=0) { $fontsize=pdf_get_value($this->pdf,"fontsize",0); $lineheight=ceil($fontsize*1.3); @@ -154,6 +168,15 @@ class lpdf $textstr=$text; + if($xloc == 0) { + $xloc = $this->page_margin; + $content_width = $this->content_width; + } else { + $content_width = $this->content_width - $xloc; + } + + $this->yloc += $lineheight/72; + $nr=0; $prevnr=-1; do @@ -171,11 +194,10 @@ class lpdf $nl=true; } - if(!$nl) - $this->yloc-=$lineheight/72; + if($nl == false) $this->yloc-=$lineheight/72; - $nr=pdf_show_boxed($this->pdf,$textstr, $this->loc($this->page_margin),$this->loc($this->yloc),$this->loc($this->content_width),$lineheight,$align,null); + $nr=pdf_show_boxed($this->pdf,$textstr, $this->loc($xloc),$this->loc($this->yloc),$this->loc($content_width),$lineheight,$align,null); if($this->yloc< (0.9 + $lineheight/72) ) $this->newPage(); @@ -764,6 +786,7 @@ class lpdf // pdf_set_parameter($this->pdf, "FontOutline", "Arial=/home/sfiab/www.sfiab.ca/sfiab/arial.ttf"); //$arial=pdf_findfont($this->pdf,"Arial","host",1); $this->normalfont=pdf_findfont($this->pdf,"Times-Roman","host",0); + $this->boldfont=pdf_findfont($this->pdf,"Times-Bold","host",0); $this->headerfont=pdf_findfont($this->pdf,"Times-Bold","host",0); if(file_exists($logo))