/[drupal]/contributions/modules/textimage/textimage.module
ViewVC logotype

Diff of /contributions/modules/textimage/textimage.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.38, Thu May 14 12:32:20 2009 UTC revision 1.39, Wed May 20 00:01:23 2009 UTC
# Line 1  Line 1 
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
# Line 614  function textimage_wrap_text($text, $fon Line 614  function textimage_wrap_text($text, $fon
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 {
# Line 657  function textimage_wrap_text($text, $fon Line 657  function textimage_wrap_text($text, $fon
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

Legend:
Removed from v.1.38  
changed lines
  Added in v.1.39

  ViewVC Help
Powered by ViewVC 1.1.2