function testCSSParseAtRulesNestedContent()
 {
     $pipeline =& PipelineFactory::create_default_pipeline('utf-8', 'test.pdf');
     $new_css_content =& parse_css_atpage_rules('body { background-color: green; } @page { @top-left { content: "TEXT"; } } #test { border: none; }', $pipeline);
     $this->assertEqual($new_css_content, 'body { background-color: green; } #test { border: none; }');
     $content =& $pipeline->_page_at_rules[CSS_PAGE_SELECTOR_ALL][0]->margin_boxes[CSS_MARGIN_BOX_SELECTOR_TOP_LEFT]->css->body->getPropertyValue(CSS_CONTENT);
     $this->assertNotNull($content);
     $this->assertEqual($content->render(new CSSCounterCollection()), "TEXT");
 }
 function testCSSParseMarginBoxesTopLeftSize()
 {
     parse_config_file('../html2ps.config');
     $media =& Media::predefined('A4');
     $media->set_margins(array('left' => 10, 'top' => 10, 'right' => 10, 'bottom' => 10));
     $pipeline =& PipelineFactory::create_default_pipeline('utf-8', 'test.pdf');
     $pipeline->_prepare($media);
     $pipeline->_cssState = array(new CSSState(CSS::get()));
     parse_css_atpage_rules('@page { @top-left { content: "TEXT"; } }', $pipeline);
     $boxes = $pipeline->reflow_margin_boxes(1, $media);
     $box =& $boxes[CSS_MARGIN_BOX_SELECTOR_TOP_LEFT];
     $this->assertNotEqual($box->get_width(), 0);
     $expected_width = $pipeline->output_driver->stringwidth('TEXT', 'Times-Roman', 'iso-8859-1', 12);
     $this->assertTrue($box->get_width() >= $expected_width);
     $this->assertEqual($box->get_height(), mm2pt(10));
 }
function parse_css_media($css, &$pipeline, $baseindex = 0)
{
    // Remove comments
    $css = preg_replace("#/\\*.*?\\*/#is", "", $css);
    // Extract @page rules
    $css = parse_css_atpage_rules($css, $pipeline);
    // Extract @import rules
    if ($num = preg_match_all("/@import[^;]+;/", $css, $matches, PREG_PATTERN_ORDER)) {
        for ($i = 0; $i < $num; $i++) {
            $this->parse_css_import($matches[0][$i], $pipeline);
        }
    }
    // Remove @import rules so they will not break further processing
    $css = preg_replace("/@import[^;]+;/", "", $css);
    while (preg_match("/([^{}]*){(.*?)}(.*)/is", $css, $matches)) {
        // Drop extracted part
        $css = $matches[3];
        // Save extracted part
        $raw_selectors = $matches[1];
        $raw_properties = $matches[2];
        $selectors = parse_css_selectors($raw_selectors);
        $properties = parse_css_properties($raw_properties, $pipeline);
        foreach ($selectors as $selector) {
            $this->_lastId++;
            $rule = array($selector, $properties, $pipeline->get_base_url(), $this->_lastId + $baseindex);
            $this->add_rule($rule, $pipeline);
        }
    }
}