public function replaceAttribsInSpread(array $newAttribs, array $storyIdsPerPage) { $contentIterator = 0; foreach ($storyIdsPerPage as $pageStories) { foreach ($this as $spread) { if ($spread->usesStory($pageStories[0])) { if (array_key_exists('FillColor', $newAttribs)) { $fillColors = $newAttribs['FillColor']; $fillColorsForThisRow = $fillColors[$contentIterator]; foreach ($pageStories as $storyId) { // nu hier checken welke xmlTag in deze story staat. $story = new Garp_Adobe_InDesign_Story($storyId, $this->_workingDir); $tag = $story->getTag(); if (array_key_exists($tag, $fillColorsForThisRow)) { $spread->setTextFrameAttribute($storyId, 'FillColor', $fillColorsForThisRow[$tag]); } } } break; } } $contentIterator++; } }
/** * This method retrieves the Stories referenced by TextFrame entries on the current Spread, * that geometrically map to this page. * This has be calculated by geometry, since a TextFrame is not directly linked to a Page, * but to a Spread. * * @return array */ protected function _buildStories() { $storiesByPageNumber = array(); $storiesByTag = array(); $pagesCount = count($this->pages); // Build an array with all textframe positions, divided into the accompanying story XML tags foreach ($this->textFrames as $textFrame) { $story = new Garp_Adobe_InDesign_Story($textFrame->storyId, $this->_workingDir); if ($tag = $story->getTag()) { $storiesByTag[$tag][] = array('storyId' => $textFrame->storyId, 'x' => $textFrame->x); } } // sort the stories by horizontal position $sortFunction = function ($storyA, $storyB) { if ($storyA['x'] == $storyB['x']) { return 0; } return $storyA['x'] > $storyB['x'] ? 1 : -1; }; foreach ($storiesByTag as &$stories) { usort($stories, $sortFunction); } // now divide the stories in pages foreach ($storiesByTag as $tagStories) { $tagStoriesCount = count($tagStories); $tagStoriesPerPage = $tagStoriesCount / $pagesCount; foreach ($tagStories as $s => $tagStory) { $page = floor($s / $tagStoriesPerPage); $pageNumber = $this->pages[$page]->index; $storiesByPageNumber[$pageNumber][] = $tagStory['storyId']; } } return $storiesByPageNumber; }
protected function _injectSingleFile($storyIdsPerPage, $newContent, $newAttribs, $targetPath = null) { $row = 0; foreach ($storyIdsPerPage as $pageStories) { foreach ($pageStories as $storyId) { $story = new Garp_Adobe_InDesign_Story($storyId, $this->_workingDir); $story->replaceContent($newContent[$row]); } $row++; } if ($newAttribs) { $this->_spreadSet->replaceAttribsInSpread($newAttribs, $storyIdsPerPage); } $this->_storage->zip($targetPath); }