frame_factory.cls.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. /**
  3. * DOMPDF - PHP5 HTML to PDF renderer
  4. *
  5. * File: $RCSfile: frame_factory.cls.php,v $
  6. * Created on: 2004-06-17
  7. *
  8. * Copyright (c) 2004 - Benj Carson <benjcarson@digitaljunkies.ca>
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public License
  21. * along with this library in the file LICENSE.LGPL; if not, write to the
  22. * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  23. * 02111-1307 USA
  24. *
  25. * Alternatively, you may distribute this software under the terms of the
  26. * PHP License, version 3.0 or later. A copy of this license should have
  27. * been distributed with this file in the file LICENSE.PHP . If this is not
  28. * the case, you can obtain a copy at http://www.php.net/license/3_0.txt.
  29. *
  30. * The latest version of DOMPDF might be available at:
  31. * http://www.dompdf.com/
  32. *
  33. * @link http://www.dompdf.com/
  34. * @copyright 2004 Benj Carson
  35. * @author Benj Carson <benjcarson@digitaljunkies.ca>
  36. * @package dompdf
  37. */
  38. /* $Id: frame_factory.cls.php 216 2010-03-11 22:49:18Z ryan.masten $ */
  39. /**
  40. * Contains frame decorating logic
  41. *
  42. * This class is responsible for assigning the correct {@link Frame_Decorator},
  43. * {@link Positioner}, and {@link Frame_Reflower} objects to {@link Frame}
  44. * objects. This is determined primarily by the Frame's display type, but
  45. * also by the Frame's node's type (e.g. DomElement vs. #text)
  46. *
  47. * @access private
  48. * @package dompdf
  49. */
  50. class Frame_Factory {
  51. static function decorate_root(Frame $root, DOMPDF $dompdf) {
  52. $frame = new Page_Frame_Decorator($root, $dompdf);
  53. $frame->set_reflower( new Page_Frame_Reflower($frame) );
  54. $root->set_decorator($frame);
  55. return $frame;
  56. }
  57. // FIXME: this is admittedly a little smelly...
  58. static function decorate_frame(Frame $frame, $dompdf) {
  59. if ( is_null($dompdf) )
  60. throw new Exception("foo");
  61. switch ($frame->get_style()->display) {
  62. case "block":
  63. $positioner = "Block";
  64. $decorator = "Block";
  65. $reflower = "Block";
  66. break;
  67. case "inline-block":
  68. $positioner = "Inline";
  69. $decorator = "Block";
  70. $reflower = "Block";
  71. break;
  72. case "inline":
  73. $positioner = "Inline";
  74. if ( $frame->get_node()->nodeName === "#text" ) {
  75. $decorator = "Text";
  76. $reflower = "Text";
  77. } else {
  78. $decorator = "Inline";
  79. $reflower = "Inline";
  80. }
  81. break;
  82. case "table":
  83. $positioner = "Block";
  84. $decorator = "Table";
  85. $reflower = "Table";
  86. break;
  87. case "inline-table":
  88. $positioner = "Inline";
  89. $decorator = "Table";
  90. $reflower = "Table";
  91. break;
  92. case "table-row-group":
  93. case "table-header-group":
  94. case "table-footer-group":
  95. $positioner = "Null";
  96. $decorator = "Table_Row_Group";
  97. $reflower = "Table_Row_Group";
  98. break;
  99. case "table-row":
  100. $positioner = "Null";
  101. $decorator = "Table_Row";
  102. $reflower = "Table_Row";
  103. break;
  104. case "table-cell":
  105. $positioner = "Table_Cell";
  106. $decorator = "Table_Cell";
  107. $reflower = "Table_Cell";
  108. break;
  109. case "list-item":
  110. $positioner = "Block";
  111. $decorator = "Block";
  112. $reflower = "Block";
  113. break;
  114. case "-dompdf-list-bullet":
  115. if ( $frame->get_style()->list_style_position === "inside" )
  116. $positioner = "Inline";
  117. else
  118. $positioner = "List_Bullet";
  119. if ( $frame->get_style()->list_style_image !== "none" )
  120. $decorator = "List_Bullet_Image";
  121. else
  122. $decorator = "List_Bullet";
  123. $reflower = "List_Bullet";
  124. break;
  125. case "-dompdf-image":
  126. $positioner = "Inline";
  127. $decorator = "Image";
  128. $reflower = "Image";
  129. break;
  130. case "-dompdf-br":
  131. $positioner = "Inline";
  132. $decorator = "Inline";
  133. $reflower = "Inline";
  134. break;
  135. default:
  136. // FIXME: should throw some sort of warning or something?
  137. case "none":
  138. $positioner = "Null";
  139. $decorator = "Null";
  140. $reflower = "Null";
  141. break;
  142. }
  143. if ( $frame->get_style()->position === "absolute" ||
  144. $frame->get_style()->position === "fixed" )
  145. $positioner = "Absolute";
  146. $positioner .= "_Positioner";
  147. $decorator .= "_Frame_Decorator";
  148. $reflower .= "_Frame_Reflower";
  149. $deco = new $decorator($frame, $dompdf);
  150. $deco->set_positioner( new $positioner($deco) );
  151. $reflow = new $reflower($deco);
  152. // Generated content is a special case
  153. if ( $frame->get_node()->nodeName === "_dompdf_generated" ) {
  154. // Decorate the reflower
  155. $gen = new Generated_Frame_Reflower( $deco );
  156. $gen->set_reflower( $reflow );
  157. $reflow = $gen;
  158. }
  159. $deco->set_reflower( $reflow );
  160. // Images are a special case
  161. // if ( $frame->get_node()->nodeName === "img" ) {
  162. // // FIXME: This is a hack
  163. // $node =$frame->get_node()->ownerDocument->createElement("img_sub");
  164. // $node->setAttribute("src", $frame->get_node()->getAttribute("src"));
  165. // $img_frame = new Frame( $node );
  166. // $style = $frame->get_style()->get_stylesheet()->create_style();
  167. // $style->inherit($frame->get_style());
  168. // $img_frame->set_style( $style );
  169. // $img_deco = new Image_Frame_Decorator($img_frame, $dompdf);
  170. // $img_deco->set_reflower( new Image_Frame_Reflower($img_deco) );
  171. // $deco->append_child($img_deco);
  172. // }
  173. return $deco;
  174. }
  175. }