Project

General

Profile

Feature #20164 » 0010666.patch

Administrator Admin, 2009-03-12 15:03

View differences:

t3lib/class.t3lib_stdgraphic.php (Arbeitskopie)
if ($spacing || $wordSpacing) { // If any kind of spacing applys, we use this function:
$this->SpacedImageTTFText($im, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, t3lib_stdGraphic::prependAbsolutePath($conf['fontFile']), $theText, $spacing, $wordSpacing, $conf['splitRendering.']);
} else {
$this->ImageTTFTextWrapper($im, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, $conf['fontFile'], $theText, $conf['splitRendering.']);
// $this->ImageTTFTextWrapper($im, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, $conf['fontFile'], $theText, $conf['splitRendering.']);
$this->renderTTFText($im, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, $conf['fontFile'], $theText, $conf['splitRendering.'], $conf);
}
}
} else { // NICETEXT::
......
if ($spacing || $wordSpacing) { // If any kind of spacing applys, we use this function:
$this->SpacedImageTTFText($maskImg, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, t3lib_stdGraphic::prependAbsolutePath($conf['fontFile']), $theText, $spacing, $wordSpacing, $conf['splitRendering.'],$sF);
} else {
$this->ImageTTFTextWrapper($maskImg, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, $conf['fontFile'], $theText, $conf['splitRendering.'],$sF);
// $this->ImageTTFTextWrapper($maskImg, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, $conf['fontFile'], $theText, $conf['splitRendering.'],$sF);
$this->renderTTFText($maskImg, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, $conf['fontFile'], $theText, $conf['splitRendering.'], $conf, $sF);
}
$this->ImageWrite($maskImg, $fileMask);
ImageDestroy($maskImg);
......
$x = ($charInf[2]-$charInf[0]);
$y = ($charInf[1]-$charInf[7]);
}
// Set original lineHeight (used by line breaks):
$theBBoxInfo['lineHeight'] = $y;
if ($spacing || $wordSpacing) { // If any kind of spacing applys, we use this function:
$x=0;
if (!$spacing && $wordSpacing) {
......
$x+=$charW+(($char==' ')?$wordSpacing:$spacing);
}
}
} elseif (isset($conf['breakWidth']) && $conf['breakWidth'] && $this->getRenderedTextWidth($conf['text'], $conf) > $conf['breakWidth']) {
$maxWidth = 0;
$currentWidth = 0;
$breakWidth = $conf['breakWidth'];
$breakSpace = $this->getBreakSpace($conf, $theBBoxInfo) * $sF;
$wordPairs = $this->getWordPairsForLineBreak($conf['text']);
// Iterate through all word pairs:
foreach ($wordPairs as $index => $wordPair) {
$wordWidth = $this->getRenderedTextWidth($wordPair, $conf);
if ($index == 0 || $currentWidth + $wordWidth <= $breakWidth) {
$currentWidth+= $wordWidth;
} else {
$maxWidth = max($maxWidth, $currentWidth);
$y+= $breakSpace;
// Restart:
$currentWidth = $wordWidth;
}
}
$x = max($maxWidth, $currentWidth) * $sF;
}
if ($sF>1) {
$x = ceil($x/$sF);
$y = ceil($y/$sF);
if ($sF > 1) {
$x = ceil($x / $sF);
$y = ceil($y / $sF);
if (is_array($theBBoxInfo)) {
reset($theBBoxInfo);
while(list($key,$val)=each($theBBoxInfo)) {
$theBBoxInfo[$key]=ceil($theBBoxInfo[$key]/$sF);
foreach ($theBBoxInfo as &$value) {
$value = ceil($value / $sF);
}
}
}
return array($x,$y,$theBBoxInfo);
return array($x, $y, $theBBoxInfo);
}
/**
......
return $sF;
}
/**
* Renders a regular text and takes care of a possible line break automatically.
*
* @param pointer (See argument for PHP function imageTTFtext())
* @param integer (See argument for PHP function imageTTFtext())
* @param integer (See argument for PHP function imageTTFtext())
* @param integer (See argument for PHP function imageTTFtext())
* @param integer (See argument for PHP function imageTTFtext())
* @param integer (See argument for PHP function imageTTFtext())
* @param string (See argument for PHP function imageTTFtext())
* @param string (See argument for PHP function imageTTFtext()). UTF-8 string, possibly with entities in.
* @param array Split-rendering configuration
* @param integer Scale factor
* @param array $conf: The configuration
* @return void
*/
protected function renderTTFText(&$im, $fontSize, $angle, $x, $y, $color, $fontFile, $string, $splitRendering, $conf, $sF = 1) {
if (isset($conf['breakWidth']) && $conf['breakWidth'] && $this->getRenderedTextWidth($string, $conf) > $conf['breakWidth']) {
$phrase = '';
$currentWidth = 0;
$breakWidth = $conf['breakWidth'];
$breakSpace = $this->getBreakSpace($conf) * $sF;
$wordPairs = $this->getWordPairsForLineBreak($string);
// Iterate through all word pairs:
foreach ($wordPairs as $index => $wordPair) {
$wordWidth = $this->getRenderedTextWidth($wordPair, $conf);
if ($index == 0 || $currentWidth + $wordWidth <= $breakWidth) {
$currentWidth+= $wordWidth;
$phrase.= $wordPair;
} else {
// Render the current phrase that is below breakWidth:
$this->ImageTTFTextWrapper($im, $fontSize, $angle, $x, $y, $color, $fontFile, $phrase, $splitRendering, $sF);
// Calculate the news height offset:
$y+= $breakSpace;
// Restart the phrase:
$currentWidth = $wordWidth;
$phrase = $wordPair;
}
}
// Render the remaining phrase:
if ($currentWidth) {
$this->ImageTTFTextWrapper($im, $fontSize, $angle, $x, $y, $color, $fontFile, $phrase, $splitRendering, $sF);
}
} else {
$this->ImageTTFTextWrapper($im, $fontSize, $angle, $x, $y, $color, $fontFile, $string, $splitRendering, $sF);
}
}
/**
* Gets the word pairs used for automatic line breaks.
*
* @param string $string
* @return array
*/
protected function getWordPairsForLineBreak($string) {
$wordPairs = array();
$wordsArray = preg_split('#([ -.,!:]+)#', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
$wordsCount = count($wordsArray);
for ($index=0; $index < $wordsCount; $index+= 2) {
$wordPairs[] = $wordsArray[$index] . $wordsArray[$index + 1];
}
return $wordPairs;
}
/**
* Gets the rendered text width.
*
* @param string $text
* @param array $conf
* @param integer
*/
protected function getRenderedTextWidth($text, $conf) {
$bounds = $this->ImageTTFBBoxWrapper($conf['fontSize'], $conf['angle'], $conf['fontFile'], $this->recodeString($text), $conf['splitRendering.']);
if ($conf['angle']< 0) {
$pixelWidth = abs($bounds[4]-$bounds[0]);
} elseif ($conf['angle'] > 0) {
$pixelWidth = abs($bounds[2]-$bounds[6]);
} else {
$pixelWidth = abs($bounds[4]-$bounds[6]);
}
return $pixelWidth;
}
/**
* Gets the break space for each new line.
*
* @param array $conf: TypoScript configuration for the currently rendered object
* @param array $boundingBox: The bounding box the the currently rendered object
* @return integer The break space
*/
protected function getBreakSpace($conf, array $boundingBox = NULL) {
if (!isset($boundingBox)) {
$boundingBox = $this->calcBBox($conf);
$boundingBox = $boundingBox[2];
}
if (isset($conf['breakSpace']) && $conf['breakSpace']) {
$breakSpace = $boundingBox['lineHeight'] * $conf['breakSpace'];
} else {
$breakSpace = $boundingBox['lineHeight'];
}
return $breakSpace;
}
/*********************************************
*
* Other GIFBUILDER objects related to TEXT
typo3/sysext/cms/tslib/class.tslib_gifbuilder.php (Arbeitskopie)
}
$this->combinedTextStrings[] = strip_tags($conf['text']);
// Max length = 100
$tlen = intval($conf['textMaxLength']) ? intval($conf['textMaxLength']) : 100;
$conf['text'] = substr($conf['text'],0,$tlen);
// Max length = 100 if automatic line braks are not defined:
if (!isset($conf['breakWidth']) || !$conf['breakWidth']) {
$tlen = (intval($conf['textMaxLength']) ? intval($conf['textMaxLength']) : 100);
$conf['text'] = substr($conf['text'], 0, $tlen);
}
if ((string)$conf['text']!='') {
// Char range map thingie:
......
* @access private
*/
function calcOffset($string) {
$numbers=explode(',',$string);
while(list($key,$val)=each($numbers)) {
$value = array();
$numbers = explode(',', $this->calculateFunctions($string));
foreach ($numbers as $key => $val) {
$val = trim($val);
if ((string)$val==(string)intval($val)) {
$value[$key]=intval($val);
if ((string)$val == (string)intval($val)) {
$value[$key] = intval($val);
} else {
$parts= t3lib_div::splitCalc($val,'+-*/%');
$value[$key]=0;
reset($parts);
while(list(,$part)=each($parts)) {
$theVal = $part[1];
$sign = $part[0];
if ((string)intval($theVal)==(string)$theVal) {
$theVal = intval($theVal);
} elseif ('['.substr($theVal,1,-1).']'==$theVal) {
$objParts=explode('.',substr($theVal,1,-1));
$theVal=0;
if (isset($this->objBB[$objParts[0]])) {
if ($objParts[1]=='w') {$theVal=intval($this->objBB[$objParts[0]][0]);}
if ($objParts[1]=='h') {$theVal=intval($this->objBB[$objParts[0]][1]);}
}
} else {
$theVal =0;
}
if ($sign=='-') {$value[$key]-=$theVal;}
if ($sign=='+') {$value[$key]+=$theVal;}
if ($sign=='/') {if (intval($theVal)) $value[$key]/=intval($theVal);}
if ($sign=='*') {$value[$key]*=$theVal;}
if ($sign=='%') {if (intval($theVal)) $value[$key]%=intval($theVal);}
}
$value[$key]=intval($value[$key]);
$value[$key] = intval($this->calculateValue($val));
}
}
$string = implode(',',$value);
return $string;
}
......
break;
}
}
/**
* Calculates the value by a given string that can be separated by commas.
* @param string $string: The string to be calculated (e.g. "2+2,[20.h]+13")
* @return string The calculated string (e.g. "4,23")
* @see calcOffset()
*/
protected function calculateValue($string) {
$calculatedValue = 0;
$parts = t3lib_div::splitCalc($string, '+-*/%');
foreach ($parts as $part) {
$theVal = $part[1];
$sign = $part[0];
if ((string)intval($theVal) == (string)$theVal) {
$theVal = intval($theVal);
} elseif ('[' . substr($theVal, 1, -1) . ']' == $theVal) {
$objParts=explode('.', substr($theVal, 1, -1));
$theVal = 0;
if (isset($this->objBB[$objParts[0]])) {
if ($objParts[1] == 'w') {
$theVal = intval($this->objBB[$objParts[0]][0]);
} elseif ($objParts[1] == 'h') {
$theVal = intval($this->objBB[$objParts[0]][1]);
} elseif ($objParts[1] == 'lineHeight') {
$theVal = intval($this->objBB[$objParts[0]][2]['lineHeight']);
}
}
} elseif (floatval($theVal)) {
$theVal = floatval($theVal);
} else {
$theVal = 0;
}
if ($sign == '-') {
$calculatedValue-= $theVal;
} elseif ($sign == '+') {
$calculatedValue+= $theVal;
} elseif ($sign == '/' && floatval($theVal)) {
$calculatedValue = round($calculatedValue / floatval($theVal));
} elseif ($sign == '*') {
$calculatedValue = round($calculatedValue * $theVal);
} elseif ($sign == '%' && intval($theVal)) {
$calculatedValue%= intval($theVal);
}
}
return $calculatedValue;
}
/**
* Calculates special functions:
* + max([10.h], [20.h]) -> gets the maximum of the given values
*
* @param string $string
* @return string Value string with the values of the special functions
*/
protected function calculateFunctions($string) {
if (preg_match_all('#max\(([^)]+)\)#', $string, $matches)) {
foreach ($matches[1] as $index => $maxExpression) {
$string = str_replace(
$matches[0][$index],
$this->calculateMaximum(
$maxExpression
),
$string
);
}
}
return $string;
}
/**
* Calculates the maximum of a set of values defined like "[10.h],[20.h],1000"
*
* @param string $string: The string to be used to calculate the maximum (e.g. "[10.h],[20.h]")
* @return integer The maxium value of the given comma separated and calculated values
*/
protected function calculateMaximum($string) {
$parts = t3lib_div::trimExplode(',', $this->calcOffset($string), true);
$maximum = (count($parts) ? max($parts) : 0);
return $maximum;
}
}
(2-2/4)