| 1 |
<?php |
<?php |
| 2 |
// $Id: textimage.module,v 1.19.2.16 2009/05/14 03:56:38 deciphered Exp $ |
// $Id: textimage.module,v 1.19.2.17 2009/05/14 12:36:47 deciphered Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 586 |
// Note: we count in bytes for speed reasons, but maintain character boundaries. |
// Note: we count in bytes for speed reasons, but maintain character boundaries. |
| 587 |
while (true) { |
while (true) { |
| 588 |
// Find the next wrap point (always after trailing whitespace). |
// Find the next wrap point (always after trailing whitespace). |
| 589 |
if (preg_match('/['. PREG_CLASS_PUNCTUATION .']['. PREG_CLASS_SEPARATOR .']*|['. PREG_CLASS_SEPARATOR .']+/u', $text, $match, PREG_OFFSET_CAPTURE, $end)) { |
if (drupal_preg_match('/['. PREG_CLASS_PUNCTUATION .']['. PREG_CLASS_SEPARATOR .']*|['. PREG_CLASS_SEPARATOR .']+/u', $text, $match, PREG_OFFSET_CAPTURE, $end)) { |
| 590 |
$end = $match[0][1] + drupal_strlen($match[0][0]); |
$end = $match[0][1] + drupal_strlen($match[0][0]); |
| 591 |
} |
} |
| 592 |
else { |
else { |
| 629 |
} |
} |
| 630 |
|
|
| 631 |
/** |
/** |
| 632 |
|
* Unicode-safe preg_match(). |
| 633 |
|
* |
| 634 |
|
* Search subject for a match to the regular expression given in pattern, |
| 635 |
|
* but return offsets in characters, where preg_match would return offsets |
| 636 |
|
* in bytes. |
| 637 |
|
* |
| 638 |
|
* @see http://php.net/manual/en/function.preg-match.php |
| 639 |
|
*/ |
| 640 |
|
if (!function_exists('drupal_preg_match')) { |
| 641 |
|
function drupal_preg_match($pattern, $subject, &$matches, $flags = NULL, $offset = 0) { |
| 642 |
|
// Convert the offset value from characters to bytes. |
| 643 |
|
$offset = strlen(drupal_substr($subject, 0, $offset, $encoding)); |
| 644 |
|
|
| 645 |
|
$return_value = preg_match($pattern, $subject, $matches, $flags, $offset); |
| 646 |
|
|
| 647 |
|
if ($return_value && ($flags & PREG_OFFSET_CAPTURE)) { |
| 648 |
|
foreach ($matches as &$match) { |
| 649 |
|
// Convert the offset returned by preg_match from bytes back to characters. |
| 650 |
|
$match[1] = drupal_strlen(substr($subject, 0, $match[1])); |
| 651 |
|
} |
| 652 |
|
} |
| 653 |
|
return $return_value; |
| 654 |
|
} |
| 655 |
|
} |
| 656 |
|
|
| 657 |
|
/** |
| 658 |
* Generate an image containing text with the given parameters. |
* Generate an image containing text with the given parameters. |
| 659 |
* |
* |
| 660 |
* @return $image |
* @return $image |