コード例 #1
0
ファイル: gd.class.php プロジェクト: greench/prestashop
 public function getTextHeight(awText $text)
 {
     $font = $text->getFont();
     if ($font instanceof awPHPFont) {
         $fontDriver = $this->phpFontDriver;
     } else {
         $fontDriver = $this->fileFontDriver;
     }
     return $fontDriver->getTextHeight($text, $this);
 }
コード例 #2
0
ファイル: Drawer.class.php プロジェクト: remyyounes/dolibarr
	/**
	 * Draw a string
	 *
	 * @var awText $text Text to print
	 * @param awPoint $point Draw the text at this point
	 */
	public function string(awText $text, awPoint $point) {
		
		$font = $text->getFont();
		
		if($text->getBackground() !== NULL or $text->border->visible()) {
		
			list($left, $right, $top, $bottom) = $text->getPadding();
			
			$width = $font->getTextWidth($text);
			$height = $font->getTextHeight($text);
			
			$x1 = floor($point->x - $left);
			$y1 = floor($point->y - $top);
			$x2 = $x1 + $width + $left + $right;
			$y2 = $y1 + $height + $top + $bottom;
			
			$this->filledRectangle(
				$text->getBackground(),
				awLine::build($x1, $y1, $x2, $y2)
			);
			
			$text->border->rectangle(
				$this,
				new awPoint($x1 - 1, $y1 - 1),
				new awPoint($x2 + 1, $y2 + 1)
			);
			
		}
		
		$font->draw($this, $point, $text);
		
	}
コード例 #3
0
ファイル: Driver.class.php プロジェクト: carriercomm/jbs
 private function getMingTextWidth(awText $text)
 {
     $font = $text->getFont();
     if ($font->getExtension() === NULL) {
         $font->setExtension('fdb');
     }
     $flashFont = new SWFFont(ARTICHOW_FONT . '/' . $font->name . '.' . $font->getExtension());
     $flashText = new SWFText();
     $flashText->setFont($flashFont);
     return $flashText->getWidth($text->getText());
 }
コード例 #4
0
 /**
  * Get a text from the labele
  *
  * @param mixed $key Key in the array text
  * @return Text
  */
 public function getText($key)
 {
     if (is_array($this->texts) and array_key_exists($key, $this->texts)) {
         $value = $this->texts[$key];
         if (is_string($this->function)) {
             $value = call_user_func($this->function, $value);
         }
         $text = new awText($value);
         $text->setFont($this->font);
         $text->setAngle($this->angle);
         $text->setColor($this->color);
         if ($this->background instanceof awColor) {
             $text->setBackgroundColor($this->background);
         } else {
             if ($this->background instanceof awGradient) {
                 $text->setBackgroundGradient($this->background);
             }
         }
         $text->border = $this->border;
         if ($this->padding !== NULL) {
             call_user_func_array(array($text, 'setPadding'), $this->padding);
         }
         return $text;
     } else {
         return NULL;
     }
 }
コード例 #5
0
 function draw($drawer)
 {
     if ($this->hide) {
         return;
     }
     $count = $this->count();
     // No legend to print
     if ($count === 0) {
         return;
     }
     // Get text widths and heights of each element of the legend
     $widths = array();
     $heights = array();
     $texts = array();
     for ($i = 0; $i < $count; $i++) {
         list(, $title, ) = $this->legends[$i];
         $text = new awText($title, $this->textFont, $this->textColor, 0);
         $font = $text->getFont();
         $widths[$i] = $font->getTextWidth($text) + $this->textMargin->left + $this->textMargin->right;
         $heights[$i] = $font->getTextHeight($text);
         $texts[$i] = $text;
     }
     // Maximum height of the font used
     $heightMax = array_max($heights);
     // Get number of columns
     if ($this->columns !== NULL) {
         $columns = $this->columns;
     } else {
         if ($this->rows !== NULL) {
             $columns = ceil($count / $this->rows);
         } else {
             $columns = $count;
         }
     }
     // Number of  rows
     $rows = (int) ceil($count / $columns);
     // Get maximum with of each column
     $widthMax = array();
     for ($i = 0; $i < $count; $i++) {
         // Get column width
         $column = $i % $columns;
         if (array_key_exists($column, $widthMax) === FALSE) {
             $widthMax[$column] = $widths[$i];
         } else {
             $widthMax[$column] = max($widthMax[$column], $widths[$i]);
         }
     }
     $width = $this->padding[0] + $this->padding[1] - $this->space;
     for ($i = 0; $i < $columns; $i++) {
         $width += $this->space + 5 + 10 + $widthMax[$i];
     }
     $height = ($heightMax + $this->space) * $rows - $this->space + $this->padding[2] + $this->padding[3];
     // Look for legends position
     list($x, $y) = $drawer->getSize();
     $p = new awPoint($this->position->x * $x, $this->position->y * $y);
     switch ($this->hAlign) {
         case LEGEND_CENTER:
             $p->x -= $width / 2;
             break;
         case LEGEND_RIGHT:
             $p->x -= $width;
             break;
     }
     switch ($this->vAlign) {
         case LEGEND_MIDDLE:
             $p->y -= $height / 2;
             break;
         case LEGEND_BOTTOM:
             $p->y -= $height;
             break;
     }
     // Draw legend shadow
     $this->shadow->draw($drawer, $p, $p->move($width, $height), SHADOW_OUT);
     // Draw legends base
     $this->drawBase($drawer, $p, $width, $height);
     // Draw each legend
     for ($i = 0; $i < $count; $i++) {
         list($component, $title, $type) = $this->legends[$i];
         $column = $i % $columns;
         $row = (int) floor($i / $columns);
         // Get width of all previous columns
         $previousColumns = 0;
         for ($j = 0; $j < $column; $j++) {
             $previousColumns += $this->space + 10 + 5 + $widthMax[$j];
         }
         // Draw legend text
         $drawer->string($texts[$i], $p->move($this->padding[0] + $previousColumns + 10 + 5 + $this->textMargin->left, $this->padding[2] + $row * ($heightMax + $this->space) + $heightMax / 2 - $heights[$i] / 2));
         // Draw legend icon
         switch ($type) {
             case LEGEND_LINE:
             case LEGEND_MARK:
             case LEGEND_MARKONLY:
                 // Get vertical position
                 $x = $this->padding[0] + $previousColumns;
                 $y = $this->padding[2] + $row * ($heightMax + $this->space) + $heightMax / 2 - $component->getLegendLineThickness();
                 // Draw two lines
                 if ($component->getLegendLineColor() !== NULL) {
                     $color = $component->getLegendLineColor();
                     if (is_a($color, 'awColor') and $type !== LEGEND_MARKONLY) {
                         $drawer->line($color, new awLine($p->move($x, $y + $component->getLegendLineThickness() / 2), $p->move($x + 10, $y + $component->getLegendLineThickness() / 2), $component->getLegendLineStyle(), $component->getLegendLineThickness()));
                         $color->free();
                         unset($color);
                     }
                 }
                 if ($type === LEGEND_MARK or $type === LEGEND_MARKONLY) {
                     $mark = $component->getLegendMark();
                     if ($mark !== NULL) {
                         $mark->draw($drawer, $p->move($x + 5.5, $y + $component->getLegendLineThickness() / 2));
                     }
                     unset($mark);
                 }
                 break;
             case LEGEND_BACKGROUND:
                 // Get vertical position
                 $x = $this->padding[0] + $previousColumns;
                 $y = $this->padding[2] + $row * ($heightMax + $this->space) + $heightMax / 2 - 5;
                 $from = $p->move($x, $y);
                 $to = $p->move($x + 10, $y + 10);
                 $background = $component->getLegendBackground();
                 if ($background !== NULL) {
                     $drawer->filledRectangle($background, new awLine($from, $to));
                     // Draw rectangle border
                     $this->border->rectangle($drawer, $from->move(0, 0), $to->move(0, 0));
                 }
                 unset($background, $from, $to);
                 break;
         }
     }
 }
コード例 #6
0
ファイル: Driver.class.php プロジェクト: greench/prestashop
 private function getGDTextHeight(awText $text)
 {
     $font = $text->getFont();
     if ($font->getExtension() === NULL) {
         $font->setExtension('ttf');
     }
     $filePath = $font->getName() . '.' . $font->getExtension();
     $box = imagettfbbox($font->getSize(), $text->getAngle(), $filePath, $text->getText());
     if ($box === FALSE) {
         awImage::drawError("Class FileFontDriver: Unable to get font height (GD).");
     }
     list(, , , $y2, , , , $y1) = $box;
     return abs($y2 - $y1);
 }
コード例 #7
0
 public function getTextHeight(awText $text)
 {
     $font = $text->getFont();
     if ($this->isCompatibleWithFont($font) === FALSE) {
         awImage::drawError('Class MingDriver: Incompatible font type (\'' . get_class($font) . '\')');
     }
     // Ming only supports FileFont
     $fontDriver = $this->fileFontDriver;
     return $fontDriver->getTextHeight($text, $this);
 }
コード例 #8
0
ファイル: Font.class.php プロジェクト: Hassanj343/candidats
 /**
  * Get the height of a string
  *
  * @param awText $text A string
  */
 public function getTextHeight(awText $text)
 {
     $box = imagettfbbox($this->size, $text->getAngle(), $this->font, $text->getText());
     if ($box === FALSE) {
         trigger_error("Unable to get font size", E_USER_ERROR);
         return;
     }
     list(, , $x2, $y2, , , $x1, $y1) = $box;
     return abs($y2 - $y1);
 }