Skip to content

Commit

Permalink
InlineBox text offset improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafał Pośpiech committed Apr 26, 2019
1 parent c129d1c commit a4629ea
Show file tree
Hide file tree
Showing 13 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions examples/H123456.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ <h3 style="border:1px solid red;">test</h3>
<h4 style="border:1px solid red;">test</h4>
<h5 style="border:1px solid red;">test</h5>
<h6 style="border:1px solid red;">test</h6>

<div style="line-height:4em;border:1px solid red;">test</div>
Binary file modified examples/H123456.pdf
Binary file not shown.
Binary file modified examples/Image.pdf
Binary file not shown.
Binary file modified examples/InvoiceTable.pdf
Binary file not shown.
Binary file modified examples/SimpleNestedDiv.pdf
Binary file not shown.
Binary file modified examples/SimpleTable.pdf
Binary file not shown.
Binary file modified examples/TableClassNames.pdf
Binary file not shown.
Binary file modified examples/WidthsSpecifiedTable.pdf
Binary file not shown.
Binary file modified examples/helloWorld.pdf
Binary file not shown.
Binary file modified examples/nestedBlockPaddingWidth.pdf
Binary file not shown.
Binary file modified examples/simpleInline.pdf
Binary file not shown.
8 changes: 4 additions & 4 deletions lib/Layout/InlineBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public function createText($content, bool $sameId = false)
/**
* Get previous sibling inline-level element text.
*
* @return string|null
* @return null|string
*/
protected function getPreviousText()
{
Expand Down Expand Up @@ -302,11 +302,11 @@ public function measureOffset()
$top = $parent->getStyle()->getOffsetTop();
$lineHeight = $this->getClosestLineBox()->getDimensions()->getHeight();
if ($rules['vertical-align'] === 'bottom') {
$top = Math::sub($lineHeight, $this->getDimensions()->getHeight());
$top = Math::sub($lineHeight, $this->getStyle()->getFont()->getTextHeight());
} elseif ($rules['vertical-align'] === 'top') {
$top = '0';
$top = $this->getStyle()->getFont()->getDescender();
} elseif ($rules['vertical-align'] === 'middle' || $rules['vertical-align'] === 'baseline') {
$height = $this->getDimensions()->getHeight();
$height = $this->getStyle()->getFont()->getTextHeight();
$top = Math::sub(Math::div($lineHeight, '2'), Math::div($height, '2'));
}
// margin top inside inline and inline block doesn't affect relative to line top position
Expand Down
2 changes: 1 addition & 1 deletion lib/Objects/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ public function getTextWidth(string $text): string
public function getTextHeight(string $text = null): string
{
if ($this->textHeight === null) {
$this->textHeight = Math::div(Math::mul($this->size->getConverted(), $this->height), $this->unitsPerEm);
$this->textHeight = Math::add($this->getAscender(), Math::mul($this->getDescender(), '-1'));
}

return $this->textHeight;
Expand Down

0 comments on commit a4629ea

Please sign in to comment.