/** * Splitting a string for ImageTTFBBox up into an array where each part has its own configuration options. * * @param string UTF-8 string * @param array Split-rendering configuration from GIFBUILDER TEXT object. * @param integer Current fontsize * @param string Current font file * @return array Array with input string splitted according to configuration */ function splitString($string, $splitRendering, $fontSize, $fontFile) { // Initialize by setting the whole string and default configuration as the first entry. $result = array(); $result[] = array('str' => $string, 'fontSize' => $fontSize, 'fontFile' => $fontFile); // Traverse the split-rendering configuration: // Splitting will create more entries in $result with individual configurations. if (is_array($splitRendering)) { $sKeyArray = t3lib_TStemplate::sortedKeyList($splitRendering); // Traverse configured options: foreach ($sKeyArray as $key) { $cfg = $splitRendering[$key . '.']; // Process each type of split rendering keyword: switch ((string) $splitRendering[$key]) { case 'highlightWord': if (strlen($cfg['value'])) { $newResult = array(); // Traverse the current parts of the result array: foreach ($result as $part) { // Explode the string value by the word value to highlight: $explodedParts = explode($cfg['value'], $part['str']); foreach ($explodedParts as $c => $expValue) { if (strlen($expValue)) { $newResult[] = array_merge($part, array('str' => $expValue)); } if ($c + 1 < count($explodedParts)) { $newResult[] = array('str' => $cfg['value'], 'fontSize' => $cfg['fontSize'] ? $cfg['fontSize'] : $part['fontSize'], 'fontFile' => $cfg['fontFile'] ? $cfg['fontFile'] : $part['fontFile'], 'color' => $cfg['color'], 'xSpaceBefore' => $cfg['xSpaceBefore'], 'xSpaceAfter' => $cfg['xSpaceAfter'], 'ySpaceBefore' => $cfg['ySpaceBefore'], 'ySpaceAfter' => $cfg['ySpaceAfter']); } } } // Set the new result as result array: if (count($newResult)) { $result = $newResult; } } break; case 'charRange': if (strlen($cfg['value'])) { // Initialize range: $ranges = t3lib_div::trimExplode(',', $cfg['value'], 1); foreach ($ranges as $i => $rangeDef) { $ranges[$i] = t3lib_div::intExplode('-', $ranges[$i]); if (!isset($ranges[$i][1])) { $ranges[$i][1] = $ranges[$i][0]; } } $newResult = array(); // Traverse the current parts of the result array: foreach ($result as $part) { // Initialize: $currentState = -1; $bankAccum = ''; // Explode the string value by the word value to highlight: $utf8Chars = $this->singleChars($part['str']); foreach ($utf8Chars as $utfChar) { // Find number and evaluate position: $uNumber = $this->csConvObj->utf8CharToUnumber($utfChar); $inRange = 0; foreach ($ranges as $rangeDef) { if ($uNumber >= $rangeDef[0] && (!$rangeDef[1] || $uNumber <= $rangeDef[1])) { $inRange = 1; break; } } if ($currentState == -1) { $currentState = $inRange; } // Initialize first char // Switch bank: if ($inRange != $currentState && !t3lib_div::inList('32,10,13,9', $uNumber)) { // Set result: if (strlen($bankAccum)) { $newResult[] = array('str' => $bankAccum, 'fontSize' => $currentState && $cfg['fontSize'] ? $cfg['fontSize'] : $part['fontSize'], 'fontFile' => $currentState && $cfg['fontFile'] ? $cfg['fontFile'] : $part['fontFile'], 'color' => $currentState ? $cfg['color'] : '', 'xSpaceBefore' => $currentState ? $cfg['xSpaceBefore'] : '', 'xSpaceAfter' => $currentState ? $cfg['xSpaceAfter'] : '', 'ySpaceBefore' => $currentState ? $cfg['ySpaceBefore'] : '', 'ySpaceAfter' => $currentState ? $cfg['ySpaceAfter'] : ''); } // Initialize new settings: $currentState = $inRange; $bankAccum = ''; } // Add char to bank: $bankAccum .= $utfChar; } // Set result for FINAL part: if (strlen($bankAccum)) { $newResult[] = array('str' => $bankAccum, 'fontSize' => $currentState && $cfg['fontSize'] ? $cfg['fontSize'] : $part['fontSize'], 'fontFile' => $currentState && $cfg['fontFile'] ? $cfg['fontFile'] : $part['fontFile'], 'color' => $currentState ? $cfg['color'] : '', 'xSpaceBefore' => $currentState ? $cfg['xSpaceBefore'] : '', 'xSpaceAfter' => $currentState ? $cfg['xSpaceAfter'] : '', 'ySpaceBefore' => $currentState ? $cfg['ySpaceBefore'] : '', 'ySpaceAfter' => $currentState ? $cfg['ySpaceAfter'] : ''); } } // Set the new result as result array: if (count($newResult)) { $result = $newResult; } } break; } } } return $result; }