Exemplo n.º 1
0
 /**
  * テキストを合成
  *
  * <pre>
  * 指定位置にテキストを追加します。$alignに右寄せ(_BEAR_ALIGN_RIGHT)を指定
  * すると$xは右からのスペースになります。fontはターミナルでfc-listで得られるフ
  * ォントの名前を使用します。イタリックは$slantにCAIRO_FONT_SLANT_ITALIC,
  *  ボールドは$weightにCAIRO_FONT_WEIGHT_BOLDを指定します。
  * </pre>
  *
  * @param string $text      テキスト
  * @param int    $x         X座標
  * @param int    $y         Y座標
  * @param int    $size      フォントサイズ
  * @param int    $align     BEAR_Img::LEFT | BEAR_Img::CENTER | BEAR_Img::RIGHT
  * @param array  $colorOne  内側カラー array($r, $g, $b)
  * @param array  $colorTwo  アウトラインカラー array($r, $g, $b)
  * @param string $font      フォント
  * @param float  $textAlpha アルファブレンディング(0..1)
  * @param float  $lineWidth ラインの幅
  * @param int    $slant     CAIRO_FONT_SLANT_NORMAL | CAIRO_FONT_SLANT_ITALIC
  * @param int    $weight    CAIRO_FONT_WEIGHT_NORMAL | CAIRO_FONT_WEIGHT_BOLD
  *
  * @return void
  */
 public function addText($text, $x = 0, $y = 0, $size = 120, $align = BEAR_Img::LEFT, $colorOne = false, $colorTwo = false, $font = 'Arial', $textAlpha = 0.85, $lineWidth = 0.75, $slant = CAIRO_FONT_SLANT_NORMAL, $weight = CAIRO_FONT_WEIGHT_NORMAL)
 {
     //フォントカラー
     cairo_set_source_rgb($this->image, 0.0, 0.0, 1.0);
     cairo_select_font_face($this->image, $font, $slant, $weight);
     cairo_set_font_size($this->image, $size);
     $this->_fontInfo = cairo_text_extents($this->image, $text);
     $this->_log->log('cairo _fontInfo', $this->_fontInfo);
     switch ($align) {
         case BEAR_Img::CENTER:
             $x = $this->_srcWidth / 2 - $this->_fontInfo['x_advance'] / 2 + $x;
             break;
         case BEAR_Img::RIGHT:
             $x = $this->_srcWidth - $this->_fontInfo['x_advance'] - $x;
             break;
         case BEAR_Img::LEFT:
         default:
             break;
     }
     cairo_move_to($this->image, $x, $y + $size);
     cairo_text_path($this->image, $text);
     //テキスト中身
     if ($colorOne) {
         $colorOneZero = $colorOne[0] / 255;
         $colorOneOne = $colorOne[1] / 255;
         $colorOneTwo = $colorOne[2] / 255;
         cairo_set_source_rgba($this->image, $colorOneZero, $colorOneOne, $colorOneTwo, $textAlpha);
     } else {
         cairo_set_source_rgba($this->image, 1, 1, 1, $textAlpha);
     }
     cairo_fill_preserve($this->image);
     //テキストボーダー
     if ($colorTwo) {
         $colorTwoZero = $colorTwo[0] / 255;
         $colorTwoOne = $colorTwo[1] / 255;
         $colorTwoTwo = $colorTwo[2] / 255;
         cairo_set_source_rgba($this->image, $colorTwoZero, $colorTwoOne, $colorTwoTwo, $textAlpha);
     } else {
         cairo_set_source_rgba($this->image, 0, 0, 1, $textAlpha);
     }
     cairo_set_line_width($this->image, $lineWidth);
     //cairo_stroke_preserve($this->image);
     cairo_stroke($this->image);
     //cairo_show_page($this->image);
 }
Exemplo n.º 2
0
 /**
  * Draws a circular arc consisting of several minor steps on the bounding 
  * lines.
  * 
  * @param ezcGraphCoordinate $center 
  * @param mixed $width 
  * @param mixed $height 
  * @param mixed $size 
  * @param mixed $startAngle 
  * @param mixed $endAngle 
  * @param ezcGraphColor $color 
  * @param bool $filled 
  * @return string Element id
  */
 protected function simulateCircularArc(ezcGraphCoordinate $center, $width, $height, $size, $startAngle, $endAngle, ezcGraphColor $color, $filled)
 {
     for ($tmpAngle = min(ceil($startAngle / 180) * 180, $endAngle); $tmpAngle <= $endAngle; $tmpAngle = min(ceil($startAngle / 180 + 1) * 180, $endAngle)) {
         $path = cairo_new_path($this->context);
         cairo_move_to($this->context, $center->x + cos(deg2rad($startAngle)) * $width / 2, $center->y + sin(deg2rad($startAngle)) * $height / 2);
         // @TODO: Use cairo_curve_to()
         for ($angle = $startAngle; $angle <= $tmpAngle; $angle = min($angle + $this->options->circleResolution, $tmpAngle)) {
             cairo_line_to($this->context, $center->x + cos(deg2rad($angle)) * $width / 2, $center->y + sin(deg2rad($angle)) * $height / 2 + $size);
             if ($angle === $tmpAngle) {
                 break;
             }
         }
         for ($angle = $tmpAngle; $angle >= $startAngle; $angle = max($angle - $this->options->circleResolution, $startAngle)) {
             cairo_line_to($this->context, $center->x + cos(deg2rad($angle)) * $width / 2, $center->y + sin(deg2rad($angle)) * $height / 2);
             if ($angle === $startAngle) {
                 break;
             }
         }
         cairo_close_path($this->context);
         $this->getStyle($color, $filled);
         cairo_stroke($this->context);
         $startAngle = $tmpAngle;
         if ($tmpAngle === $endAngle) {
             break;
         }
     }
 }