Commit 79abd95f authored by Toshi MARUYAMA's avatar Toshi MARUYAMA Committed by Eric Davis

PDF: import CJK patches (#61).

Contributed by Jun NAITOH.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5256 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent a184b21a
...@@ -37,27 +37,27 @@ ...@@ -37,27 +37,27 @@
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,'}'=>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,'}'=>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
...@@ -170,13 +170,9 @@ module PDF_Chinese ...@@ -170,13 +170,9 @@ module PDF_Chinese
b2='LR' b2='LR'
else else
b2='' b2=''
if(border.to_s.index('L')) b2='L' unless border.to_s.index('L').nil?
b2+='L' b2=b2+'R' unless border.to_s.index('R').nil?
end b=(border.to_s.index('T')) ? (b2+'T') : b2
if(border.to_s.index('R'))
b2+='R'
end
b=border.to_s.index('T') ? b2+'T' : b2
end end
end end
sep=-1 sep=-1
...@@ -205,11 +201,11 @@ module PDF_Chinese ...@@ -205,11 +201,11 @@ module PDF_Chinese
if(!ascii) if(!ascii)
sep=i sep=i
ls=l ls=l
elsif(c==' ') elsif(c.chr==' ')
sep=i sep=i
ls=l ls=l
end end
l+=ascii ? (cw[c.chr] || 0) : 1100 l+=(ascii ? cw[c.chr] : 1000) || 0
if(l>wmax) if(l>wmax)
#Automatic line break #Automatic line break
if(sep==-1 or i==j) if(sep==-1 or i==j)
...@@ -219,7 +215,7 @@ module PDF_Chinese ...@@ -219,7 +215,7 @@ module PDF_Chinese
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].chr==' ') ? sep+1 : sep
end end
sep=-1 sep=-1
j=i j=i
...@@ -280,10 +276,10 @@ module PDF_Chinese ...@@ -280,10 +276,10 @@ module PDF_Chinese
nl+=1 nl+=1
next next
end end
if(!ascii or c==' ') if(!ascii or c.chr==' ')
sep=i sep=i
end end
l+=ascii ? cw[c.chr] : 1100 l+=(ascii ? cw[c.chr] : 1000) || 0
if(l>wmax) if(l>wmax)
#Automatic line break #Automatic line break
if(sep==-1 or i==j) if(sep==-1 or i==j)
...@@ -303,7 +299,7 @@ module PDF_Chinese ...@@ -303,7 +299,7 @@ module PDF_Chinese
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].chr==' ') ? sep+1 : sep
end end
sep=-1 sep=-1
j=i j=i
......
...@@ -103,7 +103,7 @@ module PDF_Japanese ...@@ -103,7 +103,7 @@ module PDF_Japanese
o=s[i] o=s[i]
if(o<128) if(o<128)
#ASCII #ASCII
l+=cw[o.chr] l+=cw[o.chr] if cw[o.chr]
i+=1 i+=1
elsif(o>=161 and o<=223) elsif(o>=161 and o<=223)
#Half-width katakana #Half-width katakana
...@@ -146,13 +146,9 @@ module PDF_Japanese ...@@ -146,13 +146,9 @@ module PDF_Japanese
b2='LR' b2='LR'
else else
b2='' b2=''
if(border.to_s.index('L')) b2='L' unless border.to_s.index('L').nil?
b2+='L' b2=b2+'R' unless border.to_s.index('R').nil?
end b=(border.to_s.index('T')) ? (b2+'T') : b2
if(border.to_s.index('R'))
b2+='R'
end
b=border.to_s.index('T') ? b2+'T' : b2
end end
end end
sep=-1 sep=-1
...@@ -179,7 +175,7 @@ module PDF_Japanese ...@@ -179,7 +175,7 @@ module PDF_Japanese
end end
if(o<128) if(o<128)
#ASCII #ASCII
l+=cw[c.chr] l+=cw[c.chr] || 0
n=1 n=1
if(o==32) if(o==32)
sep=i sep=i
...@@ -204,7 +200,7 @@ module PDF_Japanese ...@@ -204,7 +200,7 @@ module PDF_Japanese
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].chr==' ') ? sep+1 : sep
end end
sep=-1 sep=-1
j=i j=i
...@@ -230,9 +226,9 @@ module PDF_Japanese ...@@ -230,9 +226,9 @@ module PDF_Japanese
def Write(h,txt,link='') def Write(h,txt,link='')
if(@CurrentFont['type']=='Type0') if(@CurrentFont['type']=='Type0')
SJISWrite(h,txt,link) SJISWrite(h,txt,link)
else else
super(h,txt,link) super(h,txt,link)
end end
end end
...@@ -270,7 +266,7 @@ module PDF_Japanese ...@@ -270,7 +266,7 @@ module PDF_Japanese
end end
if(o<128) if(o<128)
#ASCII #ASCII
l+=cw[c.chr] l+=cw[c.chr] || 0
n=1 n=1
if(o==32) if(o==32)
sep=i sep=i
...@@ -305,7 +301,7 @@ module PDF_Japanese ...@@ -305,7 +301,7 @@ module PDF_Japanese
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].chr==' ') ? sep+1 : sep
end end
sep=-1 sep=-1
j=i j=i
......
...@@ -101,7 +101,7 @@ UHC_widths={' ' => 333, '!' => 416, '"' => 416, '#' => 833, '$' => 625, '%' => 9 ...@@ -101,7 +101,7 @@ UHC_widths={' ' => 333, '!' => 416, '"' => 416, '#' => 833, '$' => 625, '%' => 9
while(i<nb) while(i<nb)
c=s[i] c=s[i]
if(c<128) if(c<128)
l+=cw[c.chr] l+=cw[c.chr] if cw[c.chr]
i+=1 i+=1
else else
l+=1000 l+=1000
...@@ -139,13 +139,9 @@ UHC_widths={' ' => 333, '!' => 416, '"' => 416, '#' => 833, '$' => 625, '%' => 9 ...@@ -139,13 +139,9 @@ UHC_widths={' ' => 333, '!' => 416, '"' => 416, '#' => 833, '$' => 625, '%' => 9
b2='LR' b2='LR'
else else
b2='' b2=''
if(border.to_s.index('L').nil?) b2='L' unless border.to_s.index('L').nil?
b2+='L' b2=b2+'R' unless border.to_s.index('R').nil?
end b=(border.to_s.index('T')) ? (b2+'T') : b2
if(border.to_s.index('R').nil?)
b2+='R'
end
b=border.to_s.index('T').nil? ? b2+'T' : b2
end end
end end
sep=-1 sep=-1
...@@ -158,7 +154,7 @@ UHC_widths={' ' => 333, '!' => 416, '"' => 416, '#' => 833, '$' => 625, '%' => 9 ...@@ -158,7 +154,7 @@ UHC_widths={' ' => 333, '!' => 416, '"' => 416, '#' => 833, '$' => 625, '%' => 9
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
...@@ -174,7 +170,7 @@ UHC_widths={' ' => 333, '!' => 416, '"' => 416, '#' => 833, '$' => 625, '%' => 9 ...@@ -174,7 +170,7 @@ UHC_widths={' ' => 333, '!' => 416, '"' => 416, '#' => 833, '$' => 625, '%' => 9
if(!ascii) if(!ascii)
sep=i sep=i
ls=l ls=l
elsif(c==' ') elsif(c.chr==' ')
sep=i sep=i
ls=l ls=l
end end
...@@ -188,7 +184,7 @@ UHC_widths={' ' => 333, '!' => 416, '"' => 416, '#' => 833, '$' => 625, '%' => 9 ...@@ -188,7 +184,7 @@ UHC_widths={' ' => 333, '!' => 416, '"' => 416, '#' => 833, '$' => 625, '%' => 9
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].chr==' ') ? sep+1 : sep
end end
sep=-1 sep=-1
j=i j=i
...@@ -234,7 +230,7 @@ UHC_widths={' ' => 333, '!' => 416, '"' => 416, '#' => 833, '$' => 625, '%' => 9 ...@@ -234,7 +230,7 @@ UHC_widths={' ' => 333, '!' => 416, '"' => 416, '#' => 833, '$' => 625, '%' => 9
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
...@@ -249,10 +245,10 @@ UHC_widths={' ' => 333, '!' => 416, '"' => 416, '#' => 833, '$' => 625, '%' => 9 ...@@ -249,10 +245,10 @@ UHC_widths={' ' => 333, '!' => 416, '"' => 416, '#' => 833, '$' => 625, '%' => 9
nl+=1 nl+=1
next next
end end
if(!ascii or c==' ') if(!ascii or c.chr==' ')
sep=i sep=i
end end
l+=ascii ? cw[c.chr] : 1000 l+=(ascii ? cw[c.chr] : 1000) || 0
if(l>wmax) if(l>wmax)
#Automatic line break #Automatic line break
if(sep==-1 or i==j) if(sep==-1 or i==j)
...@@ -272,7 +268,7 @@ UHC_widths={' ' => 333, '!' => 416, '"' => 416, '#' => 833, '$' => 625, '%' => 9 ...@@ -272,7 +268,7 @@ UHC_widths={' ' => 333, '!' => 416, '"' => 416, '#' => 833, '$' => 625, '%' => 9
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].chr==' ') ? sep+1 : sep
end end
sep=-1 sep=-1
j=i j=i
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment