Skip to content

Commit

Permalink
Improve frame height calculation
Browse files Browse the repository at this point in the history
Instead of the position of the frame, use the position of the content
box within the frame when calculating the frame height. Adds
frame->get_content_box to retrieve the position and dimensions of the
content box.

Closes #1288
  • Loading branch information
bsweeney committed Jan 16, 2017
1 parent 6e2b858 commit 09da06a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
34 changes: 33 additions & 1 deletion src/Frame.php
Expand Up @@ -426,7 +426,7 @@ public function get_children()
/**
* Containing block dimensions
*
* @param $i string The key of the wanted containing block's dimension (x, y, x, h)
* @param $i string The key of the wanted containing block's dimension (x, y, w, h)
*
* @return float[]|float
*/
Expand Down Expand Up @@ -517,6 +517,38 @@ public function get_break_margins()
), $this->_containing_block["h"]);
}

/**
* Return the content box (x,y,w,h) of the frame
*
* @return array
*/
public function get_content_box()
{
$style = $this->_style;
$cb = $this->_containing_block;

$x = $this->_position["x"] +
(float)$style->length_in_pt(array($style->margin_left,
$style->border_left_width,
$style->padding_left),
$cb["w"]);

$y = $this->_position["y"] +
(float)$style->length_in_pt(array($style->margin_top,
$style->border_top_width,
$style->padding_top),
$cb["h"]);

$w = $style->length_in_pt($style->width, $cb["w"]);

$h = $style->length_in_pt($style->height, $cb["h"]);

return array(0 => $x, "x" => $x,
1 => $y, "y" => $y,
2 => $w, "w" => $w,
3 => $h, "h" => $h);
}

/**
* Return the padding box (x,y,w,h) of the frame
*
Expand Down
8 changes: 8 additions & 0 deletions src/FrameDecorator/AbstractFrameDecorator.php
Expand Up @@ -270,6 +270,14 @@ function get_margin_width()
return $this->_frame->get_margin_width();
}

/**
* @return array
*/
function get_content_box()
{
return $this->_frame->get_content_box();
}

/**
* @return array
*/
Expand Down
4 changes: 2 additions & 2 deletions src/FrameReflower/Block.php
Expand Up @@ -218,8 +218,8 @@ protected function _calculate_content_height()
$lines = $this->_frame->get_line_boxes();
if (count($lines) > 0) {
$last_line = end($lines);
$position = $this->_frame->get_position();
$height = $last_line->y + $last_line->h - $position['y'];
$content_box = $this->_frame->get_content_box();
$height = $last_line->y + $last_line->h - $content_box["y"];
}
return $height;
}
Expand Down

0 comments on commit 09da06a

Please sign in to comment.