/** * テキストを合成 * * <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); }
/** * Render text depending of font type and available font extensions * * @param string $id * @param string $text * @param string $font * @param ezcGraphColor $color * @param ezcGraphCoordinate $position * @param float $size * @param float $rotation * @return void */ protected function renderText($text, $font, ezcGraphColor $color, ezcGraphCoordinate $position, $size, $rotation = null) { cairo_select_font_face($this->context, $font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_size($this->context, $size); // Store current state of context cairo_save($this->context); cairo_move_to($this->context, 0, 0); if ($rotation !== null) { // Move to the center cairo_translate($this->context, $rotation->getCenter()->x, $rotation->getCenter()->y); // Rotate around text center cairo_rotate($this->context, deg2rad($rotation->getRotation())); // Center the text cairo_translate($this->context, $position->x - $rotation->getCenter()->x, $position->y - $rotation->getCenter()->y - $size * 0.15); } else { cairo_translate($this->context, $position->x, $position->y - $size * 0.15); } cairo_new_path($this->context); $this->getStyle($color, true); cairo_show_text($this->context, $text); cairo_stroke($this->context); // Restore state of context cairo_restore($this->context); }