function testOrphans1()
    {
        $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: 190pt; }
#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($second_div->getCSSProperty(CSS_ORPHANS), 0);
        $this->assertWithinMargin($page_heights[0], $first_div->get_full_height() + pt2pt(10), 0.01);
    }
Example #2
0
 function parse($value)
 {
     if ($value == '') {
         return null;
     }
     // First attempt to create media with predefined name
     if (preg_match('/^(\\w+)(?:\\s+(portrait|landscape))?$/', $value, $matches)) {
         $name = $matches[1];
         $landscape = isset($matches[2]) && $matches[2] == 'landscape';
         $media =& Media::predefined($name);
         if (is_null($media)) {
             return null;
         }
         return array('size' => array('width' => $media->get_width(), 'height' => $media->get_height()), 'landscape' => $landscape);
     }
     // Second, attempt to create media with predefined size
     $parts = preg_split('/\\s+/', $value);
     $width_str = $parts[0];
     $height_str = isset($parts[1]) ? $parts[1] : $parts[0];
     $width = units2pt($width_str);
     $height = units2pt($height_str);
     if ($width == 0 || $height == 0) {
         return null;
     }
     return array('size' => array('width' => $width / mm2pt(1) / pt2pt(1), 'height' => $height / mm2pt(1) / pt2pt(1)), 'landscape' => false);
 }
function units2pt($value, $font_size = null)
{
    $unit = Value::unit_from_string($value);
    switch ($unit) {
        case UNIT_PT:
            return pt2pt((double) $value);
        case UNIT_PX:
            return px2pt((double) $value);
        case UNIT_MM:
            return pt2pt(mm2pt((double) $value));
        case UNIT_CM:
            return pt2pt(mm2pt((double) $value * 10));
        case UNIT_EM:
            return em2pt((double) $value, $font_size);
        case UNIT_EX:
            return ex2pt((double) $value, $font_size);
        case UNIT_IN:
            return pt2pt((double) $value * 72);
            // points used by CSS 2.1 are equal to 1/72nd of an inch.
        // points used by CSS 2.1 are equal to 1/72nd of an inch.
        case UNIT_PC:
            return pt2pt((double) $value * 12);
            // 1 pica equals to 12 points.
        // 1 pica equals to 12 points.
        default:
            global $g_config;
            if ($g_config['mode'] === 'quirks') {
                return px2pt((double) $value);
            } else {
                return 0;
            }
    }
}
    function TestInputTextHeight2()
    {
        $tree = $this->runPipeline('
<style>
* { font-size: 22pt; }
</style>
<input id="input" type="text"/>
');
        $element =& $tree->get_element_by_id('input');
        $this->assertEqual($element->get_full_height(), pt2pt(22) + $element->_get_vert_extra());
    }
    function TestInputSelectHeight2()
    {
        $tree = $this->runPipeline('
<style>
* { font-size: 33pt; }
</style>
<select id="input"></select>
');
        $element =& $tree->get_element_by_id('input');
        $this->assertEqual($element->get_full_height(), pt2pt(33) + $element->_get_vert_extra());
    }
 function testTableColumnWidth2()
 {
     $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.table.column.width.2.html'), $media, $pipeline);
     $large = $tree->get_element_by_id('large');
     $real_width = pt2pt(150);
     $width =& $large->getCSSProperty(CSS_WIDTH);
     $this->assertTrue($width->isConstant());
     $this->assertEqual($width->width, $real_width);
     $this->assertEqual($large->get_width(), $real_width);
 }
    /**
     * 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));
    }
 function show(&$driver)
 {
     $driver->save();
     // draw generic box
     GenericFormattedBox::show($driver);
     $driver->setlinewidth(0.1);
     $driver->moveto($this->get_left(), $this->get_top());
     $driver->lineto($this->get_right(), $this->get_top());
     $driver->lineto($this->get_right(), $this->get_bottom());
     $driver->lineto($this->get_left(), $this->get_bottom());
     $driver->closepath();
     $driver->stroke();
     if (!$GLOBALS['g_config']['debugnoclip']) {
         $driver->moveto($this->get_left(), $this->get_top());
         $driver->lineto($this->get_right(), $this->get_top());
         $driver->lineto($this->get_right(), $this->get_bottom());
         $driver->lineto($this->get_left(), $this->get_bottom());
         $driver->closepath();
         $driver->clip();
     }
     // Output text with the selected font
     $size = pt2pt(BROKEN_IMAGE_ALT_SIZE_PT);
     $status = $driver->setfont("Times-Roman", "iso-8859-1", $size);
     if (is_null($status)) {
         return null;
     }
     $driver->show_xy($this->alt, $this->get_left() + $this->width / 2 - $driver->stringwidth($this->alt, "Times-Roman", "iso-8859-1", $size) / 2, $this->get_top() - $this->height / 2 - $size / 2);
     $driver->restore();
     $strategy =& new StrategyLinkRenderingNormal();
     $strategy->apply($this, $driver);
     return true;
 }
Example #9
0
 function get_page_media($page_no, &$media)
 {
     $page_rules =& $this->get_page_rules($page_no);
     $size_landscape = $page_rules->get_property_value(CSS_SIZE);
     if (!is_null($size_landscape)) {
         $media->set_width($size_landscape['size']['width']);
         $media->set_height($size_landscape['size']['height']);
         $media->set_landscape($size_landscape['landscape']);
     }
     $margins = $page_rules->get_property_value(CSS_MARGIN);
     if (!is_null($margins)) {
         $media->margins['left'] = $margins->left->calc(mm2pt($media->get_width())) / mm2pt(1) / pt2pt(1);
         $media->margins['right'] = $margins->right->calc(mm2pt($media->get_width())) / mm2pt(1) / pt2pt(1);
         $media->margins['top'] = $margins->top->calc(mm2pt($media->get_height())) / mm2pt(1) / pt2pt(1);
         $media->margins['bottom'] = $margins->bottom->calc(mm2pt($media->get_height())) / mm2pt(1) / pt2pt(1);
     }
     $left_margin = $page_rules->get_property_value(CSS_MARGIN_LEFT);
     if (!is_null($left_margin)) {
         $media->margins['left'] = $left_margin->calc(mm2pt($media->get_width())) / mm2pt(1) / pt2pt(1);
     }
     $right_margin = $page_rules->get_property_value(CSS_MARGIN_RIGHT);
     if (!is_null($right_margin)) {
         $media->margins['right'] = $right_margin->calc(mm2pt($media->get_width())) / mm2pt(1) / pt2pt(1);
     }
     $top_margin = $page_rules->get_property_value(CSS_MARGIN_TOP);
     if (!is_null($top_margin)) {
         $media->margins['top'] = $top_margin->calc(mm2pt($media->get_height())) / mm2pt(1) / pt2pt(1);
     }
     $bottom_margin = $page_rules->get_property_value(CSS_MARGIN_BOTTOM);
     if (!is_null($bottom_margin)) {
         $media->margins['bottom'] = $bottom_margin->calc(mm2pt($media->get_height())) / mm2pt(1) / pt2pt(1);
     }
     $pixels = $page_rules->get_property_value(CSS_HTML2PS_PIXELS);
     if (!is_null($pixels)) {
         $media->set_pixels($pixels);
     }
 }
 function toPt($font_size)
 {
     switch ($this->_unit) {
         case UNIT_PT:
             return pt2pt($this->_number);
         case UNIT_PX:
             return px2pt($this->_number);
         case UNIT_MM:
             return pt2pt(mm2pt($this->_number));
         case UNIT_CM:
             return pt2pt(mm2pt($this->_number * 10));
         case UNIT_EM:
             return em2pt($this->_number, $font_size);
         case UNIT_EX:
             return ex2pt($this->_number, $font_size);
         case UNIT_IN:
             return pt2pt($this->_number * 72);
             // points used by CSS 2.1 are equal to 1/72nd of an inch.
         // points used by CSS 2.1 are equal to 1/72nd of an inch.
         case UNIT_PC:
             return pt2pt($this->_number * 12);
             // 1 pica equals to 12 points.
         // 1 pica equals to 12 points.
         default:
             global $g_config;
             if ($g_config['mode'] === 'quirks') {
                 return px2pt($this->_number);
             } else {
                 return 0;
             }
     }
 }
Example #11
0
 function show(&$viewport)
 {
     $viewport->save();
     // draw generic box
     GenericFormattedBox::show($viewport);
     $viewport->setlinewidth(0.1);
     $viewport->moveto($this->get_left(), $this->get_top());
     $viewport->lineto($this->get_right(), $this->get_top());
     $viewport->lineto($this->get_right(), $this->get_bottom());
     $viewport->lineto($this->get_left(), $this->get_bottom());
     $viewport->closepath();
     $viewport->stroke();
     $viewport->moveto($this->get_left(), $this->get_top());
     $viewport->lineto($this->get_right(), $this->get_top());
     $viewport->lineto($this->get_right(), $this->get_bottom());
     $viewport->lineto($this->get_left(), $this->get_bottom());
     $viewport->closepath();
     $viewport->clip();
     // Output text with the selected font
     $size = pt2pt(BROKEN_IMAGE_ALT_SIZE_PT);
     $status = $viewport->setfont("Times-Roman", $viewport->encoding("iso-8859-1"), $size);
     if (is_null($status)) {
         return null;
     }
     $viewport->show_xy($this->alt, $this->get_left() + $this->width / 2 - $viewport->stringwidth($this->alt, "Times-Roman", $viewport->encoding("iso-8859-1"), $size) / 2, $this->get_top() - $this->height / 2 - $size / 2);
     $viewport->restore();
     return true;
 }
function units2pt($value, $font_size = null)
{
    $units = substr($value, strlen($value) - 2, 2);
    switch ($units) {
        case "pt":
            return pt2pt((double) $value);
        case "px":
            return px2pt((double) $value);
        case "mm":
            return mm2pt((double) $value);
        case "cm":
            return mm2pt((double) $value * 10);
            // FIXME: check if it will work correcty in all situations (order of css rule application may vary).
        // FIXME: check if it will work correcty in all situations (order of css rule application may vary).
        case "em":
            if (is_null($font_size)) {
                $fs = get_font_size();
                //       $fs_parts = explode(" ", $fs);
                //       if (count($fs_parts) == 2) {
                //         return units2pt(((double)$value) * $fs_parts[0]*EM_KOEFF . $fs_parts[1]);
                //       } else {
                return pt2pt((double) $value * $fs * EM_KOEFF);
                //       };
            } else {
                return $font_size * (double) $value * EM_KOEFF;
            }
        case "ex":
            if (is_null($font_size)) {
                $fs = get_font_size();
                //       $fs_parts = explode(" ", $fs);
                //       if (count($fs_parts) == 2) {
                //         return units2pt(((double)$value) * $fs_parts[0]*EX_KOEFF . $fs_parts[1]);
                //       } else {
                return pt2pt((double) $value * $fs * EX_KOEFF);
                //       };
            } else {
                return $font_size * (double) $value * EX_KOEFF;
            }
        default:
            global $g_config;
            if ($g_config['mode'] === 'quirks') {
                return px2pt((double) $value);
            } else {
                return 0;
            }
    }
}