PDF: import CJK patches and all languages use TCPDF (#8312).

Contributed Jun NAITOH.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5720 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA 2011-05-09 11:12:27 +00:00
parent 3b50809423
commit 29f6dd2a9e
5 changed files with 81 additions and 93 deletions

View File

@ -210,11 +210,7 @@ module Redmine
# Returns a PDF string of a list of issues # Returns a PDF string of a list of issues
def issues_to_pdf(issues, project, query) def issues_to_pdf(issues, project, query)
if l(:general_pdf_encoding).upcase != 'UTF-8'
pdf = IFPDF.new(current_language)
else
pdf = ITCPDF.new(current_language) pdf = ITCPDF.new(current_language)
end
title = query.new_record? ? l(:label_issue_plural) : query.name title = query.new_record? ? l(:label_issue_plural) : query.name
title = "#{project} - #{title}" if project title = "#{project} - #{title}" if project
pdf.SetTitle(title) pdf.SetTitle(title)
@ -358,11 +354,7 @@ module Redmine
# Returns a PDF string of a single issue # Returns a PDF string of a single issue
def issue_to_pdf(issue) def issue_to_pdf(issue)
if l(:general_pdf_encoding).upcase != 'UTF-8'
pdf = IFPDF.new(current_language)
else
pdf = ITCPDF.new(current_language) pdf = ITCPDF.new(current_language)
end
pdf.SetTitle("#{issue.project} - ##{issue.tracker} #{issue.id}") pdf.SetTitle("#{issue.project} - ##{issue.tracker} #{issue.id}")
pdf.alias_nb_pages pdf.alias_nb_pages
pdf.footer_date = format_date(Date.today) pdf.footer_date = format_date(Date.today)

View File

@ -507,11 +507,7 @@ module Redmine
end if Object.const_defined?(:Magick) end if Object.const_defined?(:Magick)
def to_pdf def to_pdf
if l(:general_pdf_encoding).upcase != 'UTF-8'
pdf = ::Redmine::Export::PDF::IFPDF.new(current_language)
else
pdf = ::Redmine::Export::PDF::ITCPDF.new(current_language) pdf = ::Redmine::Export::PDF::ITCPDF.new(current_language)
end
pdf.SetTitle("#{l(:label_gantt)} #{project}") pdf.SetTitle("#{l(:label_gantt)} #{project}")
pdf.alias_nb_pages pdf.alias_nb_pages
pdf.footer_date = format_date(Date.today) pdf.footer_date = format_date(Date.today)

View File

@ -116,7 +116,7 @@ module PDF_Chinese
end end
def GetStringWidth(s) def GetStringWidth(s)
if(@CurrentFont['type']=='Type0') if(@current_font['type']=='Type0')
return GetMBStringWidth(s) return GetMBStringWidth(s)
else else
return super(s) return super(s)
@ -126,7 +126,7 @@ module PDF_Chinese
def GetMBStringWidth(s) def GetMBStringWidth(s)
#Multi-byte version of GetStringWidth() #Multi-byte version of GetStringWidth()
l=0 l=0
cw=@CurrentFont['cw'] cw=@current_font['cw']
nb=s.length nb=s.length
i=0 i=0
while(i<nb) while(i<nb)
@ -139,11 +139,11 @@ module PDF_Chinese
i+=2 i+=2
end end
end end
return l*@FontSize/1000 return l*@font_size/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(@current_font['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)
@ -152,11 +152,11 @@ module PDF_Chinese
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=@current_font['cw']
if(w==0) if(w==0)
w=@w-@rMargin-@x w=@w-@r_margin-@x
end end
wmax=(w-2*@cMargin)*1000/@FontSize wmax=(w-2*@c_margin)*1000/@font_size
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")
@ -233,11 +233,11 @@ module PDF_Chinese
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=@l_margin
end end
def Write(h,txt,link='') def Write(h,txt,link='')
if(@CurrentFont['type']=='Type0') if(@current_font['type']=='Type0')
MBWrite(h,txt,link) MBWrite(h,txt,link)
else else
super(h,txt,link) super(h,txt,link)
@ -246,9 +246,9 @@ module PDF_Chinese
def MBWrite(h,txt,link) def MBWrite(h,txt,link)
#Multi-byte version of Write() #Multi-byte version of Write()
cw=@CurrentFont['cw'] cw=@current_font['cw']
w=@w-@rMargin-@x w=@w-@r_margin-@x
wmax=(w-2*@cMargin)*1000/@FontSize wmax=(w-2*@c_margin)*1000/@font_size
s=txt.gsub("\r",'') s=txt.gsub("\r",'')
nb=s.length nb=s.length
sep=-1 sep=-1
@ -269,9 +269,9 @@ module PDF_Chinese
j=i j=i
l=0 l=0
if(nl==1) if(nl==1)
@x=@lMargin @x=@l_margin
w=@w-@rMargin-@x w=@w-@r_margin-@x
wmax=(w-2*@cMargin)*1000/@FontSize wmax=(w-2*@c_margin)*1000/@font_size
end end
nl+=1 nl+=1
next next
@ -283,12 +283,12 @@ module PDF_Chinese
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>@l_margin)
#Move to next line #Move to next line
@x=@lMargin @x=@l_margin
@y+=h @y+=h
w=@w-@rMargin-@x w=@w-@r_margin-@x
wmax=(w-2*@cMargin)*1000/@FontSize wmax=(w-2*@c_margin)*1000/@font_size
i+=1 i+=1
nl+=1 nl+=1
next next
@ -305,9 +305,9 @@ module PDF_Chinese
j=i j=i
l=0 l=0
if(nl==1) if(nl==1)
@x=@lMargin @x=@l_margin
w=@w-@rMargin-@x w=@w-@r_margin-@x
wmax=(w-2*@cMargin)*1000/@FontSize wmax=(w-2*@c_margin)*1000/@font_size
end end
nl+=1 nl+=1
else else
@ -316,7 +316,7 @@ module PDF_Chinese
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*@font_size,h,s[j,i-j],0,0,'',0,link)
end end
end end
@ -332,10 +332,10 @@ private
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| @font_files.each_pair do |file, info|
#Font file embedding #Font file embedding
newobj() newobj()
@FontFiles[file]['n']=@n @font_files[file]['n']=@n
if(defined('FPDF_FONTPATH')) if(defined('FPDF_FONTPATH'))
file=FPDF_FONTPATH+file file=FPDF_FONTPATH+file
end end
@ -411,7 +411,7 @@ private
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')+' '+@font_files[file]['n']+' 0 R'
end end
out(s+'>>') out(s+'>>')
out('endobj') out('endobj')

View File

@ -86,7 +86,7 @@ module PDF_Japanese
end end
def GetStringWidth(s) def GetStringWidth(s)
if(@CurrentFont['type']=='Type0') if(@current_font['type']=='Type0')
return GetSJISStringWidth(s) return GetSJISStringWidth(s)
else else
return super(s) return super(s)
@ -96,7 +96,7 @@ module PDF_Japanese
def GetSJISStringWidth(s) def GetSJISStringWidth(s)
#SJIS version of GetStringWidth() #SJIS version of GetStringWidth()
l=0 l=0
cw=@CurrentFont['cw'] cw=@current_font['cw']
nb=s.length nb=s.length
i=0 i=0
while(i<nb) while(i<nb)
@ -115,11 +115,11 @@ module PDF_Japanese
i+=2 i+=2
end end
end end
return l*@FontSize/1000 return l*@font_size/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(@current_font['type']=='Type0')
SJISMultiCell(w,h,txt,border,align,fill) SJISMultiCell(w,h,txt,border,align,fill)
else else
super(w,h,txt,border,align,fill) super(w,h,txt,border,align,fill)
@ -128,11 +128,11 @@ module PDF_Japanese
def SJISMultiCell(w,h,txt,border=0,align='L',fill=0) def SJISMultiCell(w,h,txt,border=0,align='L',fill=0)
#Output text with automatic or explicit line breaks #Output text with automatic or explicit line breaks
cw=@CurrentFont['cw'] cw=@current_font['cw']
if(w==0) if(w==0)
w=@w-@rMargin-@x w=@w-@r_margin-@x
end end
wmax=(w-2*@cMargin)*1000/@FontSize wmax=(w-2*@c_margin)*1000/@font_size
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")
@ -221,11 +221,11 @@ module PDF_Japanese
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=@l_margin
end end
def Write(h,txt,link='') def Write(h,txt,link='')
if(@CurrentFont['type']=='Type0') if(@current_font['type']=='Type0')
SJISWrite(h,txt,link) SJISWrite(h,txt,link)
else else
super(h,txt,link) super(h,txt,link)
@ -234,9 +234,9 @@ module PDF_Japanese
def SJISWrite(h,txt,link) def SJISWrite(h,txt,link)
#SJIS version of Write() #SJIS version of Write()
cw=@CurrentFont['cw'] cw=@current_font['cw']
w=@w-@rMargin-@x w=@w-@r_margin-@x
wmax=(w-2*@cMargin)*1000/@FontSize wmax=(w-2*@c_margin)*1000/@font_size
s=txt.gsub("\r",'') s=txt.gsub("\r",'')
nb=s.length nb=s.length
sep=-1 sep=-1
@ -257,9 +257,9 @@ module PDF_Japanese
l=0 l=0
if(nl==1) if(nl==1)
#Go to left margin #Go to left margin
@x=@lMargin @x=@l_margin
w=@w-@rMargin-@x w=@w-@r_margin-@x
wmax=(w-2*@cMargin)*1000/@FontSize wmax=(w-2*@c_margin)*1000/@font_size
end end
nl+=1 nl+=1
next next
@ -285,12 +285,12 @@ module PDF_Japanese
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>@l_margin)
#Move to next line #Move to next line
@x=@lMargin @x=@l_margin
@y+=h @y+=h
w=@w-@rMargin-@x w=@w-@r_margin-@x
wmax=(w-2*@cMargin)*1000/@FontSize wmax=(w-2*@c_margin)*1000/@font_size
i+=n i+=n
nl+=1 nl+=1
next next
@ -307,9 +307,9 @@ module PDF_Japanese
j=i j=i
l=0 l=0
if(nl==1) if(nl==1)
@x=@lMargin @x=@l_margin
w=@w-@rMargin-@x w=@w-@r_margin-@x
wmax=(w-2*@cMargin)*1000/@FontSize wmax=(w-2*@c_margin)*1000/@font_size
end end
nl+=1 nl+=1
else else
@ -321,7 +321,7 @@ module PDF_Japanese
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*@font_size,h,s[j,i-j],0,0,'',0,link)
end end
end end
@ -337,10 +337,10 @@ private
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| @font_files.each_pair do |file, info|
#Font file embedding #Font file embedding
newobj() newobj()
@FontFiles[file]['n']=@n @font_files[file]['n']=@n
if(defined('FPDF_FONTPATH')) if(defined('FPDF_FONTPATH'))
file=FPDF_FONTPATH+file file=FPDF_FONTPATH+file
end end
@ -414,7 +414,7 @@ private
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')+' '+@font_files[file]['n']+' 0 R'
end end
out(s+'>>') out(s+'>>')
out('endobj') out('endobj')

View File

@ -85,7 +85,7 @@ UHC_widths={' ' => 333, '!' => 416, '"' => 416, '#' => 833, '$' => 625, '%' => 9
end end
def GetStringWidth(s) def GetStringWidth(s)
if(@CurrentFont['type']=='Type0') if(@current_font['type']=='Type0')
return GetMBStringWidth(s) return GetMBStringWidth(s)
else else
return super(s) return super(s)
@ -95,7 +95,7 @@ UHC_widths={' ' => 333, '!' => 416, '"' => 416, '#' => 833, '$' => 625, '%' => 9
def GetMBStringWidth(s) def GetMBStringWidth(s)
#Multi-byte version of GetStringWidth() #Multi-byte version of GetStringWidth()
l=0 l=0
cw=@CurrentFont['cw'] cw=@current_font['cw']
nb=s.length nb=s.length
i=0 i=0
while(i<nb) while(i<nb)
@ -108,11 +108,11 @@ UHC_widths={' ' => 333, '!' => 416, '"' => 416, '#' => 833, '$' => 625, '%' => 9
i+=2 i+=2
end end
end end
return l*@FontSize/1000 return l*@font_size/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(@current_font['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)
@ -121,11 +121,11 @@ UHC_widths={' ' => 333, '!' => 416, '"' => 416, '#' => 833, '$' => 625, '%' => 9
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=@current_font['cw']
if(w==0) if(w==0)
w=@w-@rMargin-@x w=@w-@r_margin-@x
end end
wmax=(w-2*@cMargin)*1000/@FontSize wmax=(w-2*@c_margin)*1000/@font_size
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")
@ -202,11 +202,11 @@ UHC_widths={' ' => 333, '!' => 416, '"' => 416, '#' => 833, '$' => 625, '%' => 9
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=@l_margin
end end
def Write(h,txt,link='') def Write(h,txt,link='')
if(@CurrentFont['type']=='Type0') if(@current_font['type']=='Type0')
MBWrite(h,txt,link) MBWrite(h,txt,link)
else else
super(h,txt,link) super(h,txt,link)
@ -215,9 +215,9 @@ UHC_widths={' ' => 333, '!' => 416, '"' => 416, '#' => 833, '$' => 625, '%' => 9
def MBWrite(h,txt,link) def MBWrite(h,txt,link)
#Multi-byte version of Write() #Multi-byte version of Write()
cw=@CurrentFont['cw'] cw=@current_font['cw']
w=@w-@rMargin-@x w=@w-@r_margin-@x
wmax=(w-2*@cMargin)*1000/@FontSize wmax=(w-2*@c_margin)*1000/@font_size
s=txt.gsub("\r",'') s=txt.gsub("\r",'')
nb=s.length nb=s.length
sep=-1 sep=-1
@ -238,9 +238,9 @@ UHC_widths={' ' => 333, '!' => 416, '"' => 416, '#' => 833, '$' => 625, '%' => 9
j=i j=i
l=0 l=0
if(nl==1) if(nl==1)
@x=@lMargin @x=@l_margin
w=@w-@rMargin-@x w=@w-@r_margin-@x
wmax=(w-2*@cMargin)*1000/@FontSize wmax=(w-2*@c_margin)*1000/@font_size
end end
nl+=1 nl+=1
next next
@ -252,12 +252,12 @@ UHC_widths={' ' => 333, '!' => 416, '"' => 416, '#' => 833, '$' => 625, '%' => 9
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>@l_margin)
#Move to next line #Move to next line
@x=@lMargin @x=@l_margin
@y+=h @y+=h
w=@w-@rMargin-@x w=@w-@r_margin-@x
wmax=(w-2*@cMargin)*1000/@FontSize wmax=(w-2*@c_margin)*1000/@font_size
i+=1 i+=1
nl+=1 nl+=1
next next
@ -274,9 +274,9 @@ UHC_widths={' ' => 333, '!' => 416, '"' => 416, '#' => 833, '$' => 625, '%' => 9
j=i j=i
l=0 l=0
if(nl==1) if(nl==1)
@x=@lMargin @x=@l_margin
w=@w-@rMargin-@x w=@w-@r_margin-@x
wmax=(w-2*@cMargin)*1000/@FontSize wmax=(w-2*@c_margin)*1000/@font_size
end end
nl+=1 nl+=1
else else
@ -285,7 +285,7 @@ UHC_widths={' ' => 333, '!' => 416, '"' => 416, '#' => 833, '$' => 625, '%' => 9
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*@font_size,h,s[j,i-j],0,0,'',0,link)
end end
end end
@ -301,10 +301,10 @@ private
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| @font_files.each_pair do |file, info|
#Font file embedding #Font file embedding
newobj() newobj()
@FontFiles[file]['n']=@n @font_files[file]['n']=@n
if(defined('FPDF_FONTPATH')) if(defined('FPDF_FONTPATH'))
file=FPDF_FONTPATH+file file=FPDF_FONTPATH+file
end end
@ -378,7 +378,7 @@ private
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')+' '+@font_files[file]['n']+' 0 R'
end end
out(s+'>>') out(s+'>>')
out('endobj') out('endobj')