/** Quickly scan the spreads to determine how many pages are in this package. This is suitable for use * by IdmlAssembler::preparation(), but not by IdmlAssembler::assembler(). * * @return int $pageCount */ public function determinePageCount() { $pageCount = 0; // The designmap contains references to everything in the package $designmap = $this->tempDir . '/designmap.xml'; if (!file_exists($designmap)) { $this->idmlAssembler->getProgressUpdater()->setWarning("{$designmap} does not exist."); return false; } // create DOMDocument and DOMXPath objects $doc = new DomDocument(); $b = $doc->load($designmap); if ($b === false) { return false; } $xpath = new DOMXPath($doc); // There are most likely many Spread files, and they are ordered in the designmap // according to the book's page ordering. $tags = $xpath->query('//idPkg:Spread'); foreach ($tags as $tag) { $attr = $tag->attributes->getNamedItem('src'); $filename = "{$this->tempDir}/{$attr->value}"; $obj = new IdmlSpread($this); $pageCount += $obj->determinePageCount($filename); } return $pageCount; }
/** * When visiting IdmlPages for a reflowable book, nothing needs to be done. Page breaks are handled by the special * 'ChaucerEditorBreak' feature. */ public function visitPage(IdmlPage $item, $depth = 0) { // This progress indicator is simply for user feedback, it has nothing to do with book construction or page breaks. $progressUpdater = IdmlAssembler::getProgressUpdater(); if ($progressUpdater) { $progressUpdater->incrementStep(); } }
/** * When visiting IdmlPages for a fixed layout book, start a new ePub page. */ public function visitPage(IdmlPage $item, $depth = 0) { $this->clearPage(); $progressUpdater = IdmlAssembler::getProgressUpdater(); if ($progressUpdater) { $progressUpdater->incrementStep(); } }
public function addCssFonts() { if (!is_object(IdmlAssembler::getInstance()->getProcessor())) { return; } $dir = new Folder(APP . "Data/Pxe/Fonts"); $files = $dir->find(); foreach ($files as $file) { IdmlAssembler::getInstance()->getProcessor()->addFontToBook($dir->pwd() . DS . $file); } }
/** * Constructor. * * @param IdmlResourceManager $resourceManager Default is null or if you want to inject the object you can pass the param. */ public function __construct(IdmlResourceManager $resourceManager = null) { if (is_null($resourceManager)) { $this->resourceManager = IdmlAssembler::getInstance()->resourceManager; } else { $this->resourceManager = $resourceManager; } $this->boundary = IdmlBoundary::createDefault(); $this->height = null; $this->width = null; $this->ppiX = null; $this->ppiY = null; $this->idmlTag = "img"; }
public function processBook() { $idmlAssembler = IdmlAssembler::getInstance(); $idmlAssembler->init($this); $idmlAssembler->addIDMLPackages($this->sourceFiles); $idmlAssembler->preparation(); $idmlAssembler->parse(); $idmlAssembler->produce(); // Saving the book CSS here is different from the original PXE implementation. // It clobbers the template.css for PXE created by the old (now obsolete) Style Manager. if (!$idmlAssembler->pxeTagsAdded) { $bookCss = IdmlDeclarationManager::getInstance()->convertIdmlToCSS(); $this->saveBookCSS($bookCss, 'template.css', false); } $idmlAssembler->adjustMaxSteps(); return true; }
/** * Parse from DOM node. * * @param DOMElement $node */ public function parse(DOMElement $node) { parent::parse($node); $link = IdmlAssembler::getInstance()->getCurrentPackage()->getHyperlinkBySource($node->getAttribute("Self")); $this->idAttribute = $node->hasAttribute(IdmlAttributes::Self) ? $node->getAttribute(IdmlAttributes::Self) : null; $this->name = $node->hasAttribute(IdmlAttributes::Name) ? $node->getAttribute(IdmlAttributes::Name) : null; if (count($link) > 0) { if (is_array($link['Destination'])) { $this->linkType = $link['Destination']['DestinationType']; if (array_key_exists('DestinationURL', $link['Destination'])) { $this->href = $link['Destination']['DestinationURL']; } } else { $this->href = $link['Destination']; } if (!strlen($this->idmlTag)) { $this->idmlTag = 'a'; } } $this->parseChildren($node); }
/** * This function is called by the spread, after it has determined which page the text frame is on. * It is entirely legitimate to exit without assigning anything to $this->idmlStory in which case this becomes an * empty TextFrame. */ protected function loadParentStory() { // Lookup and parse the story into memory $package = IdmlAssembler::getInstance()->getCurrentPackage(); if ($package) { $story = $package->loadStory($this->parentStoryUID); // Sanity check $storyClass = get_class($story); if (substr($storyClass, 0, 14) == 'Mock_IdmlStory') { $storyClass = 'IdmlStory'; } if ($story == null || $storyClass != 'IdmlStory') { $this->story = null; return; } // Finally, now that we are sure this story has not been placed already (in some other text frame), // keep a reference to it. $this->story = $story; $story->idmlTextFrame = $this; } }
/** * This accept function is called by the parent IdmlSpread. * * @param IdmlVisitor $visitor * @param $depth is how deep in the traversal we are */ public function accept(IdmlVisitor $visitor, $depth) { // Skip the page in case it does not have any children elements. if (IdmlAssembler::getInstance()->isReflowable()) { if (count($this->childrenElements) == 0 || $this->hasOnlyEmptyTextFrames()) { return; } } $visitor->visitPage($this, $depth); // First walk the elements of the associated master spread. if (IdmlAssembler::getInstance()->isFixedLayout()) { $this->visitMasterPageItems($visitor, $this->inDesignPageName, $depth + 1); } // Then walk the elements of this page itself foreach ($this->childrenElements as $childElement) { $childElement->accept($visitor, $depth + 1); } $visitor->visitPageEnd($this, $depth); }
/** * Load story from file name. * * @param string $filename Needs absolute path to story xml file. IF empty it will use internal variable. */ public function load($filename = '') { if ($this->isLoaded) { return; } if (empty($filename)) { $filename = $this->filename; } if (!file_exists($filename)) { IdmlAssembler::getProgressUpdater()->setWarning("Story with file {$filename} is not found."); return; } $domDocument = new DOMDocument('1.0', 'UTF-8'); $storyContent = file_get_contents($filename); $ok = $domDocument->loadXML(mb_convert_encoding($storyContent, 'UTF-8')); if ($ok === false) { IdmlAssembler::getProgressUpdater()->setWarning("Could not load xml for story {$filename}"); } $storyNodes = $domDocument->getElementsByTagName('Story'); $storyNode = $storyNodes->item(1); $this->parse($storyNode); $this->isLoaded = true; }
/** * Save page. * @return Page $pageFile */ protected function savePage() { $content = $this->getPageContent(); if (Configure::read("dev.idmlHtmlDebugOutput")) { // DEBUG $this->diagnosticTool($content); // <-- Turn off in production // DEBUG } $processor = IdmlAssembler::getProcessor(); if ($processor) { $currentPageToSave = $this->pageNumber; if (!Configure::read("dev.idmlPostProcessing")) { $pageFile = $processor->savePageHTML($content, $currentPageToSave, '', 0, null, $this->pageObject->properties); $processor->savePageCSS('', $currentPageToSave); } else { $postProcessor = new IdmlPostProcessor(); $cleanHtml = $postProcessor->removeEmptyElements($content); // $num = $postProcessor->numElementsDeleted; $dual = $postProcessor->segregateCssFromHtml($cleanHtml); $html = $dual['html']; $css = $dual['css']; $pageFile = $processor->savePageHTML($html, $currentPageToSave, '', 0, null, $this->pageObject->properties); $processor->savePageCSS($css, $currentPageToSave); } IdmlAssembler::getInstance()->actualPages++; } $this->pageNumber++; return $pageFile->getIdentifier(); }
/** * Drop element into page. It will set the warning if it fails. * @param IdmlElement $element */ private function dropElementIntoPage(IdmlElement $element) { if ($element->visible == true) { // Convert element's coordinates to Page coordinates $boundary = IdmlBoundary::transform($element->boundary, $element->transformation); $idmlPage = $this->determinePageFromCoordinates($boundary); if ($idmlPage != null && get_class($idmlPage) == 'IdmlPage') { // Share mutual references between the page and the text frame. $element->page = $idmlPage; $idmlPage->addChildElement($element); } else { $element->page = null; $progressUpdater = IdmlAssembler::getProgressUpdater(); if ($progressUpdater) { $progressUpdater->setWarning('Could not find page for current text frame.'); } } } }
/** * Get the current IdmlProcessor object * @return IdmlProcessor object */ public static function getProcessor() { self::$instance = IdmlAssembler::getInstance(); if (self::$instance) { } return self::$instance->processor; return null; }