/framework/experimental/graphic/GraphicObject.php

http://zoop.googlecode.com/ · PHP · 200 lines · 43 code · 10 blank · 147 comment · 2 complexity · d0d0921b445530a2443099527082812e MD5 · raw file

  1. <?php
  2. abstract class GraphicObject
  3. {
  4. protected $context;
  5. protected $parent;
  6. function __construct($init)
  7. {
  8. if(is_a($init, 'GraphicContainer'))
  9. {
  10. $this->parent = $init;
  11. $this->context = $init->getContext();
  12. }
  13. else
  14. {
  15. assert(is_a($init, 'GraphicContext'));
  16. $this->context = $init;
  17. }
  18. }
  19. // property accessors
  20. function getContext()
  21. {
  22. return $this->context;
  23. }
  24. function isInline()
  25. {
  26. return true;
  27. }
  28. function getHeight($width)
  29. {
  30. $height = $this->draw(0, 0, $width, 0);
  31. return $height;
  32. }
  33. public function draw($x, $y, $width, $reallyDraw = true)
  34. {
  35. trigger_error("soft abstract function");
  36. }
  37. function getObjectTree($indentLevel = 0)
  38. {
  39. $tabs = '';
  40. for($i = 0; $i < $indentLevel; $i++)
  41. $tabs .= '&nbsp;&nbsp;&nbsp;&nbsp;';
  42. echo $tabs . '&lt;' . get_class($this) . '/&gt;<br>';
  43. }
  44. /*
  45. var $parent;
  46. var $width;
  47. var $position;
  48. var $left;
  49. var $top;
  50. var $repeatable;
  51. function GraphicObject(&$context)
  52. {
  53. $this->context = &$context;
  54. $this->position = 'static';
  55. $this->left = NULL;
  56. $this->top = NULL;
  57. $this->repeatable = 0;
  58. }
  59. function forcePageBreak()
  60. {
  61. return 0;
  62. }
  63. function makeRepeatable()
  64. {
  65. $this->repeatable = 1;
  66. }
  67. function isRepeatable()
  68. {
  69. return $this->repeatable;
  70. }
  71. function setParent(&$parent)
  72. {
  73. $this->parent = &$parent;
  74. }
  75. function &getParent()
  76. {
  77. return $this->parent;
  78. }
  79. function getAncestor($className)
  80. {
  81. $parent = &$this;
  82. while($parent)
  83. {
  84. if(is_a($parent, $className))
  85. return $parent;
  86. $parent = &$parent->parent;
  87. }
  88. return NULL;
  89. }
  90. function getDocument()
  91. {
  92. return $this->getAncestor('GraphicDocument');
  93. }
  94. function setWidth($width)
  95. {
  96. $this->width = $width;
  97. }
  98. function getWidth()
  99. {
  100. return $this->width;
  101. }
  102. function getContentWidth()
  103. {
  104. return $this->getWidth();
  105. }
  106. */
  107. /*
  108. function getHeight($width)
  109. {
  110. if( !isset($this->heightCache[$width]) )
  111. $this->heightCache[$width] = $this->draw(0, 0, $width, 0);
  112. return $this->heightCache[$width];
  113. }
  114. */
  115. /*
  116. function getHeight($width)
  117. {
  118. $height = $this->draw(0, 0, $width, 0);
  119. // echo get_class($this) . ' ' . $height . '<br>';
  120. return $height;
  121. }
  122. function isInline()
  123. {
  124. return 0;
  125. }
  126. function isBreakable()
  127. {
  128. return 0;
  129. }
  130. function setPosition($position)
  131. {
  132. $this->position = $position;
  133. }
  134. function getPosition()
  135. {
  136. return $this->position;
  137. }
  138. function setTop($top)
  139. {
  140. assert($this->getPosition() != 'static');
  141. $this->top = $top;
  142. }
  143. function getTop()
  144. {
  145. return $this->top;
  146. }
  147. function setLeft($left)
  148. {
  149. assert($this->getPosition() != 'static');
  150. $this->left = $left;
  151. }
  152. function getLeft()
  153. {
  154. return $this->left;
  155. }
  156. function doneDrawing()
  157. {
  158. return 1;
  159. }
  160. function draw()
  161. {
  162. trigger_error('abstract method GraphicObject::draw() called');
  163. }
  164. */
  165. }