From 4e2d7d77aae5d00ee429c47e5da69c3f02fa35f6 Mon Sep 17 00:00:00 2001 From: dave Date: Mon, 19 Mar 2007 06:56:38 +0000 Subject: [PATCH] - Fix up the pdf generation of our nametags - This also changes the newlabel function, so just thinking about it, I think there's a 0.15 missing in the alignment that was moved inside a conditional for labels... All labels will be replaced soon anyway. :p --- lpdf.php | 132 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 94 insertions(+), 38 deletions(-) diff --git a/lpdf.php b/lpdf.php index 28e455e1..e5d5adce 100644 --- a/lpdf.php +++ b/lpdf.php @@ -54,7 +54,7 @@ class lpdf //all of these are overwritten by setLabelDimensions(width,height,xspacer,yspacer); var $label_width=4; - var $label_height=2; + var $label_height=2, $label_effective_height=0; var $label_xspacer=0.125; var $label_yspacer=0.125; var $labels_per_row=2; @@ -346,25 +346,83 @@ class lpdf return $numlines; } - function addLabelText2($xp,$yp,$wp,$hp,$text) + function addLabelText2($xp,$yp,$wp,$hp,$lh,$text,$options) { +// print("$xp,$yp,$wp,$hp,$lh,$text,$options,$this->label_width"); /* Some assumptions: - we will scale the font instead of doing line wrapping - all coords are given in percentages of the label - a width or height of 0 means "don't care" - xp or yp can also be 'center', meaning center the text */ - if($wp != 0) $desired_width = ($this->label_width * $wp) / 100; - if($hp != 0) $desired_height = ($this->label_height * $hp) / 100; - + if($xp == 'center') { - } else { - $xpos = ($xp * $this->label_wdith) / 100; + if($wp == 0) $wp = 100; + $xp = 50 - ($wp / 2); } if($yp == 'center') { - } else { - $ypos = ($yp * $this->label_height) / 100; + if($hp == 0) $hp = 100; + $yp = 50 - ($hp / 2); } - + $xpos = ($xp * $this->label_width) /100; + $ypos = ($yp * $this->label_effective_height) / 100; + + $desired_width = ($this->label_width * $wp) / 100; + $desired_height = ($this->label_effective_height * $hp) / 100; + + + /* Pick a font */ + if(in_array('bold', $options)) { + $font = $this->headerfont; + } else { + $font = $this->normalfont; + } + + $align = 'left'; + if(in_array('left', $options)) $align = 'left'; + if(in_array('right', $options)) $align = 'right'; + if(in_array('center', $options)) $align = 'center'; + + /* Find the correct font size for the lineheight */ + if($lh == 0) $lh = $hp; + $desired_line_height = ($this->label_effective_height * $lh) / 100; + $desired_line_height_loc = $desired_line_height * 72; + + /* Take a guess, the font will be very small 4pt */ +// $fontpt = 4; + +// print("Desired line height=[$desired_line_height => $desired_line_height_loc]"); + + $fontpt = intval($desired_line_height_loc); +/* + while(1) { + pdf_setfont($this->pdf, $font, $fontpt); + $fontsize_loc = pdf_get_value($this->pdf, 'fontsize', 0); +// print("fontsize_loc[ $fontpt => $fontsize_loc]
"); + if($fontsize_loc > $desired_line_height_loc) { + /* Font too big, we're done + $fontpt--; + break; + } + $fontpt++; + } +*/ + pdf_setfont($this->pdf, $font, $fontpt); + +// print("$xpos, $ypos x $desired_width, $desired_height
"); + +/* pdf_rect($this->pdf, + $this->loc($this->label_current_xpos + $xpos), + $this->loc($this->label_current_ypos - ($ypos + $desired_height)), + $this->loc($desired_width), + $this->loc($desired_height)); + pdf_stroke($this->pdf); +*/ + $nr=pdf_show_boxed($this->pdf, $text, + $this->loc($this->label_current_xpos + $xpos), + $this->loc($this->label_current_ypos - ($ypos + $desired_height)), + $this->loc($desired_width), + $this->loc($desired_height), + $align,null); } function newNametag() @@ -429,7 +487,7 @@ class lpdf } - function newLabel() + function newLabel($show_box=false, $show_fairname=false, $show_logo=false) { if($this->current_label_index==$this->labels_per_page) { @@ -456,45 +514,43 @@ class lpdf } $this->label_current_ypos=$this->labels_start_ypos-(($this->current_label_row_index-1)*($this->label_height + $this->label_yspacer))-$this->label_height; - $this->label_current_xpos=$this->labels_start_xpos+(($this->current_label_col_index-1)*($this->label_width + $this->label_xspacer)); -/* - pdf_rect($this->pdf, - $this->loc($this->label_current_xpos), - $this->loc($this->label_current_ypos), - $this->loc($this->label_width), - $this->loc($this->label_height)); - pdf_stroke($this->pdf); - */ - - $this->label_current_ypos+=$this->label_height-0.15; + if($show_box == true) { + pdf_rect($this->pdf, + $this->loc($this->label_current_xpos), + $this->loc($this->label_current_ypos), + $this->loc($this->label_width), + $this->loc($this->label_height)); + pdf_stroke($this->pdf); + } + $this->label_current_ypos+=$this->label_height;//-0.15; //only put the logo on the label if we actually have the logo - /* - if($this->logoimage) + + if($show_logo == true && $this->logoimage) { //now place the logo image in the top-left-ish pdf_place_image($this->pdf,$this->logoimage, $this->loc($this->label_current_xpos+0.05), $this->loc($this->label_current_ypos-0.50),0.2); } - */ - /* - $height['title']=0.50; - $this->label_current_ypos-=$height['title']; - - pdf_setfont($this->pdf,$this->headerfont,14); - pdf_show_boxed($this->pdf,$this->page_header, - $this->loc($this->label_current_xpos+0.65), - $this->loc($this->label_current_ypos), - $this->loc($this->label_width-0.70), - $this->loc($height['title']), - "center", - null); - */ + $this->label_effective_height = $this->label_height; + if($show_fairname) { + $height['title']=0.50; + $this->label_current_ypos -= $height['title']; + $this->label_effective_height -= $height['title']; + pdf_setfont($this->pdf,$this->headerfont,14); + pdf_show_boxed($this->pdf,$this->page_header, + $this->loc($this->label_current_xpos+0.65), + $this->loc($this->label_current_ypos-0.15), + $this->loc($this->label_width-0.70), + $this->loc($height['title']), + "center", + null); + } } function addTextX($text,$xpos)