Exemplo n.º 1
0
function trim_text($str, $words = 10)
{
    $s = word_split($str, $words);
    if (strlen($s) < strlen($str)) {
        $s .= '...';
    }
    return $s;
}
Exemplo n.º 2
0
 function out_index()
 {
     $left = $this->width - 315;
     //$top = 25;
     //1. 計算能放下多少 wpt,  剩下折行, 最多 $line_len 字
     //第二行超過就變成 …
     // $total_row = count($this->waypoint);
     $line_len = 24;
     $j = 1;
     $index = 1;
     mb_internal_encoding('UTF-8');
     $line[0] = array('index' => 'No.', 'data' => "座標及說明");
     foreach ($this->waypoint as $wpt) {
         $str = sprintf("%d,%d %s", $wpt['tw67'][0], $wpt['tw67'][1], trim($wpt['name']));
         $d = word_split($str, $line_len);
         for ($i = 0; $i < count($d); $i++) {
             if ($i == 0) {
                 $line[$j]['index'] = $index++;
             } else {
                 $line[$j]['index'] = " ";
             }
             $line[$j]['data'] = $d[$i];
             $j++;
         }
     }
     //error_log(print_r($line,true));
     $total_row = count($line);
     // 總高度不能超過
     $total = floor(($this->height - 50) / $this->fontsize) - 1;
     if ($total_row > $total) {
         $total_row = $total;
     }
     //error_log("total_row=".$total_row);
     $height = $this->fontsize * $total_row + 2;
     $top = 25 + ($this->height - 50 - $height) / 2;
     // vcenter
     echo "<g id=\"index\">\n";
     // 2. 畫出框框
     printf("    <rect id='index_frame' x='%d' y='%d' height='%d' width='300' fill='#FFFFFF'/>\n", $left, $top, $height);
     printf("     <text id='index_col_num' x='%d' y='%d' font-size='%d' font-weight='bold' fill='#000000'>\n", $left, $top, $this->fontsize);
     $j = 0;
     // 號碼
     foreach ($line as $useless) {
         if ($j > $total_row) {
             break;
         }
         //printf("        <tspan x='%d' y='%d'>%s</tspan>\n",$left, ($j*$this->fontsize)+$top, $j++ );
         printf("        <tspan x='%d' y='%d'>%s</tspan>\n", $left, ($j + 1) * $this->fontsize + $top, $line[$j++]['index']);
     }
     echo "</text>\n";
     $left2 = $left + 2 * $this->fontsize;
     printf("<text id='index_col_name' x='%d' y='%d' font-size='%d' fill='#000000'>\n", $left2, $top, $this->fontsize);
     $j = 0;
     foreach ($line as $useless) {
         if ($j > $total_row) {
             break;
         }
         // printf("<tspan x='%d' y='%d'>%d,%d %s</tspan>\n",$left2, ($j*$this->fontsize)+ $top, $wpt['tw67'][0],$wpt['tw67'][1],$wpt['name']);
         printf("<tspan x='%d' y='%d'>%s</tspan>\n", $left2, ($j + 1) * $this->fontsize + $top, $line[$j]['data']);
         $j++;
     }
     echo "</text></g>";
 }
Exemplo n.º 3
0
/**
 * @brief Trim text to a susbtring of a given number of words, and append '…' if string is longer
 * than substring.
 *
 * @param str String to split
 * @param words Number of words
 *
 * @return String of subset of words
 *
 */
function trim_text($str, $words = 10)
{
    $s = word_split($str, $words);
    if (mb_strlen($s) < mb_strlen($str)) {
        $s .= '…';
    }
    return $s;
}