示例#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);
 }
示例#2
0
 /**
  * Get SVG style definition
  *
  * Returns a string with SVG style definitions created from color, 
  * fillstatus and line thickness.
  * 
  * @param ezcGraphColor $color Color
  * @param mixed $filled Filled
  * @param float $thickness Line thickness.
  * @return string Formatstring
  */
 protected function getStyle(ezcGraphColor $color, $filled = true, $thickness = 1.0)
 {
     switch (true) {
         case $color instanceof ezcGraphLinearGradient:
             $pattern = cairo_pattern_create_linear($color->startPoint->x, $color->startPoint->y, $color->endPoint->x, $color->endPoint->y);
             cairo_pattern_add_color_stop_rgba($pattern, 0, $color->startColor->red / 255, $color->startColor->green / 255, $color->startColor->blue / 255, 1 - $color->startColor->alpha / 255);
             cairo_pattern_add_color_stop_rgba($pattern, 1, $color->endColor->red / 255, $color->endColor->green / 255, $color->endColor->blue / 255, 1 - $color->endColor->alpha / 255);
             cairo_set_source($this->context, $pattern);
             cairo_fill($this->context);
             break;
         case $color instanceof ezcGraphRadialGradient:
             $pattern = cairo_pattern_create_radial(0, 0, 0, 0, 0, 1);
             cairo_pattern_add_color_stop_rgba($pattern, 0, $color->startColor->red / 255, $color->startColor->green / 255, $color->startColor->blue / 255, 1 - $color->startColor->alpha / 255);
             cairo_pattern_add_color_stop_rgba($pattern, 1, $color->endColor->red / 255, $color->endColor->green / 255, $color->endColor->blue / 255, 1 - $color->endColor->alpha / 255);
             // Scale pattern, and move it to the correct position
             $matrix = cairo_matrix_multiply($move = cairo_matrix_create_translate(-$color->center->x, -$color->center->y), $scale = cairo_matrix_create_scale(1 / $color->width, 1 / $color->height));
             cairo_pattern_set_matrix($pattern, $matrix);
             cairo_set_source($this->context, $pattern);
             cairo_fill($this->context);
             break;
         default:
             cairo_set_source_rgba($this->context, $color->red / 255, $color->green / 255, $color->blue / 255, 1 - $color->alpha / 255);
             break;
     }
     // Set line width
     cairo_set_line_width($this->context, $thickness);
     // Set requested fill state for context
     if ($filled) {
         cairo_fill_preserve($this->context);
     }
 }