コード例 #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
    /**
     * 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);
    }
コード例 #3
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);
    }
コード例 #4
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));
    }
コード例 #5
0
 function getPages(&$dom_tree, $max_page_height, $first_page_top)
 {
     $current_page_top = $first_page_top;
     $heights = array();
     /**
      * Get list of footnotes and heights of footnote content blocks
      */
     $footnotes = PageBreakLocator::_getFootnotesTraverse($dom_tree);
     usort($footnotes, 'cmp_footnote_locations');
     $locations = PageBreakLocator::_getBreakLocations($dom_tree);
     if (count($locations) == 0) {
         return array($max_page_height);
     }
     $best_location = null;
     foreach ($locations as $location) {
         if ($location->location < $current_page_top) {
             if (is_null($best_location)) {
                 $best_location = $location;
             }
             $current_pos = round_units($current_page_top - $location->location);
             $available_page_height = round_units($max_page_height - $location->_getFootnotesHeight($footnotes, $current_page_top, $location->location));
             if ($current_pos > $available_page_height) {
                 /**
                  * No more locations found on current page
                  */
                 $best_location_penalty = $best_location->getPenalty($current_page_top, $max_page_height, $footnotes);
                 if ($best_location_penalty >= MAX_PAGE_BREAK_PENALTY) {
                     error_log('Could not find good page break location');
                     $heights[] = $max_page_height;
                     $current_page_top -= $max_page_height;
                     $best_location = null;
                 } else {
                     $heights[] = $current_page_top - $best_location->location;
                     $current_page_top = $best_location->location;
                     $best_location = null;
                 }
             } else {
                 $location_penalty = $location->getPenalty($current_page_top, $max_page_height, $footnotes);
                 $best_penalty = $best_location->getPenalty($current_page_top, $max_page_height, $footnotes);
                 if ($location_penalty <= $best_penalty) {
                     /**
                      * Better page break location found on current page
                      */
                     $best_location = $location;
                 }
             }
             if ($location->penalty < 0) {
                 // Forced page break
                 $heights[] = $current_page_top - $location->location;
                 $current_page_top = $location->location;
                 $best_location = null;
             }
         }
     }
     // Last page always will have maximal height
     $heights[] = $max_page_height;
     return $heights;
 }