diff --git a/admin/reports.inc.php b/admin/reports.inc.php
index 6e38fdd..4669e9a 100644
--- a/admin/reports.inc.php
+++ b/admin/reports.inc.php
@@ -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'];
diff --git a/admin/reports_editor.php b/admin/reports_editor.php
index d44e12e..402d73d 100644
--- a/admin/reports_editor.php
+++ b/admin/reports_editor.php
@@ -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 "
Text=";
} 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 "";
echo "";
}
diff --git a/lpdf.php b/lpdf.php
index 272b041..0582de1 100644
--- a/lpdf.php
+++ b/lpdf.php
@@ -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]
");
- 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);
-*/
+ // print("$xpos, $ypos x $desired_width, $desired_height
");
+
+ 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)