diff --git a/admin/reports.inc.php b/admin/reports.inc.php index 557727b..5c145e0 100644 --- a/admin/reports.inc.php +++ b/admin/reports.inc.php @@ -33,6 +33,7 @@ require_once('../lpdf.php'); require_once('../lcsv.php'); + require_once('../tcpdf.inc.php'); $filter_ops = array( 0 => '=', 1 => '<=', @@ -48,7 +49,7 @@ $report_options = array(); $report_options['type'] = array('desc' => 'Report Format', - 'values' => array('pdf'=>'PDF', 'csv'=>'CSV', 'label'=>'Label') + 'values' => array('pdf'=>'PDF', 'csv'=>'CSV', 'label'=>'Label', 'tcpdf_label'=>'TCPDF Label') ); $report_options['group_new_page'] = array('desc' => 'Start each new grouping on a new page', 'values' => array('no'=>'No', 'yes'=>'Yes') @@ -105,6 +106,8 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */ 'label_height' => 9.5, 'y_spacing' => 0, 'rows' => 1, + 'page_format' => 'LETTER', + 'page_orientation' => 'P', ); $report_stock['fullpage_landscape'] = array('name' => 'Letter 8.5 x 11 Landscape (3/4" margin)', @@ -116,6 +119,8 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */ 'label_height' => 7, 'y_spacing' => 0, 'rows' => 1, + 'page_format' => 'LETTER', + 'page_orientation' => 'L', ); $report_stock['fullpage_full'] = array('name' => 'Letter 8.5 x 11 (no margin)', @@ -127,6 +132,8 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */ 'label_height' => 11, 'y_spacing' => 0, 'rows' => 1, + 'page_format' => 'LETTER', + 'page_orientation' => 'P', ); $report_stock['fullpage_landscape_full'] = array('name' => 'Letter 8.5 x 11 Landscape (no margin)', @@ -138,6 +145,8 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */ 'label_height' => 8.5, 'y_spacing' => 0, 'rows' => 1, + 'page_format' => 'LETTER', + 'page_orientation' => 'L', ); $report_stock['5161'] = array('name' => 'Avery 5161/5261/5961/8161, G&T 99189 (1"x4")', @@ -150,6 +159,8 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */ 'y_spacing' => 0.00, 'y_padding' => 0.05, 'rows' => 10, + 'page_format' => 'LETTER', + 'page_orientation' => 'P', ); $report_stock['5162'] = array('name' => 'Avery 5162/5262/5962/8162/8462, G&T 99190 (1 1/3"x4")', @@ -162,6 +173,8 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */ 'y_spacing' => 0.00, 'y_padding' => 0.30, 'rows' => 7, + 'page_format' => 'LETTER', + 'page_orientation' => 'P', ); $report_stock['5163'] = array('name' => 'Avery 5163/5263/5963/8163/8463, G&T 99181 (2"x4")', 'page_width' => 8.5, @@ -172,6 +185,8 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */ 'label_height' => 2, 'y_spacing' => 0.00, 'rows' => 5, + 'page_format' => 'LETTER', + 'page_orientation' => 'P', ); /* This is combined with 5161 @@ -196,6 +211,9 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */ 'label_height' => 3 + 1/3, 'y_spacing' => 0, 'rows' => 3, + 'page_format' => 'LETTER', /* tcpdf format */ + 'page_orientation' => 'P', /* tcpdf orientation */ + ); $report_stock['nametag'] = array('name' => 'Cards 4"x3"', 'page_width' => 8.5, @@ -206,6 +224,8 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */ 'label_height' => 3, 'y_spacing' => 0, 'rows' => 3, + 'page_format' => 'LETTER', + 'page_orientation' => 'P', ); $report_stock['letter_4up'] = array('name' => 'Fullpage, 4up', @@ -217,6 +237,8 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */ 'label_height' => 5, 'y_spacing' => 0.25, 'rows' => 2, + 'page_format' => 'LETTER', + 'page_orientation' => 'P', ); $report_stock['ledger'] = array('name' => 'Ledger/Tabloid 11 x 17', @@ -228,6 +250,8 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */ 'label_height' => 17, 'y_spacing' => 0, 'rows' => 1, + 'page_format' => 'LETTER', + 'page_orientation' => 'P', ); $report_stock['ledger_landscape'] = array('name' => 'Ledger/Tabloid 11 x 17 Landscape', @@ -239,6 +263,8 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */ 'label_height' => 11, 'y_spacing' => 0, 'rows' => 1, + 'page_format' => 'LETTER', + 'page_orientation' => 'P', ); @@ -322,24 +348,30 @@ foreach($report_stock as $n=>$v) { $x = 0; foreach($report[$type] as $k=>$v) { if($type == 'option') { - /* field, value, x, y, w, h, lines, face, align */ - $vals = "'$k','$v','0','0','0','0','0','',''"; + /* field, value, x, y, w, h, lines, face, align, valign, fn, fs, fsize, overflow */ + $vals = "'$k','$v','0','0','0','0','0','','','','','','0','truncate'"; } else { if($v['lines'] == 0) $v['lines'] =1; + $fs = is_array($v['fontstyle']) ? implode(',',$v['fontstyle']) : ''; $opts = "{$v['align']} {$v['valign']}"; $vals = "'{$v['field']}','{$v['value']}', '{$v['x']}','{$v['y']}','{$v['w']}', '{$v['h']}','{$v['lines']}','{$v['face']}', - '$opts'"; + '$opts','{$v['valign']}', + '{$v['fontname']}','$fs','{$v['fontsize']}', + '{$v['on_overflow']}'"; } if($q != '') $q .= ','; $q .= "({$report['id']}, '$type','$x',$vals)"; $x++; } + mysql_query("INSERT INTO reports_items(`reports_id`,`type`,`ord`, `field`,`value`,`x`, `y`, `w`, `h`, - `lines`, `face`, `align`) + `lines`, `face`, `align`,`valign`, + `fontname`,`fontstyle`,`fontsize`,`on_overflow`) VALUES $q;"); + echo mysql_error(); } @@ -404,8 +436,11 @@ foreach($report_stock as $n=>$v) { } /* Pull out all the data */ $val = array(); - $col_fields = array('field', 'x', 'y', 'w', 'h', 'lines', 'face', 'align', 'value'); + $col_fields = array('field', 'x', 'y', 'w', 'h', 'lines', 'face', 'align', 'valign', 'value', 'fontname','fontsize','on_overflow'); foreach($col_fields as $lf) $val[$lf] = $a[$lf]; + $val['fontstyle'] = explode(',', $a['fontstyle']); + /* valign, fontname, fontsize,fontstyle are unused, except in tcpdf reports + (i.e. nothign has changed, only adding on */ if($val['lines'] == 0) $val['lines'] = 1; $opts = explode(" ", $val['align']); @@ -422,6 +457,7 @@ foreach($report_stock as $n=>$v) { break; } } +//`int_r($report); return $report; } @@ -448,9 +484,7 @@ foreach($report_stock as $n=>$v) { } - -/* - print("
");
+/*	print("
");
 	print_r($_POST);
 	print_r($report);
 	print("
"); @@ -577,6 +611,20 @@ foreach($report_stock as $n=>$v) { if($report['option']['allow_multiline'] == 'yes') $table['option']['allow_multiline'] = true; break; + case 'tcpdf_label': + $label_stock = $report_stock[$report['option']['stock']]; + $show_box = ($report['option']['label_box'] == 'yes') ? true : false; + $show_fair = ($report['option']['label_fairname'] == 'yes') ? true : false; + $show_logo = ($report['option']['label_logo'] == 'yes') ? true : false; + + $rep=new pdf($report['name'], $label_stock['page_format'], $label_stock['page_orientation']); + $rep->setup_for_labels($show_box, $show_fair, $show_logo, + $label_stock['label_width'] * 25.4, $label_stock['label_height'] * 25.4, + $label_stock['x_spacing'] * 25.4, $label_stock['y_spacing'] * 25.4, + $label_stock['rows'], $label_stock['cols']); + $gen_mode = 'tcpdf_label'; + break; + default: echo "Invalid type [{$report['option']['type']}]"; exit; @@ -737,6 +785,8 @@ foreach($report_stock as $n=>$v) { $n_groups = count($report['group']); $last_group_data = array(); +// echo "
";print_r($rep);
+
 	while($i = mysql_fetch_assoc($r)) {
 
 		if($n_groups > 0) {
@@ -789,7 +839,10 @@ foreach($report_stock as $n=>$v) {
 			$show_fair = ($report['option']['label_fairname'] == 'yes') ? true : false;
 			$show_logo = ($report['option']['label_logo'] == 'yes') ? true : false;
 			$rep->newLabel($show_box, $show_fair, $show_logo);
+		} else if($gen_mode == 'tcpdf_label') {
+			$rep->label_new();
 		}
+
 		foreach($report['col'] as $o=>$d) {
 			$f = $d['field'];
 			if(is_array($fields[$f]['value_map'])) {
@@ -826,6 +879,23 @@ foreach($report_stock as $n=>$v) {
 							$d['h'], $lh,
 							$v, $opt);
 				}
+			} else if($gen_mode == 'tcpdf_label') {
+				/* Setup additional options */
+				$show_box = ($report['option']['field_box'] == 'yes') ? true : false;
+
+//				echo "
"; print_r($d);
+
+				if($f == 'static_box') {
+					$rep->label_rect($d['x'], $d['y'], $d['w'], $d['h']);
+				} else {
+					if($f == 'static_text') $v = $d['value'];
+
+					$rep->label_text($d['x'], $d['y'], $d['w'], $d['h'],
+							$v, $show_box, $d['align'], $d['valign'],
+							$d['fontname'],$d['fontstyle'],$d['fontsize'],
+							$d['on_overflow']);
+				}
+
 			}
 
 			if($fields[$f]['total'] == true)
@@ -836,6 +906,8 @@ foreach($report_stock as $n=>$v) {
 	if(count($table['data'])) {
 		$rep->addTable($table);
 	}
+
+
 	$rep->output();
 }
 
diff --git a/admin/reports_editor.php b/admin/reports_editor.php
index 0b8f8ea..a1eacf1 100644
--- a/admin/reports_editor.php
+++ b/admin/reports_editor.php
@@ -36,6 +36,7 @@
  require_once('reports_fairs.inc.php');
  require_once('reports_fundraising.inc.php');
  require_once('reports.inc.php');
+ require_once('../tcpdf.inc.php');
 
  $fields = array();
  $locs = array('X' => 'x', 'Y' => 'y', 'W' => 'w', 'H' => 'h', 'Lines' => 'lines');
@@ -89,7 +90,7 @@
 						exit;
 					}
 				} else if($l == 'valign') {
-					$aligns = array('vtop', 'vbottom', 'vcenter');
+					$aligns = array('vtop', 'vbottom', 'vcenter', 'top','middle','bottom');
 					if(!in_array($v, $aligns)) {
 						echo "Invalid valignment $v";
 						exit;
@@ -186,10 +187,14 @@ function reportReload()
 var canvasWidth=0;
 var canvasHeight=0;
 var canvasObjectIndex=0;
+var labelWidth=0;
+var labelHeight=0;
 
-function initCanvas(w,h) {
+function initCanvas(w,h,lw,lh) {
 	canvasWidth=w;
 	canvasHeight=h;
+	labelWidth=lw;
+	labelHeight=lh;
 }
 
 function createData(x,y,w,h,l,face,align,valign,value) {
@@ -235,10 +240,55 @@ function createData(x,y,w,h,l,face,align,valign,value) {
 
 	canvas.appendChild(newdiv);
 
+	canvasObjectIndex++;
+}
+
+function createDataTCPDF(x,y,w,h,align,valign,fontname,fontstyle,fontsize,value) {
+
+	var canvas=document.getElementById('layoutcanvas');
+	var newdiv=document.createElement('div');
+
+	var dx = Math.round(x * canvasWidth / labelWidth);
+	var dy = Math.round(y * canvasHeight / labelHeight);
+	var dw = Math.round(w * canvasWidth / labelWidth);
+	var dh = Math.round(h * canvasHeight / labelHeight);
+
+	
+	var fontheight=(fontsize * 25.4 / 72) * canvasHeight / labelHeight;
+	var l = Math.floor(h/fontheight);
+	if(fontheight == 0) fontheight=10;
+	if(l==0) l=1;
+
+//	alert(dh + ", fh="+fontheight);
+
+	newdiv.setAttribute('id','o_'+canvasObjectIndex);
+	newdiv.style.display="table-cell";
+	newdiv.style.position="absolute";
+	newdiv.style.width=dw+"px";
+	newdiv.style.height=dh+"px";
+	newdiv.style.left=dx+"px";
+	newdiv.style.top=dy+"px";
+	newdiv.style.textAlign=align;
+	newdiv.style.verticalAlign=valign;
+	newdiv.style.padding="0 0 0 0";
+	newdiv.style.margin="0 0 0 0";
+//	newdiv.style.vertical-align=valign;
+	newdiv.style.border="1px solid blue";
+	newdiv.style.fontSize=fontheight+"px";
+	newdiv.style.lineHeight=fontheight+"px";
+	newdiv.style.fontFamily=fontname;
+	newdiv.style.fontSizeAdjust=0.65;
+
+	var maxlength=Math.floor(dw/(fontheight*0.7))*l;
+	if(value.length>maxlength) value=value.substring(0,maxlength);
+
+	newdiv.innerHTML=value; 
+
+	canvas.appendChild(newdiv);
 
 	canvasObjectIndex++;
-
 }
+
 
 ";
  echo "\n";
  
+$doCanvasSample = false;
+$doCanvasSampletcpdf = false;
  $l_w=$report_stock[$report['option']['stock']]['label_width'];
  $l_h=$report_stock[$report['option']['stock']]['label_height'];
  if($l_w && $l_h && $report['option']['type']=="label") {
@@ -405,31 +457,69 @@ function createData(x,y,w,h,l,face,align,valign,value) {
 	$canvasheight=round($canvaswidth*$ratio);
 	echo "
"; echo "
\n"; - echo "\n"; + echo "\n"; } + if($l_w && $l_h && $report['option']['type']=="tcpdf_label") { + echo "

Label Data Locations - TCPDF

"; + + $l_w *= 25.4; + $l_h *= 25.4; + $doCanvasSampletcpdf=true; + $ratio=$l_h/$l_w; + $canvaswidth=600; + $canvasheight=round($canvaswidth*$ratio); + echo "
"; + echo "
\n"; + echo "\n"; + } + + echo ""; $x=0; - if($report['option']['type'] == 'label') { - + + if($report['option']['type'] == 'label' || $report['option']['type'] == 'tcpdf_label') { + $fontlist = array('' => 'Default'); + $fl = PDF::getFontList(); + foreach($fl as $f) $fontlist[$f] = $f; +// print_r($fl); + foreach($report['col'] as $o=>$d) { $f = $d['field']; echo ""; echo ""; echo ""; } diff --git a/db/db.code.version.txt b/db/db.code.version.txt index de8febe..fb402ef 100644 --- a/db/db.code.version.txt +++ b/db/db.code.version.txt @@ -1 +1 @@ -168 +169 diff --git a/db/db.update.169.sql b/db/db.update.169.sql new file mode 100644 index 0000000..dc733aa --- /dev/null +++ b/db/db.update.169.sql @@ -0,0 +1,8 @@ +ALTER TABLE `reports_items` ADD `fontname` VARCHAR( 32 ) NOT NULL AFTER `face` , + ADD `fontstyle` SET( 'bold', 'italic', 'underline', 'strikethrough') NOT NULL AFTER `fontname` , + ADD `fontsize` FLOAT NOT NULL AFTER `fontstyle` ; + +ALTER TABLE `reports_items` ADD `valign` ENUM( 'top', 'middle', 'bottom' ) NOT NULL; + +LTER TABLE `reports_items` ADD `on_overflow` ENUM( 'truncate', '...', 'scale' ) NOT NULL ; + diff --git a/tcpdf.inc.php b/tcpdf.inc.php new file mode 100644 index 0000000..40f5fa8 --- /dev/null +++ b/tcpdf.inc.php @@ -0,0 +1,371 @@ +SetCreator('SFIAB'); + $this->SetAuthor('SFIAB'); + $this->SetTitle(i18n($config['fairname'])); + $this->SetSubject($report_name); + $this->SetKeywords(''); + + /* Set default header data (K_PATH_IMAGES/logo.png, 16mm wide, + header, name */ + $this->SetHeaderData('logo.png', 16 /* mm */, + i18n($config['fairname']), + i18n($report_name)); + + // set header and footer fonts + $this->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); + $this->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); + + // set default monospaced font + $this->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); + + //set margins + $this->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); + $this->SetHeaderMargin(PDF_MARGIN_HEADER); + $this->SetFooterMargin(PDF_MARGIN_FOOTER); + + //set auto page breaks + $this->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); + $this->setPrintFooter(false); + + //set image scale factor + $this->setImageScale(PDF_IMAGE_SCALE_RATIO); + + $this->current_label_index = 1; + $this->current_label_row = 0; + $this->current_label_col = 0; + + //set some language-dependent strings + //$this->setLanguageArray($l); +//print_r($this->fontlist); + + } + + function _fitcell_lines($w,$h,$txt,$fontsize) + { + $index = 0; + $lines = array(); + + /* Get an array of widths */ + $width = $this->getStringWidth($txt,'','',$fontsize,true); + $chars = $this->UTF8StringToArray($txt); + $count = count($width); // strlen(utf8_decode($txt)); + + $curr_width = $this->cMargin * 2; + $last_space_index = -1; + $start_index = 0; + + for($index=0; $index<$count;$index++) { + $newline = false; + $skip = false; + + /* Special chars */ + switch($this->unichr($chars[$index])) { + case ' ': case "\r": case "\t": + $last_space_index = $index; + break; + + case "\n": + $newline = true; + $skip = true; + break; + } + + /* Check for width overflow */ + if($skip == true) { + /* Do nothing with it */ + } else if ($curr_width + $width[$index] > $w) { + /* Backup index, leave it pointing to + * the last char we print, so when we + * increment in the next iteration we + * get the next char (the one that just + * caused this overflow */ + $index--; + $newline = true; + } else { + $curr_width += $width[$index]; + } + + if($newline) { + if($last_space_index != -1) { + /* Backup to the last space index, if there is one */ + $end_index = $last_space_index; + $index = $last_space_index; + } else { + /* No, use the whole line then */ + $end_index = $index; + } + $lines[] = $this->UTF8ArrSubString($chars,$start_index,$end_index); + /* Reset width, set start index */ + $curr_width = $this->cMargin * 2; + $last_space_index = -1; + $start_index = $index+1; + } + + } + + $lines[] = $this->UTF8ArrSubString($chars,$start_index,$index); + return $lines; + } + /* Cell( float $w, [float $h = 0], [string $txt = ''], [mixed $border = 0], + [int $ln = 0], [string $align = ''], [int $fill = 0], [mixed $link = ''], + [int $stretch = 0], [boolean $ignore_min_height = false]) */ + + + function FitCell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$valign='',$on_overflow='scale') + { + $x = $this->getX(); + $y = $this->getY(); + $orig_fs = $this->getFontSizePt(); + + $fontsize = $orig_fs; + while(1) { + $lines = $this->_fitcell_lines($w, $h, $txt, $fontsize); + + $label_h = $this->cMargin * 2 + ($this->getFontSize($fontsize) * count($lines)); +// echo "h=$h; fs=".$this->getFontSize($fontsize).", lines=".count($lines).", total=$label_h\n"; + if($label_h <= $h) { + /* It fits! */ + break; + } + + if($on_overflow == 'scale') { + /* reduce the font size and try again */ + $fontsize -= 0.5; + $this->setFontSize($fontsize); +// echo "retry...\n"; + continue; + + } else if($on_overflow == '...') { + /* truncate, add ... */ + echo "Not implemented: FitCell::on_overflow=..."; + exit; + } else { + /* truncate */ + echo "Not implemented: FitCell::on_overflow=truncate"; + exit; + } + } + + /* SetX, find Y based on alignment */ + switch($valign) { + case 'M': /* Middle */ + $this->SetXY($x, $y + ($h - $label_h) / 2); + break; + case 'B': /* Bottom */ + $this->SetXY($x, $y + ($h - $label_h)); + break; + case 'T': default: /* Top */ + $this->SetXY($x, $y); + break; + } + + /* Cell( float $w, [float $h = 0], [string $txt = ''], [mixed $border = 0], + [int $ln = 0], [string $align = ''], [int $fill = 0], [mixed $link = ''], + [int $stretch = 0], [boolean $ignore_min_height = false]) */ + $this->setFontSize($fontsize); + foreach($lines as $l) { + $this->Cell($w, 0, $l, 0, 2, $align, 0, 0, 0, false); + } + + /* Restore original fontsize */ + $this->setFontSize($orig_fs); + + /* Restore original location */ + $this->SetXY($x,$y); + + /* Deal with the border and ln, leaving x,y wherever $ln + * tells us to */ + $this->Cell($w, $h, '', $border, $ln); + } + + function GetFontList() + { + if(!is_object($this)) { + $pdf = new pdf(); + return $pdf->GetFontList(); + } + $this->getFontsList(); + return $this->fontlist; + } + + function setup_for_labels($show_box, $show_fair, $show_logo, $width, $height, $xspacer, $yspacer, $rows, $cols) + { + /* No headers and footers */ + $this->setPrintHeader(false); + $this->setPrintFooter(false); + + /* No auto-pagebreaks */ + $this->SetAutoPageBreak(false); + + + /* the page size/orientation is already set */ + $pw = $this->getPageWidth(); + $ph = $this->getPageHeight(); + + $this->label_show_box = $show_box; + $this->label_show_fair = $show_fair; + $this->label_show_logo = $show_logo; + + $this->label_width=$width; + $this->label_height=$height; + $this->label_xspacer=$xspacer; + $this->label_yspacer=$yspacer; + + $this->label_rows=$rows; + $this->label_cols=$cols; + $this->labels_per_page=$rows * $cols; + + /* labels are always centered in the page */ + + $this->label_page_lmargin=( $pw - ($cols*$width) - ($xspacer*($cols-1)) )/2; + $this->label_page_tmargin=( $ph - ($rows*$height) - ($yspacer*($rows-1)) )/2; + + /* Setup so that the first call to label_new also creates + * a new page */ + $this->current_label_index = $this->labels_per_page - 1; + } + + function label_new() + { + /* Advance to new label */ +// echo "cindex=$this->current_label_index, perpage=$this->labels_per_page\n"; + if($this->current_label_index + 1 == $this->labels_per_page) { +// echo "addpage\n"; + $this->AddPage(); + $this->current_label_index = 0; + } else { + $this->current_label_index++; + } + + /* Get row/col, and position of label */ + $r = floor($this->current_label_index / $this->label_cols); + $c = floor($this->current_label_index % $this->label_cols); + + $lmargin = $this->label_page_lmargin + ($c * ($this->label_width + $this->label_xspacer) ); + $tmargin = $this->label_page_tmargin + ($r * ($this->label_height + $this->label_yspacer) ); + + /* Move margins for this label */ +// echo "r=$r, c=$c, cols=$this->label_cols\n"; +// echo "Margins -> ($lmargin, $tmargin)\n"; + $this->SetMargins($lmargin, $tmargin, $lmargin + $this->label_width); + + if($this->label_show_box) + $this->label_rect(0,0,$this->label_width, $this->label_height); + + if($this->label_show_logo) { + } + + if($this->label_show_fair) { + + } + + } + + + function output() + { + $filename=strtolower($this->subject); + $filename=ereg_replace("[^a-z0-9]","_",$filename); + parent::Output($filename.".pdf", "I"); + } + + /* align = left, center, right + valign = top, middle, bottom, + fontname, + fontstyle, + fontsize, + border = true/false + on_overflow = truncate, ..., scale */ + function label_text($x,$y,$w,$h,$text,$border,$align,$valign,$fontname,$fontstyle,$fontsize, + $on_overflow) + { + $orig_name = $this->getFontFamily(); + $orig_style = $this->getFontStyle(); + $orig_size = $this->getFontSizePt(); + $orig_x = $this->GetX(); + $orig_y = $this->GetY(); + + /* Do horiz/vert align */ + $align_data = array('left' => 'L', 'center' => 'C', 'right' => 'R'); + $valign_data = array('top' => 'T', 'middle' => 'M', 'bottom' => 'B'); + $align = $align_data[$align]; + $valign = $valign_data[$valign]; + + /* Set position and font */ + $st = array('bold' => 'B', 'italic' => 'I', 'underline' => 'U', 'strikethrough' => 'D'); + $fs = ''; + if(is_array($fontstyle)) { + foreach($fontstyle as $s) $fs .= $st[$s]; + } + + if($fontsize == 0) $fontsize = 10; /* FIXME: getdefaultfontsize? */ + + $this->SetXY($this->lMargin + $x,$this->tMargin + $y); +// echo "position (x,y)=($x,$y)\n"; +// echo "margin (l,t)=({$this->lMargin},{$this->tMargin})\n"; +// echo "(x,y)=(".($this->lMargin + $x).",".($this->tMargin + $y).")\n"; + $this->SetFont($fontname, $fs, $fontsize); + + /* Print text */ + $this->FitCell($w,$h, $text, $border ? 1 : 0, 2, + $align, $valign, $on_overflow); + + /* Restore position and font */ + $this->SetFont($orig_name, $orig_style, $orig_size); + $this->SetXY($orig_x, $orig_y); + } + + function label_rect($x,$y,$w,$h) + { + $this->Rect($this->lMargin + $x, $this->tMargin + $y, $w, $h); + } + +} diff --git a/tcpdf_config.php b/tcpdf_config.php new file mode 100644 index 0000000..aaa0db7 --- /dev/null +++ b/tcpdf_config.php @@ -0,0 +1,200 @@ +
Loc ".($o+1).": "; $script=""; foreach($locs as $k=>$v) { + if($k=='Lines' && $report['option']['type'] != 'label') continue; echo "$k="; $script.="{$d[$v]},"; } - echo 'Face='; - selector("col[$x][face]", array('' => '', 'bold' => 'Bold'), $d['face']); + + if($report['option']['type'] == 'label') { + echo 'Face='; + selector("col[$x][face]", array('' => '', 'bold' => 'Bold'), $d['face']); + } 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($report['option']['type'] == 'label') { + selector("col[$x][valign]", array('vcenter' => 'Center', 'vtop' => 'Top', 'vbottom' => 'Bottom'), + $d['valign']); + } else { + selector("col[$x][valign]", array('middle' => 'Middle', 'top' => 'Top', 'bottom' => 'Bottom'), + $d['valign']); + + echo 'Font='; + selector("col[$x][fontname]", $fontlist, $d['fontname']); + selector("col[$x][fontstyle]", array('' => '', 'bold' => 'Bold'), $d['fontstyle']); + echo ""; + echo 'pt '; + echo 'OnOverflow='; + selector("col[$x][on_overflow]", array('tuncate'=>'Truncate','...'=>'Add ...', 'scale'=>'Scale'), $d['on_overflow']); + } + if($f == 'static_text') { echo "
Text="; } else { @@ -437,6 +527,8 @@ function createData(x,y,w,h,l,face,align,valign,value) { } if($doCanvasSample) echo "\n"; + if($doCanvasSampletcpdf) + echo "\n"; $x++; } @@ -444,16 +536,32 @@ function createData(x,y,w,h,l,face,align,valign,value) { echo "
Loc ".($x+1).": "; foreach($locs as $k=>$v) { + if($k=='Lines' && $report['option']['type'] != 'label') continue; echo "$k="; } - echo 'Face='; - selector("col[$x][face]", array('' => '', 'bold' => 'Bold'), ''); + if($report['option']['type'] == 'label') { + echo 'Face='; + selector("col[$x][face]", array('' => '', 'bold' => 'Bold'), ''); + } + 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'); + if($report['option']['type'] == 'label') { + selector("col[$x][valign]", array('vcenter' => 'Center', 'vtop' => 'Top', 'vbottom' => 'Bottom'), + 'top'); + } else { + selector("col[$x][valign]", array('middle' => 'Middle', 'top' => 'Top', 'bottom' => 'Bottom'), 'middle'); + + echo 'Font='; + selector("col[$x][fontname]", $fontlist, ''); + selector("col[$x][fontstyle]", array('' => '', 'bold' => 'Bold'), ''); + echo ""; + echo 'pt '; + echo 'OnOverflow='; + selector("col[$x][on_overflow]", array('Truncate'=>'truncate','Add ...'=>'...', 'Scale'=>'scale'),''); + } echo ""; echo "