[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/ezimage/classes/ -> ezimagetextlayer.php (source)

   1  <?php
   2  //
   3  // Definition of eZImageTextLayer class
   4  //
   5  // Created on: <03-Oct-2002 15:05:09 amos>
   6  //
   7  // SOFTWARE NAME: eZ publish
   8  // SOFTWARE RELEASE: 3.9.0
   9  // BUILD VERSION: 17785
  10  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  11  // SOFTWARE LICENSE: GNU General Public License v2.0
  12  // NOTICE: >
  13  //   This program is free software; you can redistribute it and/or
  14  //   modify it under the terms of version 2.0  of the GNU General
  15  //   Public License as published by the Free Software Foundation.
  16  //
  17  //   This program is distributed in the hope that it will be useful,
  18  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20  //   GNU General Public License for more details.
  21  //
  22  //   You should have received a copy of version 2.0 of the GNU General
  23  //   Public License along with this program; if not, write to the Free
  24  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25  //   MA 02110-1301, USA.
  26  //
  27  //
  28  
  29  /*! \file ezimagetextlayer.php
  30  */
  31  
  32  /*!
  33    \class eZImageTextLayer ezimagetextlayer.php
  34    \ingroup eZImageObject
  35    \brief Layer for text information and rendering
  36  
  37  */
  38  
  39  include_once ( 'lib/ezimage/classes/ezimagelayer.php' );
  40  include_once ( 'lib/ezimage/classes/ezimagefont.php' );
  41  
  42  class eZImageTextLayer extends eZImageLayer
  43  {
  44      /*!
  45       Constructor
  46      */
  47      function eZImageTextLayer( $imageObjectRef = null, $imageObject = null,
  48                                    $width = false, $height = false,
  49                                    $font = false, $boundingBox = null, $text = null, $textAngle = 0 )
  50      {
  51          $this->eZImageLayer( $imageObjectRef, $imageObject, $width, $height, $font );
  52          $this->Text = $text;
  53          $this->TextAngle = $textAngle;
  54          $this->TextBoundingBox = $boundingBox;
  55      }
  56  
  57      /*!
  58       \virtual
  59       Draws the text on the current image object.
  60      */
  61      function processImage()
  62      {
  63          $destinationImageObject = $this->imageObjectInternal();
  64          $bbox = $this->textBoundingBox();
  65          $this->clear();
  66          $font = $this->font();
  67          $this->drawText( $font, $this->textColor(), $this->text(), $bbox[6], -$bbox[7], $this->textAngle(),
  68                           $destinationImageObject );
  69          return true;
  70      }
  71  
  72      /*!
  73       Renders the text with the other layer data. It will perform something
  74       that will look like alphablending of the text.
  75  
  76       It will copy the area which it will render on from the other layer
  77       and render on it and then merge the result back on the other layer
  78       using the transparency value. This means that the original image data
  79       is kept and the actual text will be transparent.
  80      */
  81      function mergeLayer( &$image, &$layerData, &$lastLayerData )
  82      {
  83          $position = $image->calculatePosition( $layerData['parameters'], $this->width(), $this->height() );
  84          $x = $position['x'];
  85          $y = $position['y'];
  86          $destinationImageObject = $image->imageObjectInternal( false );
  87          if ( $lastLayerData === null and
  88               $destinationImageObject === null )
  89          {
  90              $destinationImageObject = $image->imageObjectInternal();
  91              $bbox = $this->textBoundingBox();
  92              $font = $this->font();
  93              $this->drawText( $font, $this->textColor(), $this->text(), $bbox[6], -$bbox[7], $this->textAngle(),
  94                               $destinationImageObject );
  95          }
  96          else
  97          {
  98              $destinationImageObject = $image->imageObjectInternal();
  99              $imageObject = $this->imageObjectInternal();
 100              $bbox = $this->textBoundingBox();
 101              $image->copyImage( $imageObject, $destinationImageObject,
 102                                 0, 0, $this->width(), $this->height(),
 103                                 $x, $y );
 104              $font = $this->font();
 105              $this->drawText( $font, $this->textColor(), $this->text(), $bbox[6], -$bbox[7], $this->textAngle() );
 106              $image->mergeImage( $destinationImageObject, $imageObject,
 107                                  $x, $y,
 108                                  $this->width(), $this->height(), 0, 0,
 109                                  $image->getTransparencyPercent( $layerData['parameters'] ) );
 110          }
 111      }
 112  
 113      /*!
 114       Sets the current text to \a $text.
 115      */
 116      function setText( $text )
 117      {
 118          $this->Text = $text;
 119      }
 120  
 121      /*!
 122       \return the current text.
 123      */
 124      function text()
 125      {
 126          return $this->Text;
 127      }
 128  
 129      /*!
 130       Sets the angle of the text to \a $textAngle.
 131      */
 132      function setTextAngle( $textAngle )
 133      {
 134          $this->TextAngle = $textAngle;
 135      }
 136  
 137      /*!
 138       \return the current text angle.
 139      */
 140      function textAngle()
 141      {
 142          return $this->TextAngle;
 143      }
 144  
 145      /*!
 146       \return the current bounding box for the text. See the PHP function ImageTTFBBox for more info.
 147      */
 148      function textBoundingBox()
 149      {
 150          return $this->TextBoundingBox;
 151      }
 152  
 153      /*!
 154       Creates a new text layer with the text \a $text, font \a $font and adjustment
 155       \a $widthAdjustment and \a $heightAdjustment at the angle \a $angle and returns it.
 156      */
 157      function &createForText( $text, &$font, $widthAdjustment, $heightAdjustment, $angle,
 158                               $absoluteWidth = false, $absoluteHeight = false )
 159      {
 160          $Return = false;
 161          if ( get_class( $font ) != 'ezimagefont' )
 162              return $Return;
 163          if ( !function_exists( 'ImageTTFBBox' ) )
 164          {
 165              eZDebug::writeError( 'ImageTTFBBox function not in PHP, check PHP compilation', 'ezimagetextlayer.php' );
 166              return $Return;
 167          }
 168          $bbox = ImageTTFBBox( $font->pointSize(), $angle, $font->realFile(), $text );
 169  
 170          if ( !$bbox )
 171              return $Return;
 172  
 173          $xmin = min( $bbox[0], $bbox[2], $bbox[4], $bbox[6] );
 174          $xmax = max( $bbox[0], $bbox[2], $bbox[4], $bbox[6] );
 175          $ymin = min( $bbox[1], $bbox[3], $bbox[5], $bbox[7] );
 176          $ymax = max( $bbox[1], $bbox[3], $bbox[5], $bbox[7] );
 177  
 178          $width = abs( $xmax - $xmin );
 179          $height = abs( $ymax - $ymin );
 180          $width += $widthAdjustment;
 181          $height += $heightAdjustment;
 182  
 183          if ( $absoluteWidth !== false )
 184              $width = $absoluteWidth;
 185          if ( $absoluteHeight !== false)
 186              $height = $absoluteHeight;
 187  
 188          $layer = new eZImageTextLayer( null, null, $width, $height,
 189                                         $font, $bbox, $text, $angle );
 190          $layer->create( $width, $height, null );
 191          return $layer;
 192      }
 193  
 194      /// \privatesection
 195      var $TextBoundingBox;
 196      var $Text;
 197      var $Angle;
 198  }
 199  
 200  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7