table_cell_frame_reflower.cls.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * @package dompdf
  4. * @link http://dompdf.github.com/
  5. * @author Benj Carson <benjcarson@digitaljunkies.ca>
  6. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  7. */
  8. /**
  9. * Reflows table cells
  10. *
  11. * @access private
  12. * @package dompdf
  13. */
  14. class Table_Cell_Frame_Reflower extends Block_Frame_Reflower {
  15. //........................................................................
  16. function __construct(Block_Frame_Decorator $frame) {
  17. parent::__construct($frame);
  18. }
  19. //........................................................................
  20. function reflow(Block_Frame_Decorator $block = null) {
  21. $style = $this->_frame->get_style();
  22. $table = Table_Frame_Decorator::find_parent_table($this->_frame);
  23. $cellmap = $table->get_cellmap();
  24. list($x, $y) = $cellmap->get_frame_position($this->_frame);
  25. $this->_frame->set_position($x, $y);
  26. $cells = $cellmap->get_spanned_cells($this->_frame);
  27. $w = 0;
  28. foreach ( $cells["columns"] as $i ) {
  29. $col = $cellmap->get_column( $i );
  30. $w += $col["used-width"];
  31. }
  32. //FIXME?
  33. $h = $this->_frame->get_containing_block("h");
  34. $left_space = $style->length_in_pt(array($style->margin_left,
  35. $style->padding_left,
  36. $style->border_left_width),
  37. $w);
  38. $right_space = $style->length_in_pt(array($style->padding_right,
  39. $style->margin_right,
  40. $style->border_right_width),
  41. $w);
  42. $top_space = $style->length_in_pt(array($style->margin_top,
  43. $style->padding_top,
  44. $style->border_top_width),
  45. $h);
  46. $bottom_space = $style->length_in_pt(array($style->margin_bottom,
  47. $style->padding_bottom,
  48. $style->border_bottom_width),
  49. $h);
  50. $style->width = $cb_w = $w - $left_space - $right_space;
  51. $content_x = $x + $left_space;
  52. $content_y = $line_y = $y + $top_space;
  53. // Adjust the first line based on the text-indent property
  54. $indent = $style->length_in_pt($style->text_indent, $w);
  55. $this->_frame->increase_line_width($indent);
  56. $page = $this->_frame->get_root();
  57. // Set the y position of the first line in the cell
  58. $line_box = $this->_frame->get_current_line_box();
  59. $line_box->y = $line_y;
  60. // Set the containing blocks and reflow each child
  61. foreach ( $this->_frame->get_children() as $child ) {
  62. if ( $page->is_full() )
  63. break;
  64. $child->set_containing_block($content_x, $content_y, $cb_w, $h);
  65. $this->process_clear($child);
  66. $child->reflow($this->_frame);
  67. $this->process_float($child, $x + $left_space, $w - $right_space - $left_space);
  68. }
  69. // Determine our height
  70. $style_height = $style->length_in_pt($style->height, $h);
  71. $this->_frame->set_content_height($this->_calculate_content_height());
  72. $height = max($style_height, $this->_frame->get_content_height());
  73. // Let the cellmap know our height
  74. $cell_height = $height / count($cells["rows"]);
  75. if ($style_height <= $height)
  76. $cell_height += $top_space + $bottom_space;
  77. foreach ($cells["rows"] as $i)
  78. $cellmap->set_row_height($i, $cell_height);
  79. $style->height = $height;
  80. $this->_text_align();
  81. $this->vertical_align();
  82. }
  83. }