Fixes Chinese pdf export when the issue description is too long (#1170).

git-svn-id: http://redmine.rubyforge.org/svn/trunk@1497 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2008-06-07 08:39:06 +00:00
parent 9f901a0ba2
commit f4aa04b96e
1 changed files with 473 additions and 473 deletions

View File

@ -1,473 +1,473 @@
# Copyright (c) 2006 4ssoM LLC <www.4ssoM.com> # Copyright (c) 2006 4ssoM LLC <www.4ssoM.com>
# 1.12 contributed by Ed Moss. # 1.12 contributed by Ed Moss.
# #
# The MIT License # The MIT License
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy # Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal # of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights # in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is # copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions: # furnished to do so, subject to the following conditions:
# #
# The above copyright notice and this permission notice shall be included in # The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software. # all copies or substantial portions of the Software.
# #
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
# #
# This is direct port of chinese.php # This is direct port of chinese.php
# #
# Chinese PDF support. # Chinese PDF support.
# #
# Usage is as follows: # Usage is as follows:
# #
# require 'fpdf' # require 'fpdf'
# require 'chinese' # require 'chinese'
# pdf = FPDF.new # pdf = FPDF.new
# pdf.extend(PDF_Chinese) # pdf.extend(PDF_Chinese)
# #
# This allows it to be combined with other extensions, such as the bookmark # This allows it to be combined with other extensions, such as the bookmark
# module. # module.
module PDF_Chinese module PDF_Chinese
Big5_widths={' '=>250,'!'=>250,'"'=>408,'#'=>668,''=>490,'%'=>875,'&'=>698,'\''=>250, Big5_widths={' '=>250,'!'=>250,'"'=>408,'#'=>668,''=>490,'%'=>875,'&'=>698,'\''=>250,
'('=>240,')'=>240,'*'=>417,'+'=>667,','=>250,'-'=>313,'.'=>250,'/'=>520,'0'=>500,'1'=>500, '('=>240,')'=>240,'*'=>417,'+'=>667,','=>250,'-'=>313,'.'=>250,'/'=>520,'0'=>500,'1'=>500,
'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>250,''=>250, '2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>250,''=>250,
'<'=>667,'='=>667,'>'=>667,'?'=>396,'@'=>921,'A'=>677,'B'=>615,'C'=>719,'D'=>760,'E'=>625, '<'=>667,'='=>667,'>'=>667,'?'=>396,'@'=>921,'A'=>677,'B'=>615,'C'=>719,'D'=>760,'E'=>625,
'F'=>552,'G'=>771,'H'=>802,'I'=>354,'J'=>354,'K'=>781,'L'=>604,'M'=>927,'N'=>750,'O'=>823, 'F'=>552,'G'=>771,'H'=>802,'I'=>354,'J'=>354,'K'=>781,'L'=>604,'M'=>927,'N'=>750,'O'=>823,
'P'=>563,'Q'=>823,'R'=>729,'S'=>542,'T'=>698,'U'=>771,'V'=>729,'W'=>948,'X'=>771,'Y'=>677, 'P'=>563,'Q'=>823,'R'=>729,'S'=>542,'T'=>698,'U'=>771,'V'=>729,'W'=>948,'X'=>771,'Y'=>677,
'Z'=>635,'['=>344,'\\'=>520,']'=>344,'^'=>469,'_'=>500,'`'=>250,'a'=>469,'b'=>521,'c'=>427, 'Z'=>635,'['=>344,'\\'=>520,']'=>344,'^'=>469,'_'=>500,'`'=>250,'a'=>469,'b'=>521,'c'=>427,
'd'=>521,'e'=>438,'f'=>271,'g'=>469,'h'=>531,'i'=>250,'j'=>250,'k'=>458,'l'=>240,'m'=>802, 'd'=>521,'e'=>438,'f'=>271,'g'=>469,'h'=>531,'i'=>250,'j'=>250,'k'=>458,'l'=>240,'m'=>802,
'n'=>531,'o'=>500,'p'=>521,'q'=>521,'r'=>365,'s'=>333,'t'=>292,'u'=>521,'v'=>458,'w'=>677, 'n'=>531,'o'=>500,'p'=>521,'q'=>521,'r'=>365,'s'=>333,'t'=>292,'u'=>521,'v'=>458,'w'=>677,
'x'=>479,'y'=>458,'z'=>427,'{'=>480,'|'=>496,'end'=>480,'~'=>667} 'x'=>479,'y'=>458,'z'=>427,'{'=>480,'|'=>496,'end'=>480,'~'=>667}
GB_widths={' '=>207,'!'=>270,'"'=>342,'#'=>467,''=>462,'%'=>797,'&'=>710,'\''=>239, GB_widths={' '=>207,'!'=>270,'"'=>342,'#'=>467,''=>462,'%'=>797,'&'=>710,'\''=>239,
'('=>374,')'=>374,'*'=>423,'+'=>605,','=>238,'-'=>375,'.'=>238,'/'=>334,'0'=>462,'1'=>462, '('=>374,')'=>374,'*'=>423,'+'=>605,','=>238,'-'=>375,'.'=>238,'/'=>334,'0'=>462,'1'=>462,
'2'=>462,'3'=>462,'4'=>462,'5'=>462,'6'=>462,'7'=>462,'8'=>462,'9'=>462,':'=>238,''=>238, '2'=>462,'3'=>462,'4'=>462,'5'=>462,'6'=>462,'7'=>462,'8'=>462,'9'=>462,':'=>238,''=>238,
'<'=>605,'='=>605,'>'=>605,'?'=>344,'@'=>748,'A'=>684,'B'=>560,'C'=>695,'D'=>739,'E'=>563, '<'=>605,'='=>605,'>'=>605,'?'=>344,'@'=>748,'A'=>684,'B'=>560,'C'=>695,'D'=>739,'E'=>563,
'F'=>511,'G'=>729,'H'=>793,'I'=>318,'J'=>312,'K'=>666,'L'=>526,'M'=>896,'N'=>758,'O'=>772, 'F'=>511,'G'=>729,'H'=>793,'I'=>318,'J'=>312,'K'=>666,'L'=>526,'M'=>896,'N'=>758,'O'=>772,
'P'=>544,'Q'=>772,'R'=>628,'S'=>465,'T'=>607,'U'=>753,'V'=>711,'W'=>972,'X'=>647,'Y'=>620, 'P'=>544,'Q'=>772,'R'=>628,'S'=>465,'T'=>607,'U'=>753,'V'=>711,'W'=>972,'X'=>647,'Y'=>620,
'Z'=>607,'['=>374,'\\'=>333,']'=>374,'^'=>606,'_'=>500,'`'=>239,'a'=>417,'b'=>503,'c'=>427, 'Z'=>607,'['=>374,'\\'=>333,']'=>374,'^'=>606,'_'=>500,'`'=>239,'a'=>417,'b'=>503,'c'=>427,
'd'=>529,'e'=>415,'f'=>264,'g'=>444,'h'=>518,'i'=>241,'j'=>230,'k'=>495,'l'=>228,'m'=>793, 'd'=>529,'e'=>415,'f'=>264,'g'=>444,'h'=>518,'i'=>241,'j'=>230,'k'=>495,'l'=>228,'m'=>793,
'n'=>527,'o'=>524,'p'=>524,'q'=>504,'r'=>338,'s'=>336,'t'=>277,'u'=>517,'v'=>450,'w'=>652, 'n'=>527,'o'=>524,'p'=>524,'q'=>504,'r'=>338,'s'=>336,'t'=>277,'u'=>517,'v'=>450,'w'=>652,
'x'=>466,'y'=>452,'z'=>407,'{'=>370,'|'=>258,'end'=>370,'~'=>605} 'x'=>466,'y'=>452,'z'=>407,'{'=>370,'|'=>258,'end'=>370,'~'=>605}
def AddCIDFont(family,style,name,cw,cMap,registry) def AddCIDFont(family,style,name,cw,cMap,registry)
#ActionController::Base::logger.debug registry.to_a.join(":").to_s #ActionController::Base::logger.debug registry.to_a.join(":").to_s
fontkey=family.downcase+style.upcase fontkey=family.downcase+style.upcase
unless @fonts[fontkey].nil? unless @fonts[fontkey].nil?
Error("Font already added: family style") Error("Font already added: family style")
end end
i=@fonts.length+1 i=@fonts.length+1
name=name.gsub(' ','') name=name.gsub(' ','')
@fonts[fontkey]={'i'=>i,'type'=>'Type0','name'=>name,'up'=>-130,'ut'=>40,'cw'=>cw, 'CMap'=>cMap,'registry'=>registry} @fonts[fontkey]={'i'=>i,'type'=>'Type0','name'=>name,'up'=>-130,'ut'=>40,'cw'=>cw, 'CMap'=>cMap,'registry'=>registry}
end end
def AddCIDFonts(family,name,cw,cMap,registry) def AddCIDFonts(family,name,cw,cMap,registry)
AddCIDFont(family,'',name,cw,cMap,registry) AddCIDFont(family,'',name,cw,cMap,registry)
AddCIDFont(family,'B',name+',Bold',cw,cMap,registry) AddCIDFont(family,'B',name+',Bold',cw,cMap,registry)
AddCIDFont(family,'I',name+',Italic',cw,cMap,registry) AddCIDFont(family,'I',name+',Italic',cw,cMap,registry)
AddCIDFont(family,'BI',name+',BoldItalic',cw,cMap,registry) AddCIDFont(family,'BI',name+',BoldItalic',cw,cMap,registry)
end end
def AddBig5Font(family='Big5',name='MSungStd-Light-Acro') def AddBig5Font(family='Big5',name='MSungStd-Light-Acro')
#Add Big5 font with proportional Latin #Add Big5 font with proportional Latin
cw=Big5_widths cw=Big5_widths
cMap='ETenms-B5-H' cMap='ETenms-B5-H'
registry={'ordering'=>'CNS1','supplement'=>0} registry={'ordering'=>'CNS1','supplement'=>0}
#ActionController::Base::logger.debug registry.to_a.join(":").to_s #ActionController::Base::logger.debug registry.to_a.join(":").to_s
AddCIDFonts(family,name,cw,cMap,registry) AddCIDFonts(family,name,cw,cMap,registry)
end end
def AddBig5hwFont(family='Big5-hw',name='MSungStd-Light-Acro') def AddBig5hwFont(family='Big5-hw',name='MSungStd-Light-Acro')
#Add Big5 font with half-witdh Latin #Add Big5 font with half-witdh Latin
cw = {} cw = {}
32.upto(126) do |i| 32.upto(126) do |i|
cw[i.chr]=500 cw[i.chr]=500
end end
cMap='ETen-B5-H' cMap='ETen-B5-H'
registry={'ordering'=>'CNS1','supplement'=>0} registry={'ordering'=>'CNS1','supplement'=>0}
AddCIDFonts(family,name,cw,cMap,registry) AddCIDFonts(family,name,cw,cMap,registry)
end end
def AddGBFont(family='GB',name='STSongStd-Light-Acro') def AddGBFont(family='GB',name='STSongStd-Light-Acro')
#Add GB font with proportional Latin #Add GB font with proportional Latin
cw=GB_widths cw=GB_widths
cMap='GBKp-EUC-H' cMap='GBKp-EUC-H'
registry={'ordering'=>'GB1','supplement'=>2} registry={'ordering'=>'GB1','supplement'=>2}
AddCIDFonts(family,name,cw,cMap,registry) AddCIDFonts(family,name,cw,cMap,registry)
end end
def AddGBhwFont(family='GB-hw',name='STSongStd-Light-Acro') def AddGBhwFont(family='GB-hw',name='STSongStd-Light-Acro')
#Add GB font with half-width Latin #Add GB font with half-width Latin
32.upto(126) do |i| 32.upto(126) do |i|
cw[i.chr]=500 cw[i.chr]=500
end end
cMap='GBK-EUC-H' cMap='GBK-EUC-H'
registry={'ordering'=>'GB1','supplement'=>2} registry={'ordering'=>'GB1','supplement'=>2}
AddCIDFonts(family,name,cw,cMap,registry) AddCIDFonts(family,name,cw,cMap,registry)
end end
def GetStringWidth(s) def GetStringWidth(s)
if(@CurrentFont['type']=='Type0') if(@CurrentFont['type']=='Type0')
return GetMBStringWidth(s) return GetMBStringWidth(s)
else else
return super(s) return super(s)
end end
end end
def GetMBStringWidth(s) def GetMBStringWidth(s)
#Multi-byte version of GetStringWidth() #Multi-byte version of GetStringWidth()
l=0 l=0
cw=@CurrentFont['cw'] cw=@CurrentFont['cw']
nb=s.length nb=s.length
i=0 i=0
while(i<nb) while(i<nb)
c=s[i] c=s[i]
if(c<128) if(c<128)
l+=cw[c.chr] if cw[c.chr] l+=cw[c.chr] if cw[c.chr]
i+=1 i+=1
else else
l+=1000 l+=1000
i+=2 i+=2
end end
end end
return l*@FontSize/1000 return l*@FontSize/1000
end end
def MultiCell(w,h,txt,border=0,align='L',fill=0) def MultiCell(w,h,txt,border=0,align='L',fill=0)
if(@CurrentFont['type']=='Type0') if(@CurrentFont['type']=='Type0')
MBMultiCell(w,h,txt,border,align,fill) MBMultiCell(w,h,txt,border,align,fill)
else else
super(w,h,txt,border,align,fill) super(w,h,txt,border,align,fill)
end end
end end
def MBMultiCell(w,h,txt,border=0,align='L',fill=0) def MBMultiCell(w,h,txt,border=0,align='L',fill=0)
#Multi-byte version of MultiCell() #Multi-byte version of MultiCell()
cw=@CurrentFont['cw'] cw=@CurrentFont['cw']
if(w==0) if(w==0)
w=@w-@rMargin-@x w=@w-@rMargin-@x
end end
wmax=(w-2*@cMargin)*1000/@FontSize wmax=(w-2*@cMargin)*1000/@FontSize
s=txt.gsub("\r",'') s=txt.gsub("\r",'')
nb=s.length nb=s.length
if(nb>0 and s[nb-1]=="\n") if(nb>0 and s[nb-1]=="\n")
nb-=1 nb-=1
end end
b=0 b=0
if(border) if(border)
if(border==1) if(border==1)
border='LTRB' border='LTRB'
b='LRT' b='LRT'
b2='LR' b2='LR'
else else
b2='' b2=''
if(border.to_s.index('L')) if(border.to_s.index('L'))
b2+='L' b2+='L'
end end
if(border.to_s.index('R')) if(border.to_s.index('R'))
b2+='R' b2+='R'
end end
b=border.to_s.index('T') ? b2+'T' : b2 b=border.to_s.index('T') ? b2+'T' : b2
end end
end end
sep=-1 sep=-1
i=0 i=0
j=0 j=0
l=0 l=0
nl=1 nl=1
while(i<nb) while(i<nb)
#Get next character #Get next character
c=s[i] c=s[i]
#Check if ASCII or MB #Check if ASCII or MB
ascii=(c<128) ascii=(c<128)
if(c=="\n") if(c.chr=="\n")
#Explicit line break #Explicit line break
Cell(w,h,s[j,i-j],b,2,align,fill) Cell(w,h,s[j,i-j],b,2,align,fill)
i+=1 i+=1
sep=-1 sep=-1
j=i j=i
l=0 l=0
nl+=1 nl+=1
if(border and nl==2) if(border and nl==2)
b=b2 b=b2
end end
next next
end end
if(!ascii) if(!ascii)
sep=i sep=i
ls=l ls=l
elsif(c==' ') elsif(c==' ')
sep=i sep=i
ls=l ls=l
end end
l+=ascii ? (cw[c.chr] || 0) : 1000 l+=ascii ? (cw[c.chr] || 0) : 1100
if(l>wmax) if(l>wmax)
#Automatic line break #Automatic line break
if(sep==-1 or i==j) if(sep==-1 or i==j)
if(i==j) if(i==j)
i+=ascii ? 1 : 2 i+=ascii ? 1 : 3
end end
Cell(w,h,s[j,i-j],b,2,align,fill) Cell(w,h,s[j,i-j],b,2,align,fill)
else else
Cell(w,h,s[j,sep-j],b,2,align,fill) Cell(w,h,s[j,sep-j],b,2,align,fill)
i=(s[sep]==' ') ? sep+1 : sep i=(s[sep]==' ') ? sep+1 : sep
end end
sep=-1 sep=-1
j=i j=i
l=0 l=0
# nl+=1 # nl+=1
if(border and nl==2) if(border and nl==2)
b=b2 b=b2
end end
else else
i+=ascii ? 1 : 2 i+=ascii ? 1 : 3
end end
end end
#Last chunk #Last chunk
if(border and not border.to_s.index('B').nil?) if(border and not border.to_s.index('B').nil?)
b+='B' b+='B'
end end
Cell(w,h,s[j,i-j],b,2,align,fill) Cell(w,h,s[j,i-j],b,2,align,fill)
@x=@lMargin @x=@lMargin
end end
def Write(h,txt,link='') def Write(h,txt,link='')
if(@CurrentFont['type']=='Type0') if(@CurrentFont['type']=='Type0')
MBWrite(h,txt,link) MBWrite(h,txt,link)
else else
super(h,txt,link) super(h,txt,link)
end end
end end
def MBWrite(h,txt,link) def MBWrite(h,txt,link)
#Multi-byte version of Write() #Multi-byte version of Write()
cw=@CurrentFont['cw'] cw=@CurrentFont['cw']
w=@w-@rMargin-@x w=@w-@rMargin-@x
wmax=(w-2*@cMargin)*1000/@FontSize wmax=(w-2*@cMargin)*1000/@FontSize
s=txt.gsub("\r",'') s=txt.gsub("\r",'')
nb=s.length nb=s.length
sep=-1 sep=-1
i=0 i=0
j=0 j=0
l=0 l=0
nl=1 nl=1
while(i<nb) while(i<nb)
#Get next character #Get next character
c=s[i] c=s[i]
#Check if ASCII or MB #Check if ASCII or MB
ascii=(c<128) ascii=(c<128)
if(c=="\n") if(c.chr=="\n")
#Explicit line break #Explicit line break
Cell(w,h,s[j,i-j],0,2,'',0,link) Cell(w,h,s[j,i-j],0,2,'',0,link)
i+=1 i+=1
sep=-1 sep=-1
j=i j=i
l=0 l=0
if(nl==1) if(nl==1)
@x=@lMargin @x=@lMargin
w=@w-@rMargin-@x w=@w-@rMargin-@x
wmax=(w-2*@cMargin)*1000/@FontSize wmax=(w-2*@cMargin)*1000/@FontSize
end end
nl+=1 nl+=1
next next
end end
if(!ascii or c==' ') if(!ascii or c==' ')
sep=i sep=i
end end
l+=ascii ? cw[c.chr] : 1000 l+=ascii ? cw[c.chr] : 1100
if(l>wmax) if(l>wmax)
#Automatic line break #Automatic line break
if(sep==-1 or i==j) if(sep==-1 or i==j)
if(@x>@lMargin) if(@x>@lMargin)
#Move to next line #Move to next line
@x=@lMargin @x=@lMargin
@y+=h @y+=h
w=@w-@rMargin-@x w=@w-@rMargin-@x
wmax=(w-2*@cMargin)*1000/@FontSize wmax=(w-2*@cMargin)*1000/@FontSize
i+=1 i+=1
nl+=1 nl+=1
next next
end end
if(i==j) if(i==j)
i+=ascii ? 1 : 2 i+=ascii ? 1 : 3
end end
Cell(w,h,s[j,i-j],0,2,'',0,link) Cell(w,h,s[j,i-j],0,2,'',0,link)
else else
Cell(w,h,s[j,sep-j],0,2,'',0,link) Cell(w,h,s[j,sep-j],0,2,'',0,link)
i=(s[sep]==' ') ? sep+1 : sep i=(s[sep]==' ') ? sep+1 : sep
end end
sep=-1 sep=-1
j=i j=i
l=0 l=0
if(nl==1) if(nl==1)
@x=@lMargin @x=@lMargin
w=@w-@rMargin-@x w=@w-@rMargin-@x
wmax=(w-2*@cMargin)*1000/@FontSize wmax=(w-2*@cMargin)*1000/@FontSize
end end
nl+=1 nl+=1
else else
i+=ascii ? 1 : 2 i+=ascii ? 1 : 3
end end
end end
#Last chunk #Last chunk
if(i!=j) if(i!=j)
Cell(l/1000*@FontSize,h,s[j,i-j],0,0,'',0,link) Cell(l/1000*@FontSize,h,s[j,i-j],0,0,'',0,link)
end end
end end
private private
def putfonts() def putfonts()
nf=@n nf=@n
@diffs.each do |diff| @diffs.each do |diff|
#Encodings #Encodings
newobj() newobj()
out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['+diff+']>>') out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['+diff+']>>')
out('endobj') out('endobj')
end end
# mqr=get_magic_quotes_runtime() # mqr=get_magic_quotes_runtime()
# set_magic_quotes_runtime(0) # set_magic_quotes_runtime(0)
@FontFiles.each_pair do |file, info| @FontFiles.each_pair do |file, info|
#Font file embedding #Font file embedding
newobj() newobj()
@FontFiles[file]['n']=@n @FontFiles[file]['n']=@n
if(defined('FPDF_FONTPATH')) if(defined('FPDF_FONTPATH'))
file=FPDF_FONTPATH+file file=FPDF_FONTPATH+file
end end
size=filesize(file) size=filesize(file)
if(!size) if(!size)
Error('Font file not found') Error('Font file not found')
end end
out('<</Length '+size) out('<</Length '+size)
if(file[-2]=='.z') if(file[-2]=='.z')
out('/Filter /FlateDecode') out('/Filter /FlateDecode')
end end
out('/Length1 '+info['length1']) out('/Length1 '+info['length1'])
unless info['length2'].nil? unless info['length2'].nil?
out('/Length2 '+info['length2']+' /Length3 0') out('/Length2 '+info['length2']+' /Length3 0')
end end
out('>>') out('>>')
f=fopen(file,'rb') f=fopen(file,'rb')
putstream(fread(f,size)) putstream(fread(f,size))
fclose(f) fclose(f)
out('endobj') out('endobj')
end end
# #
# set_magic_quotes_runtime(mqr) # set_magic_quotes_runtime(mqr)
# #
@fonts.each_pair do |k, font| @fonts.each_pair do |k, font|
#Font objects #Font objects
newobj() newobj()
@fonts[k]['n']=@n @fonts[k]['n']=@n
out('<</Type /Font') out('<</Type /Font')
if(font['type']=='Type0') if(font['type']=='Type0')
putType0(font) putType0(font)
else else
name=font['name'] name=font['name']
out('/BaseFont /'+name) out('/BaseFont /'+name)
if(font['type']=='core') if(font['type']=='core')
#Standard font #Standard font
out('/Subtype /Type1') out('/Subtype /Type1')
if(name!='Symbol' and name!='ZapfDingbats') if(name!='Symbol' and name!='ZapfDingbats')
out('/Encoding /WinAnsiEncoding') out('/Encoding /WinAnsiEncoding')
end end
else else
#Additional font #Additional font
out('/Subtype /'+font['type']) out('/Subtype /'+font['type'])
out('/FirstChar 32') out('/FirstChar 32')
out('/LastChar 255') out('/LastChar 255')
out('/Widths '+(@n+1)+' 0 R') out('/Widths '+(@n+1)+' 0 R')
out('/FontDescriptor '+(@n+2)+' 0 R') out('/FontDescriptor '+(@n+2)+' 0 R')
if(font['enc']) if(font['enc'])
if !font['diff'].nil? if !font['diff'].nil?
out('/Encoding '+(nf+font['diff'])+' 0 R') out('/Encoding '+(nf+font['diff'])+' 0 R')
else else
out('/Encoding /WinAnsiEncoding') out('/Encoding /WinAnsiEncoding')
end end
end end
end end
out('>>') out('>>')
out('endobj') out('endobj')
if(font['type']!='core') if(font['type']!='core')
#Widths #Widths
newobj() newobj()
cw=font['cw'] cw=font['cw']
s='[' s='['
32.upto(255) do |i| 32.upto(255) do |i|
s+=cw[i.chr]+' ' s+=cw[i.chr]+' '
end end
out(s+']') out(s+']')
out('endobj') out('endobj')
#Descriptor #Descriptor
newobj() newobj()
s='<</Type /FontDescriptor /FontName /'+name s='<</Type /FontDescriptor /FontName /'+name
font['desc'].each_pair do |k, v| font['desc'].each_pair do |k, v|
s+=' /'+k+' '+v s+=' /'+k+' '+v
end end
file=font['file'] file=font['file']
if(file) if(file)
s+=' /FontFile'+(font['type']=='Type1' ? '' : '2')+' '+@FontFiles[file]['n']+' 0 R' s+=' /FontFile'+(font['type']=='Type1' ? '' : '2')+' '+@FontFiles[file]['n']+' 0 R'
end end
out(s+'>>') out(s+'>>')
out('endobj') out('endobj')
end end
end end
end end
end end
def putType0(font) def putType0(font)
#Type0 #Type0
out('/Subtype /Type0') out('/Subtype /Type0')
out('/BaseFont /'+font['name']+'-'+font['CMap']) out('/BaseFont /'+font['name']+'-'+font['CMap'])
out('/Encoding /'+font['CMap']) out('/Encoding /'+font['CMap'])
out('/DescendantFonts ['+(@n+1).to_s+' 0 R]') out('/DescendantFonts ['+(@n+1).to_s+' 0 R]')
out('>>') out('>>')
out('endobj') out('endobj')
#CIDFont #CIDFont
newobj() newobj()
out('<</Type /Font') out('<</Type /Font')
out('/Subtype /CIDFontType0') out('/Subtype /CIDFontType0')
out('/BaseFont /'+font['name']) out('/BaseFont /'+font['name'])
out('/CIDSystemInfo <</Registry '+textstring('Adobe')+' /Ordering '+textstring(font['registry']['ordering'])+' /Supplement '+font['registry']['supplement'].to_s+'>>') out('/CIDSystemInfo <</Registry '+textstring('Adobe')+' /Ordering '+textstring(font['registry']['ordering'])+' /Supplement '+font['registry']['supplement'].to_s+'>>')
out('/FontDescriptor '+(@n+1).to_s+' 0 R') out('/FontDescriptor '+(@n+1).to_s+' 0 R')
if(font['CMap']=='ETen-B5-H') if(font['CMap']=='ETen-B5-H')
w='13648 13742 500' w='13648 13742 500'
elsif(font['CMap']=='GBK-EUC-H') elsif(font['CMap']=='GBK-EUC-H')
w='814 907 500 7716 [500]' w='814 907 500 7716 [500]'
else else
# ActionController::Base::logger.debug font['cw'].keys.sort.join(' ').to_s # ActionController::Base::logger.debug font['cw'].keys.sort.join(' ').to_s
# ActionController::Base::logger.debug font['cw'].values.join(' ').to_s # ActionController::Base::logger.debug font['cw'].values.join(' ').to_s
w='1 [' w='1 ['
font['cw'].keys.sort.each {|key| font['cw'].keys.sort.each {|key|
w+=font['cw'][key].to_s + " " w+=font['cw'][key].to_s + " "
# ActionController::Base::logger.debug key.to_s # ActionController::Base::logger.debug key.to_s
# ActionController::Base::logger.debug font['cw'][key].to_s # ActionController::Base::logger.debug font['cw'][key].to_s
} }
w +=']' w +=']'
end end
out('/W ['+w+']>>') out('/W ['+w+']>>')
out('endobj') out('endobj')
#Font descriptor #Font descriptor
newobj() newobj()
out('<</Type /FontDescriptor') out('<</Type /FontDescriptor')
out('/FontName /'+font['name']) out('/FontName /'+font['name'])
out('/Flags 6') out('/Flags 6')
out('/FontBBox [0 -200 1000 900]') out('/FontBBox [0 -200 1000 900]')
out('/ItalicAngle 0') out('/ItalicAngle 0')
out('/Ascent 800') out('/Ascent 800')
out('/Descent -200') out('/Descent -200')
out('/CapHeight 800') out('/CapHeight 800')
out('/StemV 50') out('/StemV 50')
out('>>') out('>>')
out('endobj') out('endobj')
end end
end end