示例#1
0
文件: Box.php 项目: molovo/graphite
 /**
  * Prepare the content for rendering.
  *
  * @param string|array $content A string, or an array of strings
  *
  * @return array
  */
 private function prepareContent($content)
 {
     // If a string is passed, separate it by newline characters
     if (is_string($content)) {
         $content = explode("\n", $content);
     }
     // Loop through the lines, and set the box's width to that
     // of the longest line
     $this->width = 0;
     foreach ($content as $line) {
         $len = mb_strlen($this->graphite->strip($line), 'UTF-8');
         if ($len > $this->width) {
             $this->width = $len;
         }
     }
     // Pad each line of the content to the box's width
     foreach ($content as $i => $line) {
         $len = mb_strlen($this->graphite->strip($line), 'UTF-8');
         $content[$i] = $line . $this->graphite->repeat(' ', $this->width - $len);
     }
     // Store the array of lines
     return $this->content = $content;
 }