Exemplo n.º 1
0
 /** 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 fixed layout book, start a new ePub page.
  */
 public function visitPage(IdmlPage $item, $depth = 0)
 {
     $this->clearPage();
     $progressUpdater = IdmlAssembler::getProgressUpdater();
     if ($progressUpdater) {
         $progressUpdater->incrementStep();
     }
 }
 /**
  * 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();
     }
 }
Exemplo n.º 4
0
 /**
  * Parse the portion of a spread.xml file that contains a <Page>
  * 
  * @param DOMNode $domNode is a single <Page> node within the document
  */
 public function parse($domNode)
 {
     $attributes = $domNode->attributes;
     $this->UID = $attributes->getNamedItem('Self')->value;
     // like 'ud3'
     $this->appliedMasterUID = $attributes->getNamedItem('AppliedMaster')->value;
     // like 'ud3' or 'n'
     $this->inDesignPageName = $attributes->getNamedItem('Name')->value;
     // ordinary pages are numbers, master spreads are letters
     $itemTransform = $attributes->getNamedItem('ItemTransform')->value;
     // like "1 0 0 1 0 -396"
     $masterPageTransform = $attributes->getNamedItem('MasterPageTransform')->value;
     // like "1 0 0 1 0 0"
     $geometricBounds = $attributes->getNamedItem('GeometricBounds')->value;
     // like "0 0 792 612"
     $overrideList = $attributes->getNamedItem('OverrideList')->value;
     // like "ufb u174"
     $this->transformation = new IdmlTransformation($itemTransform);
     $this->masterPageTransform = new IdmlTransformation($masterPageTransform);
     $this->boundary = IdmlBoundary::createFromIDMLString($geometricBounds);
     $this->idssCoordinates = IdmlBoundary::transform($this->boundary, $this->transformation);
     if ($overrideList != '') {
         $this->masterSpreadOverrides = explode(' ', $overrideList);
     }
     $pageX = $this->transformation->xTranslate();
     if ($pageX < 0) {
         $this->pagePosition = 'left';
     } else {
         $this->pagePosition = 'right';
     }
     // Increment progress step.
     $p = IdmlAssembler::getProgressUpdater();
     if ($p) {
         $p->incrementStep();
     }
 }
Exemplo n.º 5
0
 /**
  * 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;
 }
Exemplo n.º 6
0
 /**
  * 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.');
             }
         }
     }
 }