| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package dompdf |
| 4 |
* @link https://github.com/dompdf/dompdf |
| 5 |
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License |
| 6 |
*/ |
| 7 |
namespace Dompdf\Positioner; |
| 8 |
|
| 9 |
use Dompdf\FrameDecorator\AbstractFrameDecorator; |
| 10 |
use Dompdf\FrameDecorator\Inline as InlineFrameDecorator; |
| 11 |
use Dompdf\Exception; |
| 12 |
use Dompdf\Helpers; |
| 13 |
|
| 14 |
/** |
| 15 |
* Positions inline frames |
| 16 |
* |
| 17 |
* @package dompdf |
| 18 |
*/ |
| 19 |
class Inline extends AbstractPositioner |
| 20 |
{ |
| 21 |
|
| 22 |
/** |
| 23 |
* @param AbstractFrameDecorator $frame |
| 24 |
* @throws Exception |
| 25 |
*/ |
| 26 |
function position(AbstractFrameDecorator $frame): void |
| 27 |
{ |
| 28 |
// Find our nearest block level parent and access its lines property |
| 29 |
$block = $frame->find_block_parent(); |
| 30 |
|
| 31 |
if (!$block) { |
| 32 |
throw new Exception("No block-level parent found. Not good."); |
| 33 |
} |
| 34 |
|
| 35 |
$cb = $frame->get_containing_block(); |
| 36 |
$line = $block->get_current_line_box(); |
| 37 |
|
| 38 |
if (!$frame->is_text_node() && !($frame instanceof InlineFrameDecorator)) { |
| 39 |
// Atomic inline boxes and replaced inline elements |
| 40 |
// (inline-block, inline-table, img etc.) |
| 41 |
$width = $frame->get_margin_width(); |
| 42 |
$available_width = $cb["w"] - $line->left - $line->w - $line->right; |
| 43 |
|
| 44 |
if (Helpers::lengthGreater($width, $available_width)) { |
| 45 |
$block->add_line(); |
| 46 |
$line = $block->get_current_line_box(); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
$frame->set_position($cb["x"] + $line->w, $line->y); |
| 51 |
} |
| 52 |
} |
| 53 |
|