From 2948fe8d6055f6dfe6289e64bce426b5e0bb552f Mon Sep 17 00:00:00 2001 From: cassiopc Date: Fri, 31 Aug 2012 11:02:27 +0200 Subject: inclusion of dir 1.5.1 for boca --- boca-1.5.1/src/libchart/classes/Text.php | 139 +++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 boca-1.5.1/src/libchart/classes/Text.php (limited to 'boca-1.5.1/src/libchart/classes/Text.php') diff --git a/boca-1.5.1/src/libchart/classes/Text.php b/boca-1.5.1/src/libchart/classes/Text.php new file mode 100644 index 0000000..7f7177c --- /dev/null +++ b/boca-1.5.1/src/libchart/classes/Text.php @@ -0,0 +1,139 @@ + + + $this->fontCondensed = dirname(__FILE__) . "/../fonts/DejaVuSansCondensed.ttf"; + $this->fontCondensedBold = dirname(__FILE__) . "/../fonts/DejaVuSansCondensed-Bold.ttf"; + } + + /** + * Print text + * + * @access public + * @param Image GD image + * @param integer text coordinate (x) + * @param integer text coordinate (y) + * @param Color text color + * @param string text value + * @param string font file name + * @param bitfield text alignment + */ + + function printText($img, $px, $py, $color, $text, $fontFileName, $align = 0) + { + if(!($align & $this->HORIZONTAL_CENTER_ALIGN) && !($align & $this->HORIZONTAL_RIGHT_ALIGN)) + $align |= $this->HORIZONTAL_LEFT_ALIGN; + + if(!($align & $this->VERTICAL_CENTER_ALIGN) && !($align & $this->VERTICAL_BOTTOM_ALIGN)) + $align |= $this->VERTICAL_TOP_ALIGN; + + $fontSize = 8; + $lineSpacing = 1; + + list($llx, $lly, $lrx, $lry, $urx, $ury, $ulx, $uly) = imageftbbox($fontSize, 0, $fontFileName, $text, array("linespacing" => $lineSpacing)); + + $textWidth = $lrx - $llx; + $textHeight = $lry - $ury; + + $angle = 0; + + if($align & $this->HORIZONTAL_CENTER_ALIGN) + $px -= $textWidth / 2; + + if($align & $this->HORIZONTAL_RIGHT_ALIGN) + $px -= $textWidth; + + if($align & $this->VERTICAL_CENTER_ALIGN) + $py += $textHeight / 2; + + if($align & $this->VERTICAL_TOP_ALIGN) + $py += $textHeight; + + imagettftext($img, $fontSize, $angle, $px, $py, $color->getColor($img), $fontFileName, $text); + } + + /** + * Print text centered horizontally on the image + * + * @access public + * @param Image GD image + * @param integer text coordinate (y) + * @param Color text color + * @param string text value + * @param string font file name + */ + + function printCentered($img, $py, $color, $text, $fontFileName) + { + $this->printText($img, imagesx($img) / 2, $py, $color, $text, $fontFileName, $this->HORIZONTAL_CENTER_ALIGN | $this->VERTICAL_CENTER_ALIGN); + } + + /** + * Print text in diagonal + * + * @access public + * @param Image GD image + * @param integer text coordinate (x) + * @param integer text coordinate (y) + * @param Color text color + * @param string text value + */ + + function printDiagonal($img, $px, $py, $color, $text) + { + $fontSize = 8; + $fontFileName = $this->fontCondensed; + + $lineSpacing = 1; + + list($lx, $ly, $rx, $ry) = imageftbbox($fontSize, 0, $fontFileName, $text, array("linespacing" => $lineSpacing)); + $textWidth = $rx - $lx; + + $angle = -45; + + imagettftext($img, $fontSize, $angle, $px, $py, $color->getColor($img), $fontFileName, $text); + } + } +?> -- cgit v1.2.3