| 1 |
<?php |
<?php |
| 2 |
// $Id: textimage.module,v 1.37 2009/05/14 03:53:24 deciphered Exp $ |
// $Id: textimage.module,v 1.38 2009/05/14 12:32:20 deciphered Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 614 |
// Note: we count in bytes for speed reasons, but maintain character boundaries. |
// Note: we count in bytes for speed reasons, but maintain character boundaries. |
| 615 |
while (true) { |
while (true) { |
| 616 |
// Find the next wrap point (always after trailing whitespace). |
// Find the next wrap point (always after trailing whitespace). |
| 617 |
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)) { |
| 618 |
$end = $match[0][1] + drupal_strlen($match[0][0]); |
$end = $match[0][1] + drupal_strlen($match[0][0]); |
| 619 |
} |
} |
| 620 |
else { |
else { |
| 657 |
} |
} |
| 658 |
|
|
| 659 |
/** |
/** |
| 660 |
|
* Unicode-safe preg_match(). |
| 661 |
|
* |
| 662 |
|
* Search subject for a match to the regular expression given in pattern, |
| 663 |
|
* but return offsets in characters, where preg_match would return offsets |
| 664 |
|
* in bytes. |
| 665 |
|
* |
| 666 |
|
* @see http://php.net/manual/en/function.preg-match.php |
| 667 |
|
*/ |
| 668 |
|
if (!function_exists('drupal_preg_match')) { |
| 669 |
|
function drupal_preg_match($pattern, $subject, &$matches, $flags = NULL, $offset = 0) { |
| 670 |
|
// Convert the offset value from characters to bytes. |
| 671 |
|
$offset = strlen(drupal_substr($subject, 0, $offset, $encoding)); |
| 672 |
|
|
| 673 |
|
$return_value = preg_match($pattern, $subject, $matches, $flags, $offset); |
| 674 |
|
|
| 675 |
|
if ($return_value && ($flags & PREG_OFFSET_CAPTURE)) { |
| 676 |
|
foreach ($matches as &$match) { |
| 677 |
|
// Convert the offset returned by preg_match from bytes back to characters. |
| 678 |
|
$match[1] = drupal_strlen(substr($subject, 0, $match[1])); |
| 679 |
|
} |
| 680 |
|
} |
| 681 |
|
return $return_value; |
| 682 |
|
} |
| 683 |
|
} |
| 684 |
|
|
| 685 |
|
/** |
| 686 |
* Generate an image containing text with the given parameters. |
* Generate an image containing text with the given parameters. |
| 687 |
* |
* |
| 688 |
* @return $image |
* @return $image |