Feature #20164 » 0010666_v3.patch

Administrator Admin, 2009-05-03 00:52

View differences:

t3lib/class.t3lib_stdgraphic.php (Arbeitskopie)
616 616
					if ($spacing || $wordSpacing)	{		// If any kind of spacing applys, we use this function:
617 617
						$this->SpacedImageTTFText($im, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, t3lib_stdGraphic::prependAbsolutePath($conf['fontFile']), $theText, $spacing, $wordSpacing, $conf['splitRendering.']);
618 618
					} else {
619
						$this->ImageTTFTextWrapper($im, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, $conf['fontFile'], $theText, $conf['splitRendering.']);
619
						// $this->ImageTTFTextWrapper($im, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, $conf['fontFile'], $theText, $conf['splitRendering.']);
620
						$this->renderTTFText($im, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, $conf['fontFile'], $theText, $conf['splitRendering.'], $conf);
620 621
					}
621 622
				}
622 623
			} else {		// NICETEXT::
......
641 642
				if ($spacing || $wordSpacing)	{		// If any kind of spacing applys, we use this function:
642 643
					$this->SpacedImageTTFText($maskImg, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, t3lib_stdGraphic::prependAbsolutePath($conf['fontFile']), $theText, $spacing, $wordSpacing, $conf['splitRendering.'],$sF);
643 644
				} else {
644
					$this->ImageTTFTextWrapper($maskImg, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, $conf['fontFile'], $theText, $conf['splitRendering.'],$sF);
645
					// $this->ImageTTFTextWrapper($maskImg, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, $conf['fontFile'], $theText, $conf['splitRendering.'],$sF);
646
					$this->renderTTFText($maskImg, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, $conf['fontFile'], $theText, $conf['splitRendering.'], $conf, $sF);
645 647
				}
646 648
				$this->ImageWrite($maskImg, $fileMask);
647 649
				ImageDestroy($maskImg);
......
778 780
			$x = ($charInf[2]-$charInf[0]);
779 781
			$y = ($charInf[1]-$charInf[7]);
780 782
		}
783
			// Set original lineHeight (used by line breaks):
784
		$theBBoxInfo['lineHeight'] = $y;
785

  
781 786
		if ($spacing || $wordSpacing)	{		// If any kind of spacing applys, we use this function:
782 787
			$x=0;
783 788
			if (!$spacing && $wordSpacing)	{
......
797 802
					$x+=$charW+(($char==' ')?$wordSpacing:$spacing);
798 803
				}
799 804
			}
805
		} elseif (isset($conf['breakWidth']) && $conf['breakWidth'] && $this->getRenderedTextWidth($conf['text'], $conf) > $conf['breakWidth']) {
806
			$maxWidth = 0;
807
			$currentWidth = 0;
808
			$breakWidth = $conf['breakWidth'];
809
			$breakSpace = $this->getBreakSpace($conf, $theBBoxInfo);
810

  
811
			$wordPairs = $this->getWordPairsForLineBreak($conf['text']);
812
				// Iterate through all word pairs:
813
			foreach ($wordPairs as $index => $wordPair) {
814
				$wordWidth = $this->getRenderedTextWidth($wordPair, $conf);
815
				if ($index == 0 || $currentWidth + $wordWidth <= $breakWidth) {
816
					$currentWidth+= $wordWidth;
817
				} else {
818
					$maxWidth = max($maxWidth, $currentWidth);
819
					$y+= $breakSpace;
820
						// Restart:
821
					$currentWidth = $wordWidth;
822
				}
823
			}
824
			$x = max($maxWidth, $currentWidth) * $sF;
800 825
		}
801 826

  
802
		if ($sF>1) {
803
			$x = ceil($x/$sF);
804
			$y = ceil($y/$sF);
827
		if ($sF > 1) {
828
			$x = ceil($x / $sF);
829
			$y = ceil($y / $sF);
805 830
			if (is_array($theBBoxInfo))	{
806
				reset($theBBoxInfo);
807
				while(list($key,$val)=each($theBBoxInfo))	{
808
					$theBBoxInfo[$key]=ceil($theBBoxInfo[$key]/$sF);
831
				foreach ($theBBoxInfo as &$value) {
832
					$value = ceil($value / $sF);
809 833
				}
810 834
			}
811 835
		}
812
		return array($x,$y,$theBBoxInfo);
836
		return array($x, $y, $theBBoxInfo);
813 837
	}
814 838

  
815 839
	/**
......
1237 1261
		return $sF;
1238 1262
	}
1239 1263

  
1264
	/**
1265
	 * Renders a regular text and takes care of a possible line break automatically.
1266
	 *
1267
	 * @param	pointer		(See argument for PHP function imageTTFtext())
1268
	 * @param	integer		(See argument for PHP function imageTTFtext())
1269
	 * @param	integer		(See argument for PHP function imageTTFtext())
1270
	 * @param	integer		(See argument for PHP function imageTTFtext())
1271
	 * @param	integer		(See argument for PHP function imageTTFtext())
1272
	 * @param	integer		(See argument for PHP function imageTTFtext())
1273
	 * @param	string		(See argument for PHP function imageTTFtext())
1274
	 * @param	string		(See argument for PHP function imageTTFtext()). UTF-8 string, possibly with entities in.
1275
	 * @param	array		Split-rendering configuration
1276
	 * @param	integer		Scale factor
1277
	 * @param	array		$conf: The configuration
1278
	 * @return	void
1279
	 */
1280
	protected function renderTTFText(&$im, $fontSize, $angle, $x, $y, $color, $fontFile, $string, $splitRendering, $conf, $sF = 1) {
1281
		if (isset($conf['breakWidth']) && $conf['breakWidth'] && $this->getRenderedTextWidth($string, $conf) > $conf['breakWidth']) {
1282
			$phrase = '';
1283
			$currentWidth = 0;
1240 1284

  
1285
			$breakWidth = $conf['breakWidth'];
1286
			$breakSpace = $this->getBreakSpace($conf);
1241 1287

  
1288
			$wordPairs = $this->getWordPairsForLineBreak($string);
1289
				// Iterate through all word pairs:
1290
			foreach ($wordPairs as $index => $wordPair) {
1291
				$wordWidth = $this->getRenderedTextWidth($wordPair, $conf);
1292
				if ($index == 0 || $currentWidth + $wordWidth <= $breakWidth) {
1293
					$currentWidth+= $wordWidth;
1294
					$phrase.= $wordPair;
1295
				} else {
1296
						// Render the current phrase that is below breakWidth:
1297
					$this->ImageTTFTextWrapper($im, $fontSize, $angle, $x, $y, $color, $fontFile, $phrase, $splitRendering, $sF);
1298
						// Calculate the news height offset:
1299
					$y+= $breakSpace;
1300
						// Restart the phrase:
1301
					$currentWidth = $wordWidth;
1302
					$phrase = $wordPair;
1303
				}
1304
			}
1305
				// Render the remaining phrase:
1306
			if ($currentWidth) {
1307
				$this->ImageTTFTextWrapper($im, $fontSize, $angle, $x, $y, $color, $fontFile, $phrase, $splitRendering, $sF);
1308
			}
1309
		} else {
1310
			$this->ImageTTFTextWrapper($im, $fontSize, $angle, $x, $y, $color, $fontFile, $string, $splitRendering, $sF);
1311
		}
1312
	}
1242 1313

  
1314
	/**
1315
	 * Gets the word pairs used for automatic line breaks.
1316
	 *
1317
	 * @param	string		$string
1318
	 * @return	array
1319
	 */
1320
	protected function getWordPairsForLineBreak($string) {
1321
		$wordPairs = array();
1243 1322

  
1323
		$wordsArray = preg_split('#([ -.,!:]+)#', $string, -1,  PREG_SPLIT_DELIM_CAPTURE);
1324
		$wordsCount = count($wordsArray);
1325
		for ($index=0; $index < $wordsCount; $index+= 2) {
1326
			$wordPairs[] = $wordsArray[$index] . $wordsArray[$index + 1];
1327
		}
1244 1328

  
1329
		return $wordPairs;
1330
	}
1245 1331

  
1332
	/**
1333
	 * Gets the rendered text width.
1334
	 *
1335
	 * @param	string		$text
1336
	 * @param	array		$conf
1337
	 * @param	integer		
1338
	 */
1339
	protected function getRenderedTextWidth($text, $conf) {
1340
		$bounds = $this->ImageTTFBBoxWrapper($conf['fontSize'], $conf['angle'], $conf['fontFile'], $this->recodeString($text), $conf['splitRendering.']);
1341
		if ($conf['angle']< 0) {
1342
			$pixelWidth = abs($bounds[4]-$bounds[0]);
1343
		} elseif ($conf['angle'] > 0) {
1344
			$pixelWidth = abs($bounds[2]-$bounds[6]);
1345
		} else {
1346
			$pixelWidth = abs($bounds[4]-$bounds[6]);
1347
		}
1348
		return $pixelWidth;
1349
	}
1246 1350

  
1351
	/**
1352
	 * Gets the break space for each new line.
1353
	 *
1354
	 * @param	array		$conf: TypoScript configuration for the currently rendered object
1355
	 * @param	array		$boundingBox: The bounding box the the currently rendered object
1356
	 * @return	integer		The break space
1357
	 */
1358
	protected function getBreakSpace($conf, array $boundingBox = NULL) {
1359
		if (!isset($boundingBox)) {
1360
			$boundingBox = $this->calcBBox($conf);
1361
			$boundingBox = $boundingBox[2];
1362
		}
1247 1363

  
1364
		if (isset($conf['breakSpace']) && $conf['breakSpace']) {
1365
			$breakSpace = $boundingBox['lineHeight'] * $conf['breakSpace'];
1366
		} else {
1367
			$breakSpace = $boundingBox['lineHeight'];
1368
		}
1248 1369

  
1370
		return $breakSpace;
1371
	}
1249 1372

  
1373

  
1374

  
1375

  
1376

  
1377

  
1378

  
1379

  
1380

  
1381

  
1382

  
1250 1383
	/*********************************************
1251 1384
	 *
1252 1385
	 * Other GIFBUILDER objects related to TEXT
typo3/sysext/cms/tslib/class.tslib_gifbuilder.php (Arbeitskopie)
507 507
		}
508 508
		$this->combinedTextStrings[] = strip_tags($conf['text']);
509 509

  
510
			// Max length = 100
511
		$tlen = intval($conf['textMaxLength']) ? intval($conf['textMaxLength']) : 100;
512
		$conf['text'] = substr($conf['text'],0,$tlen);
510
			// Max length = 100 if automatic line braks are not defined:
511
		if (!isset($conf['breakWidth']) || !$conf['breakWidth']) {
512
			$tlen = (intval($conf['textMaxLength']) ? intval($conf['textMaxLength']) : 100);
513
			$conf['text'] = substr($conf['text'], 0, $tlen);
514
		}
513 515
		if ((string)$conf['text']!='')	{
514 516

  
515 517
				// Char range map thingie:
......
575 577
			if ((string)$val == (string)intval($val)) {
576 578
				$value[$key] = intval($val);
577 579
			} else {
578
				$value[$key] = intval($this->calculateValue($val));
580
				$value[$key] = $this->calculateValue($val);
579 581
			}
580 582
		}
581 583

  
......
681 683
						$theVal = $this->objBB[$objParts[0]][0];
682 684
					} elseif ($objParts[1] == 'h') {
683 685
						$theVal = $this->objBB[$objParts[0]][1];
686
					} elseif ($objParts[1] == 'lineHeight') {
687
						$theVal = $this->objBB[$objParts[0]][2]['lineHeight'];
684 688
					}
685 689
					$theVal = intval($theVal);
686 690
				}
691
			} elseif (floatval($theVal)) {
692
				$theVal = floatval($theVal);
687 693
			} else {
688 694
				$theVal = 0;
689 695
			}
......
701 707
			}
702 708
		}
703 709

  
704
		return $calculatedValue;
710
		return round($calculatedValue);
705 711
	}
706 712

  
707 713
	/**
(4-4/4)