diff --git a/lam/lib/baseModule.inc b/lam/lib/baseModule.inc index 89659ca7..d9f9895d 100644 --- a/lam/lib/baseModule.inc +++ b/lam/lib/baseModule.inc @@ -836,15 +836,9 @@ abstract class baseModule { if (isset($this->attributes[$attrName]) && (sizeof($this->attributes[$attrName]) > 0)) { natcasesort($this->attributes[$attrName]); $value = implode($delimiter, $this->attributes[$attrName]); - // TODO workarounds for PDF parser, remove when migrated to other PDF library - $value = str_replace("\r\n", " ", $value); - $value = str_replace("\n", " ", $value); - $value = str_replace("\r", " ", $value); - // TODO workaround for UFPDF, remove when migrated to other PDF library $value = trim($value); } $result[get_class($this) . '_' . $name][] = new PDFLabelValue($label, $value); -// $result[get_class($this) . '_' . $name] = array('' . $label . '' . $value . ''); } /** @@ -862,7 +856,6 @@ abstract class baseModule { $value = implode($delimiter, $value); } $result[get_class($this) . '_' . $name][] = new PDFLabelValue($label, $value); -// $result[get_class($this) . '_' . $name] = array('' . $label . '' . $value . ''); } /** @@ -877,19 +870,6 @@ abstract class baseModule { return; } $result[get_class($this) . '_' . $name][] = $table; -/* if (!empty($table->label)) { - $result[get_class($this) . '_' . $name][] = '' . $table->label . ':'; - } - foreach ($table->rows as $row) { - $xml = ''; - foreach ($row->cells as $cell) { - $width = empty($cell->width) ? '' : ' width="' . $cell->width . '"'; - $content = ($cell->bold) ? '' . $cell->content . '' : $cell->content; - $xml .= '' . $content . ''; - } - $xml .= ''; - $result[get_class($this) . '_' . $name][] = $xml; - }*/ } /** diff --git a/lam/lib/pdf.inc b/lam/lib/pdf.inc index 881e939c..18ae05f5 100644 --- a/lam/lib/pdf.inc +++ b/lam/lib/pdf.inc @@ -32,9 +32,16 @@ $Id$ * @package PDF */ -/** PDF line width */ -define('LAMPDF_LINEWIDTH',190); +/** line width */ +define('LAMPDF_LINEWIDTH', 190); +/** line height */ +define('LAMPDF_LINEHEIGHT', 5); +/** width of a label */ +define('LAMPDF_LABELWIDTH', 50); +/** font size */ define('LAMPDF_FONT_SIZE', 7); +/** font size for bigger text */ +define('LAMPDF_FONT_SIZE_BIG', 10); /** XML functions */ include_once('xml_parser.inc'); @@ -42,9 +49,6 @@ include_once('xml_parser.inc'); /** access to PDF configuration files */ include_once('pdfstruct.inc'); -$key = false; -$line_width = LAMPDF_LINEWIDTH; - /** * This function creates the PDF output of one or more accounts. * @@ -65,8 +69,6 @@ function createModulePDF($accounts, $pdf_structure="default", $returnAsString = /** LAM PDF generator class */ include_once("lamPDF.inc"); - global $key; - $account_type = $accounts[0]->get_type(); // Get PDF structure from xml file $load = \LAM\PDF\loadPDFStructure($account_type->getId(), $pdf_structure); @@ -115,23 +117,24 @@ function createModulePDF($accounts, $pdf_structure="default", $returnAsString = else { $section_headline = $name; } - $pdf->setFont($fontName,"B",10); + $pdf->setFont($fontName, "B", LAMPDF_FONT_SIZE_BIG); $pdf->Write(0,$section_headline . ":"); - $pdf->Ln(6); + $pdf->Ln(LAMPDF_LINEHEIGHT); } // We have a section to end elseif($entry['tag'] == "SECTION" && $entry['type'] == "close") { - $pdf->Ln(9); + $pdf->Ln(LAMPDF_LINEHEIGHT * 2); } // We have to include a static text. elseif($entry['tag'] == "TEXT") { - // Load PDF text from structure array - $info_string = $entry['value']; - // Set font for text - $pdf->setFont($fontName,"",10); - $pdf->MultiCell(0,5,$info_string,0,"L",0); - // Print linebreak afterwards - $pdf->Ln(6); + $pdf->setFont($fontName, "", LAMPDF_FONT_SIZE); + $info_string = str_replace("\r", "", $entry['value']); + $info_string = explode("\n", $info_string); + foreach ($info_string as $text) { + $pdf->MultiCell(0, LAMPDF_LINEHEIGHT, trim($text), 0, "L", 0); + $pdf->Ln(0); + } + $pdf->Ln(LAMPDF_LINEHEIGHT * 2); } // We have to include an entry from the account elseif($entry['tag'] == "ENTRY") { @@ -152,16 +155,9 @@ function createModulePDF($accounts, $pdf_structure="default", $returnAsString = else if ($valueEntry instanceof PDFTable) { printTable($pdf, $valueEntry, $fontName); } - // Substitue XML syntax with valid FPDF methods - /**$methods = processLine($line,true,$fontName); - // Call every method - foreach($methods as $method) { - call_user_func_array(array(&$pdf,$method[0]),$method[1]); - }*/ } } } - $key = false; } } } @@ -202,172 +198,42 @@ function getSectionHeadline($entry) { */ function printLabelValue(&$pdf, $valueEntry, $fontName) { $pdf->SetFont($fontName, 'B', LAMPDF_FONT_SIZE); - $pdf->Cell(50, 5, $valueEntry->getLabel() . ':',0,0,'R',0); + $pdf->Cell(LAMPDF_LABELWIDTH, LAMPDF_LINEHEIGHT, $valueEntry->getLabel() . ':', 0, 0, 'R', 0); $pdf->SetFont($fontName, '', LAMPDF_FONT_SIZE); - $pdf->MultiCell(0, 5, $valueEntry->getValue(), 0, 'L', 0); + $pdf->MultiCell(0, LAMPDF_LINEHEIGHT, $valueEntry->getValue(), 0, 'L', 0); + $pdf->Ln(0); } /** * Prints a PDFTable entry. * * @param lamPDF $pdf PDF - * @param PDFTable $valueEntry entry + * @param PDFTable $table entry * @param string $fontName font name */ -function printTable(&$pdf, $valueEntry, $fontName) { -} - -/** - * Creates the XML code for an PDF entry. - * - * @param string $line XML code of PDF entry - * @param boolean $first_td True if this is the first column - * @param String $fontName font name - * - * @return array XML codes - */ -function processLine($line, $first_td = true, $fontName) { - global $key, $line_width; - - // PCRE matching tag - $block_pattern = '/<\/block>/'; - // PCRE matching a tag - $key_pattern = '/()(.+)<\/key>(.*<\/block>)/'; - // PCRE matching a tag - // !!FIXME!! value must contain at least one character - $value_pattern = '/(.*)(.*)<\/value>(<\/block>)/'; - // PCRE matching a tag - $td_pattern = '/(.*?)(.+?)<\/td>(.*<\/block>)/'; - // PCRE matching tag - $tr_pattern = '/<\/tr>/'; - // PCRE matching a

tag - $p_pattern = '/(.*)

(.+)<\/p>(.*<\/block>)/'; - // PCRE matching a
tag - $br_pattern = '/
/'; - - $return = array(); - if(preg_match($key_pattern,$line,$matches)) { - $key = true; - $line_width = $line_width - 50; - $format = processFormatTags($matches[2],'B'); - $return[] = array('setFont',array($fontName,$format[0],7)); - $return[] = array('Cell',array(50,5,$format[1] . ':',0,0,'R',0)); - $return[] = array('setFont',array($fontName,'',7)); - return array_merge($return,processLine($matches[1] . $matches[3],false,$fontName)); +function printTable(&$pdf, $table, $fontName) { + if (!empty($table->getHeadline())) { + $pdf->SetFont($fontName, 'B', LAMPDF_FONT_SIZE); + $pdf->Cell(LAMPDF_LABELWIDTH, LAMPDF_LINEHEIGHT, $table->getHeadline() . ':', 0 , 0, 'L', 0); + $pdf->Ln(LAMPDF_LINEHEIGHT); } - elseif(preg_match($value_pattern,$line,$matches)) { - $format = processFormatTags($matches[2],''); - $return[] = array('setFont',array($fontName,$format[0],7)); - $return[] = array('MultiCell',array(0,5,$format[1],0,'L',0)); - $return[] = array('setFont',array($fontName,'',7)); - return array_merge($return,processLine($matches[1] . $matches[3],true,$fontName)); - } - elseif(preg_match($p_pattern,$line,$matches)) { - $format = processFormatTags($matches[2],''); - $return[] = array('setFont',array($fontName,$format[0],7)); - $return[] = array('Write',array(5,$format[1])); - $return[] = array('setFont',array($fontName,'',7)); - return array_merge($return,processLine($matches[1] . $matches[3],true,$fontName)); - } - elseif(preg_match($td_pattern,$line,$matches)) { - if($first_td && $key) { - $first_td = !$first_td; - $return[] = array('Cell',array(50,5,'',0,0,'L',0)); + foreach ($table->rows as $row) { + foreach ($row->cells as $cell) { + $width = $cell->width; + if (!empty($width) && (strpos($width, '%') !== false)) { + $width = ceil(LAMPDF_LINEWIDTH * substr($width, 0, -1) / 100); + } + if ($cell->bold) { + $pdf->SetFont($fontName, 'B', LAMPDF_FONT_SIZE); + } + $pdf->Cell($width, LAMPDF_LINEHEIGHT, $cell->content, 0, 0, $cell->align, 0); + if ($cell->bold) { + $pdf->SetFont($fontName, '', LAMPDF_FONT_SIZE); + } } - $format = processFormatTags($matches[3],''); - $attrs = processAttributes($matches[2],array('width' => $line_width,'height' => 5,'align' => 'L')); - $return[] = array('setFont',array($fontName,$format[0],7)); - $return[] = array('Cell',array($attrs['width'],$attrs['height'],$format[1],0,0,$attrs['align'],0)); - $return[] = array('setFont',array($fontName,'',7)); - return array_merge($return,processLine($matches[1] . $matches[4],$first_td,$fontName)); - } - elseif(preg_match($br_pattern,$line,$matches)) { - return array(array('Ln',array(5))); - } - elseif(preg_match($block_pattern,$line,$matches)) { - $line_width = LAMPDF_LINEWIDTH; - return array(); - } - elseif(preg_match($tr_pattern,$line,$matches)) { - $line_width = LAMPDF_LINEWIDTH; - return array(array('Ln',array(5))); - } -} - -/** - * Formats the XML code. - * - * @param string $line XML code of PDF entry - * @param string $style style commands - * - * @return array XML code - */ -function processFormatTags($line,$style) { - // PCRE matching a tag - $i_pattern = '/(.*)(.+)<\/i>(.*)/'; - // PCRE matching a tag - $b_pattern = '/(.*)(.+)<\/b>(.*)/'; - // PCRE matching a tag - $u_pattern = '/(.*)(.+)<\/u>(.*)/'; - // Replacement pattern when one of the above pattern matched - $replace = "\$1\$2\$3"; - - if(preg_match($i_pattern,$line,$matches)) { - $style .= "I"; - $line = preg_replace($i_pattern,$replace,$line); - } - if(preg_match($b_pattern,$line,$matches)) { - $style .= "B"; - $line = preg_replace($b_pattern,$replace,$line); - } - if(preg_match($u_pattern,$line,$matches)) { - $style .= "U"; - $line = preg_replace($u_pattern,$replace,$line); - } - return array($style,$line); -} - -/** - * Processes width, height and alignment attributes. - * - * @param string $attrs attributes - * @param array $return XML code - * - * @return array XML code - */ -function processAttributes($attrs,$return = array()) { - global $line_width; - - // PCRE matching width attribute - $width_pattern = '/(.*)width\=\"(\\d+)(\%?)\"(.*)/'; - // PCRE matching height attribute - $height_pattern = '/(.*)height\=\"(\\d+)\"(.*)/'; - // PCRE matching align attribute - $align_pattern = '/(.*)align\=\"(L|R|C)\"(.*)/'; - - // Remove leading and trailing whitespaces - $attrs = trim($attrs); - - if(preg_match($width_pattern,$attrs,$matches)) { - if($matches[3] == '%') { - $return['width'] = ceil($line_width * $matches[2] / 100); - } - else { - $return['width'] = ceil($matches[2]); - } - return processAttributes($matches[1] . $matches[4],$return); - } - elseif(preg_match($height_pattern,$attrs,$matches)) { - $return['height'] = $matches[2]; - return processAttributes($matches[1] . $matches[3],$return); - } - elseif(preg_match($align_pattern,$attrs,$matches)) { - $return['align'] = $matches[2]; - return processAttributes($matches[1] . $matches[3],$return); - } - else { - return $return; + $pdf->Ln(LAMPDF_LINEHEIGHT); } + $pdf->Ln(LAMPDF_LINEHEIGHT); } /** @@ -409,15 +275,6 @@ class PDFTable implements PDFEntry { $this->label = $label; } - /** - * Returns the label. - * - * @return string $label label - */ - public function getLabel() { - return $this->label; - } - /** * {@inheritDoc} * @see PDFEntry::getHeadline() diff --git a/lam/lib/xml_parser.inc b/lam/lib/xml_parser.inc index f06bb328..fb425911 100644 --- a/lam/lib/xml_parser.inc +++ b/lam/lib/xml_parser.inc @@ -60,7 +60,8 @@ class xmlParser { if(file_exists($filename)) { $xmlStructure = array(); $xmlIndex = array(); - xml_parse_into_struct($this->xmlParser, implode("\n", file($filename)), $xmlStructure, $xmlIndex); + $xmlContent = + xml_parse_into_struct($this->xmlParser, implode("", file($filename)), $xmlStructure, $xmlIndex); return array($xmlStructure, $xmlIndex); } return array(); diff --git a/lam/templates/pdfedit/pdfpage.php b/lam/templates/pdfedit/pdfpage.php index aa295ac2..e31b46f1 100644 --- a/lam/templates/pdfedit/pdfpage.php +++ b/lam/templates/pdfedit/pdfpage.php @@ -143,11 +143,11 @@ if(isset($_GET['submit'])) { // add a new text field elseif(isset($_GET['add_text'])) { // Check if text for static text field is specified - if(!isset($_GET['text_text']) || ($_GET['text_text'] == '')) { + if(empty($_GET['text_text'])) { StatusMessage('ERROR',_('No static text specified'),_('The static text must contain at least one character.')); } else { - $entry = array(array('tag' => 'TEXT','type' => 'complete','level' => '2','value' => $_GET['text_text'])); + $entry = array(array('tag' => 'TEXT','type' => 'complete','level' => '2','value' => str_replace("\r", "\n", $_GET['text_text']))); // Insert new field in structure array_splice($_SESSION['currentPDFStructure'],$_GET['add_text_position'],0,$entry); }