Footnote.php
6.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<?php
/*
PHPRtfLite
Copyright 2010-2012 Steffen Zeidler <sigma_z@sigma-scripts.de>
This file is part of PHPRtfLite.
PHPRtfLite is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
PHPRtfLite is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with PHPRtfLite. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* class for creating footnotes in rtf documents.
* @version 1.2
* @author Steffen Zeidler <sigma_z@sigma-scripts.de>
* @copyright 2010-2012 Steffen Zeidler
* @package PHPRtfLite_Footnote
*/
class PHPRtfLite_Footnote
{
/**
* constants for numbering type
* 0 => Arabic numbering (1, 2, 3, ...)
* 1 => Alphabetic lowercase (a, b, c, ...)
* 2 => Alphabetic uppercase (A, B, C, ...)
* 3 => Roman lowercase (i, ii, iii, ...)
* 4 => Roman uppercase (I, II, III, ...)
* 5 => Chicago Manual of Style (*, [dagger], [daggerdbl], §)
* 6 => Footnote Korean numbering 1 (*chosung).
* 7 => Footnote Korean numbering 2 (*ganada).
* 8 => Footnote Circle numbering (*circlenum).
* 9 => Footnote kanji numbering without the digit character (*dbnum1).
* 10 => Footnote kanji numbering with the digit character (*dbnum2).
* 11 => Footnote kanji numbering 3 (*dbnum3).
* 12 => Footnote kanji numbering 4 (*dbnum4).
* 13 => Footnote double-byte numbering (*dbchar).
* 14 => Footnote Chinese numbering 1 (*gb1).
* 15 => Footnote Chinese numbering 2 (*gb2).
* 16 => Footnote Chinese numbering 3 (*gb3).
* 17 => Footnote Chinese numbering 4 (*gb4).
* 18 => Footnote numbering—Chinese Zodiac numbering 1 (* zodiac1).
* 19 => Footnote numbering—Chinese Zodiac numbering 2 (* zodiac2).
* 20 => Footnote numbering—Chinese Zodiac numbering 3 (* zodiac3).
*/
const NUMTYPE_ARABIC_NUMBERS = 0;
const NUMTYPE_ALPHABETH_LC = 1;
const NUMTYPE_ALPHABETH_UC = 2;
const NUMTYPE_ROMAN_LC = 3;
const NUMTYPE_ROMAN_UC = 4;
const NUMTYPE_CHICAGO = 5;
const NUMTYPE_KOREAN_1 = 6;
const NUMTYPE_KOREAN_2 = 7;
const NUMTYPE_CIRCLE = 8;
const NUMTYPE_KANJI_1 = 9;
const NUMTYPE_KANJI_2 = 10;
const NUMTYPE_KANJI_3 = 11;
const NUMTYPE_KANJI_4 = 12;
const NUMTYPE_DOUBLE_BYTE = 13;
const NUMTYPE_CHINESE_1 = 14;
const NUMTYPE_CHINESE_2 = 15;
const NUMTYPE_CHINESE_3 = 16;
const NUMTYPE_CHINESE_4 = 17;
const NUMTYPE_CHINESE_ZODIAC_1 = 18;
const NUMTYPE_CHINESE_ZODIAC_2 = 19;
const NUMTYPE_CHINESE_ZODIAC_3 = 20;
const TYPE_SUPER = 'super';
const TYPE_SUB = 'sub';
const TYPE_NORMAL = 'normal';
/**
* footnote/endnote text
* @var string
*/
protected $_text;
/**
* font
* @var PHPRtfLite_Font
*/
protected $_font;
/**
* paragraph format
* @var PHPRtfLite_ParFormat
*/
protected $_parFormat;
/**
* rtf document
* @var PHPRtfLite
*/
protected $_rtf;
/**
* type setting type (superscript/subscript/normal)
* @var string
*/
protected $_typeSettingType = self::TYPE_SUPER;
/**
* default font
* @var PHPRtfLite_Font
*/
protected static $_defaultFont;
/**
* construtor
*
* @param PHPRtfLite $rtf
* @param string $text
* @param PHPRtfLite_Font $font if font is not set, use defaultFont
* @param PHPRtfLite_ParFormat $parFormat
*/
public function __construct(PHPRtfLite $rtf,
$text,
PHPRtfLite_Font $font = null,
PHPRtfLite_ParFormat $parFormat = null)
{
$this->_rtf = $rtf;
$this->_text = $text;
if (!$font && self::$_defaultFont) {
$font = self::$_defaultFont;
}
if ($font) {
$rtf->registerFont($font);
}
if ($parFormat) {
$rtf->registerParFormat($parFormat);
}
$this->_font = $font;
$this->_parFormat = $parFormat;
}
/**
* sets default font for notes
*
* @param PHPRtfLite_Font $font
*/
public static function setDefaultFont(PHPRtfLite_Font $font)
{
self::$_defaultFont = $font;
}
/**
* gets default font
*
* @return PHPRtfLite_Font
*/
public static function getDefaultFont()
{
return self::$_defaultFont;
}
/**
* sets font
*
* @param PHPRtfLite_Font $font
*/
public function setFont(PHPRtfLite_Font $font)
{
$this->_rtf->registerFont($font);
$this->_font = $font;
}
/**
* gets font
*
* @return PHPRtfLite_Font
*/
public function getFont()
{
return $this->_font;
}
/**
* sets paragraph format
*
* @param PHPRtfLite_ParFormat $parFormat
*/
public function setParFormat(PHPRtfLite_ParFormat $parFormat)
{
$this->_rtf->registerParFormat($parFormat);
$this->_parFormat = $parFormat;
}
/**
* gets paragraph format
*
* @return PHPRtfLite_ParFormat
*/
public function getParFormat()
{
return $this->_parFormat;
}
public function setTypeSettingType($type)
{
$this->_typeSettingType = $type;
}
/**
* gets type as rtf code
*
* @return string
*/
protected function getTypeAsRtfCode()
{
return '\footnote';
}
/**
* renders footnote/endnote
*/
public function render()
{
$stream = $this->_rtf->getWriter();
$typeSetting = $this->_typeSettingType != self::TYPE_NORMAL
? '\\' . $this->_typeSettingType
: '';
$stream->write(
'{' . $typeSetting . '\chftn}'
. '{' . $this->getTypeAsRtfCode()
. '\pard\plain\lin283\fi-283 '
);
if ($this->_parFormat) {
$stream->write($this->_parFormat->getContent());
}
if ($this->_font) {
$stream->write($this->_font->getContent());
}
$stream->write('{\up6\chftn}' . "\r\n"
. PHPRtfLite::quoteRtfCode($this->_text)
. '} ');
}
}