00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 include_once( 'lib/ezimage/classes/ezimagelayer.php' );
00042 include_once( 'lib/ezimage/classes/ezimagefont.php' );
00043
00044 class eZImageTextLayer extends eZImageLayer
00045 {
00046
00047
00048
00049 function eZImageTextLayer( $imageObjectRef = null, $imageObject = null,
00050 $width = false, $height = false,
00051 $font = false, $boundingBox = null, $text = null, $textAngle = 0 )
00052 {
00053 $this->eZImageLayer( $imageObjectRef, $imageObject, $width, $height, $font );
00054 $this->Text = $text;
00055 $this->TextAngle = $textAngle;
00056 $this->TextBoundingBox = $boundingBox;
00057 }
00058
00059
00060
00061
00062
00063 function processImage()
00064 {
00065 $destinationImageObject = $this->imageObjectInternal();
00066 $bbox = $this->textBoundingBox();
00067 $this->clear();
00068 $font = $this->font();
00069 $this->drawText( $font, $this->textColor(), $this->text(), $bbox[6], -$bbox[7], $this->textAngle(),
00070 $destinationImageObject );
00071 return true;
00072 }
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 function mergeLayer( &$image, &$layerData, &$lastLayerData )
00084 {
00085 $position = $image->calculatePosition( $layerData['parameters'], $this->width(), $this->height() );
00086 $x = $position['x'];
00087 $y = $position['y'];
00088 $destinationImageObject = $image->imageObjectInternal( false );
00089 if ( $lastLayerData === null and
00090 $destinationImageObject === null )
00091 {
00092 $destinationImageObject = $image->imageObjectInternal();
00093 $bbox = $this->textBoundingBox();
00094 $font = $this->font();
00095 $this->drawText( $font, $this->textColor(), $this->text(), $bbox[6], -$bbox[7], $this->textAngle(),
00096 $destinationImageObject );
00097 }
00098 else
00099 {
00100 $destinationImageObject = $image->imageObjectInternal();
00101 $imageObject = $this->imageObjectInternal();
00102 $bbox = $this->textBoundingBox();
00103 $image->copyImage( $imageObject, $destinationImageObject,
00104 0, 0, $this->width(), $this->height(),
00105 $x, $y );
00106 $font = $this->font();
00107 $this->drawText( $font, $this->textColor(), $this->text(), $bbox[6], -$bbox[7], $this->textAngle() );
00108 $image->mergeImage( $destinationImageObject, $imageObject,
00109 $x, $y,
00110 $this->width(), $this->height(), 0, 0,
00111 $image->getTransparencyPercent( $layerData['parameters'] ) );
00112 }
00113 }
00114
00115
00116
00117
00118 function setText( $text )
00119 {
00120 $this->Text = $text;
00121 }
00122
00123
00124
00125
00126 function text()
00127 {
00128 return $this->Text;
00129 }
00130
00131
00132
00133
00134 function setTextAngle( $textAngle )
00135 {
00136 $this->TextAngle = $textAngle;
00137 }
00138
00139
00140
00141
00142 function textAngle()
00143 {
00144 return $this->TextAngle;
00145 }
00146
00147
00148
00149
00150 function textBoundingBox()
00151 {
00152 return $this->TextBoundingBox;
00153 }
00154
00155
00156
00157
00158
00159 function &createForText( $text, &$font, $widthAdjustment, $heightAdjustment, $angle,
00160 $absoluteWidth = false, $absoluteHeight = false )
00161 {
00162 $Return = false;
00163 if ( get_class( $font ) != 'ezimagefont' )
00164 return $Return;
00165 if ( !function_exists( 'ImageTTFBBox' ) )
00166 {
00167 eZDebug::writeError( 'ImageTTFBBox function not in PHP, check PHP compilation', 'ezimagetextlayer.php' );
00168 return $Return;
00169 }
00170 $bbox = ImageTTFBBox( $font->pointSize(), $angle, $font->realFile(), $text );
00171
00172 if ( !$bbox )
00173 return $Return;
00174
00175 $xmin = min( $bbox[0], $bbox[2], $bbox[4], $bbox[6] );
00176 $xmax = max( $bbox[0], $bbox[2], $bbox[4], $bbox[6] );
00177 $ymin = min( $bbox[1], $bbox[3], $bbox[5], $bbox[7] );
00178 $ymax = max( $bbox[1], $bbox[3], $bbox[5], $bbox[7] );
00179
00180 $width = abs( $xmax - $xmin );
00181 $height = abs( $ymax - $ymin );
00182 $width += $widthAdjustment;
00183 $height += $heightAdjustment;
00184
00185 if ( $absoluteWidth !== false )
00186 $width = $absoluteWidth;
00187 if ( $absoluteHeight !== false)
00188 $height = $absoluteHeight;
00189
00190 $layer = new eZImageTextLayer( null, null, $width, $height,
00191 $font, $bbox, $text, $angle );
00192 $layer->create( $width, $height, null );
00193 return $layer;
00194 }
00195
00196
00197 var $TextBoundingBox;
00198 var $Text;
00199 var $Angle;
00200 }
00201
00202 ?>