Пример #1
0
 function &_layout_item($data_id, &$media, $offset, &$context, &$postponed_filter)
 {
     $this->_reset_page_at_rules();
     $this->reset_css();
     $font = $this->_cssState[0]->get_property(CSS_FONT);
     $font->units2pt(0);
     $this->_cssState[0]->set_property(CSS_FONT, $font);
     $data = $this->fetch($data_id);
     if (is_null($data)) {
         $dummy = null;
         return $dummy;
     }
     // Run raw data filters
     for ($i = 0; $i < count($this->data_filters); $i++) {
         $data = $this->data_filters[$i]->process($data);
     }
     // Parse the raw data
     $box =& $this->parser->process($data->get_content(), $this, $media);
     $this->_dispatcher->fire('after-parse', array('pipeline' => &$this, 'document' => &$box, 'media' => $media));
     /**
      * Run obligatory tree filters
      */
     /**
      * height-constraint processing filter;
      */
     $filter = new PreTreeFilterHeightConstraint();
     $filter->process($box, $data, $this);
     /**
      * Footnote support filter
      */
     $filter = new PreTreeFilterFootnotes();
     $filter->process($box, $data, $this);
     // Run pre-layout tree filters
     for ($i = 0, $size = count($this->pre_tree_filters); $i < $size; $i++) {
         $this->pre_tree_filters[$i]->process($box, $data, $this);
     }
     $context = new FlowContext();
     /**
      * Extract absolute/fixed positioned boxes
      */
     $positioned_filter = new PostTreeFilterPositioned($context);
     $positioned_filter->process($box, null, $this);
     $postponed_filter = new PostTreeFilterPostponed($this->output_driver);
     $postponed_filter->process($box, null, $this);
     $this->output_driver->prepare();
     // Force generation of custom characters for margin boxes
     for ($i = 0; $i <= 1; $i++) {
         $this->get_page_media(1, $media);
         $at_rules = $this->_getMarginBoxes($i, $media);
         $boxes = array();
         foreach ($at_rules as $at_rule) {
             $selector = $at_rule->getSelector();
             $boxes[$selector] =& BoxPageMargin::create($this, $at_rule);
         }
     }
     $status = $this->layout_engine->process($box, $media, $this->output_driver, $context);
     if (is_null($status)) {
         error_log('Pipeline::_process_item: layout routine failed');
         $dummy = null;
         return $dummy;
     }
     // Run post-layout tree filters
     for ($i = 0; $i < count($this->post_tree_filters); $i++) {
         $this->post_tree_filters[$i]->process($box);
     }
     return $box;
 }
 function &_layout_item($data_id, &$media, $offset, &$context, &$postponed_filter)
 {
     //echo 'start:'.microtime().'<br>';
     $this->_reset_page_at_rules();
     $css_cache = CSSCache::get();
     $this->_defaultCSS = $css_cache->compile('resource://default.css', file_get_contents(HTML2PS_DIR . '/default.css'));
     $this->_css = array();
     $this->pushCSS();
     $this->_cssState = array(new CSSState(CSS::get()));
     $font = $this->_cssState[0]->getProperty(CSS_FONT);
     $font->units2pt(0);
     $this->_cssState[0]->setProperty(CSS_FONT, $font);
     $data = $this->fetch($data_id);
     if (is_null($data)) {
         return null;
     }
     // Run raw data filters
     for ($i = 0; $i < count($this->data_filters); $i++) {
         $data = $this->data_filters[$i]->process($data);
     }
     // Parse the raw data
     # kornev, optimize
     //echo '001:'.microtime().'<br>';
     $box =& $this->parser->process($data->get_content(), $this, $media);
     $this->_dispatcher->fire('after-parse', array('pipeline' => &$this, 'document' => &$box, 'media' => $media));
     //echo '002:'.microtime().'<br>';
     /**
      * height-constraint processing filter;
      */
     $filter = new PreTreeFilterHeightConstraint();
     $filter->process($box, $data, $this);
     /**
      * Footnote support filter
      */
     $filter = new PreTreeFilterFootnotes();
     $filter->process($box, $data, $this);
     // Run pre-layout tree filters
     for ($i = 0, $size = count($this->pre_tree_filters); $i < $size; $i++) {
         $this->pre_tree_filters[$i]->process($box, $data, $this);
     }
     $context = new FlowContext();
     /**
      * Extract absolute/fixed positioned boxes
      */
     $positioned_filter = new PostTreeFilterPositioned($context);
     $positioned_filter->process($box, null, $this);
     $postponed_filter = new PostTreeFilterPostponed($this->output_driver);
     $postponed_filter->process($box, null, $this);
     $this->output_driver->prepare();
     //echo 'start creations'.microtime().'<br>';
     # kornev, optimize
     $status = $this->layout_engine->process($box, $media, $this->output_driver, $context);
     //echo 'end creations'.microtime().'<br>';
     if (is_null($status)) {
         error_log('Pipeline::_process_item: layout routine failed');
         $dummy = null;
         return $dummy;
     }
     // Run post-layout tree filters
     for ($i = 0; $i < count($this->post_tree_filters); $i++) {
         $this->post_tree_filters[$i]->process($box);
     }
     return $box;
 }
Пример #3
0
 function &_layout_item($data_id, &$media, $offset, &$context, &$postponed_filter)
 {
     $this->_reset_page_at_rules();
     $css_cache = CSSCache::get();
     $this->_defaultCSS = $css_cache->compile("resource://default.css", file_get_contents(HTML2PS_DIR . '/default.css'));
     $this->_css = array();
     $this->pushCSS();
     $this->_cssState = array(new CSSState(CSS::get()));
     $font = $this->_cssState[0]->getProperty(CSS_FONT);
     $font->units2pt(0);
     $this->_cssState[0]->setProperty(CSS_FONT, $font);
     $data = $this->fetch($data_id);
     if (is_null($data)) {
         $dummy = null;
         return $dummy;
     }
     // Run raw data filters
     for ($i = 0; $i < count($this->data_filters); $i++) {
         $data = $this->data_filters[$i]->process($data);
     }
     // Parse the raw data
     $box =& $this->parser->process($data->get_content(), $this);
     /**
      * Run obligatory tree filters
      */
     /**
      * height-constraint processing filter;
      */
     $filter = new PreTreeFilterHeightConstraint();
     $filter->process($box, $data, $this);
     /**
      * Footnote support filter
      */
     $filter = new PreTreeFilterFootnotes();
     $filter->process($box, $data, $this);
     // Run pre-layout tree filters
     for ($i = 0, $size = count($this->pre_tree_filters); $i < $size; $i++) {
         $this->pre_tree_filters[$i]->process($box, $data, $this);
     }
     /**
      * Auto-detect top/bottom margin size (only if both top and bottom margins have zero value)
      */
     if ($media->margins['top'] == 0 && $media->margins['bottom'] == 0) {
         $boxes = $this->reflow_margin_boxes(0, $media);
         $media->margins['top'] = max($boxes[CSS_MARGIN_BOX_SELECTOR_TOP]->get_real_full_height(), $boxes[CSS_MARGIN_BOX_SELECTOR_TOP_LEFT_CORNER]->get_real_full_height(), $boxes[CSS_MARGIN_BOX_SELECTOR_TOP_LEFT]->get_real_full_height(), $boxes[CSS_MARGIN_BOX_SELECTOR_TOP_CENTER]->get_real_full_height(), $boxes[CSS_MARGIN_BOX_SELECTOR_TOP_RIGHT]->get_real_full_height(), $boxes[CSS_MARGIN_BOX_SELECTOR_TOP_RIGHT_CORNER]->get_real_full_height()) / mm2pt(1);
         $media->margins['bottom'] = max($boxes[CSS_MARGIN_BOX_SELECTOR_BOTTOM]->get_real_full_height(), $boxes[CSS_MARGIN_BOX_SELECTOR_BOTTOM_LEFT_CORNER]->get_real_full_height(), $boxes[CSS_MARGIN_BOX_SELECTOR_BOTTOM_LEFT]->get_real_full_height(), $boxes[CSS_MARGIN_BOX_SELECTOR_BOTTOM_CENTER]->get_real_full_height(), $boxes[CSS_MARGIN_BOX_SELECTOR_BOTTOM_RIGHT]->get_real_full_height(), $boxes[CSS_MARGIN_BOX_SELECTOR_BOTTOM_RIGHT_CORNER]->get_real_full_height()) / mm2pt(1);
         $this->output_driver->update_media($media);
     }
     $context = new FlowContext();
     /**
      * Extract absolute/fixed positioned boxes
      */
     $positioned_filter = new PostTreeFilterPositioned($context);
     $positioned_filter->process($box, null, $this);
     $postponed_filter = new PostTreeFilterPostponed($this->output_driver);
     $postponed_filter->process($box, null, $this);
     $this->output_driver->prepare();
     $status = $this->layout_engine->process($box, $media, $this->output_driver, $context);
     if (is_null($status)) {
         error_log("Pipeline::_process_item: layout routine failed");
         $dummy = null;
         return $dummy;
     }
     // Run post-layout tree filters
     for ($i = 0; $i < count($this->post_tree_filters); $i++) {
         $this->post_tree_filters[$i]->process($box);
     }
     return $box;
 }
 function _process_item($data_id, &$media, $offset = 0)
 {
     $g_css = array();
     $data = $this->fetch($data_id);
     if ($data == null) {
         return null;
     }
     // Run raw data filters
     for ($i = 0; $i < count($this->data_filters); $i++) {
         $data = $this->data_filters[$i]->process($data);
     }
     // Parse the raw data
     $box =& $this->parser->process($data->get_content(), $this);
     // Run the height-constraint processing filter;
     // it is obligatory
     $filter = new PreTreeFilterHeightConstraint();
     $filter->process($box, $data, $this);
     // Run pre-layout tree filters
     for ($i = 0; $i < count($this->pre_tree_filters); $i++) {
         $this->pre_tree_filters[$i]->process($box, $data, $this);
     }
     $context = $this->layout_engine->process($box, $media, $this->output_driver);
     if (is_null($context)) {
         return null;
     }
     // Run post-layout tree filters
     for ($i = 0; $i < count($this->post_tree_filters); $i++) {
         $this->post_tree_filters[$i]->process($box);
     }
     $context->sort_absolute_positioned_by_z_index();
     // Make batch-processing offset
     $box->offset(0, $offset);
     // Output PDF pages using chosen PDF driver
     for ($i = 0; $i < $this->output_driver->get_expected_pages(); $i++) {
         $this->output_driver->save();
         $this->output_driver->setup_clip();
         if (is_null($box->show($this->output_driver))) {
             return null;
         }
         // Absolute positioned boxes should be shown after all other boxes, because
         // they're placed higher in the stack-order
         for ($j = 0; $j < count($context->absolute_positioned); $j++) {
             if ($context->absolute_positioned[$j]->visibility === VISIBILITY_VISIBLE) {
                 if (is_null($context->absolute_positioned[$j]->show($this->output_driver))) {
                     return null;
                 }
             }
         }
         $this->output_driver->restore();
         for ($j = 0; $j < count($context->fixed_positioned); $j++) {
             if ($context->fixed_positioned[$j]->visibility === VISIBILITY_VISIBLE) {
                 if (is_null($context->fixed_positioned[$j]->show_fixed($this->output_driver))) {
                     return null;
                 }
             }
         }
         global $g_config;
         if ($g_config['draw_page_border']) {
             $this->output_driver->draw_page_border();
         }
         // Add page if currently rendered page is not last
         if ($i < $this->output_driver->get_expected_pages() - 1) {
             $this->output_driver->next_page();
         }
     }
     // Clear CSS for this item
     return true;
 }