- Implement vertical alignment for labels

- Implement boxes around text for testing (and maybe for a purpose?)
This commit is contained in:
dave 2007-10-05 20:12:19 +00:00
parent 95a3816068
commit f922adb9af
3 changed files with 83 additions and 30 deletions

View File

@ -200,10 +200,11 @@ foreach($stock as $n=>$v) {
/* field, value, x, y, w, h, lines, face, align */
$vals = "'$k','$v','0','0','0','0','0','',''";
} else {
$opts = "{$v['align']} {$v['valign']}";
$vals = "'{$v['field']}','{$v['value']}',
'{$v['x']}','{$v['y']}','{$v['w']}',
'{$v['h']}','{$v['lines']}','{$v['face']}',
'{$v['align']}'";
'$opts'";
}
if($q != '') $q .= ',';
$q .= "({$report['id']}, '$type','$x',$vals)";
@ -281,6 +282,15 @@ foreach($stock as $n=>$v) {
foreach($col_fields as $lf) $val[$lf] = $a[$lf];
if($val['lines'] == 0) $val['lines'] = 1;
$opts = explode(" ", $val['align']);
$align_opts = array ('left', 'right', 'center');
$valign_opts = array ('vtop', 'vbottom', 'vcenter');
$style_opts = array ('bold');
foreach($opts as $o) {
if(in_array($o, $align_opts)) $val['align'] = $o;
if(in_array($o, $valign_opts)) $val['valign'] = $o;
if(in_array($o, $valign_opts)) $val['face'] = $o;
}
$report[$t][$a['ord']] = $val;
break;
@ -583,6 +593,7 @@ foreach($stock as $n=>$v) {
$opt = array();
if($d['face'] == 'bold') $opt[] = 'bold';
$opt[] = $d['align'];
$opt[] = $d['valign'];
/* Special column, override result with static text */
if($f == 'static_text') $v = $d['value'];

View File

@ -146,7 +146,13 @@ function reportChange()
echo "Invalid alignment $v";
exit;
}
}
} else if($l == 'valign') {
$aligns = array('vtop', 'vbottom', 'vcenter');
if(!in_array($v, $aligns)) {
echo "Invalid valignment $v";
exit;
}
}
$a[$l] = $v;
}
if(trim($a['field']) == '') continue;
@ -337,6 +343,9 @@ function reportChange()
echo 'Align';
selector("col[$x][align]", array('center' => 'Center', 'left' => 'Left', 'right' => 'Right'),
$d['align']);
echo 'vAlign';
selector("col[$x][valign]", array('vcenter' => 'Center', 'vtop' => 'Top', 'vbottom' => 'Bottom'),
$d['valign']);
if($f == 'static_text') {
echo "<br />Text=<input type=\"text\" size=\"40\" name=\"col[$x][value]\" value=\"{$d['value']}\">";
} else {
@ -356,6 +365,9 @@ function reportChange()
echo 'Align';
selector("col[$x][align]", array('center' => 'Center', 'left' => 'Left', 'right' => 'Right'),
'center');
echo 'vAlign';
selector("col[$x][valign]", array('vcenter' => 'Center', 'vtop' => 'Top', 'vbottom' => 'Bottom'),
'top');
echo "<input type=\"hidden\" name=\"col[$x][value]\" value=\"\">";
echo "</td></tr>";
}

View File

@ -306,51 +306,81 @@ class lpdf
}
$align = 'left';
$valign = 'top';
$boxtext = false;
if(in_array('left', $options)) $align = 'left';
if(in_array('right', $options)) $align = 'right';
if(in_array('center', $options)) $align = 'center';
if(in_array('vtop', $options)) $valign = 'top';
if(in_array('vcenter', $options)) $valign = 'center';
if(in_array('vbottom', $options)) $valign = 'bottom';
if(in_array('boxtext', $options)) $boxtext = true;
/* 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);
*/
// print("$xpos, $ypos x $desired_width, $desired_height<br>");
if($boxtext == true) {
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);
}
$x = $this->label_current_xpos + $xpos;
$y = $this->label_current_ypos - ($ypos + $desired_height);
$lines = 1;
$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),
$this->loc($x), $this->loc($y),
$this->loc($desired_width), $this->loc($desired_line_height),
$align,'blind');
while($nr > 0) {
$nr=pdf_show_boxed($this->pdf, substr($text, -$nr),
$this->loc($x), $this->loc($y),
$this->loc($desired_width), $this->loc($desired_line_height),
$align,'blind');
$lines ++;
}
/* Now adjust the ypos, and do it for real */
if($valign == 'top') {
$y = $this->label_current_ypos - ($ypos + $desired_line_height);
} else if($valign == 'center') {
$extra = ($desired_height - ($lines * $desired_line_height)) / 2;
$y = $this->label_current_ypos - ($ypos + $desired_line_height) - $extra;
} else {
echo "Unimplemented valign [$valign]";
exit();
}
$nr=pdf_show_boxed($this->pdf, $text,
$this->loc($x), $this->loc($y),
$this->loc($desired_width), $this->loc($desired_line_height),
$align,null);
while($nr > 0) {
$y -= $desired_line_height;
$nr=pdf_show_boxed($this->pdf, substr($text, -$nr),
$this->loc($x), $this->loc($y),
$this->loc($desired_width), $this->loc($desired_line_height),
$align,null);
}
}
function newLabel($show_box=false, $show_fairname=false, $show_logo=false)