1
|
|
|
<?php |
2
|
|
|
if (!defined('XOOPS_ROOT_PATH')) { |
3
|
|
|
die('XOOPS root path not defined'); |
4
|
|
|
} |
5
|
|
|
|
6
|
|
|
require('fpdf.php'); |
7
|
|
|
|
8
|
|
|
$UHC_widths=array(' '=>333,'!'=>416,'"'=>416,'#'=>833,'$'=>625,'%'=>916,'&'=>833,'\''=>250, |
9
|
|
|
'('=>500,')'=>500,'*'=>500,'+'=>833,','=>291,'-'=>833,'.'=>291,'/'=>375,'0'=>625,'1'=>625, |
10
|
|
|
'2'=>625,'3'=>625,'4'=>625,'5'=>625,'6'=>625,'7'=>625,'8'=>625,'9'=>625,':'=>333,';'=>333, |
11
|
|
|
'<'=>833,'='=>833,'>'=>916,'?'=>500,'@'=>1000,'A'=>791,'B'=>708,'C'=>708,'D'=>750,'E'=>708, |
12
|
|
|
'F'=>666,'G'=>750,'H'=>791,'I'=>375,'J'=>500,'K'=>791,'L'=>666,'M'=>916,'N'=>791,'O'=>750, |
13
|
|
|
'P'=>666,'Q'=>750,'R'=>708,'S'=>666,'T'=>791,'U'=>791,'V'=>750,'W'=>1000,'X'=>708,'Y'=>708, |
14
|
|
|
'Z'=>666,'['=>500,'\\'=>375,']'=>500,'^'=>500,'_'=>500,'`'=>333,'a'=>541,'b'=>583,'c'=>541, |
15
|
|
|
'd'=>583,'e'=>583,'f'=>375,'g'=>583,'h'=>583,'i'=>291,'j'=>333,'k'=>583,'l'=>291,'m'=>875, |
16
|
|
|
'n'=>583,'o'=>583,'p'=>583,'q'=>583,'r'=>458,'s'=>541,'t'=>375,'u'=>583,'v'=>583,'w'=>833, |
17
|
|
|
'x'=>625,'y'=>625,'z'=>500,'{'=>583,'|'=>583,'}'=>583,'~'=>750); |
18
|
|
|
|
19
|
|
|
class PDF_Korean extends FPDF |
20
|
|
|
{ |
21
|
|
View Code Duplication |
function AddCIDFont($family,$style,$name,$cw,$CMap,$registry) |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
$fontkey=strtolower($family).strtoupper($style); |
24
|
|
|
if(isset($this->fonts[$fontkey])) |
25
|
|
|
$this->Error("Font already added: $family $style"); |
26
|
|
|
$i=count($this->fonts)+1; |
27
|
|
|
$name=str_replace(' ','',$name); |
28
|
|
|
$this->fonts[$fontkey]=array('i'=>$i,'type'=>'Type0','name'=>$name,'up'=>-130,'ut'=>40,'cw'=>$cw,'CMap'=>$CMap,'registry'=>$registry); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
View Code Duplication |
function AddCIDFonts($family,$name,$cw,$CMap,$registry) |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
$this->AddCIDFont($family,'',$name,$cw,$CMap,$registry); |
34
|
|
|
$this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry); |
35
|
|
|
$this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry); |
36
|
|
|
$this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
function AddUHCFont($family='UHC',$name='HYSMyeongJoStd-Medium-Acro') |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
//Add UHC font with proportional Latin |
42
|
|
|
$cw=$GLOBALS['UHC_widths']; |
43
|
|
|
$CMap='KSCms-UHC-H'; |
44
|
|
|
$registry=array('ordering'=>'Korea1','supplement'=>1); |
45
|
|
|
$this->AddCIDFonts($family,$name,$cw,$CMap,$registry); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
View Code Duplication |
function AddUHChwFont($family='UHC-hw',$name='HYSMyeongJoStd-Medium-Acro') |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
//Add UHC font with half-witdh Latin |
51
|
|
|
for($i=32;$i<=126;$i++) |
52
|
|
|
$cw[chr($i)]=500; |
|
|
|
|
53
|
|
|
$CMap='KSCms-UHC-HW-H'; |
54
|
|
|
$registry=array('ordering'=>'Korea1','supplement'=>1); |
55
|
|
|
$this->AddCIDFonts($family,$name,$cw,$CMap,$registry); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
View Code Duplication |
function GetStringWidth($s) |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
if($this->CurrentFont['type']=='Type0') |
61
|
|
|
return $this->GetMBStringWidth($s); |
62
|
|
|
else |
63
|
|
|
return parent::GetStringWidth($s); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
View Code Duplication |
function GetMBStringWidth($s) |
|
|
|
|
67
|
|
|
{ |
68
|
|
|
//Multi-byte version of GetStringWidth() |
69
|
|
|
$l=0; |
70
|
|
|
$cw=&$this->CurrentFont['cw']; |
71
|
|
|
$nb=strlen($s); |
72
|
|
|
$i=0; |
73
|
|
|
while($i<$nb) |
74
|
|
|
{ |
75
|
|
|
$c=$s[$i]; |
76
|
|
|
if(ord($c)<128) |
77
|
|
|
{ |
78
|
|
|
$l+=$cw[$c]; |
79
|
|
|
$i++; |
80
|
|
|
} |
81
|
|
|
else |
82
|
|
|
{ |
83
|
|
|
$l+=1000; |
84
|
|
|
$i+=2; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $l*$this->FontSize/1000; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
View Code Duplication |
function MultiCell($w,$h,$txt,$border=0,$align='L',$fill=0) |
|
|
|
|
92
|
|
|
{ |
93
|
|
|
if($this->CurrentFont['type']=='Type0') |
94
|
|
|
$this->MBMultiCell($w,$h,$txt,$border,$align,$fill); |
95
|
|
|
else |
96
|
|
|
parent::MultiCell($w,$h,$txt,$border,$align,$fill); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
View Code Duplication |
function MBMultiCell($w,$h,$txt,$border=0,$align='L',$fill=0) |
|
|
|
|
100
|
|
|
{ |
101
|
|
|
//Multi-byte version of MultiCell() |
102
|
|
|
$cw=&$this->CurrentFont['cw']; |
103
|
|
|
if($w==0) |
104
|
|
|
$w=$this->w-$this->rMargin-$this->x; |
105
|
|
|
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize; |
106
|
|
|
$s=str_replace("\r",'',$txt); |
107
|
|
|
$nb=strlen($s); |
108
|
|
|
if($nb>0 and $s[$nb-1]=="\n") |
109
|
|
|
$nb--; |
110
|
|
|
$b=0; |
111
|
|
|
if($border) |
112
|
|
|
{ |
113
|
|
|
if($border==1) |
114
|
|
|
{ |
115
|
|
|
$border='LTRB'; |
116
|
|
|
$b='LRT'; |
117
|
|
|
$b2='LR'; |
118
|
|
|
} |
119
|
|
|
else |
120
|
|
|
{ |
121
|
|
|
$b2=''; |
122
|
|
|
if(is_int(strpos($border,'L'))) |
123
|
|
|
$b2.='L'; |
124
|
|
|
if(is_int(strpos($border,'R'))) |
125
|
|
|
$b2.='R'; |
126
|
|
|
$b=is_int(strpos($border,'T')) ? $b2.'T' : $b2; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
$sep=-1; |
130
|
|
|
$i=0; |
131
|
|
|
$j=0; |
132
|
|
|
$l=0; |
133
|
|
|
$nl=1; |
134
|
|
|
while($i<$nb) |
135
|
|
|
{ |
136
|
|
|
//Get next character |
137
|
|
|
$c=$s[$i]; |
138
|
|
|
//Check if ASCII or MB |
139
|
|
|
$ascii=(ord($c)<128); |
140
|
|
|
if($c=="\n") |
141
|
|
|
{ |
142
|
|
|
//Explicit line break |
143
|
|
|
$this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
144
|
|
|
$i++; |
145
|
|
|
$sep=-1; |
146
|
|
|
$j=$i; |
147
|
|
|
$l=0; |
148
|
|
|
$nl++; |
149
|
|
|
if($border and $nl==2) |
150
|
|
|
$b=$b2; |
|
|
|
|
151
|
|
|
continue; |
152
|
|
|
} |
153
|
|
|
if(!$ascii) |
154
|
|
|
{ |
155
|
|
|
$sep=$i; |
156
|
|
|
$ls=$l; |
|
|
|
|
157
|
|
|
} |
158
|
|
|
elseif($c==' ') |
159
|
|
|
{ |
160
|
|
|
$sep=$i; |
161
|
|
|
$ls=$l; |
|
|
|
|
162
|
|
|
} |
163
|
|
|
$l+=$ascii ? $cw[$c] : 1000; |
164
|
|
|
if($l>$wmax) |
165
|
|
|
{ |
166
|
|
|
//Automatic line break |
167
|
|
|
if($sep==-1 or $i==$j) |
168
|
|
|
{ |
169
|
|
|
if($i==$j) |
170
|
|
|
$i+=$ascii ? 1 : 2; |
171
|
|
|
$this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
172
|
|
|
} |
173
|
|
|
else |
174
|
|
|
{ |
175
|
|
|
$this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill); |
176
|
|
|
$i=($s[$sep]==' ') ? $sep+1 : $sep; |
177
|
|
|
} |
178
|
|
|
$sep=-1; |
179
|
|
|
$j=$i; |
180
|
|
|
$l=0; |
181
|
|
|
$nl++; |
182
|
|
|
if($border and $nl==2) |
183
|
|
|
$b=$b2; |
184
|
|
|
} |
185
|
|
|
else |
186
|
|
|
$i+=$ascii ? 1 : 2; |
187
|
|
|
} |
188
|
|
|
//Last chunk |
189
|
|
|
if($border and is_int(strpos($border,'B'))) |
190
|
|
|
$b.='B'; |
191
|
|
|
$this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
192
|
|
|
$this->x=$this->lMargin; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
View Code Duplication |
function Write($h,$txt,$link='') |
|
|
|
|
196
|
|
|
{ |
197
|
|
|
if($this->CurrentFont['type']=='Type0') |
198
|
|
|
$this->MBWrite($h,$txt,$link); |
199
|
|
|
else |
200
|
|
|
parent::Write($h,$txt,$link); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
View Code Duplication |
function MBWrite($h,$txt,$link) |
|
|
|
|
204
|
|
|
{ |
205
|
|
|
//Multi-byte version of Write() |
206
|
|
|
$cw=&$this->CurrentFont['cw']; |
207
|
|
|
$w=$this->w-$this->rMargin-$this->x; |
208
|
|
|
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize; |
209
|
|
|
$s=str_replace("\r",'',$txt); |
210
|
|
|
$nb=strlen($s); |
211
|
|
|
$sep=-1; |
212
|
|
|
$i=0; |
213
|
|
|
$j=0; |
214
|
|
|
$l=0; |
215
|
|
|
$nl=1; |
216
|
|
|
while($i<$nb) |
217
|
|
|
{ |
218
|
|
|
//Get next character |
219
|
|
|
$c=$s[$i]; |
220
|
|
|
//Check if ASCII or MB |
221
|
|
|
$ascii=(ord($c)<128); |
222
|
|
|
if($c=="\n") |
223
|
|
|
{ |
224
|
|
|
//Explicit line break |
225
|
|
|
$this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link); |
226
|
|
|
$i++; |
227
|
|
|
$sep=-1; |
228
|
|
|
$j=$i; |
229
|
|
|
$l=0; |
230
|
|
|
if($nl==1) |
231
|
|
|
{ |
232
|
|
|
$this->x=$this->lMargin; |
233
|
|
|
$w=$this->w-$this->rMargin-$this->x; |
234
|
|
|
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize; |
235
|
|
|
} |
236
|
|
|
$nl++; |
237
|
|
|
continue; |
238
|
|
|
} |
239
|
|
|
if(!$ascii or $c==' ') |
240
|
|
|
$sep=$i; |
241
|
|
|
$l+=$ascii ? $cw[$c] : 1000; |
242
|
|
|
if($l>$wmax) |
243
|
|
|
{ |
244
|
|
|
//Automatic line break |
245
|
|
|
if($sep==-1 or $i==$j) |
246
|
|
|
{ |
247
|
|
|
if($this->x>$this->lMargin) |
248
|
|
|
{ |
249
|
|
|
//Move to next line |
250
|
|
|
$this->x=$this->lMargin; |
251
|
|
|
$this->y+=$h; |
252
|
|
|
$w=$this->w-$this->rMargin-$this->x; |
253
|
|
|
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize; |
254
|
|
|
$i++; |
255
|
|
|
$nl++; |
256
|
|
|
continue; |
257
|
|
|
} |
258
|
|
|
if($i==$j) |
259
|
|
|
$i+=$ascii ? 1 : 2; |
260
|
|
|
$this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link); |
261
|
|
|
} |
262
|
|
|
else |
263
|
|
|
{ |
264
|
|
|
$this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',0,$link); |
265
|
|
|
$i=($s[$sep]==' ') ? $sep+1 : $sep; |
266
|
|
|
} |
267
|
|
|
$sep=-1; |
268
|
|
|
$j=$i; |
269
|
|
|
$l=0; |
270
|
|
|
if($nl==1) |
271
|
|
|
{ |
272
|
|
|
$this->x=$this->lMargin; |
273
|
|
|
$w=$this->w-$this->rMargin-$this->x; |
274
|
|
|
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize; |
275
|
|
|
} |
276
|
|
|
$nl++; |
277
|
|
|
} |
278
|
|
|
else |
279
|
|
|
$i+=$ascii ? 1 : 2; |
280
|
|
|
} |
281
|
|
|
//Last chunk |
282
|
|
|
if($i!=$j) |
283
|
|
|
$this->Cell($l/1000*$this->FontSize,$h,substr($s,$j,$i-$j),0,0,'',0,$link); |
284
|
|
|
} |
285
|
|
|
|
286
|
|
View Code Duplication |
function _putfonts() |
|
|
|
|
287
|
|
|
{ |
288
|
|
|
$nf=$this->n; |
289
|
|
|
foreach($this->diffs as $diff) |
290
|
|
|
{ |
291
|
|
|
//Encodings |
292
|
|
|
$this->_newobj(); |
293
|
|
|
$this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.']>>'); |
294
|
|
|
$this->_out('endobj'); |
295
|
|
|
} |
296
|
|
|
$mqr=get_magic_quotes_runtime(); |
297
|
|
|
set_magic_quotes_runtime(0); |
298
|
|
|
foreach($this->FontFiles as $file=>$info) |
299
|
|
|
{ |
300
|
|
|
//Font file embedding |
301
|
|
|
$this->_newobj(); |
302
|
|
|
$this->FontFiles[$file]['n']=$this->n; |
303
|
|
|
if(defined('FPDF_FONTPATH')) |
304
|
|
|
$file=FPDF_FONTPATH.$file; |
305
|
|
|
$size=filesize($file); |
306
|
|
|
if(!$size) |
307
|
|
|
$this->Error('Font file not found'); |
308
|
|
|
$this->_out('<</Length '.$size); |
309
|
|
|
if(substr($file,-2)=='.z') |
310
|
|
|
$this->_out('/Filter /FlateDecode'); |
311
|
|
|
$this->_out('/Length1 '.$info['length1']); |
312
|
|
|
if(isset($info['length2'])) |
313
|
|
|
$this->_out('/Length2 '.$info['length2'].' /Length3 0'); |
314
|
|
|
$this->_out('>>'); |
315
|
|
|
$f=fopen($file,'rb'); |
316
|
|
|
$this->_putstream(fread($f,$size)); |
317
|
|
|
fclose($f); |
318
|
|
|
$this->_out('endobj'); |
319
|
|
|
} |
320
|
|
|
set_magic_quotes_runtime($mqr); |
321
|
|
|
foreach($this->fonts as $k=>$font) |
322
|
|
|
{ |
323
|
|
|
//Font objects |
324
|
|
|
$this->_newobj(); |
325
|
|
|
$this->fonts[$k]['n']=$this->n; |
326
|
|
|
$this->_out('<</Type /Font'); |
327
|
|
|
if($font['type']=='Type0') |
328
|
|
|
$this->_putType0($font); |
329
|
|
|
else |
330
|
|
|
{ |
331
|
|
|
$name=$font['name']; |
332
|
|
|
$this->_out('/BaseFont /'.$name); |
333
|
|
|
if($font['type']=='core') |
334
|
|
|
{ |
335
|
|
|
//Standard font |
336
|
|
|
$this->_out('/Subtype /Type1'); |
337
|
|
|
if($name!='Symbol' and $name!='ZapfDingbats') |
338
|
|
|
$this->_out('/Encoding /WinAnsiEncoding'); |
339
|
|
|
} |
340
|
|
|
else |
341
|
|
|
{ |
342
|
|
|
//Additional font |
343
|
|
|
$this->_out('/Subtype /'.$font['type']); |
344
|
|
|
$this->_out('/FirstChar 32'); |
345
|
|
|
$this->_out('/LastChar 255'); |
346
|
|
|
$this->_out('/Widths '.($this->n+1).' 0 R'); |
347
|
|
|
$this->_out('/FontDescriptor '.($this->n+2).' 0 R'); |
348
|
|
|
if($font['enc']) |
349
|
|
|
{ |
350
|
|
|
if(isset($font['diff'])) |
351
|
|
|
$this->_out('/Encoding '.($nf+$font['diff']).' 0 R'); |
352
|
|
|
else |
353
|
|
|
$this->_out('/Encoding /WinAnsiEncoding'); |
354
|
|
|
} |
355
|
|
|
} |
356
|
|
|
$this->_out('>>'); |
357
|
|
|
$this->_out('endobj'); |
358
|
|
|
if($font['type']!='core') |
359
|
|
|
{ |
360
|
|
|
//Widths |
361
|
|
|
$this->_newobj(); |
362
|
|
|
$cw=&$font['cw']; |
363
|
|
|
$s='['; |
364
|
|
|
for($i=32;$i<=255;$i++) |
365
|
|
|
$s.=$cw[chr($i)].' '; |
366
|
|
|
$this->_out($s.']'); |
367
|
|
|
$this->_out('endobj'); |
368
|
|
|
//Descriptor |
369
|
|
|
$this->_newobj(); |
370
|
|
|
$s='<</Type /FontDescriptor /FontName /'.$name; |
371
|
|
|
foreach($font['desc'] as $k=>$v) |
372
|
|
|
$s.=' /'.$k.' '.$v; |
373
|
|
|
$file=$font['file']; |
374
|
|
|
if($file) |
375
|
|
|
$s.=' /FontFile'.($font['type']=='Type1' ? '' : '2').' '.$this->FontFiles[$file]['n'].' 0 R'; |
376
|
|
|
$this->_out($s.'>>'); |
377
|
|
|
$this->_out('endobj'); |
378
|
|
|
} |
379
|
|
|
} |
380
|
|
|
} |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
function _putType0($font) |
|
|
|
|
384
|
|
|
{ |
385
|
|
|
//Type0 |
386
|
|
|
$this->_out('/Subtype /Type0'); |
387
|
|
|
$this->_out('/BaseFont /'.$font['name'].'-'.$font['CMap']); |
388
|
|
|
$this->_out('/Encoding /'.$font['CMap']); |
389
|
|
|
$this->_out('/DescendantFonts ['.($this->n+1).' 0 R]'); |
390
|
|
|
$this->_out('>>'); |
391
|
|
|
$this->_out('endobj'); |
392
|
|
|
//CIDFont |
393
|
|
|
$this->_newobj(); |
394
|
|
|
$this->_out('<</Type /Font'); |
395
|
|
|
$this->_out('/Subtype /CIDFontType0'); |
396
|
|
|
$this->_out('/BaseFont /'.$font['name']); |
397
|
|
|
$this->_out('/CIDSystemInfo <</Registry (Adobe) /Ordering ('.$font['registry']['ordering'].') /Supplement '.$font['registry']['supplement'].'>>'); |
398
|
|
|
$this->_out('/FontDescriptor '.($this->n+1).' 0 R'); |
399
|
|
|
if($font['CMap']=='KSCms-UHC-HW-H') |
400
|
|
|
$W='8094 8190 500'; |
401
|
|
|
else |
402
|
|
|
$W='1 ['.implode(' ',$font['cw']).']'; |
403
|
|
|
$this->_out('/W ['.$W.']>>'); |
404
|
|
|
$this->_out('endobj'); |
405
|
|
|
//Font descriptor |
406
|
|
|
$this->_newobj(); |
407
|
|
|
$this->_out('<</Type /FontDescriptor'); |
408
|
|
|
$this->_out('/FontName /'.$font['name']); |
409
|
|
|
$this->_out('/Flags 6'); |
410
|
|
|
$this->_out('/FontBBox [0 -200 1000 900]'); |
411
|
|
|
$this->_out('/ItalicAngle 0'); |
412
|
|
|
$this->_out('/Ascent 800'); |
413
|
|
|
$this->_out('/Descent -200'); |
414
|
|
|
$this->_out('/CapHeight 800'); |
415
|
|
|
$this->_out('/StemV 50'); |
416
|
|
|
$this->_out('>>'); |
417
|
|
|
$this->_out('endobj'); |
418
|
|
|
} |
419
|
|
|
} |
420
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.