function &create() { $box =& new NullBox(); $css_state = new CSSState(CSS::get()); $css_state->pushState(); $box->readCSS($css_state); return $box; }
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 fake_box(&$box) { // Create the fake box object $fake_state = new CSSState(CSS::get()); $fake_state->pushState(); $fake = null; $fake_box = new BlockBox($fake); $fake_box->readCSS($fake_state); // Setup fake box size $fake_box->put_left($this->left); $fake_box->put_width($this->right - $this->left); $fake_box->put_top($this->top - $box->baseline); $fake_box->put_height($this->top - $this->bottom); // Setup padding value $fake_box->setCSSProperty(CSS_PADDING, $box->getCSSProperty(CSS_PADDING)); // Setup fake box border and background $fake_box->setCSSProperty(CSS_BACKGROUND, $box->getCSSProperty(CSS_BACKGROUND)); $fake_box->setCSSProperty(CSS_BORDER, $box->getCSSProperty(CSS_BORDER)); return $fake_box; }
function register_css_property(&$handler) { $property = $handler->get_property_code(); $name = $handler->get_property_name(); $css =& CSS::get(); $css->_handlers[$property] =& $handler; $css->_mapping[$name] = $property; }
public function rebuild() { $flavorId = $this->flavor_folder; if (!$flavorId) { throw new \Exception('Cannot merge a theme without a flavor.'); } $db = new \Core\Db(); $moduleList = $db->select('module_id')->singleData('module_id')->from(':module')->where('is_active=1')->all(); $css = new CSS($this); try { $data = $css->get(); $moduleData = $css->getModule($moduleList); $css->reBuildModule($moduleList, $this->name); $appData = $css->getApp(); $css->set($data, null, $moduleData . $appData, $this->name); } catch (\Exception $e) { if (PHPFOX_DEBUG) { exit("error:" . $e->getMessage()); } return false; } }
function reset_css() { $css_cache = CSSCache::get(); $this->_defaultCSS = $css_cache->compile('resource://default.css', file_get_contents(HTML2PS_DIR . 'default.css'), $this); $this->_css = array(); $this->push_css(); $this->_cssState = array(new CSSState(CSS::get())); }
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; }
public function rebuild() { $flavorId = $this->flavor_folder; if (!$flavorId) { throw new \Exception('Cannot merge a theme without a flavor.'); } $css = new CSS($this); try { $data = $css->get(); $css->set($data); } catch (\Exception $e) { return false; } }
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; }