Index: css_defaults.php =================================================================== --- css_defaults.php (revision 13936) +++ 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: pdf_helper.php =================================================================== --- pdf_helper.php (revision 13936) +++ 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,24 @@ function InitPDF($doc) { - $this->PDF = new kTCPDFRenderer(); +// $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()); +// $this->CurPDFElem->SetCSSProperty('width', $this->PDF->getWidth()); +// $this->CurPDFElem->SetCSSProperty('height', $this->PDF->getHeight()); +// $this->PDF->SetFont('helvetica', $this->PtPerEm); + } + + 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 +162,30 @@ } } + /** + * Sets page size + * + */ + function ProcessBody() + { + $page_orientation = $page_format = null; + + $size_x = $this->CurPDFElem->GetCSSProperty('size-x'); + $size_y = $this->CurPDFElem->GetCSSProperty('size-y'); + $size_orientation = $this->CurPDFElem->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); @@ -171,8 +213,12 @@ $line = $this->CurPDFElem; } - $this->CurPDFElem = $this->CurPDFElem->AddChild( $elem ); + $this->CurPDFElem = $this->CurPDFElem->AddChild( $elem ); + if ($child->Name == 'BODY') { + $this->ProcessBody(); + } + $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: pdf_renderer_tcpdf.php =================================================================== --- pdf_renderer_tcpdf.php (revision 13936) +++ pdf_renderer_tcpdf.php (working copy) @@ -33,11 +33,19 @@ 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); Index: pdf_styles.php =================================================================== --- pdf_styles.php (revision 13936) +++ 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;