##// END OF EJS Templates
PDF: back out r5253 (#7794, #61)....
Toshi MARUYAMA -
r5161:516320e82b0f
parent child
Show More
@@ -1,464 +1,464
1 # Copyright (c) 2006 4ssoM LLC <www.4ssoM.com>
1 # Copyright (c) 2006 4ssoM LLC <www.4ssoM.com>
2 # 1.12 contributed by Ed Moss.
2 # 1.12 contributed by Ed Moss.
3 #
3 #
4 # The MIT License
4 # The MIT License
5 #
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
11 # furnished to do so, subject to the following conditions:
12 #
12 #
13 # The above copyright notice and this permission notice shall be included in
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
14 # all copies or substantial portions of the Software.
15 #
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 # THE SOFTWARE.
22 # THE SOFTWARE.
23 #
23 #
24 # This is direct port of japanese.php
24 # This is direct port of japanese.php
25 #
25 #
26 # Japanese PDF support.
26 # Japanese PDF support.
27 #
27 #
28 # Usage is as follows:
28 # Usage is as follows:
29 #
29 #
30 # require 'fpdf'
30 # require 'fpdf'
31 # require 'chinese'
31 # require 'chinese'
32 # pdf = FPDF.new
32 # pdf = FPDF.new
33 # pdf.extend(PDF_Japanese)
33 # pdf.extend(PDF_Japanese)
34 #
34 #
35 # This allows it to be combined with other extensions, such as the bookmark
35 # This allows it to be combined with other extensions, such as the bookmark
36 # module.
36 # module.
37
37
38 module PDF_Japanese
38 module PDF_Japanese
39 CONTROL_CHARACTERS = (0x00...0x20).inject({}){|map, c| map[c.chr] = 278; map }.freeze
39
40 SJIS_widths={' ' => 278, '!' => 299, '"' => 353, '#' => 614, '$' => 614, '%' => 721, '&' => 735, '\'' => 216,
40 SJIS_widths={' ' => 278, '!' => 299, '"' => 353, '#' => 614, '$' => 614, '%' => 721, '&' => 735, '\'' => 216,
41 '(' => 323, ')' => 323, '*' => 449, '+' => 529, ',' => 219, '-' => 306, '.' => 219, '/' => 453, '0' => 614, '1' => 614,
41 '(' => 323, ')' => 323, '*' => 449, '+' => 529, ',' => 219, '-' => 306, '.' => 219, '/' => 453, '0' => 614, '1' => 614,
42 '2' => 614, '3' => 614, '4' => 614, '5' => 614, '6' => 614, '7' => 614, '8' => 614, '9' => 614, ':' => 219, ';' => 219,
42 '2' => 614, '3' => 614, '4' => 614, '5' => 614, '6' => 614, '7' => 614, '8' => 614, '9' => 614, ':' => 219, ';' => 219,
43 '<' => 529, '=' => 529, '>' => 529, '?' => 486, '@' => 744, 'A' => 646, 'B' => 604, 'C' => 617, 'D' => 681, 'E' => 567,
43 '<' => 529, '=' => 529, '>' => 529, '?' => 486, '@' => 744, 'A' => 646, 'B' => 604, 'C' => 617, 'D' => 681, 'E' => 567,
44 'F' => 537, 'G' => 647, 'H' => 738, 'I' => 320, 'J' => 433, 'K' => 637, 'L' => 566, 'M' => 904, 'N' => 710, 'O' => 716,
44 'F' => 537, 'G' => 647, 'H' => 738, 'I' => 320, 'J' => 433, 'K' => 637, 'L' => 566, 'M' => 904, 'N' => 710, 'O' => 716,
45 'P' => 605, 'Q' => 716, 'R' => 623, 'S' => 517, 'T' => 601, 'U' => 690, 'V' => 668, 'W' => 990, 'X' => 681, 'Y' => 634,
45 'P' => 605, 'Q' => 716, 'R' => 623, 'S' => 517, 'T' => 601, 'U' => 690, 'V' => 668, 'W' => 990, 'X' => 681, 'Y' => 634,
46 'Z' => 578, '[' => 316, '\\' => 614, ']' => 316, '^' => 529, '_' => 500, '`' => 387, 'a' => 509, 'b' => 566, 'c' => 478,
46 'Z' => 578, '[' => 316, '\\' => 614, ']' => 316, '^' => 529, '_' => 500, '`' => 387, 'a' => 509, 'b' => 566, 'c' => 478,
47 'd' => 565, 'e' => 503, 'f' => 337, 'g' => 549, 'h' => 580, 'i' => 275, 'j' => 266, 'k' => 544, 'l' => 276, 'm' => 854,
47 'd' => 565, 'e' => 503, 'f' => 337, 'g' => 549, 'h' => 580, 'i' => 275, 'j' => 266, 'k' => 544, 'l' => 276, 'm' => 854,
48 'n' => 579, 'o' => 550, 'p' => 578, 'q' => 566, 'r' => 410, 's' => 444, 't' => 340, 'u' => 575, 'v' => 512, 'w' => 760,
48 'n' => 579, 'o' => 550, 'p' => 578, 'q' => 566, 'r' => 410, 's' => 444, 't' => 340, 'u' => 575, 'v' => 512, 'w' => 760,
49 'x' => 503, 'y' => 529, 'z' => 453, '{' => 326, '|' => 380, '}' => 326, '~' => 387}.merge(CONTROL_CHARACTERS).freeze
49 'x' => 503, 'y' => 529, 'z' => 453, '{' => 326, '|' => 380, '}' => 326, '~' => 387}
50
50
51 def AddCIDFont(family,style,name,cw,cMap,registry)
51 def AddCIDFont(family,style,name,cw,cMap,registry)
52 fontkey=family.downcase+style.upcase
52 fontkey=family.downcase+style.upcase
53 unless @fonts[fontkey].nil?
53 unless @fonts[fontkey].nil?
54 Error("CID font already added: family style")
54 Error("CID font already added: family style")
55 end
55 end
56 i=@fonts.length+1
56 i=@fonts.length+1
57 @fonts[fontkey]={'i'=>i,'type'=>'Type0','name'=>name,'up'=>-120,'ut'=>40,'cw'=>cw,
57 @fonts[fontkey]={'i'=>i,'type'=>'Type0','name'=>name,'up'=>-120,'ut'=>40,'cw'=>cw,
58 'CMap'=>cMap,'registry'=>registry}
58 'CMap'=>cMap,'registry'=>registry}
59 end
59 end
60
60
61 def AddCIDFonts(family,name,cw,cMap,registry)
61 def AddCIDFonts(family,name,cw,cMap,registry)
62 AddCIDFont(family,'',name,cw,cMap,registry)
62 AddCIDFont(family,'',name,cw,cMap,registry)
63 AddCIDFont(family,'B',name+',Bold',cw,cMap,registry)
63 AddCIDFont(family,'B',name+',Bold',cw,cMap,registry)
64 AddCIDFont(family,'I',name+',Italic',cw,cMap,registry)
64 AddCIDFont(family,'I',name+',Italic',cw,cMap,registry)
65 AddCIDFont(family,'BI',name+',BoldItalic',cw,cMap,registry)
65 AddCIDFont(family,'BI',name+',BoldItalic',cw,cMap,registry)
66 end
66 end
67
67
68 def AddSJISFont(family='SJIS')
68 def AddSJISFont(family='SJIS')
69 #Add SJIS font with proportional Latin
69 #Add SJIS font with proportional Latin
70 name='KozMinPro-Regular-Acro'
70 name='KozMinPro-Regular-Acro'
71 cw=SJIS_widths
71 cw=SJIS_widths
72 cMap='90msp-RKSJ-H'
72 cMap='90msp-RKSJ-H'
73 registry={'ordering'=>'Japan1','supplement'=>2}
73 registry={'ordering'=>'Japan1','supplement'=>2}
74 AddCIDFonts(family,name,cw,cMap,registry)
74 AddCIDFonts(family,name,cw,cMap,registry)
75 end
75 end
76
76
77 def AddSJIShwFont(family='SJIS-hw')
77 def AddSJIShwFont(family='SJIS-hw')
78 #Add SJIS font with half-width Latin
78 #Add SJIS font with half-width Latin
79 name='KozMinPro-Regular-Acro'
79 name='KozMinPro-Regular-Acro'
80 32.upto(126) do |i|
80 32.upto(126) do |i|
81 cw[i.chr]=500
81 cw[i.chr]=500
82 end
82 end
83 cMap='90ms-RKSJ-H'
83 cMap='90ms-RKSJ-H'
84 registry={'ordering'=>'Japan1','supplement'=>2}
84 registry={'ordering'=>'Japan1','supplement'=>2}
85 AddCIDFonts(family,name,cw,cMap,registry)
85 AddCIDFonts(family,name,cw,cMap,registry)
86 end
86 end
87
87
88 def GetStringWidth(s)
88 def GetStringWidth(s)
89 if(@CurrentFont['type']=='Type0')
89 if(@CurrentFont['type']=='Type0')
90 return GetSJISStringWidth(s)
90 return GetSJISStringWidth(s)
91 else
91 else
92 return super(s)
92 return super(s)
93 end
93 end
94 end
94 end
95
95
96 def GetSJISStringWidth(s)
96 def GetSJISStringWidth(s)
97 #SJIS version of GetStringWidth()
97 #SJIS version of GetStringWidth()
98 l=0
98 l=0
99 cw=@CurrentFont['cw']
99 cw=@CurrentFont['cw']
100 nb=s.length
100 nb=s.length
101 i=0
101 i=0
102 while(i<nb)
102 while(i<nb)
103 o=s[i]
103 o=s[i]
104 if(o<128)
104 if(o<128)
105 #ASCII
105 #ASCII
106 l+=cw[o.chr] if cw[o.chr]
106 l+=cw[o.chr] if cw[o.chr]
107 i+=1
107 i+=1
108 elsif(o>=161 and o<=223)
108 elsif(o>=161 and o<=223)
109 #Half-width katakana
109 #Half-width katakana
110 l+=500
110 l+=500
111 i+=1
111 i+=1
112 else
112 else
113 #Full-width character
113 #Full-width character
114 l+=1000
114 l+=1000
115 i+=2
115 i+=2
116 end
116 end
117 end
117 end
118 return l*@FontSize/1000
118 return l*@FontSize/1000
119 end
119 end
120
120
121 def MultiCell(w,h,txt,border=0,align='L',fill=0)
121 def MultiCell(w,h,txt,border=0,align='L',fill=0)
122 if(@CurrentFont['type']=='Type0')
122 if(@CurrentFont['type']=='Type0')
123 SJISMultiCell(w,h,txt,border,align,fill)
123 SJISMultiCell(w,h,txt,border,align,fill)
124 else
124 else
125 super(w,h,txt,border,align,fill)
125 super(w,h,txt,border,align,fill)
126 end
126 end
127 end
127 end
128
128
129 def SJISMultiCell(w,h,txt,border=0,align='L',fill=0)
129 def SJISMultiCell(w,h,txt,border=0,align='L',fill=0)
130 #Output text with automatic or explicit line breaks
130 #Output text with automatic or explicit line breaks
131 cw=@CurrentFont['cw']
131 cw=@CurrentFont['cw']
132 if(w==0)
132 if(w==0)
133 w=@w-@rMargin-@x
133 w=@w-@rMargin-@x
134 end
134 end
135 wmax=(w-2*@cMargin)*1000/@FontSize
135 wmax=(w-2*@cMargin)*1000/@FontSize
136 s=txt.gsub("\r",'')
136 s=txt.gsub("\r",'')
137 nb=s.length
137 nb=s.length
138 if(nb>0 and s[nb-1]=="\n")
138 if(nb>0 and s[nb-1]=="\n")
139 nb-=1
139 nb-=1
140 end
140 end
141 b=0
141 b=0
142 if(border)
142 if(border)
143 if(border==1)
143 if(border==1)
144 border='LTRB'
144 border='LTRB'
145 b='LRT'
145 b='LRT'
146 b2='LR'
146 b2='LR'
147 else
147 else
148 b2=''
148 b2=''
149 b2='L' unless border.to_s.index('L').nil?
149 b2='L' unless border.to_s.index('L').nil?
150 b2=b2+'R' unless border.to_s.index('R').nil?
150 b2=b2+'R' unless border.to_s.index('R').nil?
151 b=(border.to_s.index('T')) ? (b2+'T') : b2
151 b=(border.to_s.index('T')) ? (b2+'T') : b2
152 end
152 end
153 end
153 end
154 sep=-1
154 sep=-1
155 i=0
155 i=0
156 j=0
156 j=0
157 l=0
157 l=0
158 nl=1
158 nl=1
159 while(i<nb)
159 while(i<nb)
160 #Get next character
160 #Get next character
161 c=s[i]
161 c=s[i]
162 o=c #o=ord(c)
162 o=c #o=ord(c)
163 if(o==10)
163 if(o==10)
164 #Explicit line break
164 #Explicit line break
165 Cell(w,h,s[j,i-j],b,2,align,fill)
165 Cell(w,h,s[j,i-j],b,2,align,fill)
166 i+=1
166 i+=1
167 sep=-1
167 sep=-1
168 j=i
168 j=i
169 l=0
169 l=0
170 nl+=1
170 nl+=1
171 if(border and nl==2)
171 if(border and nl==2)
172 b=b2
172 b=b2
173 end
173 end
174 next
174 next
175 end
175 end
176 if(o<128)
176 if(o<128)
177 #ASCII
177 #ASCII
178 l+=cw[c.chr] || 0
178 l+=cw[c.chr] || 0
179 n=1
179 n=1
180 if(o==32)
180 if(o==32)
181 sep=i
181 sep=i
182 end
182 end
183 elsif(o>=161 and o<=223)
183 elsif(o>=161 and o<=223)
184 #Half-width katakana
184 #Half-width katakana
185 l+=500
185 l+=500
186 n=1
186 n=1
187 sep=i
187 sep=i
188 else
188 else
189 #Full-width character
189 #Full-width character
190 l+=1000
190 l+=1000
191 n=2
191 n=2
192 sep=i
192 sep=i
193 end
193 end
194 if(l>wmax)
194 if(l>wmax)
195 #Automatic line break
195 #Automatic line break
196 if(sep==-1 or i==j)
196 if(sep==-1 or i==j)
197 if(i==j)
197 if(i==j)
198 i+=n
198 i+=n
199 end
199 end
200 Cell(w,h,s[j,i-j],b,2,align,fill)
200 Cell(w,h,s[j,i-j],b,2,align,fill)
201 else
201 else
202 Cell(w,h,s[j,sep-j],b,2,align,fill)
202 Cell(w,h,s[j,sep-j],b,2,align,fill)
203 i=(s[sep].chr==' ') ? sep+1 : sep
203 i=(s[sep].chr==' ') ? sep+1 : sep
204 end
204 end
205 sep=-1
205 sep=-1
206 j=i
206 j=i
207 l=0
207 l=0
208 nl+=1
208 nl+=1
209 if(border and nl==2)
209 if(border and nl==2)
210 b=b2
210 b=b2
211 end
211 end
212 else
212 else
213 i+=n
213 i+=n
214 if(o>=128)
214 if(o>=128)
215 sep=i
215 sep=i
216 end
216 end
217 end
217 end
218 end
218 end
219 #Last chunk
219 #Last chunk
220 if(border and not border.to_s.index('B').nil?)
220 if(border and not border.to_s.index('B').nil?)
221 b+='B'
221 b+='B'
222 end
222 end
223 Cell(w,h,s[j,i-j],b,2,align,fill)
223 Cell(w,h,s[j,i-j],b,2,align,fill)
224 @x=@lMargin
224 @x=@lMargin
225 end
225 end
226
226
227 def Write(h,txt,link='')
227 def Write(h,txt,link='')
228 if(@CurrentFont['type']=='Type0')
228 if(@CurrentFont['type']=='Type0')
229 SJISWrite(h,txt,link)
229 SJISWrite(h,txt,link)
230 else
230 else
231 super(h,txt,link)
231 super(h,txt,link)
232 end
232 end
233 end
233 end
234
234
235 def SJISWrite(h,txt,link)
235 def SJISWrite(h,txt,link)
236 #SJIS version of Write()
236 #SJIS version of Write()
237 cw=@CurrentFont['cw']
237 cw=@CurrentFont['cw']
238 w=@w-@rMargin-@x
238 w=@w-@rMargin-@x
239 wmax=(w-2*@cMargin)*1000/@FontSize
239 wmax=(w-2*@cMargin)*1000/@FontSize
240 s=txt.gsub("\r",'')
240 s=txt.gsub("\r",'')
241 nb=s.length
241 nb=s.length
242 sep=-1
242 sep=-1
243 i=0
243 i=0
244 j=0
244 j=0
245 l=0
245 l=0
246 nl=1
246 nl=1
247 while(i<nb)
247 while(i<nb)
248 #Get next character
248 #Get next character
249 c=s[i]
249 c=s[i]
250 o=c
250 o=c
251 if(o==10)
251 if(o==10)
252 #Explicit line break
252 #Explicit line break
253 Cell(w,h,s[j,i-j],0,2,'',0,link)
253 Cell(w,h,s[j,i-j],0,2,'',0,link)
254 i+=1
254 i+=1
255 sep=-1
255 sep=-1
256 j=i
256 j=i
257 l=0
257 l=0
258 if(nl==1)
258 if(nl==1)
259 #Go to left margin
259 #Go to left margin
260 @x=@lMargin
260 @x=@lMargin
261 w=@w-@rMargin-@x
261 w=@w-@rMargin-@x
262 wmax=(w-2*@cMargin)*1000/@FontSize
262 wmax=(w-2*@cMargin)*1000/@FontSize
263 end
263 end
264 nl+=1
264 nl+=1
265 next
265 next
266 end
266 end
267 if(o<128)
267 if(o<128)
268 #ASCII
268 #ASCII
269 l+=cw[c.chr] || 0
269 l+=cw[c.chr] || 0
270 n=1
270 n=1
271 if(o==32)
271 if(o==32)
272 sep=i
272 sep=i
273 end
273 end
274 elsif(o>=161 and o<=223)
274 elsif(o>=161 and o<=223)
275 #Half-width katakana
275 #Half-width katakana
276 l+=500
276 l+=500
277 n=1
277 n=1
278 sep=i
278 sep=i
279 else
279 else
280 #Full-width character
280 #Full-width character
281 l+=1000
281 l+=1000
282 n=2
282 n=2
283 sep=i
283 sep=i
284 end
284 end
285 if(l>wmax)
285 if(l>wmax)
286 #Automatic line break
286 #Automatic line break
287 if(sep==-1 or i==j)
287 if(sep==-1 or i==j)
288 if(@x>@lMargin)
288 if(@x>@lMargin)
289 #Move to next line
289 #Move to next line
290 @x=@lMargin
290 @x=@lMargin
291 @y+=h
291 @y+=h
292 w=@w-@rMargin-@x
292 w=@w-@rMargin-@x
293 wmax=(w-2*@cMargin)*1000/@FontSize
293 wmax=(w-2*@cMargin)*1000/@FontSize
294 i+=n
294 i+=n
295 nl+=1
295 nl+=1
296 next
296 next
297 end
297 end
298 if(i==j)
298 if(i==j)
299 i+=n
299 i+=n
300 end
300 end
301 Cell(w,h,s[j,i-j],0,2,'',0,link)
301 Cell(w,h,s[j,i-j],0,2,'',0,link)
302 else
302 else
303 Cell(w,h,s[j,sep-j],0,2,'',0,link)
303 Cell(w,h,s[j,sep-j],0,2,'',0,link)
304 i=(s[sep].chr==' ') ? sep+1 : sep
304 i=(s[sep].chr==' ') ? sep+1 : sep
305 end
305 end
306 sep=-1
306 sep=-1
307 j=i
307 j=i
308 l=0
308 l=0
309 if(nl==1)
309 if(nl==1)
310 @x=@lMargin
310 @x=@lMargin
311 w=@w-@rMargin-@x
311 w=@w-@rMargin-@x
312 wmax=(w-2*@cMargin)*1000/@FontSize
312 wmax=(w-2*@cMargin)*1000/@FontSize
313 end
313 end
314 nl+=1
314 nl+=1
315 else
315 else
316 i+=n
316 i+=n
317 if(o>=128)
317 if(o>=128)
318 sep=i
318 sep=i
319 end
319 end
320 end
320 end
321 end
321 end
322 #Last chunk
322 #Last chunk
323 if(i!=j)
323 if(i!=j)
324 Cell(l/1000*@FontSize,h,s[j,i-j],0,0,'',0,link)
324 Cell(l/1000*@FontSize,h,s[j,i-j],0,0,'',0,link)
325 end
325 end
326 end
326 end
327
327
328 private
328 private
329
329
330 def putfonts()
330 def putfonts()
331 nf=@n
331 nf=@n
332 @diffs.each do |diff|
332 @diffs.each do |diff|
333 #Encodings
333 #Encodings
334 newobj()
334 newobj()
335 out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['+diff+']>>')
335 out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['+diff+']>>')
336 out('endobj')
336 out('endobj')
337 end
337 end
338 # mqr=get_magic_quotes_runtime()
338 # mqr=get_magic_quotes_runtime()
339 # set_magic_quotes_runtime(0)
339 # set_magic_quotes_runtime(0)
340 @FontFiles.each_pair do |file, info|
340 @FontFiles.each_pair do |file, info|
341 #Font file embedding
341 #Font file embedding
342 newobj()
342 newobj()
343 @FontFiles[file]['n']=@n
343 @FontFiles[file]['n']=@n
344 if(defined('FPDF_FONTPATH'))
344 if(defined('FPDF_FONTPATH'))
345 file=FPDF_FONTPATH+file
345 file=FPDF_FONTPATH+file
346 end
346 end
347 size=filesize(file)
347 size=filesize(file)
348 if(!size)
348 if(!size)
349 Error('Font file not found')
349 Error('Font file not found')
350 end
350 end
351 out('<</Length '+size)
351 out('<</Length '+size)
352 if(file[-2]=='.z')
352 if(file[-2]=='.z')
353 out('/Filter /FlateDecode')
353 out('/Filter /FlateDecode')
354 end
354 end
355 out('/Length1 '+info['length1'])
355 out('/Length1 '+info['length1'])
356 unless info['length2'].nil?
356 unless info['length2'].nil?
357 out('/Length2 '+info['length2']+' /Length3 0')
357 out('/Length2 '+info['length2']+' /Length3 0')
358 end
358 end
359 out('>>')
359 out('>>')
360 f=fopen(file,'rb')
360 f=fopen(file,'rb')
361 putstream(fread(f,size))
361 putstream(fread(f,size))
362 fclose(f)
362 fclose(f)
363 out('endobj')
363 out('endobj')
364 end
364 end
365 # set_magic_quotes_runtime(mqr)
365 # set_magic_quotes_runtime(mqr)
366 @fonts.each_pair do |k, font|
366 @fonts.each_pair do |k, font|
367 #Font objects
367 #Font objects
368 newobj()
368 newobj()
369 @fonts[k]['n']=@n
369 @fonts[k]['n']=@n
370 out('<</Type /Font')
370 out('<</Type /Font')
371 if(font['type']=='Type0')
371 if(font['type']=='Type0')
372 putType0(font)
372 putType0(font)
373 else
373 else
374 name=font['name']
374 name=font['name']
375 out('/BaseFont /'+name)
375 out('/BaseFont /'+name)
376 if(font['type']=='core')
376 if(font['type']=='core')
377 #Standard font
377 #Standard font
378 out('/Subtype /Type1')
378 out('/Subtype /Type1')
379 if(name!='Symbol' and name!='ZapfDingbats')
379 if(name!='Symbol' and name!='ZapfDingbats')
380 out('/Encoding /WinAnsiEncoding')
380 out('/Encoding /WinAnsiEncoding')
381 end
381 end
382 else
382 else
383 #Additional font
383 #Additional font
384 out('/Subtype /'+font['type'])
384 out('/Subtype /'+font['type'])
385 out('/FirstChar 32')
385 out('/FirstChar 32')
386 out('/LastChar 255')
386 out('/LastChar 255')
387 out('/Widths '+(@n+1)+' 0 R')
387 out('/Widths '+(@n+1)+' 0 R')
388 out('/FontDescriptor '+(@n+2)+' 0 R')
388 out('/FontDescriptor '+(@n+2)+' 0 R')
389 if(font['enc'])
389 if(font['enc'])
390 if !font['diff'].nil?
390 if !font['diff'].nil?
391 out('/Encoding '+(nf+font['diff'])+' 0 R')
391 out('/Encoding '+(nf+font['diff'])+' 0 R')
392 else
392 else
393 out('/Encoding /WinAnsiEncoding')
393 out('/Encoding /WinAnsiEncoding')
394 end
394 end
395 end
395 end
396 end
396 end
397 out('>>')
397 out('>>')
398 out('endobj')
398 out('endobj')
399 if(font['type']!='core')
399 if(font['type']!='core')
400 #Widths
400 #Widths
401 newobj()
401 newobj()
402 cw=font['cw']
402 cw=font['cw']
403 s='['
403 s='['
404 32.upto(255) do |i|
404 32.upto(255) do |i|
405 s+=cw[i.chr]+' '
405 s+=cw[i.chr]+' '
406 end
406 end
407 out(s+']')
407 out(s+']')
408 out('endobj')
408 out('endobj')
409 #Descriptor
409 #Descriptor
410 newobj()
410 newobj()
411 s='<</Type /FontDescriptor /FontName /'+name
411 s='<</Type /FontDescriptor /FontName /'+name
412 font['desc'].each_pair do |k, v|
412 font['desc'].each_pair do |k, v|
413 s+=' /'+k+' '+v
413 s+=' /'+k+' '+v
414 end
414 end
415 file=font['file']
415 file=font['file']
416 if(file)
416 if(file)
417 s+=' /FontFile'+(font['type']=='Type1' ? '' : '2')+' '+@FontFiles[file]['n']+' 0 R'
417 s+=' /FontFile'+(font['type']=='Type1' ? '' : '2')+' '+@FontFiles[file]['n']+' 0 R'
418 end
418 end
419 out(s+'>>')
419 out(s+'>>')
420 out('endobj')
420 out('endobj')
421 end
421 end
422 end
422 end
423 end
423 end
424 end
424 end
425
425
426 def putType0(font)
426 def putType0(font)
427 #Type0
427 #Type0
428 out('/Subtype /Type0')
428 out('/Subtype /Type0')
429 out('/BaseFont /'+font['name']+'-'+font['CMap'])
429 out('/BaseFont /'+font['name']+'-'+font['CMap'])
430 out('/Encoding /'+font['CMap'])
430 out('/Encoding /'+font['CMap'])
431 out('/DescendantFonts ['+(@n+1).to_s+' 0 R]')
431 out('/DescendantFonts ['+(@n+1).to_s+' 0 R]')
432 out('>>')
432 out('>>')
433 out('endobj')
433 out('endobj')
434 #CIDFont
434 #CIDFont
435 newobj()
435 newobj()
436 out('<</Type /Font')
436 out('<</Type /Font')
437 out('/Subtype /CIDFontType0')
437 out('/Subtype /CIDFontType0')
438 out('/BaseFont /'+font['name'])
438 out('/BaseFont /'+font['name'])
439 out('/CIDSystemInfo <</Registry (Adobe) /Ordering ('+font['registry']['ordering']+') /Supplement '+font['registry']['supplement'].to_s+'>>')
439 out('/CIDSystemInfo <</Registry (Adobe) /Ordering ('+font['registry']['ordering']+') /Supplement '+font['registry']['supplement'].to_s+'>>')
440 out('/FontDescriptor '+(@n+1).to_s+' 0 R')
440 out('/FontDescriptor '+(@n+1).to_s+' 0 R')
441 w='/W [1 ['
441 w='/W [1 ['
442 font['cw'].keys.sort.each {|key|
442 font['cw'].keys.sort.each {|key|
443 w+=font['cw'][key].to_s + " "
443 w+=font['cw'][key].to_s + " "
444 # ActionController::Base::logger.debug key.to_s
444 # ActionController::Base::logger.debug key.to_s
445 # ActionController::Base::logger.debug font['cw'][key].to_s
445 # ActionController::Base::logger.debug font['cw'][key].to_s
446 }
446 }
447 out(w+'] 231 325 500 631 [500] 326 389 500]')
447 out(w+'] 231 325 500 631 [500] 326 389 500]')
448 out('>>')
448 out('>>')
449 out('endobj')
449 out('endobj')
450 #Font descriptor
450 #Font descriptor
451 newobj()
451 newobj()
452 out('<</Type /FontDescriptor')
452 out('<</Type /FontDescriptor')
453 out('/FontName /'+font['name'])
453 out('/FontName /'+font['name'])
454 out('/Flags 6')
454 out('/Flags 6')
455 out('/FontBBox [0 -200 1000 900]')
455 out('/FontBBox [0 -200 1000 900]')
456 out('/ItalicAngle 0')
456 out('/ItalicAngle 0')
457 out('/Ascent 800')
457 out('/Ascent 800')
458 out('/Descent -200')
458 out('/Descent -200')
459 out('/CapHeight 800')
459 out('/CapHeight 800')
460 out('/StemV 60')
460 out('/StemV 60')
461 out('>>')
461 out('>>')
462 out('endobj')
462 out('endobj')
463 end
463 end
464 end
464 end
General Comments 0
You need to be logged in to leave comments. Login now