pdf_paradise 0.3.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +933 -0
  3. data/bin/automatic_pdf_title +7 -0
  4. data/bin/burst_this_pdf_file +7 -0
  5. data/bin/combine_these_pdf_pages +7 -0
  6. data/bin/compress_via_hexapdf +7 -0
  7. data/bin/convert_markdown_to_pdf +7 -0
  8. data/bin/convert_pdf_to_text +7 -0
  9. data/bin/delete_first_page_of_this_pdf_file +7 -0
  10. data/bin/djvu_to_pdf +7 -0
  11. data/bin/merge_then_open +7 -0
  12. data/bin/n_pages +10 -0
  13. data/bin/open_main_pdf +7 -0
  14. data/bin/pdf_paradise +9 -0
  15. data/bin/rotate_pdf +7 -0
  16. data/bin/set_main_book +7 -0
  17. data/bin/set_title_of_this_pdf_file +15 -0
  18. data/doc/README.gen +871 -0
  19. data/doc/todo/todo.md +13 -0
  20. data/images/Logo_for_the_pdf_paradise_project.avif +0 -0
  21. data/lib/pdf_paradise/base/base.rb +344 -0
  22. data/lib/pdf_paradise/base/colours.rb +67 -0
  23. data/lib/pdf_paradise/colours/colours.rb +27 -0
  24. data/lib/pdf_paradise/commandline/commandline.rb +109 -0
  25. data/lib/pdf_paradise/commandline/help.rb +77 -0
  26. data/lib/pdf_paradise/commandline/menu.rb +173 -0
  27. data/lib/pdf_paradise/compress/compress_this_pdf_file.rb +108 -0
  28. data/lib/pdf_paradise/compress/compress_via_hexapdf.rb +27 -0
  29. data/lib/pdf_paradise/compress/compress_via_qpdf.rb +32 -0
  30. data/lib/pdf_paradise/constants/constants.rb +76 -0
  31. data/lib/pdf_paradise/convert_text_to_pdf.rb +94 -0
  32. data/lib/pdf_paradise/css/project.css +17 -0
  33. data/lib/pdf_paradise/fpdf/README.md +2 -0
  34. data/lib/pdf_paradise/fpdf/bookmark.rb +129 -0
  35. data/lib/pdf_paradise/fpdf/chinese.rb +454 -0
  36. data/lib/pdf_paradise/fpdf/fpdf.rb +1902 -0
  37. data/lib/pdf_paradise/fpdf/fpdf_eps.rb +138 -0
  38. data/lib/pdf_paradise/fpdf/makefont.rb +1794 -0
  39. data/lib/pdf_paradise/gui/README.md +6 -0
  40. data/lib/pdf_paradise/gui/fox/split_pdf_file.rb +77 -0
  41. data/lib/pdf_paradise/gui/gtk2/pdf_viewer/pdf_viewer.rb +34 -0
  42. data/lib/pdf_paradise/gui/gtk2/split_pdf_file/split_pdf_file.rb +34 -0
  43. data/lib/pdf_paradise/gui/gtk2/statistics_widget/statistics_widget.rb +34 -0
  44. data/lib/pdf_paradise/gui/gtk3/controller/controller.rb +214 -0
  45. data/lib/pdf_paradise/gui/gtk3/pdf_viewer/pdf_viewer.rb +34 -0
  46. data/lib/pdf_paradise/gui/gtk3/split_pdf_file/split_pdf_file.rb +34 -0
  47. data/lib/pdf_paradise/gui/jruby/delete_the_first_or_the_last_page_of_this_pdf_file/delete_the_first_or_the_last_page_of_this_pdf_file.rb +167 -0
  48. data/lib/pdf_paradise/gui/jruby/remove_the_first_page_of_this_pdf_file/remove_the_first_page_of_this_pdf_file.rb +103 -0
  49. data/lib/pdf_paradise/gui/libui/extract_all_images_from_this_pdf_file/extract_all_images_from_this_pdf_file.rb +223 -0
  50. data/lib/pdf_paradise/gui/libui/remove_the_first_page_of_this_pdf_file/remove_the_first_page_of_this_pdf_file.rb +267 -0
  51. data/lib/pdf_paradise/gui/libui/rotate_pdf_file/rotate_pdf_file.rb +219 -0
  52. data/lib/pdf_paradise/gui/libui/statistics_widget/statistics_widget.rb +233 -0
  53. data/lib/pdf_paradise/gui/shared_code/pdf_viewer/pdf_viewer.css +5 -0
  54. data/lib/pdf_paradise/gui/shared_code/pdf_viewer/pdf_viewer_module.rb +287 -0
  55. data/lib/pdf_paradise/gui/shared_code/remove_the_first_page_of_this_pdf_file_module/remove_the_first_page_of_this_pdf_file_module.rb +31 -0
  56. data/lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file_module.rb +295 -0
  57. data/lib/pdf_paradise/gui/universal_widgets/convert_pdf_to_text/convert_pdf_to_text.rb +366 -0
  58. data/lib/pdf_paradise/gui/universal_widgets/delete_the_first_or_the_last_page_of_this_pdf_file/delete_the_first_or_the_last_page_of_this_pdf_file.rb +776 -0
  59. data/lib/pdf_paradise/gui/universal_widgets/statistics_widget/statistics_widget.rb +407 -0
  60. data/lib/pdf_paradise/gui/universal_widgets/to_pdf/to_pdf.rb +351 -0
  61. data/lib/pdf_paradise/hexapdf/001_rainbow_pattern_example.rb +0 -0
  62. data/lib/pdf_paradise/hexapdf/hexapdf.rb +123 -0
  63. data/lib/pdf_paradise/images/PDF_PARADISE_LOGO.png +0 -0
  64. data/lib/pdf_paradise/main_pdf/main_pdf.rb +474 -0
  65. data/lib/pdf_paradise/merge_pdf/menu.rb +63 -0
  66. data/lib/pdf_paradise/merge_pdf/merge_pdf.rb +307 -0
  67. data/lib/pdf_paradise/merge_pdf_namespace.rb +9 -0
  68. data/lib/pdf_paradise/merge_then_open/merge_then_open.rb +105 -0
  69. data/lib/pdf_paradise/prawn_addons/README.md +2 -0
  70. data/lib/pdf_paradise/prawn_addons/prawn_addons.rb +17 -0
  71. data/lib/pdf_paradise/project/project.rb +22 -0
  72. data/lib/pdf_paradise/remove_pdf_password.rb +391 -0
  73. data/lib/pdf_paradise/requires/batch_require_toplevel_files.rb +22 -0
  74. data/lib/pdf_paradise/requires/colours.rb +11 -0
  75. data/lib/pdf_paradise/requires/colours_and_esystem_and_save_file_and_fileutils_and_opn.rb +13 -0
  76. data/lib/pdf_paradise/requires/esystem_and_colours.rb +11 -0
  77. data/lib/pdf_paradise/requires/esystem_and_opn_and_colours.rb +10 -0
  78. data/lib/pdf_paradise/requires/require_the_whole_project.rb +30 -0
  79. data/lib/pdf_paradise/requires/require_utility_scripts.rb +9 -0
  80. data/lib/pdf_paradise/set_main_book.rb +156 -0
  81. data/lib/pdf_paradise/set_pdf_title.rb +220 -0
  82. data/lib/pdf_paradise/sinatra/embeddable_interface.rb +389 -0
  83. data/lib/pdf_paradise/toplevel_methods/convert_epub_to_pdf.rb +27 -0
  84. data/lib/pdf_paradise/toplevel_methods/convert_markdown_to_pdf.rb +45 -0
  85. data/lib/pdf_paradise/toplevel_methods/convert_ppt_to_pdf.rb +35 -0
  86. data/lib/pdf_paradise/toplevel_methods/e.rb +16 -0
  87. data/lib/pdf_paradise/toplevel_methods/esystem.rb +20 -0
  88. data/lib/pdf_paradise/toplevel_methods/misc.rb +228 -0
  89. data/lib/pdf_paradise/toplevel_methods/number_pages.rb +38 -0
  90. data/lib/pdf_paradise/toplevel_methods/opened_pdf_files.rb +221 -0
  91. data/lib/pdf_paradise/toplevel_methods/query_pdf_title.rb +201 -0
  92. data/lib/pdf_paradise/toplevel_methods/reduce_size_of_this_pdf_file.rb +46 -0
  93. data/lib/pdf_paradise/toplevel_methods/roebe.rb +17 -0
  94. data/lib/pdf_paradise/toplevel_methods/to_pdf.rb +12 -0
  95. data/lib/pdf_paradise/utility_scripts/README.md +3 -0
  96. data/lib/pdf_paradise/utility_scripts/automatic_pdf_title.rb +104 -0
  97. data/lib/pdf_paradise/utility_scripts/check_syntax_of_pdf_files.rb +106 -0
  98. data/lib/pdf_paradise/utility_scripts/combine_these_pdf_pages.rb +118 -0
  99. data/lib/pdf_paradise/utility_scripts/convert_pdf_to_text.rb +179 -0
  100. data/lib/pdf_paradise/utility_scripts/delete_last_page_of_this_pdf_file.rb +180 -0
  101. data/lib/pdf_paradise/utility_scripts/delete_the_first_page_of_this_pdf_file/delete_the_first_page_of_this_pdf_file.rb +429 -0
  102. data/lib/pdf_paradise/utility_scripts/delete_this_page_of_this_pdf_file.rb +356 -0
  103. data/lib/pdf_paradise/utility_scripts/djvu_to_pdf.rb +87 -0
  104. data/lib/pdf_paradise/utility_scripts/extract_all_images_from_this_pdf_file.rb +129 -0
  105. data/lib/pdf_paradise/utility_scripts/extract_pdf_page.rb +283 -0
  106. data/lib/pdf_paradise/utility_scripts/pdf_file_n_total_pages.rb +348 -0
  107. data/lib/pdf_paradise/utility_scripts/pdf_optimizer.rb +111 -0
  108. data/lib/pdf_paradise/utility_scripts/pdf_statistics.rb +148 -0
  109. data/lib/pdf_paradise/utility_scripts/pdf_to_html.rb +75 -0
  110. data/lib/pdf_paradise/utility_scripts/remove_images.rb +110 -0
  111. data/lib/pdf_paradise/utility_scripts/rotate_pdf_file.rb +303 -0
  112. data/lib/pdf_paradise/utility_scripts/split_pdf.rb +364 -0
  113. data/lib/pdf_paradise/utility_scripts/to_pdf.rb +130 -0
  114. data/lib/pdf_paradise/utility_scripts/to_qdf.rb +66 -0
  115. data/lib/pdf_paradise/version/version.rb +19 -0
  116. data/lib/pdf_paradise/www/README.md +2 -0
  117. data/lib/pdf_paradise/www/sinatra/app.rb +304 -0
  118. data/lib/pdf_paradise/yaml/working_on_these_pdf_files.yml +4 -0
  119. data/lib/pdf_paradise.rb +5 -0
  120. data/pdf_paradise.gemspec +61 -0
  121. data/test/fpdf/001_minimal_example.rb +12 -0
  122. data/test/fpdf/002.pdf +0 -0
  123. data/test/fpdf/002_header_and_footer_example.rb +64 -0
  124. data/test/fpdf/003.pdf +98 -0
  125. data/test/fpdf/003_justified_paragraphs.rb +96 -0
  126. data/test/fpdf/file1.md +3 -0
  127. data/test/fpdf/file2.md +3 -0
  128. data/test/fpdf/test.pdf +0 -0
  129. data/test/testing_pdf_paradise.rb +12 -0
  130. metadata +239 -0
@@ -0,0 +1,454 @@
1
+ # Chinese support ported by Brian Ollenberger from Oliver Plathey's
2
+ # Chinese PDF support.
3
+ #
4
+ # First added in 1.53b
5
+ #
6
+ # This is currently totally untested. Please let me know if you
7
+ # run into any bugs.
8
+ #
9
+ # Usage is as follows:
10
+ #
11
+ # require 'fpdf'
12
+ # require 'chinese'
13
+ # pdf = FPDF.new
14
+ # pdf.extend(PDF_Chinese)
15
+ #
16
+ # This allows it to be combined with other extensions, such as the bookmark
17
+ # module.
18
+
19
+ # === PDF_Chinese
20
+ module PDF_Chinese
21
+ # === Big5_widths
22
+ Big5_widths = {
23
+ ' '=>250,'!'=>250,'"'=>408,'#'=>668,'$'=>490,'%'=>875,'&'=>698,'\''=>250,
24
+ '('=>240,')'=>240,'*'=>417,'+'=>667,','=>250,'-'=>313,'.'=>250,'/'=>520,'0'=>500,'1'=>500,
25
+ '2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>250,';'=>250,
26
+ '<'=>667,'='=>667,'>'=>667,'?'=>396,'@'=>921,'A'=>677,'B'=>615,'C'=>719,'D'=>760,'E'=>625,
27
+ 'F'=>552,'G'=>771,'H'=>802,'I'=>354,'J'=>354,'K'=>781,'L'=>604,'M'=>927,'N'=>750,'O'=>823,
28
+ 'P'=>563,'Q'=>823,'R'=>729,'S'=>542,'T'=>698,'U'=>771,'V'=>729,'W'=>948,'X'=>771,'Y'=>677,
29
+ 'Z'=>635,'['=>344,'\\'=>520,']'=>344,'^'=>469,'_'=>500,'`'=>250,'a'=>469,'b'=>521,'c'=>427,
30
+ 'd'=>521,'e'=>438,'f'=>271,'g'=>469,'h'=>531,'i'=>250,'j'=>250,'k'=>458,'l'=>240,'m'=>802,
31
+ 'n'=>531,'o'=>500,'p'=>521,'q'=>521,'r'=>365,'s'=>333,'t'=>292,'u'=>521,'v'=>458,'w'=>677,
32
+ 'x'=>479,'y'=>458,'z'=>427,'{'=>480,'|'=>496,'}'=>480,'~'=>667}
33
+
34
+ GB_widths = {' '=>207,'!'=>270,'"'=>342,'#'=>467,'$'=>462,'%'=>797,'&'=>710,'\''=>239,
35
+ '('=>374,')'=>374,'*'=>423,'+'=>605,','=>238,'-'=>375,'.'=>238,'/'=>334,'0'=>462,'1'=>462,
36
+ '2'=>462,'3'=>462,'4'=>462,'5'=>462,'6'=>462,'7'=>462,'8'=>462,'9'=>462,':'=>238,';'=>238,
37
+ '<'=>605,'='=>605,'>'=>605,'?'=>344,'@'=>748,'A'=>684,'B'=>560,'C'=>695,'D'=>739,'E'=>563,
38
+ 'F'=>511,'G'=>729,'H'=>793,'I'=>318,'J'=>312,'K'=>666,'L'=>526,'M'=>896,'N'=>758,'O'=>772,
39
+ 'P'=>544,'Q'=>772,'R'=>628,'S'=>465,'T'=>607,'U'=>753,'V'=>711,'W'=>972,'X'=>647,'Y'=>620,
40
+ 'Z'=>607,'['=>374,'\\'=>333,']'=>374,'^'=>606,'_'=>500,'`'=>239,'a'=>417,'b'=>503,'c'=>427,
41
+ 'd'=>529,'e'=>415,'f'=>264,'g'=>444,'h'=>518,'i'=>241,'j'=>230,'k'=>495,'l'=>228,'m'=>793,
42
+ 'n'=>527,'o'=>524,'p'=>524,'q'=>504,'r'=>338,'s'=>336,'t'=>277,'u'=>517,'v'=>450,'w'=>652,
43
+ 'x'=>466,'y'=>452,'z'=>407,'{'=>370,'|'=>258,'}'=>370,'~'=>605}
44
+
45
+ def AddCIDFont(family,style,name,cw,cMap,registry)
46
+ fontkey=family.downcase + style.upcase;
47
+ unless @fonts[fontkey].nil?
48
+ Error("Font already added: #{family} #{style}")
49
+ end
50
+ i=@fonts.length+1
51
+ name.sub!(' ', '')
52
+ @fonts[fontkey]={'i'=>i,'type'=>'Type0','name'=>name,'up'=>-130,
53
+ 'ut'=>40,'cw'=>cw,'CMap'=>cMap,'registry'=>registry}
54
+ end
55
+
56
+ def AddCIDFonts(family,name,cw,cMap,registry)
57
+ AddCIDFont(family,'',name,cw,cMap,registry)
58
+ AddCIDFont(family,'B',name+',Bold',cw,cMap,registry)
59
+ AddCIDFont(family,'I',name+',Italic',cw,cMap,registry)
60
+ AddCIDFont(family,'BI',name+',BoldItalic',cw,cMap,registry)
61
+ end
62
+
63
+ # === add_big_five_font
64
+ def add_big_five_font(family='Big5',name='MSungStd-Light-Acro')
65
+ # Add Big5 font with proportional Latin
66
+ cw=Big5_widths
67
+ cMap='ETenms-B5-H'
68
+ registry = {
69
+ 'ordering'=>'CNS1','supplement'=>0
70
+ }
71
+ AddCIDFonts(family,name,cw,cMap,registry)
72
+ end; alias AddBig5Font add_big_five_font # === AddBig5Font
73
+
74
+ def AddBig5hwFont(family='Big5-hw',name='MSungStd-Light-Acro')
75
+ # Add Big5 font with half-width Latin
76
+ cw = {}
77
+ 32.upto(126) do |i|
78
+ cw[i.chr]=500
79
+ end
80
+ cMap='ETen-B5-H'
81
+ registry={'ordering'=>'CNS1','supplement'=>0}
82
+ AddCIDFonts(family,name,cw,cMap,registry)
83
+ end
84
+
85
+ def AddGBFont(family='GB',name='STSongStd-Light-Acro')
86
+ # Add GB font with proportional Latin
87
+ cw=GB_widths
88
+ cMap='GBKp-EUC-H'
89
+ registry={'ordering'=>'GB1','supplement'=>2}
90
+ AddCIDFonts(family,name,cw,cMap,registry)
91
+ end
92
+
93
+ def AddGBhwFont(family='GB-hw',name='STSongStd-Light-Acro')
94
+ # Add GB font with half-width Latin
95
+ 32.upto(126) do |i|
96
+ cw[i.chr]=500
97
+ end
98
+ cMap='GBK-EUC-H'
99
+ registry={'ordering'=>'GB1','supplement'=>2}
100
+ AddCIDFonts(family,name,cw,cMap,registry)
101
+ end
102
+
103
+ # === GetStringWidth
104
+ def GetStringWidth(s)
105
+ case @CurrentFont['type']
106
+ when 'Type0'
107
+ GetMBStringWidth(s)
108
+ else
109
+ super(s)
110
+ end
111
+ end
112
+
113
+ def GetMBStringWidth(s)
114
+ # Multi-byte version of GetStringWidth()
115
+ l = 0
116
+ cw = @CurrentFont['cw']
117
+ nb = s.length
118
+ i = 0
119
+ while i<nb
120
+ c=s[i]
121
+ if c.ord < 128
122
+ l += cw[c]
123
+ i += 1
124
+ else
125
+ l += 1000
126
+ i += 2
127
+ end
128
+ end
129
+ return l * @FontSize/1000
130
+ end
131
+
132
+ def MultiCell(w,h,txt,border=0,align='L',fill=0)
133
+ if @CurrentFont['type']=='Type0'
134
+ MBMultiCell(w,h,txt,border,align,fill)
135
+ else
136
+ super(w,h,txt,border,align,fill)
137
+ end
138
+ end
139
+
140
+ def MBMultiCell(w,h,txt,border=0,align='L',fill=0)
141
+ # Multi-byte version of MultiCell()
142
+ cw=@CurrentFont['cw']
143
+ w=@w-@rMargin-@x if w==0
144
+ wmax=(w-2*@cMargin)*1000/@FontSize
145
+ txt.sub("\r", '')
146
+ nb=s.length
147
+ nb -= 1 if nb>0 and s[nb-1]=="\n"
148
+ b=0
149
+ if border
150
+ if border==1
151
+ border='LTRB'
152
+ b='LRT'
153
+ b2='LR'
154
+ else
155
+ b2=''
156
+ b2+='L' unless border.index('L').nil?
157
+ b2+='R' unless border.index('R').nil?
158
+ b = (border.index('T')) ? (b2+'T') : b2
159
+ end
160
+ end
161
+ sep=-1
162
+ i=0
163
+ j=0
164
+ l=0
165
+ nl=1
166
+ while i<nb
167
+ # Get next character
168
+ c=s[i]
169
+ # Check if ASCII or MB
170
+ ascii = false
171
+ if c < 128
172
+ ascii = true
173
+ end
174
+ if c.chr=="\n"
175
+ # Explicit line break
176
+ Cell(w,h,s[j..i-j],b,2,align,fill)
177
+ i+=1
178
+ sep=-1
179
+ j=i
180
+ l=0
181
+ nl+=1
182
+ if border and nl==2
183
+ b=b2
184
+ end
185
+ next
186
+ end
187
+ if not ascii
188
+ sep=i
189
+ ls=l
190
+ elsif c.chr==' '
191
+ sep=i
192
+ ls=l
193
+ end
194
+ if ascii
195
+ l += cw[c.chr]
196
+ else
197
+ l += 1000
198
+ end
199
+ if l>wmax
200
+ # Automatic line break
201
+ if sep==-1 or i==j
202
+ i += ascii ? 1 : 2 if i==j
203
+ Cell(w,h,s[j..i-j],b,2,align,fill)
204
+ else
205
+ Cell(w,h,s[j..sep-j],b,2,align,fill)
206
+ i=(s[sep]==' ') ? sep+1 : sep
207
+ end
208
+ sep=-1
209
+ j=i
210
+ l=0
211
+ nl+=1
212
+ if border and nl==2
213
+ b=b2
214
+ end
215
+ else
216
+ i+=$ascii ? 1 : 2
217
+ end
218
+ end
219
+
220
+ # Last chunk
221
+ b += 'B' if border and not border.index('B').nil?
222
+ Cell(w,h,s[i..i-j],b,2,align,fill)
223
+ @x=@lMargin
224
+ end
225
+
226
+ def Write(h,txt,link='')
227
+ if @CurrentFont['type']=='Type0'
228
+ MBWrite(h,txt,link)
229
+ else
230
+ super(h,txt,link)
231
+ end
232
+ end
233
+
234
+ def MBWrite(h,txt,link)
235
+ # Multi-byte version of Write()
236
+ cw=@CurrentFont['cw']
237
+ w=@w-@rMargin-@x
238
+ wmax=(w-2*@cMargin)*1000/@FontSize
239
+ s=txt.sub("\r", ' ')
240
+ nb=s.length
241
+ sep=-1
242
+ i=0
243
+ j=0
244
+ l=0
245
+ nl=1
246
+ while i<nb
247
+ # Get next character
248
+ c=s[i]
249
+ # Check if ASCII or MB
250
+ ascii = false
251
+ if c < 128
252
+ ascii = true
253
+ end
254
+ if c.chr=="\n"
255
+ #Explicit line break
256
+ Cell(w,h,s[j..i-j],0,2,'',0,link)
257
+ i+=1
258
+ sep=-1
259
+ j=i
260
+ l=0
261
+ if nl==1
262
+ @x=@lMargin
263
+ w=@w-@rMargin-@x
264
+ wmax=(w-2*@cMargin)*1000/@FontSize
265
+ end
266
+ nl+=1
267
+ next
268
+ end
269
+ sep=i if not ascii or c.chr==' '
270
+ if ascii
271
+ l += cw[c.chr]
272
+ else
273
+ l += 1000
274
+ end
275
+ if l>wmax
276
+ # Automatic line break
277
+ if sep==-1 or i==j
278
+ if @x>@lMargin
279
+ # Move to next line
280
+ @x=@lMargin
281
+ @y+=h
282
+ w=@w-@rMargin-@x
283
+ wmax=(w-2*@cMargin)*1000/@FontSize
284
+ i+=1
285
+ nl+=1
286
+ next
287
+ end
288
+ i+=ascii ? 1 : 2 if i==j
289
+ Cell(w,h,s[j..i-j],0,2,'',0,link)
290
+ else
291
+ Cell(w,h,s[j..sep-j],0,2,'',0,link)
292
+ i=(s[sep]==' ') ? sep+1 : sep
293
+ end
294
+ sep=-1
295
+ j=i
296
+ l=0
297
+ if nl==1
298
+ @x=@lMargin
299
+ w=@w-@rMargin-@x
300
+ wmax=(w-2*@cMargin)*1000/@FontSize
301
+ end
302
+ nl+=1
303
+ else
304
+ i+=ascii ? 1 : 2
305
+ end
306
+ end
307
+
308
+ #Last chunk
309
+ if i!=j
310
+ Cell(l/1000*@FontSize,h,s[j..i-j],0,0,'',0,link)
311
+ end
312
+ end
313
+
314
+ private
315
+
316
+ def putfonts
317
+ nf=@n
318
+ @diffs.each do |diff|
319
+ # Encodings
320
+ newobj
321
+ out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding '+
322
+ '/Differences ['+diff+']>>')
323
+ out('endobj')
324
+ end
325
+ @FontFiles.each_pair do |file, info|
326
+ # Font file embedding
327
+ newobj
328
+ @FontFiles[file]['n']=@n
329
+
330
+ if self.class.const_defined? 'FPDF_FONTPATH'
331
+ if FPDF_FONTPATH[-1,1] == '/'
332
+ file = FPDF_FONTPATH + file
333
+ else
334
+ file = FPDF_FONTPATH + '/' + file
335
+ end
336
+ end
337
+ size = File.size(file)
338
+ unless File.exists?(file)
339
+ Error('Font file not found')
340
+ end
341
+ out('<</Length '+size.to_s)
342
+ if file[-2]=='.z'
343
+ out('/Filter /FlateDecode')
344
+ end
345
+ out('/Length1 '+info['length1'])
346
+ if info['length2']
347
+ out('/Length2 '+info['length2']+' /Length3 0')
348
+ end
349
+ out('>>')
350
+ putstream(IO.read(file))
351
+ out('endobj')
352
+ end
353
+
354
+ @fonts.each_pair do |k, font|
355
+ # Font objects
356
+ newobj
357
+ @fonts[k]['n']=@n
358
+ out('<</Type /Font')
359
+ if font['type']=='Type0'
360
+ putType0(font)
361
+ else
362
+ name=font['name']
363
+ out('/BaseFont /'+name)
364
+ if font['type']=='core'
365
+ #Standard font
366
+ out('/Subtype /Type1')
367
+ if name!='Symbol' and name!='ZapfDingbats'
368
+ out('/Encoding /WinAnsiEncoding')
369
+ end
370
+ else
371
+ # Additional font
372
+ out('/Subtype /' + font['type'])
373
+ out('/FirstChar 32')
374
+ out('/LastChar 255')
375
+ out('/Widths '+(@n+1).to_s+' 0 R')
376
+ out('/FontDescriptor '+(@n+2).to_s+' 0 R')
377
+ if font['enc']
378
+ if font['diff']
379
+ out('/Encoding '+(nf+font['diff']).to_s+' 0 R')
380
+ else
381
+ out('/Encoding /WinAnsiEncoding')
382
+ end
383
+ end
384
+ end
385
+ out('>>')
386
+ out('endobj')
387
+ if font['type']!='core'
388
+ # Widths
389
+ newobj
390
+ cw=font['cw']
391
+ s='['
392
+ 32.upto(255) do |i|
393
+ s+=cw[i.chr].to_s+' '
394
+ end
395
+ out(s+']')
396
+ out('endobj')
397
+ # Descriptor
398
+ newobj
399
+ s='<</Type /FontDescriptor /FontName /'+name
400
+ font['desc'].each_pair do |k, v|
401
+ s+=' /'+k+' '+v
402
+ end
403
+ file=font['file']
404
+ if file
405
+ s+=' /FontFile'+((font['type']=='Type1') ? '' : '2')+
406
+ ' '+@FontFiles[file]['n']+' 0 R'
407
+ end
408
+ out(s+'>>')
409
+ out('endobj')
410
+ end
411
+ end
412
+ end
413
+ end
414
+
415
+ def putType0(font)
416
+ # Type0
417
+ out('/Subtype /Type0')
418
+ out('/BaseFont /'+font['name']+'-'+font['CMap'])
419
+ out('/Encoding /'+font['CMap'])
420
+ out('/DescendantFonts ['+(@n+1).to_s+' 0 R]')
421
+ out('>>')
422
+ out('endobj')
423
+ # CIDFont
424
+ newobj
425
+ out('<</Type /Font')
426
+ out('/Subtype /CIDFontType0')
427
+ out('/BaseFont /'+font['name'])
428
+ out('/CIDSystemInfo <</Registry '+textstring('Adobe')+' /Ordering '+
429
+ textstring(font['registry']['ordering'])+' /Supplement '+
430
+ font['registry']['supplement'].to_s+'>>')
431
+ out('/FontDescriptor '+(@n+1).to_s+' 0 R')
432
+ w='1 ['+font['cw'].values.join(' ')+']'
433
+ if font['CMap']=='ETen-B5-H'
434
+ w='13648 13742 500'
435
+ elsif(font['CMap']=='GBK-EUC-H')
436
+ w='814 907 500 7716 [500]'
437
+ end
438
+ out('/W ['+w+']>>')
439
+ out('endobj')
440
+ # Font descriptor
441
+ newobj
442
+ out('<</Type /FontDescriptor')
443
+ out('/FontName /'+font['name'])
444
+ out('/Flags 6')
445
+ out('/FontBBox [0 -200 1000 900]')
446
+ out('/ItalicAngle 0')
447
+ out('/Ascent 800')
448
+ out('/Descent -200')
449
+ out('/CapHeight 800')
450
+ out('/StemV 50')
451
+ out('>>')
452
+ out('endobj')
453
+ end
454
+ end