/*!
Creates a new text layer with the text \a $text, font \a $font and adjustment
\a $widthAdjustment and \a $heightAdjustment at the angle \a $angle and returns it.
6047
static function createForText( $text, &$font, $widthAdjustment, $heightAdjustment, $angle,
                             $absoluteWidth = false, $absoluteHeight = false )
    {
        $Return = false;
        if ( !( $font instanceof eZImageFont ) )
            return $Return;
        if ( !function_exists( 'ImageTTFBBox' ) )
        {
            eZDebug::writeError( 'ImageTTFBBox function not in PHP, check PHP compilation', 'ezimagetextlayer.php' );
            return $Return;
        }
        $bbox = ImageTTFBBox( $font->pointSize(), $angle, $font->realFile(), $text );

        if ( !$bbox )
            return $Return;

        $xmin = min( $bbox[0], $bbox[2], $bbox[4], $bbox[6] );
        $xmax = max( $bbox[0], $bbox[2], $bbox[4], $bbox[6] );
        $ymin = min( $bbox[1], $bbox[3], $bbox[5], $bbox[7] );
        $ymax = max( $bbox[1], $bbox[3], $bbox[5], $bbox[7] );

        $width = abs( $xmax - $xmin );
        $height = abs( $ymax - $ymin );
        $width += $widthAdjustment;
        $height += $heightAdjustment;

        if ( $absoluteWidth !== false )
            $width = $absoluteWidth;
        if ( $absoluteHeight !== false)
            $height = $absoluteHeight;

        $layer = new eZImageTextLayer( null, null, $width, $height,
                                       $font, $bbox, $text, $angle );
        $layer->create( $width, $height, null );
        return $layer;
    }
795021
private function text($text, $size, $x, $y, $color = 'black', $font = 'swiss_normal', $angle = 0)
    {
        imagettftext($this->image, $size, $angle, $x, $y, $this->colors[$color], $this->fonts[$font], $text);
    }
1034405
@Override protected void resizeDynamicText() {
        double maxWidth = width - size * 0.1;
        double fontSize = size * textSize.factor;

        boolean customFontEnabled = tile.isCustomFontEnabled();
        Font    customFont        = tile.getCustomFont();
        Font    font              = (customFontEnabled && customFont != null) ? Font.font(customFont.getFamily(), fontSize) : Fonts.latoRegular(fontSize);

        titleText.setFont(font);
        titleText.setText(tile.getTitle());
        if (titleText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(titleText, maxWidth, fontSize); }
        switch(tile.getTitleAlignment()) {
            default    :
            case LEFT  : titleText.relocate(size * 0.05, size * 0.05); break;
            case CENTER: titleText.relocate((width - titleText.getLayoutBounds().getWidth()) * 0.5, size * 0.05); break;
            case RIGHT : titleText.relocate(width - (size * 0.05) - titleText.getLayoutBounds().getWidth(), size * 0.05); break;
        }
        titleText.setY(size * 0.05);

        maxWidth = width - size * 0.8;
        amPmText.setFont(font);
        amPmText.setText(tile.getTime().get(ChronoField.AMPM_OF_DAY) == 0 ? "AM" : "PM");
        Helper.adjustTextSize(amPmText, maxWidth, fontSize);
        amPmText.setX((width - amPmText.getLayoutBounds().getWidth()) * 0.5);
        amPmText.setY(height * 0.5 - size * 0.1);

        maxWidth = width - size * 0.4;
        dateText.setFont(font);
        if (dateText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(dateText, maxWidth, fontSize); }
        dateText.setX((width - dateText.getLayoutBounds().getWidth()) * 0.5);
        dateText.setY(height * 0.5 + size * 0.15);

        maxWidth = width - size * 0.1;

        text.setText(tile.getText());
        text.setFont(font);
        if (text.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(text, maxWidth, fontSize); }
        switch(tile.getTextAlignment()) {
            default    :
            case LEFT  : text.setX(size * 0.05); break;
            case CENTER: text.setX((width - text.getLayoutBounds().getWidth()) * 0.5); break;
            case RIGHT : text.setX(width - (size * 0.05) - text.getLayoutBounds().getWidth()); break;
        }
        text.setY(height - size * 0.05);
    }
1350448
function setTextRotation($angle)
    {
        switch ($angle)
        {
            case 0:
                $this->_rotation = 0;
                break;
            case 90:
                if ($this->_BIFF_version == 0x0500) {
                $this->_rotation = 3;
                } elseif ($this->_BIFF_version == 0x0600) {
                    $this->_rotation = 180;
                }
                break;
            case 270:
                if ($this->_BIFF_version == 0x0500) {
                $this->_rotation = 2;
                } elseif ($this->_BIFF_version == 0x0600) {
                    $this->_rotation = 90;
                }
                break;
            case -1:
                if ($this->_BIFF_version == 0x0500) {
                $this->_rotation = 1;
                } elseif ($this->_BIFF_version == 0x0600) {
                    $this->_rotation = 255;
                }
                break;
            default :
                return $this->raiseError("Invalid value for angle.".
                                  " Possible values are: 0, 90, 270 and -1 ".
                                  "for stacking top-to-bottom.");
                $this->_rotation = 0;
                break;
        }
    }
953519
function() {
        var ctx = this._drawContext;
        ctx.font = this._fontString();
        this.w = ctx.measureText(this._text).width;

        var size = this._textFont.size || this.defaultSize;
        this.h = 1.1 * this._getFontHeight(size);

        /* Offset the MBR for text alignment*/
        if (this._textAlign === "left" || this._textAlign === "start") {
            this.offsetBoundary(0, 0, 0, 0);
        } else if (this._textAlign === "center") {
            this.offsetBoundary(this.w / 2, 0, -this.w / 2, 0);
        } else if (this._textAlign === "end" || this._textAlign === "right") {
            this.offsetBoundary(this.w, 0, -this.w, 0);
        }
    }
471146
public function addTextToCaptionBox($text, $fontColor = '#fff', $fontSize = 12, $angle = 0, $font = null)
		#
		# Author:   Jarrod Oberto
		# Date:   03 Aug 11
		# Purpose:  Simplify adding text to a caption box by automatically
		#       locating the center of the caption box
		# Params in:  The usually text paams (less a couple)
		# Params out: n/a
		# Notes:
		#
	{

		// *** Get the caption box measurements
		if (count($this->captionBoxPositionArray) == 4)
		{
			$x1 = $this->captionBoxPositionArray['x1'];
			$x2 = $this->captionBoxPositionArray['x2'];
			$y1 = $this->captionBoxPositionArray['y1'];
			$y2 = $this->captionBoxPositionArray['y2'];
		}
		else
		{
			if ($this->debug)
			{
				throw new Exception('No caption box found.');
			}
			else
			{
				return false;
			}
		}


		// *** Get text font
		$font = $this->getTextFont($font);

		// *** Get text size
		$textSizeArray = $this->getTextSize($fontSize, $angle, $font, $text);
		$textWidth = $textSizeArray['width'];
		$textHeight = $textSizeArray['height'];

		// *** Find the width/height middle points
		$boxXMiddle = (($x2 - $x1) / 2);
		$boxYMiddle = (($y2 - $y1) / 2);

		// *** Box middle - half the text width/height
		$xPos = ($x1 + $boxXMiddle) - ($textWidth / 2);
		$yPos = ($y1 + $boxYMiddle) - ($textHeight / 2);

		$pos = $xPos . 'x' . $yPos;

		$this->addText($text, $pos, $padding = 0, $fontColor, $fontSize, $angle, $font);

	}
50824
function (text, options) {
    "use strict";

    var marginX     = options.marginX !== undefined ? options.marginX : 2;
    var marginY     = options.marginY !== undefined ? options.marginY : 1;
    var margin      = new Array(marginX+1).join(" ");
    var indent      = options.indent !== undefined ? options.indent :  "  ";
    var maxLength   = 0;
    var linesOfText = text.split('\n');

    var pattern = options.pattern || {
      T: "/", B: "/", TR: "//", BR: "//", TL: "//", BL: "//", R: "//", L: "//"
    };

    linesOfText.forEach(function (line) {
      maxLength = Math.max(maxLength, line.length);
    });

    var top    = pattern.TL + new Array(2 * marginX + maxLength + 1).join(pattern.T) + pattern.TR;
    var empty  = pattern.L  + new Array(2 * marginX + maxLength + 1).join(" ")       + pattern.R;
    var bottom = pattern.BL + new Array(2 * marginX + maxLength + 1).join(pattern.B) + pattern.BR;

    linesOfText = linesOfText.map(function (line) {
      while (line.length < maxLength) {
        line += " ";
      }
      return pattern.L + margin + line + margin + pattern.R;
    });

    // vertical margin
    for (var i=0; i<marginY; i++) {
      linesOfText.unshift(empty);
      linesOfText.push(empty);
    }

    // top and bottom lines
    linesOfText.unshift(top);
    linesOfText.push(bottom);

    return linesOfText.map(function (line) {
      return indent + line;
    }).join('\n');
  }
443210
function drawText(text, dx, dy, ctx) {
  var dx0 = dx;
  for (var i = 0; i < text.length; i++) {
    var n = text.charCodeAt(i);
    var sx = (n&63)*8;
    var sy = (n>>6)*10 + 56;
    var width = _fontwidths[n];
    ctx.drawImage(fontimg, sx, sy, width, 10, dx, dy, width, 10);
    dx += width + 1;
  }
  return dx - dx0;
}
215858
public function expandFontShorthand() {
		$aRules = $this->getRulesAssoc();
		if (!isset($aRules['font']))
			return;
		$oRule = $aRules['font'];
		// reset properties to 'normal' per http://www.w3.org/TR/21/fonts.html#font-shorthand
		$aFontProperties = array(
			'font-style' => 'normal',
			'font-variant' => 'normal',
			'font-weight' => 'normal',
			'font-size' => 'normal',
			'line-height' => 'normal'
		);
		$mRuleValue = $oRule->getValue();
		$aValues = array();
		if (!$mRuleValue instanceof RuleValueList) {
			$aValues[] = $mRuleValue;
		} else {
			$aValues = $mRuleValue->getListComponents();
		}
		foreach ($aValues as $mValue) {
			if (!$mValue instanceof Value) {
				$mValue = mb_strtolower($mValue);
			}
			if (in_array($mValue, array('normal', 'inherit'))) {
				foreach (array('font-style', 'font-weight', 'font-variant') as $sProperty) {
					if (!isset($aFontProperties[$sProperty])) {
						$aFontProperties[$sProperty] = $mValue;
					}
				}
			} else if (in_array($mValue, array('italic', 'oblique'))) {
				$aFontProperties['font-style'] = $mValue;
			} else if ($mValue == 'small-caps') {
				$aFontProperties['font-variant'] = $mValue;
			} else if (
					in_array($mValue, array('bold', 'bolder', 'lighter'))
					|| ($mValue instanceof Size
					&& in_array($mValue->getSize(), range(100, 900, 100)))
			) {
				$aFontProperties['font-weight'] = $mValue;
			} else if ($mValue instanceof RuleValueList && $mValue->getListSeparator() == '/') {
				list($oSize, $oHeight) = $mValue->getListComponents();
				$aFontProperties['font-size'] = $oSize;
				$aFontProperties['line-height'] = $oHeight;
			} else if ($mValue instanceof Size && $mValue->getUnit() !== null) {
				$aFontProperties['font-size'] = $mValue;
			} else {
				$aFontProperties['font-family'] = $mValue;
			}
		}
		foreach ($aFontProperties as $sProperty => $mValue) {
			$oNewRule = new Rule($sProperty, $this->iLineNo);
			$oNewRule->addValue($mValue);
			$oNewRule->setIsImportant($oRule->getIsImportant());
			$this->addRule($oNewRule);
		}
		$this->removeRule('font');
	}
960630
@Override protected void resizeDynamicText() {
        double oneThirdWidth = width / 3;
        double fontSize      = size * 0.1;

        description.setFont(Fonts.latoRegular(fontSize));
        description.setLayoutY(height * 0.175);

        fontSize = size * 0.075;

        leftValueLabel.setFont(Fonts.latoRegular(fontSize));
        middleValueLabel.setFont(Fonts.latoRegular(fontSize));
        rightValueLabel.setFont(Fonts.latoRegular(fontSize));

        leftValueLabel.relocate(0, height * 0.59);
        middleValueLabel.relocate(oneThirdWidth, height * 0.59);
        rightValueLabel.relocate(width - oneThirdWidth, height * 0.59);
    }
135534
public function createFontShorthand() {
		$aFontProperties = array(
			'font-style', 'font-variant', 'font-weight', 'font-size', 'line-height', 'font-family'
		);
		$aRules = $this->getRulesAssoc();
		if (!isset($aRules['font-size']) || !isset($aRules['font-family'])) {
			return;
		}
		$oNewRule = new Rule('font', $this->iLineNo);
		foreach (array('font-style', 'font-variant', 'font-weight') as $sProperty) {
			if (isset($aRules[$sProperty])) {
				$oRule = $aRules[$sProperty];
				$mRuleValue = $oRule->getValue();
				$aValues = array();
				if (!$mRuleValue instanceof RuleValueList) {
					$aValues[] = $mRuleValue;
				} else {
					$aValues = $mRuleValue->getListComponents();
				}
				if ($aValues[0] !== 'normal') {
					$oNewRule->addValue($aValues[0]);
				}
			}
		}
		// Get the font-size value
		$oRule = $aRules['font-size'];
		$mRuleValue = $oRule->getValue();
		$aFSValues = array();
		if (!$mRuleValue instanceof RuleValueList) {
			$aFSValues[] = $mRuleValue;
		} else {
			$aFSValues = $mRuleValue->getListComponents();
		}
		// But wait to know if we have line-height to add it
		if (isset($aRules['line-height'])) {
			$oRule = $aRules['line-height'];
			$mRuleValue = $oRule->getValue();
			$aLHValues = array();
			if (!$mRuleValue instanceof RuleValueList) {
				$aLHValues[] = $mRuleValue;
			} else {
				$aLHValues = $mRuleValue->getListComponents();
			}
			if ($aLHValues[0] !== 'normal') {
				$val = new RuleValueList('/', $this->iLineNo);
				$val->addListComponent($aFSValues[0]);
				$val->addListComponent($aLHValues[0]);
				$oNewRule->addValue($val);
			}
		} else {
			$oNewRule->addValue($aFSValues[0]);
		}
		$oRule = $aRules['font-family'];
		$mRuleValue = $oRule->getValue();
		$aFFValues = array();
		if (!$mRuleValue instanceof RuleValueList) {
			$aFFValues[] = $mRuleValue;
		} else {
			$aFFValues = $mRuleValue->getListComponents();
		}
		$oFFValue = new RuleValueList(',', $this->iLineNo);
		$oFFValue->setListComponents($aFFValues);
		$oNewRule->addValue($oFFValue);

		$this->addRule($oNewRule);
		foreach ($aFontProperties as $sProperty) {
			$this->removeRule($sProperty);
		}
	}
518870
function makeHead(lLabel, lText, rLabel, rText) {
    if (!lText) {
        return "";
    }
    
    var fillSpace = 78, result = "<div class='line'>";
    
    fillSpace -= 2 + lLabel.length + 1 + lText.length;
    
    if (rText) {
        fillSpace -= 2 + rLabel.length + 2 + rText.length;
    }
    
    if (fillSpace < 0) {
        fillSpace = 0;
    }
    
    var span = new Span(4, 7, false);
    
    span.text = " " + lLabel + " ";
    
    result += span.toString();
    
    span.f = 7;
    span.b = 4;
    span.text = " " + lText + " ".repeat(fillSpace);
    
    result += span.toString();
    
    // result += makeSpan({f:4,b:7,text:" "+lLabel+" "}) + makeSpan({f:7,b:4,text:" "+lText+" ".repeat(fillSpace)});
    
    if (rText) {
        span.f = 4;
        span.b = 7;
        span.text = " " + rLabel + " ";
        
        result += span.toString();
        
        span.f = 7;
        span.b = 4;
        span.text = " " + rText + " ";
        
        result += span.toString();
        // result += makeSpan({f:4,b:7,text:" "+rLabel+" "}) + makeSpan({f:7,b:4,text:" "+rText+" "});
    }
    
    result += "</div>";
    
    return result;
}
411882
function makeText2D (object) {
  return new Promise(resolve => {
    var wordArray = object.getProperty('text').split(' ');
    const style = {
      fontSize: units.convert(object, 'font-size'),
      fontFamily: object.style['font-family'],
      color: objectUtils.parseColor(object.style['color'])
    };

    for (let i = 0; i < wordArray.length; i++) {
      wordArray[i] = new Word2D(wordArray[i], style, object);
    }

    resolve(wordArray);
  });
}
846204
public function create($totalWidth, $columns, $index = 0, $height = 4.0, $autoNewLine = false, $maxLines = 1)
    {
        $totalCoef
            = ($totalWidth - 1) / array_reduce($columns, function ($carry, $item) {
                return $carry + $item['width'];
            });

        $frame = new Frame();
        $frame->setHeight($height);
        $frame->setWidth($totalWidth);

        $postX = 1;
        foreach ($columns as $columnData) {
            $coeff = $totalCoef;
            if (isset($columnData['text'])) {
                $element = $this->createTextColumn($totalCoef, $columnData, $postX, $height, $autoNewLine, $maxLines);
            } elseif (isset($columnData['iconUrl'])) {
                $element = $this->createIconColumn($columnData, $postX, $height);
            } elseif (isset($columnData['input'])) {
                $element = $this->createInputColumn($totalCoef, $columnData, $postX);
            } elseif (isset($columnData['renderer'])) {
                $element = $this->createRendererColumn($columnData, $postX);
            }

            if (!isset($element)) {
                throw new \Exception('Element not found.');
            }

            if (isset($columnData['action'])) {
                $element->setAction($columnData['action']);
            }

            $frame->addChild($element);
            $postX += $columnData["width"] * $coeff;
        }

        $frame->addChild($this->backGroundFactory->create($totalWidth, $height, $index));

        return $frame;
    }
343164
public function addText($text, $pos = '20x20', $padding = 0, $fontColor = '#fff', $fontSize = 12, $angle = 0, $font = null)
		# Author:     Jarrod Oberto
		# Date:       18-11-09
		# Purpose:    Add text to an image
		# Param in:
		# Param out:
		# Reference:  http://php.net/manual/en/function.imagettftext.php
		# Notes:      Make sure you supply the font.
		#
	{

		// *** Convert color
		$rgbArray = $this->formatColor($fontColor);
		$r = $rgbArray['r'];
		$g = $rgbArray['g'];
		$b = $rgbArray['b'];

		// *** Get text font
		$font = $this->getTextFont($font);

		// *** Get text size
		$textSizeArray = $this->getTextSize($fontSize, $angle, $font, $text);
		$textWidth = $textSizeArray['width'];
		$textHeight = $textSizeArray['height'];

		// *** Find co-ords to place text
		$posArray = $this->calculatePosition($pos, $padding, $textWidth, $textHeight, false);
		$x = $posArray['width'];
		$y = $posArray['height'];

		$fontColor = imagecolorallocate($this->imageResized, $r, $g, $b);

		// *** Add text
		imagettftext($this->imageResized, $fontSize, $angle, $x, $y, $fontColor, $font, $text);
	}
32424
function Shaded_box($text, $font = '', $fontstyle = 'B', $szfont = '', $width = '70%', $style = 'DF', $radius = 2.5, $fill = '#FFFFFF', $color = '#000000', $pad = 2)
	{
		// F (shading - no line),S (line, no shading),DF (both)
		if (empty($this->directWrite)) {
			$this->directWrite = new DirectWrite($this, $this->otl, $this->sizeConverter, $this->colorConverter);
		}
		$this->directWrite->Shaded_box($text, $font, $fontstyle, $szfont, $width, $style, $radius, $fill, $color, $pad);
	}
1091421
public function MultiTexto($txt, $x=null, $y=null, $align='', $w=0, $border=0, $fill=false)
    {
        if ($x==null) $x = $this->GetX();
        if ($y==null) $y = $this->GetY();
        $textrendermode = $this->textrendermode;
        $textstrokewidth = $this->textstrokewidth;
        $this->setTextRenderingMode(0, true, false);
        $this->SetXY($x, $y);
        $this->MultiCell($w, 0, $txt, $border, $align, $fill);
        // restore previous rendering mode
        $this->textrendermode = $textrendermode;
        $this->textstrokewidth = $textstrokewidth;
    }