コード例 #1
0
    function testPagebreakTable2()
    {
        $media = new Media(array('width' => 100, 'height' => 200 / mm2pt(1)), array('top' => 0, 'bottom' => 0, 'left' => 0, 'right' => 0));
        $tree = $this->runPipeline('
<html>
<head>
body   { font-size: 10pt; line-height: 1; padding: 0; margin: 0; }
table  { line-height: 1; }
</style>
</head>
<body>
<table cellpadding="0" cellspacing="0" id="table">
<tr><td id="cell">TEXT1_1<br/>TEXT1_2</td></tr>
</table>
</body>
</html>
', $media);
        $locations = PageBreakLocator::_getBreakLocations($tree);
        $table = $tree->get_element_by_id('table');
        $cell = $tree->get_element_by_id('cell');
        $line1 = $cell->content[0]->getLineBox(0);
        $this->assertEqual(count($locations), 3, "Testing number of page breaks inside a table with one cell & several text lines inside [%s]");
        $this->assertEqual($locations[0]->location, $table->get_top_margin(), "First page break should be at the table top [%s]");
        $this->assertEqual($locations[1]->location, $line1->bottom, "Second page break should be at the bottom of the first line box in the table cell [%s]");
        $this->assertEqual($locations[2]->location, $table->get_bottom_margin(), "Last page break should be at the table bottom [%s]");
    }
コード例 #2
0
    function testPagebreakBorderTestNoBorder()
    {
        $media = new Media(array('width' => 100, 'height' => 200 / mm2pt(1)), array('top' => 0, 'bottom' => 0, 'left' => 0, 'right' => 0));
        $tree = $this->runPipeline('
<html>
<head>
<style type="text/css">
body   { font-size: 10pt; line-height: 1; orphans:0; widows: 0; padding: 0; margin: 0; }
#first { line-height: 1; height: 180pt; }
#second { width: 3em; }
</style>
</head>
<body>
<div id="first">&nbsp;</div>
<div id="second">
LINE1<!--Page break should be here-->
LINE2
LINE3
LINE4
LINE5
</div>
</body>
</html>
', $media);
        /**
         * Calculate page heights
         */
        $page_heights = PageBreakLocator::getPages($tree, mm2pt($media->real_height()), mm2pt($media->height() - $media->margins['top']));
        $first_div = $tree->get_element_by_id('first');
        $second_div = $tree->get_element_by_id('second');
        $this->assertEqual(count($page_heights), 2, sprintf("Two pages expected, got %s", count($page_heights)));
        $this->assertEqual($page_heights[0], $first_div->get_full_height() + pt2pt(20));
    }
コード例 #3
0
 function testPagebreakFixedHeight1()
 {
     $media = new Media(array('width' => 100, 'height' => 200 / mm2pt(1)), array('top' => 0, 'bottom' => 0, 'left' => 0, 'right' => 0));
     $tree = $this->runPipeline(file_get_contents('test.pagebreak.fixed.height.1.html'), $media);
     $page_heights = PageBreakLocator::getPages($tree, mm2pt($media->real_height()), mm2pt($media->height() - $media->margins['top']));
     $div = $tree->get_element_by_id('div');
     $this->assertEqual(count($page_heights), 2, sprintf("Two pages expected, got %s", count($page_heights)));
     $this->assertEqual($page_heights[0], 200);
 }
コード例 #4
0
 function testCSSPageBreakAfter2()
 {
     $tree = $this->runPipeline(file_get_contents('test.css.page.break.after.2.html'), $media);
     $page_heights = PageBreakLocator::getPages($tree, mm2pt($media->real_height()), mm2pt($media->height() - $media->margins['top']));
     $this->assertEqual(count($page_heights), 2);
     $div = $tree->get_element_by_id('div');
     $h1 = $tree->get_element_by_id('h1');
     $this->assertEqual($page_heights[0], $div->get_full_height());
 }
コード例 #5
0
    /**
     * Checks if it is possible to make an incorrect page break in a table with
     * different font size in different cells
     */
    function testPagebreakTableBr1()
    {
        $media = new Media(array('width' => 100, 'height' => 200 / mm2pt(1)), array('top' => 0, 'bottom' => 0, 'left' => 0, 'right' => 0));
        $tree = $this->runPipeline('
<html>
<head>
body { 
  font-size: 10pt; 
  line-height: 1; 
  padding: 0; 
  margin: 0; 
}

td.small { 
  font-size: 20pt; 
}
</style>
</head>
<body>
<table cellpadding="0" cellspacing="0">
<tr>
<td>
SMALL<br/>
SMALL<br/>
SMALL<br/>
SMALL<br/>
SMALL<br/>
</td>
</tr>
</table>
</body>
</html>
', $media);
        /**
         * Calculate page heights
         */
        $locations = PageBreakLocator::_getBreakLocations($tree);
        $this->assertEqual(count($locations), 6);
    }
コード例 #6
0
ファイル: test.pagebreak.br.php プロジェクト: aedvalson/Nexus
    function testPagebreakWithBR()
    {
        $media = new Media(array('width' => 100, 'height' => 200 / mm2pt(1)), array('top' => 0, 'bottom' => 0, 'left' => 0, 'right' => 0));
        $tree = $this->runPipeline('
<html>
<head>
body   { font-size: 10pt; line-height: 1; padding: 0; margin: 0; }
</style>
</head>
<body>
<div>
LINE1<br/>
LINE2<br/>
LINE3<br/>
LINE4<br/>
LINE5<br/>
</div>
</body>
</html>
', $media);
        $locations = PageBreakLocator::_getBreakLocations($tree);
        $this->assertEqual(count($locations), 6);
    }
コード例 #7
0
    /**
     * Checks if it is possible to make an incorrect page break in a table with
     * different font size in different cells
     */
    function testPagebreakTableLines1()
    {
        $media = new Media(array('width' => 100, 'height' => 200 / mm2pt(1)), array('top' => 0, 'bottom' => 0, 'left' => 0, 'right' => 0));
        $tree = $this->runPipeline('
<html>
<head>
<style type="text/css">
body { 
  font-size: 10pt; 
  line-height: 1; 
  padding: 0; 
  margin: 0; 
  width: 10pt;
}

div { 
  width: 10pt;
  orphans: 0;
  widows: 0;
}

td#small { 
  font-size: 20pt; 
  line-height: 1; 
  width: 10pt;
  vertical-align: top;
}

td#large { 
  font-size: 30pt; 
  line-height: 1; 
  width: 10pt;
  vertical-align: top;
}
</style>
</head>
<body>
<table cellpadding="0" cellspacing="0">
<tr>
<td id="small">
<div>
SMALL
SMALL
SMALL
SMALL
SMALL
SMALL
SMALL
SMALL
SMALL
SMALL
</div>
</td>
<td id="large">
<div>
LARGE
LARGE
LARGE
LARGE
LARGE
LARGE
LARGE
</div>
</td>
</tr>
</table>
</body>
</html>
', $media);
        $small = $tree->get_element_by_id('small');
        $font_size =& $small->getCSSProperty(CSS_FONT_SIZE);
        $this->assertEqual($font_size->getPoints(), 20);
        $large = $tree->get_element_by_id('large');
        $font_size =& $large->getCSSProperty(CSS_FONT_SIZE);
        $this->assertEqual($font_size->getPoints(), 30);
        $locations = PageBreakLocator::_getBreakLocations($tree);
        $this->assertEqual(count($locations), 5);
        $page_heights = PageBreakLocator::getPages($tree, mm2pt($media->real_height()), mm2pt($media->height() - $media->margins['top']));
        $this->assertEqual(count($page_heights), 2, sprintf("Two pages expected, got %s", count($page_heights)));
        $this->assertEqual($page_heights[0], pt2pt(180));
    }
コード例 #8
0
 function _getPagesTraverse(&$box, $penalty)
 {
     if (!is_a($box, 'GenericContainerBox')) {
         return array();
     }
     $locations = array();
     for ($i = 0, $content_size = count($box->content); $i < $content_size; $i++) {
         $previous_child =& PageBreakLocator::_getPrevious($i, $box->content, $content_size);
         $next_child =& PageBreakLocator::_getNext($i, $box->content, $content_size);
         $child =& $box->content[$i];
         /**
          * Note that page-break-xxx properties apply to block-level elements only
          */
         if (is_a($child, 'BRBox')) {
             // Do nothing
         } elseif ($child->isBlockLevel()) {
             $locations = array_merge($locations, PageBreakLocator::_getPagesTraverseBlock($child, $next_child, $previous_child, $penalty));
         } elseif (is_a($child, 'TableCellBox')) {
             $null = null;
             $child_locations = PageBreakLocator::_getPagesTraverseBlock($child, $null, $null, $penalty);
             $locations = array_merge($locations, $child_locations);
         } elseif (is_a($child, 'InlineBox')) {
             $more_before = 0;
             $more_after = 0;
             if (is_a($previous_child, 'BRBox')) {
                 $more_before = PageBreakLocator::_getMoreBefore($i, $box->content, $content_size);
             }
             if (is_a($next_child, 'BRBox')) {
                 $more_after = PageBreakLocator::_getMoreAfter($i, $box->content, $content_size);
             }
             $locations = array_merge($locations, PageBreakLocator::_getPagesTraverseInline($child, $penalty, $more_before, $more_after));
         } elseif (is_a($child, 'TableRowBox')) {
             $locations = array_merge($locations, PageBreakLocator::_getPagesTraverseTableRow($child, $penalty));
         }
     }
     return $locations;
 }
コード例 #9
0
 function run(&$pipeline, &$media, &$box)
 {
     $page_heights = PageBreakLocator::get_pages($box, mm2pt($media->real_height()), mm2pt($media->height() - $media->margins['top']));
     return $page_heights;
 }
コード例 #10
0
 function _show_item(&$box, $offset, &$context, &$media, &$postponed_filter)
 {
     $context->sort_absolute_positioned_by_z_index();
     // Make batch-processing offset
     $box->offset(0, $offset);
     /**
      * Calculate page heights
      */
     if ($GLOBALS['g_config']['smartpagebreak']) {
         $page_heights = PageBreakLocator::getPages($box, mm2pt($media->real_height()), mm2pt($media->height() - $media->margins['top']));
     } else {
         $num_pages = ceil($box->get_height() / mm2pt($media->real_height()));
         $page_heights = array();
         for ($i = 0; $i < $num_pages; $i++) {
             $page_heights[] = mm2pt($media->real_height());
         }
     }
     $expected_pages = count($page_heights);
     $this->output_driver->set_expected_pages($expected_pages);
     $this->_resetCounter('pages', $expected_pages);
     $this->_resetCounter('page', 0);
     $this->_dispatcher->fire('before-document', array('pipeline' => $this, 'document' => $box));
     // Output PDF pages using chosen PDF driver
     for ($i = 0; $i < $expected_pages; $i++) {
         $this->_resetCounter('footnote', 0);
         $this->_incrementCounter('page', 1);
         $this->output_driver->save();
         /**
          * Note that margin boxes should be rendered before 'setup_clip', as it will trim all
          * content rendered outside the 'main' page area
          */
         $this->render_margin_boxes($i + 1, $media);
         $this->render_page_box($i + 1, $media);
         $this->output_driver->setPageHeight($page_heights[$i]);
         $this->output_driver->setup_clip();
         $this->_dispatcher->fire('before-page', array('pipeline' => $this, 'document' => $box, 'pageno' => $i));
         if (is_null($box->show($this->output_driver))) {
             error_log("Pipeline::_process_item: output routine failed");
             return null;
         }
         /**
          * Show postponed boxes - relative and floating boxes, as they should be 
          * shown over boxes on the same layer
          */
         $this->output_driver->show_postponed();
         $this->renderAbsolutePositioned($context);
         $this->output_driver->restore();
         $this->renderFixedPositioned($context);
         $this->renderFootnotes();
         global $g_config;
         if ($g_config['draw_page_border']) {
             $this->output_driver->draw_page_border();
         }
         $this->_dispatcher->fire('after-page', array('pipeline' => $this, 'document' => $box, 'pageno' => $i));
         // Add page if currently rendered page is not last
         if ($i < $expected_pages - 1) {
             $this->output_driver->next_page($page_heights[$i]);
         }
         // Restore postponed list for the next page
         $postponed_filter->process($box, null, $this);
     }
     $this->_dispatcher->fire('after-document', array('pipeline' => $this, 'document' => $box));
 }
コード例 #11
0
ファイル: test.pagebreak.php プロジェクト: aedvalson/Nexus
    function testPagebreakText4()
    {
        $media = new Media(array('width' => 100, 'height' => 300), array('top' => 0, 'bottom' => 0, 'left' => 0, 'right' => 0));
        $tree = $this->runPipeline('
<html>
<head>
<style type="text/css">
body    { font-size: 20mm; line-height: 1; padding: 0; margin: 0; orphans: 0; widows: 0; }
#wrap   { width: 2em; }
#first  { line-height: 1; }
#second { line-height: 1; page-break-before: avoid; page-break-inside: avoid; }
#third  { line-height: 1; }
</style>
</head>
<body>
<div id="wrap">
<div id="first">
LINE1
LINE2
LINE3
LINE4
LINE5
LINE6
LINE7
LINE8
LINE9
LINE10
LINE11
LINE12
LINE13
</div><!--Page break should be here-->
<div id="second">
LINE1
LINE2
LINE3
</div>
<div id="third">
LINE1
LINE2
LINE3
</div>
</div>
</body>
</html>
', $media);
        /**
         * Calculate page heights
         */
        $page_heights = PageBreakLocator::getPages($tree, mm2pt($media->real_height()), mm2pt($media->height() - $media->margins['top']));
        $first_div = $tree->get_element_by_id('first');
        $second_div = $tree->get_element_by_id('second');
        $third_div = $tree->get_element_by_id('third');
        $this->assertEqual(count($page_heights), 2, sprintf("2 pages expected, got %s", count($page_heights)));
        $this->assertWithinMargin($page_heights[0], $first_div->get_full_height() - mm2pt(20), 0.01);
    }