Index: units/pdf/css_defaults.php =================================================================== --- units/pdf/css_defaults.php (revision 13936) +++ units/pdf/css_defaults.php (working copy) @@ -543,6 +543,30 @@ 'inherited' => true, 'percentages' => '' ), + 'SIZE' => array( + 'initial' =>'auto', + 'applies' => 'block-level elements', + 'inherited' => true /*false*/, + 'percentages' => '' + ), + 'SIZE-X' => array( + 'initial' =>'auto', + 'applies' => 'block-level elements', + 'inherited' => true /*false*/, + 'percentages' => '' + ), + 'SIZE-Y' => array( + 'initial' =>'auto', + 'applies' => 'block-level elements', + 'inherited' => true /*false*/, + 'percentages' => '' + ), + 'SIZE-ORIENTATION' => array( + 'initial' =>'auto', + 'applies' => 'block-level elements', + 'inherited' => true /*false*/, + 'percentages' => '' + ), 'POSITION' => array( 'initial' =>'static', 'applies' => '', Index: units/pdf/pdf_helper.php =================================================================== --- units/pdf/pdf_helper.php (revision 13936) +++ units/pdf/pdf_helper.php (working copy) @@ -44,10 +44,20 @@ var $DimensionsMode = 1; + /** + * Enter description here... + * + * @var kPDFStylesheet + */ var $Stylesheet; var $PtPerEm = 10; + /** + * Enter description here... + * + * @var kPDFElement + */ public $Document = null; const DM_NORMAL = 0; @@ -111,16 +121,19 @@ function InitPDF($doc) { - $this->PDF = new kTCPDFRenderer(); - $this->Stylesheet = new kPDFStylesheet(); $this->CurPDFElem = kPDFElemFactory::CreateFromNode($doc, $this); $this->Document = $this->CurPDFElem; -// $this->CurPDFElem = new kPDFPage($page1, new kXMLNode('_NONE_', array('style' => 'display: block; width: '.$page1->getWidth().';')), $this); $this->CurPDFElem->Init(); - $this->CurPDFElem->SetCSSProperty('width', $this->PDF->getWidth()); - $this->CurPDFElem->SetCSSProperty('height', $this->PDF->getHeight()); + } + + function SetPageSize($page_orientation = null, $page_format = null) + { + $this->PDF = new kTCPDFRenderer($page_orientation, $page_format); + + $this->Document->SetCSSProperty('width', $this->PDF->getWidth()); + $this->Document->SetCSSProperty('height', $this->PDF->getHeight()); $this->PDF->SetFont('helvetica', $this->PtPerEm); } @@ -144,6 +157,35 @@ } } + /** + * Sets page size + * + * @param kPDFElement $element + * + */ + function ProcessBody(&$element) + { + $page_orientation = $page_format = null; + + $element_clone = clone $element; + $element_clone->Init(); + + $size_x = $element_clone->GetCSSProperty('size-x'); + $size_y = $element_clone->GetCSSProperty('size-y'); + $size_orientation = $element_clone->GetCSSProperty('size-orientation'); + + if ($size_x != 'auto' && $size_y != 'auto') { + $page_format = Array ($size_x, $size_y); + } + + if ($size_orientation != 'auto') { + $page_orientation = $size_orientation == 'landscape' ? 'L' : 'P'; + } + + // size: auto|width height landscape|portrait + $this->SetPageSize($page_orientation, $page_format); + } + function ProcessNode($node) { $children = count($node->Children); @@ -158,6 +200,10 @@ $display = $elem->GetDisplayLevel(); if ($display == 'none') continue; + if ($child->Name == 'BODY') { + $this->ProcessBody($elem); + } + // http://manual.prod.intechnic.lv/css21/visuren.html#anonymous-block-level if ($display == 'block' && $this->CurPDFElem->GetDisplayLevel() == 'inline') { $this->CurPDFElem->Closed(); @@ -171,7 +217,7 @@ $line = $this->CurPDFElem; } - $this->CurPDFElem = $this->CurPDFElem->AddChild( $elem ); + $this->CurPDFElem = $this->CurPDFElem->AddChild( $elem ); $this->ProcessNode($child); $this->CurPDFElem = $current; @@ -181,6 +227,14 @@ } class kPDFElemFactory { + + /** + * Enter description here... + * + * @param kXMLNode5 $node + * @param kPDFHelper $helper + * @return kPDFElement + */ static function CreateFromNode($node, $helper) { /* @todo Create elements, based on their display, rather than tag name - pure CSS rendering */ @@ -253,7 +307,6 @@ public $Spacers = 0; - function __construct($node, $helper) { $this->Node = $node; @@ -708,6 +761,9 @@ 'BACKGROUND-COLOR', 'TEXT-ALIGN', 'TEXT-TRANSFORM', 'TABLE-LAYOUT', + + // related to printing + 'SIZE', 'SIZE-X', 'SIZE-Y', 'SIZE-ORIENTATION', 'PAGE-BREAK-AFTER' ); @@ -868,6 +924,9 @@ elseif (preg_match('/([.0-9]+)(px)/i', $value, $regs)) { $value = $regs[1] * 72 / 96; } + elseif (preg_match('/([.0-9]+)(in)/i', $value, $regs)) { + $value = $regs[1] * 72; + } elseif (preg_match('/([.0-9]+)(pt)/i', $value, $regs)) { $value = $regs[1]; } @@ -995,7 +1054,6 @@ // $this->ContentWidthNewLine(); } - } class kPDFLine extends kPDFElement { Index: units/pdf/pdf_renderer_tcpdf.php =================================================================== --- units/pdf/pdf_renderer_tcpdf.php (revision 13936) +++ units/pdf/pdf_renderer_tcpdf.php (working copy) @@ -33,15 +33,29 @@ public $CurFont = null; public $CurFontSize = null; - function __construct() + function __construct($page_orientation = null, $page_format = null) { $this->IncludeTCPDF(); - $this->PDF = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true); + if ( !isset($page_orientation) ) { + $page_orientation = PDF_PAGE_ORIENTATION; + } + + if ( !isset($page_format) ) { + $page_format = PDF_PAGE_FORMAT; + } + + $this->PDF = new TCPDF($page_orientation, PDF_UNIT, $page_format, true); $this->PDF->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $this->PDF->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); $this->PDF->setPrintHeader(false); $this->PDF->setPrintFooter(false); + + // remove TCPDF defaults + $this->PDF->SetMargins(0, 0); // margins of 1cm from each page side + $this->PDF->SetCellPadding(0); // cell padding + $this->PDF->SetAutoPageBreak(false); // don't auto-break pages, since kPDFHelper checks it + $this->PDF->AddPage(); // $this->PDF->SetX(50); @@ -57,7 +71,7 @@ define('K_PATH_MAIN', FULL_PATH.'/tcpdf/'); define('K_PATH_URL', PROTOCOL.SERVER_NAME.(defined('PORT')?':'.PORT : '').rtrim(BASE_PATH, '/').'/tcpdf/'); define ("K_PATH_FONTS", K_PATH_MAIN."fonts/"); - define ("K_PATH_CACHE", K_PATH_MAIN."cache/"); + define ("K_PATH_CACHE", WRITEABLE . '/cache' ); // K_PATH_MAIN."cache/" define ("K_PATH_URL_CACHE", K_PATH_URL."cache/"); define ("K_PATH_IMAGES", K_PATH_MAIN."images/"); define ("K_BLANK_IMAGE", K_PATH_IMAGES."_blank.png"); Index: units/pdf/pdf_styles.php =================================================================== --- units/pdf/pdf_styles.php (revision 13936) +++ units/pdf/pdf_styles.php (working copy) @@ -233,6 +233,36 @@ break; } break; + + case 'SIZE': + $size = array_map('trim', explode(' ', strtolower($value))); + + switch ( count($size) ) { + case 1: + // orientation only + if ($size[0] == 'auto') { + $res[$property] = $value; + } + else { + $res['SIZE-ORIENTATION'] = $size[0]; + } + break; + + case 2: + // size only + $res['SIZE-X'] = $size[0]; + $res['SIZE-Y'] = $size[1]; + break; + + case 3: + // size and orientation + $res['SIZE-X'] = $size[0]; + $res['SIZE-Y'] = $size[1]; + $res['SIZE-ORIENTATION'] = $size[2]; + break; + } + break; + default: $res[$property] = $value; } @@ -351,6 +381,14 @@ $d++; } } + /*elseif (preg_match('/^@('.$ident.')/i', $simple_selector, $regs)) { + $main = '@' . $regs[1]; + $d++; + + if ($regs[1] == 'page') { + + } + }*/ else { $main = '*'; } @@ -489,10 +527,7 @@ '#{name}' =>'HASH', - '@import' =>'IMPORT_SYM', - '@page' =>'PAGE_SYM', - '@media' =>'MEDIA_SYM', - '@charset' =>'CHARSET_SYM', + '@{ident}' => 'ATKEYWORD', '!{w}important' =>'IMPORTANT_SYM', @@ -688,7 +723,6 @@ $this->Macros = $replaced_macros; } - public function GetHTMLVisualPropsSelector($node) { if (!$node->Attributes) return false;