"Fossies" - the Fresh Open Source Software Archive

Member "icingaweb2-2.11.4/library/vendor/dompdf/vendor/dompdf/dompdf/src/Positioner/Absolute.php" (26 Jan 2023, 4668 Bytes) of package /linux/www/icingaweb2-2.11.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    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\FrameReflower\Block;
   11 
   12 /**
   13  * Positions absolutely positioned frames
   14  */
   15 class Absolute extends AbstractPositioner
   16 {
   17 
   18     /**
   19      * @param AbstractFrameDecorator $frame
   20      */
   21     function position(AbstractFrameDecorator $frame): void
   22     {
   23         if ($frame->get_reflower() instanceof Block) {
   24             $style = $frame->get_style();
   25             [$cbx, $cby, $cbw, $cbh] = $frame->get_containing_block();
   26 
   27             // If the `top` value is `auto`, the frame will be repositioned
   28             // after its height has been resolved
   29             $left = (float) $style->length_in_pt($style->left, $cbw);
   30             $top = (float) $style->length_in_pt($style->top, $cbh);
   31 
   32             $frame->set_position($cbx + $left, $cby + $top);
   33         } else {
   34             // Legacy positioning logic for image and table frames
   35             // TODO: Resolve dimensions, margins, and offsets similar to the
   36             // block case in the reflowers and use the simplified logic above
   37             $style = $frame->get_style();
   38             $block_parent = $frame->find_block_parent();
   39             $current_line = $block_parent->get_current_line_box();
   40     
   41             list($x, $y, $w, $h) = $frame->get_containing_block();
   42             $inflow_x = $block_parent->get_content_box()["x"] + $current_line->left + $current_line->w;
   43             $inflow_y = $current_line->y;
   44 
   45             $top = $style->length_in_pt($style->top, $h);
   46             $right = $style->length_in_pt($style->right, $w);
   47             $bottom = $style->length_in_pt($style->bottom, $h);
   48             $left = $style->length_in_pt($style->left, $w);
   49 
   50             list($width, $height) = [$frame->get_margin_width(), $frame->get_margin_height()];
   51 
   52             $orig_width = $style->get_specified("width");
   53             $orig_height = $style->get_specified("height");
   54 
   55             /****************************
   56              *
   57              * Width auto:
   58              * ____________| left=auto | left=fixed |
   59              * right=auto  |     A     |     B      |
   60              * right=fixed |     C     |     D      |
   61              *
   62              * Width fixed:
   63              * ____________| left=auto | left=fixed |
   64              * right=auto  |     E     |     F      |
   65              * right=fixed |     G     |     H      |
   66              *****************************/
   67 
   68             if ($left === "auto") {
   69                 if ($right === "auto") {
   70                     // A or E - Keep the frame at the same position
   71                     $x = $inflow_x;
   72                 } else {
   73                     if ($orig_width === "auto") {
   74                         // C
   75                         $x += $w - $width - $right;
   76                     } else {
   77                         // G
   78                         $x += $w - $width - $right;
   79                     }
   80                 }
   81             } else {
   82                 if ($right === "auto") {
   83                     // B or F
   84                     $x += (float)$left;
   85                 } else {
   86                     if ($orig_width === "auto") {
   87                         // D - TODO change width
   88                         $x += (float)$left;
   89                     } else {
   90                         // H - Everything is fixed: left + width win
   91                         $x += (float)$left;
   92                     }
   93                 }
   94             }
   95 
   96             // The same vertically
   97             if ($top === "auto") {
   98                 if ($bottom === "auto") {
   99                     // A or E - Keep the frame at the same position
  100                     $y = $inflow_y;
  101                 } else {
  102                     if ($orig_height === "auto") {
  103                         // C
  104                         $y += (float)$h - $height - (float)$bottom;
  105                     } else {
  106                         // G
  107                         $y += (float)$h - $height - (float)$bottom;
  108                     }
  109                 }
  110             } else {
  111                 if ($bottom === "auto") {
  112                     // B or F
  113                     $y += (float)$top;
  114                 } else {
  115                     if ($orig_height === "auto") {
  116                         // D - TODO change height
  117                         $y += (float)$top;
  118                     } else {
  119                         // H - Everything is fixed: top + height win
  120                         $y += (float)$top;
  121                     }
  122                 }
  123             }
  124 
  125             $frame->set_position($x, $y);
  126         }
  127     }
  128 }