1<?php 2 3/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 4 5/** 6 * 3d Library 7 * 8 * PHP versions 5 9 * 10 * LICENSE: 11 * This library is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU Lesser General Public 13 * License as published by the Free Software Foundation; either 14 * version 2.1 of the License, or (at your option) any later version. 15 * 16 * This library is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 * Lesser General Public License for more details. 20 * 21 * You should have received a copy of the GNU Lesser General Public 22 * License along with this library; if not, write to the Free Software 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 24 * 25 * @category Image 26 * @package Image_3D 27 * @author Kore Nordmann <3d@kore-nordmann.de> 28 * @copyright 1997-2005 Kore Nordmann 29 * @license http://www.gnu.org/licenses/lgpl.txt lgpl 2.1 30 * @version CVS: $Id$ 31 * @link http://pear.php.net/package/PackageName 32 * @since File available since Release 0.1.0 33 */ 34 35require_once('Image/3D/Matrix/Move.php'); 36require_once('Image/3D/Paintable/Object.php'); 37require_once('Image/3D/Paintable/Object/Cube.php'); 38 39/** 40 * Image_3D_Object_Text 41 * 42 * @category Image 43 * @package Image_3D 44 * @author Kore Nordmann <3d@kore-nordmann.de> 45 * @copyright 1997-2005 Kore Nordmann 46 * @license http://www.gnu.org/licenses/lgpl.txt lgpl 2.1 47 * @version Release: @package_version@ 48 * @link http://pear.php.net/package/PackageName 49 * @since Class available since Release 0.1.0 50 */ 51class Image_3D_Object_Text extends Image_3D_Object { 52 53 protected $_text; 54 protected $_characterSpacing; 55 56 protected $_chars; 57 58 public function __construct($string) { 59 parent::__construct(); 60 61 $this->_text = (string) $string; 62 $this->_points = array(); 63 $this->_characterSpacing = 5.5; 64 65 $textdata = '@data_dir@/Image_3D/data/TextData.dat'; 66 if (is_readable($textdata)) { 67 $this->_chars = unserialize(file_get_contents($textdata)); 68 } elseif (is_readable('data/TextData.dat')) { 69 $this->_chars = unserialize(file_get_contents('data/TextData.dat')); 70 } else { 71 throw new Exception('File for textdata not found.'); 72 } 73 74 $this->_generateCubes(); 75 } 76 77 public function setCharSpacing($charSpacing) 78 { 79 $this->_characterSpacing = 5 + (float) $charSpacing; 80 } 81 82 protected function _generateCubes() 83 { 84 $length = strlen($this->_text); 85 86 for ($i = 0; $i < $length; $i++) { 87 $char = $this->_chars[ord($this->_text{$i})]; 88 foreach ($char as $x => $row) { 89 foreach ($row as $y => $pixel) { 90//printf("Dot %d %.1f %.1f\n", $pixel, $x + $i * $this->_characterSpacing, $y); 91 if ($pixel) { 92 $tmp = new Image_3D_Object_Cube(array(1, 1, 1)); 93 $tmp->transform(new Image_3D_Matrix_Move(array($x + $i * $this->_characterSpacing, $y, 0))); 94 $polygones = $tmp->getPolygones(); 95 foreach ($polygones as $polygon) $this->_addPolygon($polygon); 96 unset($tmp); 97 } 98 } 99 } 100 } 101 } 102} 103