table_cell_frame_reflower.cls.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /**
  3. * DOMPDF - PHP5 HTML to PDF renderer
  4. *
  5. * File: $RCSfile: table_cell_frame_reflower.cls.php,v $
  6. * Created on: 2004-06-07
  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: table_cell_frame_reflower.cls.php 216 2010-03-11 22:49:18Z ryan.masten $ */
  39. /**
  40. * Reflows table cells
  41. *
  42. * @access private
  43. * @package dompdf
  44. */
  45. class Table_Cell_Frame_Reflower extends Block_Frame_Reflower {
  46. //........................................................................
  47. function __construct(Frame $frame) {
  48. parent::__construct($frame);
  49. }
  50. //........................................................................
  51. function reflow() {
  52. $style = $this->_frame->get_style();
  53. $table = Table_Frame_Decorator::find_parent_table($this->_frame);
  54. $cellmap = $table->get_cellmap();
  55. list($x, $y) = $cellmap->get_frame_position($this->_frame);
  56. $this->_frame->set_position($x, $y);
  57. $cells = $cellmap->get_spanned_cells($this->_frame);
  58. $w = 0;
  59. foreach ( $cells["columns"] as $i ) {
  60. $col = $cellmap->get_column( $i );
  61. $w += $col["used-width"];
  62. }
  63. //FIXME?
  64. $h = $this->_frame->get_containing_block("h");
  65. $left_space = $style->length_in_pt(array($style->margin_left,
  66. $style->padding_left,
  67. $style->border_left_width),
  68. $w);
  69. $right_space = $style->length_in_pt(array($style->padding_right,
  70. $style->margin_right,
  71. $style->border_right_width),
  72. $w);
  73. $top_space = $style->length_in_pt(array($style->margin_top,
  74. $style->padding_top,
  75. $style->border_top_width),
  76. $w);
  77. $bottom_space = $style->length_in_pt(array($style->margin_bottom,
  78. $style->padding_bottom,
  79. $style->border_bottom_width),
  80. $w);
  81. $style->width = $cb_w = $w - $left_space - $right_space;
  82. $content_x = $x + $left_space;
  83. $content_y = $line_y = $y + $top_space;
  84. // Adjust the first line based on the text-indent property
  85. $indent = $style->length_in_pt($style->text_indent, $w);
  86. $this->_frame->increase_line_width($indent);
  87. // Set the y position of the first line in the cell
  88. $page = $this->_frame->get_root();
  89. $this->_frame->set_current_line($line_y);
  90. // Set the containing blocks and reflow each child
  91. foreach ( $this->_frame->get_children() as $child ) {
  92. if ( $page->is_full() )
  93. break;
  94. $child->set_containing_block($content_x, $content_y, $cb_w, $h);
  95. $child->reflow();
  96. $this->_frame->add_frame_to_line( $child );
  97. }
  98. // Determine our height
  99. $style_height = $style->length_in_pt($style->height, $w);
  100. $this->_frame->set_content_height($this->_calculate_content_height());
  101. $height = max($style_height, $this->_frame->get_content_height());
  102. // Let the cellmap know our height
  103. $cell_height = $height / count($cells["rows"]);
  104. if ($style_height < $height)
  105. $cell_height += $top_space + $bottom_space;
  106. foreach ($cells["rows"] as $i)
  107. $cellmap->set_row_height($i, $cell_height);
  108. $style->height = $height;
  109. $this->_text_align();
  110. $this->vertical_align();
  111. }
  112. }