- 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
This commit is contained in:
dave 2007-03-19 06:56:38 +00:00
parent 2f23e31a40
commit 4e2d7d77aa

132
lpdf.php
View File

@ -54,7 +54,7 @@ class lpdf
//all of these are overwritten by setLabelDimensions(width,height,xspacer,yspacer); //all of these are overwritten by setLabelDimensions(width,height,xspacer,yspacer);
var $label_width=4; var $label_width=4;
var $label_height=2; var $label_height=2, $label_effective_height=0;
var $label_xspacer=0.125; var $label_xspacer=0.125;
var $label_yspacer=0.125; var $label_yspacer=0.125;
var $labels_per_row=2; var $labels_per_row=2;
@ -346,25 +346,83 @@ class lpdf
return $numlines; 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: /* Some assumptions:
- we will scale the font instead of doing line wrapping - we will scale the font instead of doing line wrapping
- all coords are given in percentages of the label - all coords are given in percentages of the label
- a width or height of 0 means "don't care" - a width or height of 0 means "don't care"
- xp or yp can also be 'center', meaning center the text */ - 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') { if($xp == 'center') {
} else { if($wp == 0) $wp = 100;
$xpos = ($xp * $this->label_wdith) / 100; $xp = 50 - ($wp / 2);
} }
if($yp == 'center') { if($yp == 'center') {
} else { if($hp == 0) $hp = 100;
$ypos = ($yp * $this->label_height) / 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]<br />");
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<br>");
/* 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() 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) 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_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)); $this->label_current_xpos=$this->labels_start_xpos+(($this->current_label_col_index-1)*($this->label_width + $this->label_xspacer));
/* if($show_box == true) {
pdf_rect($this->pdf, pdf_rect($this->pdf,
$this->loc($this->label_current_xpos), $this->loc($this->label_current_xpos),
$this->loc($this->label_current_ypos), $this->loc($this->label_current_ypos),
$this->loc($this->label_width), $this->loc($this->label_width),
$this->loc($this->label_height)); $this->loc($this->label_height));
pdf_stroke($this->pdf); pdf_stroke($this->pdf);
*/ }
$this->label_current_ypos+=$this->label_height;//-0.15;
$this->label_current_ypos+=$this->label_height-0.15;
//only put the logo on the label if we actually have the logo //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 //now place the logo image in the top-left-ish
pdf_place_image($this->pdf,$this->logoimage, pdf_place_image($this->pdf,$this->logoimage,
$this->loc($this->label_current_xpos+0.05), $this->loc($this->label_current_xpos+0.05),
$this->loc($this->label_current_ypos-0.50),0.2); $this->loc($this->label_current_ypos-0.50),0.2);
} }
*/
/* $this->label_effective_height = $this->label_height;
$height['title']=0.50; if($show_fairname) {
$this->label_current_ypos-=$height['title']; $height['title']=0.50;
$this->label_current_ypos -= $height['title'];
pdf_setfont($this->pdf,$this->headerfont,14); $this->label_effective_height -= $height['title'];
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);
*/
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) function addTextX($text,$xpos)