Skip to content

Commit

Permalink
Zend_Pdf: require_unce usage redesign. ZF-7436 (ZF-2702).
Browse files Browse the repository at this point in the history
git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18992 44c647ce-9c0f-0410-b52a-842ac1e357ba
  • Loading branch information
alexander committed Nov 15, 2009
1 parent 08ea2f8 commit 5fc332c
Show file tree
Hide file tree
Showing 100 changed files with 692 additions and 601 deletions.
12 changes: 9 additions & 3 deletions demos/Zend/Pdf/demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@
set_include_path( dirname(dirname(dirname(dirname(__FILE__))))
. DIRECTORY_SEPARATOR . 'library' );

/**
* @see Zend_Pdf
*/
require_once 'Zend/Pdf.php';
require_once 'Zend/Pdf/Style.php';
require_once 'Zend/Pdf/Color/Cmyk.php';
require_once 'Zend/Pdf/Color/Html.php';
require_once 'Zend/Pdf/Color/GrayScale.php';
require_once 'Zend/Pdf/Color/Rgb.php';
require_once 'Zend/Pdf/Page.php';
require_once 'Zend/Pdf/Font.php';


if (!isset($argv[1])) {
echo "USAGE: php demo.php <pdf_file> [<output_pdf_file>]\n";
Expand Down Expand Up @@ -64,6 +69,7 @@

try {
// Create new image object
require_once 'Zend/Pdf/Image.php';
$stampImage = Zend_Pdf_Image::imageWithPath(dirname(__FILE__) . '/stamp.jpg');
} catch (Zend_Pdf_Exception $e) {
// Example of operating with image loading exceptions.
Expand Down
91 changes: 33 additions & 58 deletions library/Zend/Pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,16 @@
* @version $Id$
*/

/** Zend_Pdf_Page */
require_once 'Zend/Pdf/Page.php';

/** Zend_Pdf_Cmap */
require_once 'Zend/Pdf/Cmap.php';
/** User land classes and interfaces turned on by Zend/Pdf.php file inclusion. */
/** @todo Section should be removed with ZF 2.0 release as obsolete */

/** Zend_Pdf_Font */
require_once 'Zend/Pdf/Font.php';
/** Zend_Pdf_Page */
require_once 'Zend/Pdf/Page.php';

/** Zend_Pdf_Style */
require_once 'Zend/Pdf/Style.php';

/** Zend_Pdf_Parser */
require_once 'Zend/Pdf/Parser.php';

/** Zend_Pdf_Trailer */
require_once 'Zend/Pdf/Trailer.php';

/** Zend_Pdf_Trailer_Generator */
require_once 'Zend/Pdf/Trailer/Generator.php';

/** Zend_Pdf_Color */
require_once 'Zend/Pdf/Color.php';

/** Zend_Pdf_Color_GrayScale */
require_once 'Zend/Pdf/Color/GrayScale.php';

Expand All @@ -55,50 +41,24 @@
/** Zend_Pdf_Color_Html */
require_once 'Zend/Pdf/Color/Html.php';

/** Zend_Pdf_Image */
require_once 'Zend/Pdf/Resource/Image.php';

/** Zend_Pdf_Image */
require_once 'Zend/Pdf/Image.php';

/** Zend_Pdf_Image_Jpeg */
require_once 'Zend/Pdf/Resource/Image/Jpeg.php';

/** Zend_Pdf_Image_Tiff */
require_once 'Zend/Pdf/Resource/Image/Tiff.php';

/** Zend_Pdf_Image_Png */
require_once 'Zend/Pdf/Resource/Image/Png.php';

/** Zend_Memory */
require_once 'Zend/Memory.php';

/** Zend_Pdf_Action */
require_once 'Zend/Pdf/Action.php';

/** Zend_Pdf_Destination */
require_once 'Zend/Pdf/Destination.php';

/** Zend_Pdf_Destination_Explicit */
require_once 'Zend/Pdf/Destination/Explicit.php';

/** Zend_Pdf_Destination_Named */
require_once 'Zend/Pdf/Destination/Named.php';

/** Zend_Pdf_Outline_Created */
require_once 'Zend/Pdf/Outline/Created.php';

/** Zend_Pdf_Outline_Loaded */
require_once 'Zend/Pdf/Outline/Loaded.php';
/** Zend_Pdf_Font */
require_once 'Zend/Pdf/Font.php';

/** Zend_Pdf_RecursivelyIteratableObjectsContainer */
require_once 'Zend/Pdf/RecursivelyIteratableObjectsContainer.php';

/** Zend_Pdf_NameTree */
require_once 'Zend/Pdf/NameTree.php';
/** Internally used classes */
require_once 'Zend/Pdf/Element.php';
require_once 'Zend/Pdf/Element/Array.php';
require_once 'Zend/Pdf/Element/String/Binary.php';
require_once 'Zend/Pdf/Element/Boolean.php';
require_once 'Zend/Pdf/Element/Dictionary.php';
require_once 'Zend/Pdf/Element/Name.php';
require_once 'Zend/Pdf/Element/Null.php';
require_once 'Zend/Pdf/Element/Numeric.php';
require_once 'Zend/Pdf/Element/String.php';

/** Zend_Pdf_Destination */
require_once 'Zend/Pdf/Exception.php';

/**
* General entity which describes PDF document.
Expand Down Expand Up @@ -251,6 +211,7 @@ class Zend_Pdf
static public function getMemoryManager()
{
if (self::$_memoryManager === null) {
require_once 'Zend/Memory.php';
self::$_memoryManager = Zend_Memory::factory('none');
}

Expand Down Expand Up @@ -334,9 +295,11 @@ public function save($filename, $updateOnly = false)
*/
public function __construct($source = null, $revision = null, $load = false)
{
require_once 'Zend/Pdf/ElementFactory.php';
$this->_objFactory = Zend_Pdf_ElementFactory::createFactory(1);

if ($source !== null) {
require_once 'Zend/Pdf/Parser.php';
$this->_parser = new Zend_Pdf_Parser($source, $this->_objFactory, $load);
$this->_pdfHeaderVersion = $this->_parser->getPDFVersion();
$this->_trailer = $this->_parser->getTrailer();
Expand Down Expand Up @@ -397,7 +360,8 @@ public function __construct($source = null, $revision = null, $load = false)

$trailerDictionary->Size = new Zend_Pdf_Element_Numeric(0);

$this->_trailer = new Zend_Pdf_Trailer_Generator($trailerDictionary);
require_once 'Zend/Pdf/Trailer/Generator.php';
$this->_trailer = new Zend_Pdf_Trailer_Generator($trailerDictionary);

/**
* Document catalog indirect object.
Expand Down Expand Up @@ -502,6 +466,8 @@ protected function _loadPages(Zend_Pdf_Element_Reference $pages, $attributes = a
}
}
}

require_once 'Zend/Pdf/Page.php';
$this->pages[] = new Zend_Pdf_Page($child, $this->_objFactory);
}
}
Expand All @@ -526,6 +492,8 @@ protected function _loadNamedDestinations(Zend_Pdf_Element_Reference $root, $pdf
// PDF version is 1.2+
// Look for Destinations structure at Name dictionary
if ($root->Names !== null && $root->Names->Dests !== null) {
require_once 'Zend/Pdf/NameTree.php';
require_once 'Zend/Pdf/Target.php';
foreach (new Zend_Pdf_NameTree($root->Names->Dests) as $name => $destination) {
$this->_namedTargets[$name] = Zend_Pdf_Target::load($destination);
}
Expand All @@ -539,6 +507,7 @@ protected function _loadNamedDestinations(Zend_Pdf_Element_Reference $root, $pdf
throw new Zend_Pdf_Exception('Document catalog Dests entry must be a dictionary.');
}

require_once 'Zend/Pdf/Target.php';
foreach ($root->Dests->getKeys() as $destKey) {
$this->_namedTargets[$destKey] = Zend_Pdf_Target::load($root->Dests->$destKey);
}
Expand Down Expand Up @@ -576,6 +545,7 @@ protected function _loadOutlines(Zend_Pdf_Element_Reference $root)
while ($outlineDictionary !== null && !$processedDictionaries->contains($outlineDictionary)) {
$processedDictionaries->attach($outlineDictionary);

require_once 'Zend/Pdf/Outline/Loaded.php';
$this->outlines[] = new Zend_Pdf_Outline_Loaded($outlineDictionary);

$outlineDictionary = $outlineDictionary->Next;
Expand Down Expand Up @@ -640,6 +610,7 @@ protected function _dumpPages()
}

// Refresh outlines
require_once 'Zend/Pdf/RecursivelyIteratableObjectsContainer.php';
$iterator = new RecursiveIteratorIterator(new Zend_Pdf_RecursivelyIteratableObjectsContainer($this->outlines), RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $outline) {
$target = $outline->getTarget();
Expand Down Expand Up @@ -809,6 +780,7 @@ protected function _dumpOutlines()
*/
public function newPage($param1, $param2 = null)
{
require_once 'Zend/Pdf/Page.php';
if ($param2 === null) {
return new Zend_Pdf_Page($param1, $this->_objFactory);
} else {
Expand Down Expand Up @@ -866,6 +838,7 @@ public function getJavaScript()
public function getOpenAction()
{
if ($this->_trailer->Root->OpenAction !== null) {
require_once 'Zend/Pdf/Target.php';
return Zend_Pdf_Target::load($this->_trailer->Root->OpenAction);
} else {
return null;
Expand Down Expand Up @@ -1043,7 +1016,7 @@ public function resolveDestination(Zend_Pdf_Destination $destination, $refreshPa
*
* @todo Give appropriate name and make method public
*
* @param $action
* @param Zend_Pdf_Action $action
* @param boolean $refreshPagesHash Refresh page collection hashes before processing
* @return Zend_Pdf_Action|null
*/
Expand Down Expand Up @@ -1120,6 +1093,7 @@ public function extractFonts()
foreach ($fontResourcesUnique as $resourceId => $fontDictionary) {
try {
// Try to extract font
require_once 'Zend/Pdf/Resource/Font/Extracted.php';
$extractedFont = new Zend_Pdf_Resource_Font_Extracted($fontDictionary);

$fonts[$resourceId] = $extractedFont;
Expand Down Expand Up @@ -1178,6 +1152,7 @@ public function extractFont($fontName)

try {
// Try to extract font
require_once 'Zend/Pdf/Resource/Font/Extracted.php';
return new Zend_Pdf_Resource_Font_Extracted($fontDictionary);
} catch (Zend_Pdf_Exception $e) {
if ($e->getMessage() != 'Unsupported font type.') {
Expand Down
12 changes: 9 additions & 3 deletions library/Zend/Pdf/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
* @version $Id$
*/

/** Zend_Pdf_ElementFactory */
require_once 'Zend/Pdf/ElementFactory.php';

/** Internally used classes */
require_once 'Zend/Pdf/Element.php';
require_once 'Zend/Pdf/Element/Array.php';


/** Zend_Pdf_Target */
require_once 'Zend/Pdf/Target.php';
Expand Down Expand Up @@ -68,6 +71,7 @@ abstract class Zend_Pdf_Action extends Zend_Pdf_Target implements RecursiveItera
*/
public function __construct(Zend_Pdf_Element $dictionary, SplObjectStorage $processedActions)
{
require_once 'Zend/Pdf/Element.php';
if ($dictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
require_once 'Zend/Pdf/Exception.php';
throw new Zend_Pdf_Exception('$dictionary mast be a direct or an indirect dictionary object.');
Expand Down Expand Up @@ -114,6 +118,7 @@ public static function load(Zend_Pdf_Element $dictionary, SplObjectStorage $proc
$processedActions = new SplObjectStorage();
}

require_once 'Zend/Pdf/Element.php';
if ($dictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
require_once 'Zend/Pdf/Exception.php';
throw new Zend_Pdf_Exception('$dictionary mast be a direct or an indirect dictionary object.');
Expand Down Expand Up @@ -287,6 +292,7 @@ public function dumpAction(Zend_Pdf_ElementFactory_Interface $factory, SplObject
break;

default:
require_once 'Zend/Pdf/Element/Array.php';
$pdfChildArray = new Zend_Pdf_Element_Array();
foreach ($this->next as $child) {

Expand Down Expand Up @@ -364,7 +370,7 @@ public function valid()
/**
* Returns the child action.
*
* @return Zend_Pdf_Outline|null
* @return Zend_Pdf_Action|null
*/
public function getChildren()
{
Expand Down
14 changes: 8 additions & 6 deletions library/Zend/Pdf/Action/GoTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
* @version $Id$
*/

/** Zend_Pdf_Action */
require_once 'Zend/Pdf/Action.php';

/** Zend_Pdf_Destination */
/** Internally used classes */
require_once 'Zend/Pdf/Destination.php';

require_once 'Zend/Pdf/Element/Dictionary.php';
require_once 'Zend/Pdf/Element/Name.php';


/** Zend_Pdf_Action */
require_once 'Zend/Pdf/Action.php';

/**
* PDF 'Go to' action
Expand Down Expand Up @@ -81,7 +84,7 @@ public static function create($destination)
$dictionary->Type = new Zend_Pdf_Element_Name('Action');
$dictionary->S = new Zend_Pdf_Element_Name('GoTo');
$dictionary->Next = null;
$dictionary->D = $destination->getResource();
$dictionary->D = $destination->getResource();

return new Zend_Pdf_Action_GoTo($dictionary, new SplObjectStorage());
}
Expand Down Expand Up @@ -111,4 +114,3 @@ public function getDestination()
return $this->_destination;
}
}

9 changes: 5 additions & 4 deletions library/Zend/Pdf/Annotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
* @version $Id$
*/

/** @see Zend_Pdf_ElementFactory */
require_once 'Zend/Pdf/ElementFactory.php';

/** Internally used classes */
require_once 'Zend/Pdf/Element.php';

/**
* Abstract PDF annotation representation class
Expand Down Expand Up @@ -169,6 +168,8 @@ public function getText() {
* @return Zend_Pdf_Annotation
*/
public function setText($text) {
require_once 'Zend/Pdf/Element/String.php';

if ($this->_annotationDictionary->Contents === null) {
$this->_annotationDictionary->touch();
$this->_annotationDictionary->Contents = new Zend_Pdf_Element_String($text);
Expand Down Expand Up @@ -220,7 +221,7 @@ public function __construct(Zend_Pdf_Element $annotationDictionary)
*
* @internal
* @param $destinationArray
* @return Zend_Pdf_Destination
* @return Zend_Pdf_Annotation
*/
public static function load(Zend_Pdf_Element $resource)
{
Expand Down
10 changes: 9 additions & 1 deletion library/Zend/Pdf/Annotation/FileAttachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@
* @version $Id$
*/

/** Internally used classes */
require_once 'Zend/Pdf/Element.php';
require_once 'Zend/Pdf/Element/Array.php';
require_once 'Zend/Pdf/Element/Dictionary.php';
require_once 'Zend/Pdf/Element/Name.php';
require_once 'Zend/Pdf/Element/Numeric.php';
require_once 'Zend/Pdf/Element/String.php';


/** Zend_Pdf_Annotation */
require_once 'Zend/Pdf/Annotation.php';


/**
* A file attachment annotation contains a reference to a file,
* which typically is embedded in the PDF file.
Expand Down
Loading

0 comments on commit 5fc332c

Please sign in to comment.