Subversion Repositories Applications.gtt

Rev

Rev 61 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
60 jpm 1
<?php
2
/*
3
 * This work is hereby released into the Public Domain.
4
 * To view a copy of the public domain dedication,
5
 * visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
6
 * Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
7
 *
8
 */
9
 
10
require_once dirname(__FILE__)."/../Graph.class.php";
11
 
12
/**
13
 * Common font characteristics and methods.
14
 * Declared abstract only so that it can't be instanciated.
15
 * Users have to call 'new awPHPFont' or 'new awFileFont',
16
 * or any of their inherited classes (awFont1, awTuffy, awTTFFont, etc.)
17
 *
18
 * @package Artichow
19
 */
20
abstract class awFont {
21
 
22
	/**
23
	 * Build the font
24
	 *
25
	 */
26
	public function __construct() {
27
 
28
	}
29
 
30
	/**
31
	 * Draw a text
32
	 *
33
	 * @param awDriver $driver
34
	 * @param awPoint $p Draw text at this point
35
	 * @param awText $text The text
36
	 * @param int $width Text box width
37
	 */
38
	public function draw(awDriver $driver, awPoint $point, awText $text, $width = NULL) {
39
 
40
		$driver->string($this, $text, $point, $width);
41
 
42
	}
43
 
44
}
45
 
46
registerClass('Font', TRUE);
47
 
48
/**
49
 * Class for fonts that cannot be transformed,
50
 * like the built-in PHP fonts for example.
51
 *
52
 * @package Artichow
53
 */
54
class awPHPFont extends awFont {
55
 
56
	/**
57
	 * The used font identifier
58
	 *
59
	 * @var int
60
	 */
61
	public $font;
62
 
63
	public function __construct($font = NULL) {
64
		parent::__construct();
65
 
66
		if($font !== NULL) {
67
			$this->font = (int)$font;
68
		}
69
	}
70
 
71
}
72
 
73
registerClass('PHPFont');
74
 
75
/**
76
 * Class for fonts that can be transformed (rotated, skewed, etc.),
77
 * like TTF or FDB fonts for example.
78
 *
79
 * @package Artichow
80
 */
81
class awFileFont extends awFont {
82
 
83
	/**
84
	 * The name of the font, without the extension
85
	 *
86
	 * @var string
87
	 */
88
	protected $name;
89
 
90
	/**
91
	 * The size of the font
92
	 *
93
	 * @var int
94
	 */
95
	protected $size;
96
 
97
	/**
98
	 * The font filename extension
99
	 *
100
	 * @var string
101
	 */
102
	protected $extension;
103
 
104
	public function __construct($name, $size) {
105
		parent::__construct();
106
 
107
		$this->setName($name);
108
		$this->setSize($size);
109
	}
110
 
111
	/**
112
	 * Set the name of the font. The $name variable can contain the full path,
113
	 * or just the filename. Artichow will try to do The Right Thing,
114
	 * as well as set the extension property correctly if possible.
115
	 *
116
	 * @param string $name
117
	 */
118
	public function setName($name) {
119
		$fontInfo = pathinfo((string)$name);
120
 
121
		if(strpos($fontInfo['dirname'], '/') !== 0) {
122
			// Path is not absolute, use ARTICHOW_FONT
123
			$name = ARTICHOW_FONT.DIRECTORY_SEPARATOR.$fontInfo['basename'];
124
			$fontInfo = pathinfo($name);
125
		}
126
 
127
		$this->name = $fontInfo['dirname'].DIRECTORY_SEPARATOR.$fontInfo['basename'];
128
 
129
		if(array_key_exists('extension', $fontInfo) and $fontInfo['extension'] !== '') {
130
			$this->setExtension($fontInfo['extension']);
131
		}
132
	}
133
 
134
	/**
135
	 * Return the name of the font, i.e. the absolute path and the filename, without the extension.
136
	 *
137
	 * @return string
138
	 */
139
	public function getName() {
140
		return $this->name;
141
	}
142
 
143
	/**
144
	 * Set the size of the font, in pixels
145
	 *
146
	 * @param int $size
147
	 */
148
	public function setSize($size) {
149
		$this->size = (int)$size;
150
	}
151
 
152
	/**
153
	 * Return the size of the font, in pixels
154
	 *
155
	 * @return int
156
	 */
157
	public function getSize() {
158
		return $this->size;
159
	}
160
 
161
	/**
162
	 * Set the extension, without the dot
163
	 *
164
	 * @param string $extension
165
	 */
166
	public function setExtension($extension) {
167
		$this->extension = (string)$extension;
168
	}
169
 
170
	/**
171
	 * Get the filename extension for that font
172
	 *
173
	 * @return string
174
	 */
175
	public function getExtension() {
176
		return $this->extension;
177
	}
178
 
179
}
180
 
181
registerClass('FileFont');
182
 
183
/**
184
 * Class representing TTF fonts
185
 *
186
 * @package Artichow
187
 */
188
class awTTFFont extends awFileFont {
189
 
190
	public function __construct($name, $size) {
191
		parent::__construct($name, $size);
192
 
193
		if($this->getExtension() === NULL) {
194
			$this->setExtension('ttf');
195
		}
196
	}
197
 
198
}
199
 
200
registerClass('TTFFont');
201
 
202
 
203
 
204
$php = '';
205
 
206
for($i = 1; $i <= 5; $i++) {
207
 
208
	$php .= '
209
	class awFont'.$i.' extends awPHPFont {
210
 
211
		public function __construct() {
212
			parent::__construct('.$i.');
213
		}
214
 
215
	}
216
	';
217
 
218
	if(ARTICHOW_PREFIX !== 'aw') {
219
		$php .= '
220
		class '.ARTICHOW_PREFIX.'Font'.$i.' extends awFont'.$i.' {
221
		}
222
		';
223
	}
224
 
225
}
226
 
227
eval($php);
228
 
229
$php = '';
230
 
231
foreach($fonts as $font) {
232
 
233
	$php .= '
234
	class aw'.$font.' extends awFileFont {
235
 
236
		public function __construct($size) {
237
			parent::__construct(\''.$font.'\', $size);
238
		}
239
 
240
	}
241
	';
242
 
243
	if(ARTICHOW_PREFIX !== 'aw') {
244
		$php .= '
245
		class '.ARTICHOW_PREFIX.$font.' extends aw'.$font.' {
246
		}
247
		';
248
	}
249
 
250
}
251
 
252
eval($php);
253
 
254
 
255
 
256
/*
257
 * Environment modification for GD2 and TTF fonts
258
 */
259
if(function_exists('putenv')) {
260
	putenv('GDFONTPATH='.ARTICHOW_FONT);
261
}
262
 
263
?>