|
eZ Publish
[trunk]
|
00001 <?php 00002 /** 00003 * File containing the eZImageTextLayer class. 00004 * 00005 * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved. 00006 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 00007 * @version //autogentag// 00008 * @package lib 00009 */ 00010 00011 /*! 00012 \class eZImageTextLayer ezimagetextlayer.php 00013 \ingroup eZImageObject 00014 \brief Layer for text information and rendering 00015 00016 */ 00017 00018 class eZImageTextLayer extends eZImageLayer 00019 { 00020 /*! 00021 Constructor 00022 */ 00023 function eZImageTextLayer( $imageObjectRef = null, $imageObject = null, 00024 $width = false, $height = false, 00025 $font = false, $boundingBox = null, $text = null, $textAngle = 0 ) 00026 { 00027 $this->eZImageLayer( $imageObjectRef, $imageObject, $width, $height, $font ); 00028 $this->Text = $text; 00029 $this->TextAngle = $textAngle; 00030 $this->TextBoundingBox = $boundingBox; 00031 } 00032 00033 /*! 00034 \virtual 00035 Draws the text on the current image object. 00036 */ 00037 function processImage() 00038 { 00039 $destinationImageObject = $this->imageObjectInternal(); 00040 $bbox = $this->textBoundingBox(); 00041 $this->clear(); 00042 $font = $this->font(); 00043 $this->drawText( $font, $this->textColor(), $this->text(), $bbox[6], -$bbox[7], $this->textAngle(), 00044 $destinationImageObject ); 00045 return true; 00046 } 00047 00048 /*! 00049 Renders the text with the other layer data. It will perform something 00050 that will look like alphablending of the text. 00051 00052 It will copy the area which it will render on from the other layer 00053 and render on it and then merge the result back on the other layer 00054 using the transparency value. This means that the original image data 00055 is kept and the actual text will be transparent. 00056 */ 00057 function mergeLayer( $image, $layerData, $lastLayerData ) 00058 { 00059 $position = $image->calculatePosition( $layerData['parameters'], $this->width(), $this->height() ); 00060 $x = $position['x']; 00061 $y = $position['y']; 00062 $destinationImageObject = $image->imageObjectInternal( false ); 00063 if ( $lastLayerData === null and 00064 $destinationImageObject === null ) 00065 { 00066 $destinationImageObject = $image->imageObjectInternal(); 00067 $bbox = $this->textBoundingBox(); 00068 $font = $this->font(); 00069 $this->drawText( $font, $this->textColor(), $this->text(), $bbox[6], -$bbox[7], $this->textAngle(), 00070 $destinationImageObject ); 00071 } 00072 else 00073 { 00074 $destinationImageObject = $image->imageObjectInternal(); 00075 $imageObject = $this->imageObjectInternal(); 00076 $bbox = $this->textBoundingBox(); 00077 $image->copyImage( $imageObject, $destinationImageObject, 00078 0, 0, $this->width(), $this->height(), 00079 $x, $y ); 00080 $font = $this->font(); 00081 $this->drawText( $font, $this->textColor(), $this->text(), $bbox[6], -$bbox[7], $this->textAngle() ); 00082 $image->mergeImage( $destinationImageObject, $imageObject, 00083 $x, $y, 00084 $this->width(), $this->height(), 0, 0, 00085 $image->getTransparencyPercent( $layerData['parameters'] ) ); 00086 } 00087 } 00088 00089 /*! 00090 Sets the current text to \a $text. 00091 */ 00092 function setText( $text ) 00093 { 00094 $this->Text = $text; 00095 } 00096 00097 /*! 00098 \return the current text. 00099 */ 00100 function text() 00101 { 00102 return $this->Text; 00103 } 00104 00105 /*! 00106 Sets the angle of the text to \a $textAngle. 00107 */ 00108 function setTextAngle( $textAngle ) 00109 { 00110 $this->TextAngle = $textAngle; 00111 } 00112 00113 /*! 00114 \return the current text angle. 00115 */ 00116 function textAngle() 00117 { 00118 return $this->TextAngle; 00119 } 00120 00121 /*! 00122 \return the current bounding box for the text. See the PHP function ImageTTFBBox for more info. 00123 */ 00124 function textBoundingBox() 00125 { 00126 return $this->TextBoundingBox; 00127 } 00128 00129 /*! 00130 Creates a new text layer with the text \a $text, font \a $font and adjustment 00131 \a $widthAdjustment and \a $heightAdjustment at the angle \a $angle and returns it. 00132 */ 00133 static function createForText( $text, &$font, $widthAdjustment, $heightAdjustment, $angle, 00134 $absoluteWidth = false, $absoluteHeight = false ) 00135 { 00136 $Return = false; 00137 if ( !( $font instanceof eZImageFont ) ) 00138 return $Return; 00139 if ( !function_exists( 'ImageTTFBBox' ) ) 00140 { 00141 eZDebug::writeError( 'ImageTTFBBox function not in PHP, check PHP compilation', 'ezimagetextlayer.php' ); 00142 return $Return; 00143 } 00144 $bbox = ImageTTFBBox( $font->pointSize(), $angle, $font->realFile(), $text ); 00145 00146 if ( !$bbox ) 00147 return $Return; 00148 00149 $xmin = min( $bbox[0], $bbox[2], $bbox[4], $bbox[6] ); 00150 $xmax = max( $bbox[0], $bbox[2], $bbox[4], $bbox[6] ); 00151 $ymin = min( $bbox[1], $bbox[3], $bbox[5], $bbox[7] ); 00152 $ymax = max( $bbox[1], $bbox[3], $bbox[5], $bbox[7] ); 00153 00154 $width = abs( $xmax - $xmin ); 00155 $height = abs( $ymax - $ymin ); 00156 $width += $widthAdjustment; 00157 $height += $heightAdjustment; 00158 00159 if ( $absoluteWidth !== false ) 00160 $width = $absoluteWidth; 00161 if ( $absoluteHeight !== false) 00162 $height = $absoluteHeight; 00163 00164 $layer = new eZImageTextLayer( null, null, $width, $height, 00165 $font, $bbox, $text, $angle ); 00166 $layer->create( $width, $height, null ); 00167 return $layer; 00168 } 00169 00170 /// \privatesection 00171 public $TextBoundingBox; 00172 public $Text; 00173 public $Angle; 00174 } 00175 00176 ?>