Add margin when static horizontal position is used -PDF
RTL supported

@param float $x Static position

@return float
553142
public function addMarginX(float $x): float
    {
        $m = $this->getMargins();
        if ($this->getRTL()) {
            $x += $m['right'];
        } else {
            $x += $m['left'];
        }
        $this->SetX($x);

        return $x;
    }
588918
public function setPosition()
    {
        // get the current position
        $currentX = $this->pdf->GetX();
        $currentY = $this->pdf->GetY();

        // save it
        $this->value['xc'] = $currentX;
        $this->value['yc'] = $currentY;

        if ($this->value['position'] === 'relative' || $this->value['position'] === 'absolute') {
            if ($this->value['right'] !== null) {
                $x = $this->getLastWidth(true) - $this->value['right'] - $this->value['width'];
                if ($this->value['margin']['r']) {
                    $x-= $this->value['margin']['r'];
                }
            } else {
                $x = $this->value['left'];
                if ($this->value['margin']['l']) {
                    $x+= $this->value['margin']['l'];
                }
            }

            if ($this->value['bottom'] !== null) {
                $y = $this->getLastHeight(true) - $this->value['bottom'] - $this->value['height'];
                if ($this->value['margin']['b']) {
                    $y-= $this->value['margin']['b'];
                }
            } else {
                $y = $this->value['top'];
                if ($this->value['margin']['t']) {
                    $y+= $this->value['margin']['t'];
                }
            }

            if ($this->value['position'] === 'relative') {
                $this->value['x'] = $currentX + $x;
                $this->value['y'] = $currentY + $y;
            } else {
                $this->value['x'] = $this->getLastAbsoluteX()+$x;
                $this->value['y'] = $this->getLastAbsoluteY()+$y;
            }
        } else {
            $this->value['x'] = $currentX;
            $this->value['y'] = $currentY;
            if ($this->value['margin']['l']) {
                $this->value['x']+= $this->value['margin']['l'];
            }
            if ($this->value['margin']['t']) {
                $this->value['y']+= $this->value['margin']['t'];
            }
        }

        // save the new position
        $this->pdf->SetXY($this->value['x'], $this->value['y']);
    }
441261
public function setMargin()
    {
        $margins = \func_get_args();

        if(count($margins) === 1 && is_string(current($margins)))
        {
            $margins = explode(' ', current($margins));
        }

        $marginLabels = array('margin-top', 'margin-right', 'margin-bottom', 'margin-left');
        $this->setComposeAttribute($marginLabels, $margins);

        return $this;
    }
965630
protected function setX($x)
	{
		if ( ! is_numeric($x) || $x < 0)
		{
			throw new \InvalidArgumentException('The value of x must be a positive numeric.');
		}
		
		$this->x = (int) $x;
		
		return $this;
	}
1097586
protected function _addMargins($float, $xLeft, $yTop, $xRight, $yBottom)
    {
        // get the current float margins, for top and bottom
        $oldTop    = $this->_getMargins($yTop);
        $oldBottom = $this->_getMargins($yBottom);

        // update the top float margin
        if ($float === 'left'  && $oldTop[0]<$xRight) {
            $oldTop[0] = $xRight;
        }
        if ($float === 'right' && $oldTop[1]>$xLeft) {
            $oldTop[1] = $xLeft;
        }

        $yTop = floor($yTop*100);
        $yBottom = floor($yBottom*100);

        // erase all the float margins that are smaller than the new one
        foreach ($this->_pageMarges as $mY => $mX) {
            if ($mY<$yTop) {
                continue;
            }
            if ($mY>$yBottom) {
                break;
            }
            if ($float === 'left' && $this->_pageMarges[$mY][0]<$xRight) {
                unset($this->_pageMarges[$mY]);
            }
            if ($float === 'right' && $this->_pageMarges[$mY][1]>$xLeft) {
                unset($this->_pageMarges[$mY]);
            }
        }

        // save the new Top and Bottom margins
        $this->_pageMarges[$yTop] = $oldTop;
        $this->_pageMarges[$yBottom] = $oldBottom;

        // sort the margins
        ksort($this->_pageMarges);

        // we are just after float
        $this->_isAfterFloat = true;
    }
460508
private static function logStirlingApproximation($x) {
		$t = 0.5*log(2*pi()) - 0.5*log($x) + $x*(log($x))-$x;

		$x2 = $x * $x;
		$x3 = $x2 * $x;
		$x4 = $x3 * $x;

		$err_term = log(1 + (1.0/(12*$x)) + (1.0/(288*$x2)) - (139.0/(51840*$x3))
			- (571.0/(2488320*$x4)));

		$res = $t + $err_term;
		return $res;
	}
1225724
private function calculatePosition($pos, $padding, $assetWidth, $assetHeight, $upperLeft = true)
		#
		# Author:   Jarrod Oberto
		# Date:   08-05-11
		# Purpose:  Calculate the x, y pixel cordinates of the asset to place
		# Params in:  (str) $pos: Either something like: "tl", "l", "br" or an
		#         exact position like: "100x50"
		#       (int) $padding: The amount of padding from the edge. Only
		#         used for the predefined $pos.
		#       (int) $assetWidth: The width of the asset to add to the image
		#       (int) $assetHeight: The height of the asset to add to the image
		#       (bol) $upperLeft: if true, the asset will be positioned based
		#         on the upper left x, y coords. If false, it means you're
		#         using the lower left as the basepoint and this will
		#         convert it to the upper left position
		# Params out:
		# NOTE: this is done from the UPPER left corner!! But will convert lower
		#   left basepoints to upper left if $upperleft is set to false
		#
		#
	{
		$pos = fix_strtolower($pos);

		// *** If co-ords have been entered
		if (strstr($pos, 'x'))
		{
			$pos = str_replace(' ', '', $pos);

			$xyArray = explode('x', $pos);
			list($width, $height) = $xyArray;

		}
		else
		{

			switch ($pos)
			{
				case 'tl':
					$width = 0 + $padding;
					$height = 0 + $padding;
					break;

				case 't':
					$width = ($this->width / 2) - ($assetWidth / 2);
					$height = 0 + $padding;
					break;

				case 'tr':
					$width = $this->width - $assetWidth - $padding;
					$height = 0 + $padding;;
					break;

				case 'l':
					$width = 0 + $padding;
					$height = ($this->height / 2) - ($assetHeight / 2);
					break;

				case 'm':
					$width = ($this->width / 2) - ($assetWidth / 2);
					$height = ($this->height / 2) - ($assetHeight / 2);
					break;

				case 'r':
					$width = $this->width - $assetWidth - $padding;
					$height = ($this->height / 2) - ($assetHeight / 2);
					break;

				case 'bl':
					$width = 0 + $padding;
					$height = $this->height - $assetHeight - $padding;
					break;

				case 'b':
					$width = ($this->width / 2) - ($assetWidth / 2);
					$height = $this->height - $assetHeight - $padding;
					break;

				case 'br':
					$width = $this->width - $assetWidth - $padding;
					$height = $this->height - $assetHeight - $padding;
					break;

				default:
					$width = 0;
					$height = 0;
					break;
			}
		}

		if ( ! $upperLeft)
		{
			$height = $height + $assetHeight;
		}

		return array( 'width' => $width, 'height' => $height );
	}
107594
public final function setX(float $x): self {
        $this->coordinates[self::X] = $this->gf
                ->getPrecisionModel()
                ->makePrecise($x);
        return $this;
    }
279887
public function setIndent($pValue = 0) {
		if ($pValue > 0) {
			if ($this->getHorizontal() != self::HORIZONTAL_GENERAL &&
				$this->getHorizontal() != self::HORIZONTAL_LEFT &&
				$this->getHorizontal() != self::HORIZONTAL_RIGHT) {
				$pValue = 0; // indent not supported
			}
		}
		if ($this->_isSupervisor) {
			$styleArray = $this->getStyleArray(array('indent' => $pValue));
			$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
		} else {
			$this->_indent = $pValue;
		}
		return $this;
	}
819785
public function setPositionXL($positionXL = self::xlLegendPositionRight)
    {
        if (!array_key_exists($positionXL, self::$positionXLref)) {
            return false;
        }

        $this->position = self::$positionXLref[$positionXL];
        return true;
    }
1133160
public function marginBottom($margin = null)
    {
        if ($margin === null) {
            return $this->_marginBottom;
        }
        $this->_marginBottom = $margin;

        return $this;
    }
528089
public function resizeX($x)
    {
        return $this->handle()->resize($x, null, function ($constraint) {
            $constraint->aspectRatio();
        });
    }
836282
@Pure
	public double fx2docX(double x) {
		return this.centeringTransform.toGlobalX((x - this.canvasWidth.get() / 2.) / this.scale.get());
	}
1292767
public function margin(int $left, ?int $right = null): self
    {
        $this->leftMargin = $left;
        $this->rightMargin = $right ?? $left;

        return $this;
    }
1260201
function get_text_x_inline( $text, $context, $key ) {
            return _fs_text_x_inline( $text, $context, $key, $this->_slug );
        }
1181862
public function getLayoutWidth()
    {
        $paperWidth     = $this->_paperWidth !== null   ? $this->_paperWidth    : $this->_rtf->getPaperWidth();
        $marginLeft     = $this->_marginLeft !== null   ? $this->_marginLeft    : $this->_rtf->getMarginLeft();
        $marginRight    = $this->_marginRight !== null  ? $this->_marginRight   : $this->_rtf->getMarginRight();
        $layoutWidth    = $paperWidth - $marginLeft - $marginRight;

        if ($layoutWidth <= 0) {
            throw new PHPRtfLite_Exception('The paper layout width is lower or equal zero!');
        }

        return $layoutWidth;
    }
915556
public function addText($text, $x = 0, $y = 0, $fontSize = 16, $color = '#000', $fontFamily = 5, $angle = 0) {
		$color = $this->getColorWithRGB($color);
		if (is_string($fontFamily) && is_file($fontFamily)) {
			return imagettftext($this->image, $fontSize, $angle, $x, $y, $color, $fontFamily, $text);
		}
		$fontFamily = intval($fontFamily);
		return imagestring($this->image, $fontFamily, $x, $y, $text, $color);
	}