/[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.19.2.17, Thu May 14 12:36:47 2009 UTC revision 1.19.2.18, Wed May 20 00:03:48 2009 UTC
# Line 1  Line 1 
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
# Line 586  function textimage_wrap_text($text, $fon Line 586  function textimage_wrap_text($text, $fon
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 {
# Line 629  function textimage_wrap_text($text, $fon Line 629  function textimage_wrap_text($text, $fon
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

Legend:
Removed from v.1.19.2.17  
changed lines
  Added in v.1.19.2.18

  ViewVC Help
Powered by ViewVC 1.1.2