Project

General

Profile

Patch #8312 ยป switch_from_fpdf_to_tcpdf_r5670.patch

Jun NAITOH, 2011-05-06 16:06

View differences:

vendor/plugins/rfpdf/lib/fpdf/chinese.rb (working copy)
end
def GetStringWidth(s)
if(@CurrentFont['type']=='Type0')
if(@current_font['type']=='Type0')
return GetMBStringWidth(s)
else
return super(s)
......
def GetMBStringWidth(s)
#Multi-byte version of GetStringWidth()
l=0
cw=@CurrentFont['cw']
cw=@current_font['cw']
nb=s.length
i=0
while(i<nb)
......
i+=2
end
end
return l*@FontSize/1000
return l*@font_size/1000
end
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)
else
super(w,h,txt,border,align,fill)
......
def MBMultiCell(w,h,txt,border=0,align='L',fill=0)
#Multi-byte version of MultiCell()
cw=@CurrentFont['cw']
cw=@current_font['cw']
if(w==0)
w=@w-@rMargin-@x
w=@w-@r_margin-@x
end
wmax=(w-2*@cMargin)*1000/@FontSize
wmax=(w-2*@c_margin)*1000/@font_size
s=txt.gsub("\r",'')
nb=s.length
if(nb>0 and s[nb-1]=="\n")
......
b+='B'
end
Cell(w,h,s[j,i-j],b,2,align,fill)
@x=@lMargin
@x=@l_margin
end
def Write(h,txt,link='')
if(@CurrentFont['type']=='Type0')
if(@current_font['type']=='Type0')
MBWrite(h,txt,link)
else
super(h,txt,link)
......
def MBWrite(h,txt,link)
#Multi-byte version of Write()
cw=@CurrentFont['cw']
w=@w-@rMargin-@x
wmax=(w-2*@cMargin)*1000/@FontSize
cw=@current_font['cw']
w=@w-@r_margin-@x
wmax=(w-2*@c_margin)*1000/@font_size
s=txt.gsub("\r",'')
nb=s.length
sep=-1
......
j=i
l=0
if(nl==1)
@x=@lMargin
w=@w-@rMargin-@x
wmax=(w-2*@cMargin)*1000/@FontSize
@x=@l_margin
w=@w-@r_margin-@x
wmax=(w-2*@c_margin)*1000/@font_size
end
nl+=1
next
......
if(l>wmax)
#Automatic line break
if(sep==-1 or i==j)
if(@x>@lMargin)
if(@x>@l_margin)
#Move to next line
@x=@lMargin
@x=@l_margin
@y+=h
w=@w-@rMargin-@x
wmax=(w-2*@cMargin)*1000/@FontSize
w=@w-@r_margin-@x
wmax=(w-2*@c_margin)*1000/@font_size
i+=1
nl+=1
next
......
j=i
l=0
if(nl==1)
@x=@lMargin
w=@w-@rMargin-@x
wmax=(w-2*@cMargin)*1000/@FontSize
@x=@l_margin
w=@w-@r_margin-@x
wmax=(w-2*@c_margin)*1000/@font_size
end
nl+=1
else
......
end
#Last chunk
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
# mqr=get_magic_quotes_runtime()
# set_magic_quotes_runtime(0)
@FontFiles.each_pair do |file, info|
@font_files.each_pair do |file, info|
#Font file embedding
newobj()
@FontFiles[file]['n']=@n
@font_files[file]['n']=@n
if(defined('FPDF_FONTPATH'))
file=FPDF_FONTPATH+file
end
......
end
file=font['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
out(s+'>>')
out('endobj')
vendor/plugins/rfpdf/lib/fpdf/korean.rb (working copy)
end
def GetStringWidth(s)
if(@CurrentFont['type']=='Type0')
if(@current_font['type']=='Type0')
return GetMBStringWidth(s)
else
return super(s)
......
def GetMBStringWidth(s)
#Multi-byte version of GetStringWidth()
l=0
cw=@CurrentFont['cw']
cw=@current_font['cw']
nb=s.length
i=0
while(i<nb)
......
i+=2
end
end
return l*@FontSize/1000
return l*@font_size/1000
end
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)
else
super(w,h,txt,border,align,fill)
......
def MBMultiCell(w,h,txt,border=0,align='L',fill=0)
#Multi-byte version of MultiCell()
cw=@CurrentFont['cw']
cw=@current_font['cw']
if(w==0)
w=@w-@rMargin-@x
w=@w-@r_margin-@x
end
wmax=(w-2*@cMargin)*1000/@FontSize
wmax=(w-2*@c_margin)*1000/@font_size
s=txt.gsub("\r",'')
nb=s.length
if(nb>0 and s[nb-1]=="\n")
......
b+='B'
end
Cell(w,h,s[j,i-j],b,2,align,fill)
@x=@lMargin
@x=@l_margin
end
def Write(h,txt,link='')
if(@CurrentFont['type']=='Type0')
if(@current_font['type']=='Type0')
MBWrite(h,txt,link)
else
super(h,txt,link)
......
def MBWrite(h,txt,link)
#Multi-byte version of Write()
cw=@CurrentFont['cw']
w=@w-@rMargin-@x
wmax=(w-2*@cMargin)*1000/@FontSize
cw=@current_font['cw']
w=@w-@r_margin-@x
wmax=(w-2*@c_margin)*1000/@font_size
s=txt.gsub("\r",'')
nb=s.length
sep=-1
......
j=i
l=0
if(nl==1)
@x=@lMargin
w=@w-@rMargin-@x
wmax=(w-2*@cMargin)*1000/@FontSize
@x=@l_margin
w=@w-@r_margin-@x
wmax=(w-2*@c_margin)*1000/@font_size
end
nl+=1
next
......
if(l>wmax)
#Automatic line break
if(sep==-1 or i==j)
if(@x>@lMargin)
if(@x>@l_margin)
#Move to next line
@x=@lMargin
@x=@l_margin
@y+=h
w=@w-@rMargin-@x
wmax=(w-2*@cMargin)*1000/@FontSize
w=@w-@r_margin-@x
wmax=(w-2*@c_margin)*1000/@font_size
i+=1
nl+=1
next
......
j=i
l=0
if(nl==1)
@x=@lMargin
w=@w-@rMargin-@x
wmax=(w-2*@cMargin)*1000/@FontSize
@x=@l_margin
w=@w-@r_margin-@x
wmax=(w-2*@c_margin)*1000/@font_size
end
nl+=1
else
......
end
#Last chunk
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
# mqr=get_magic_quotes_runtime()
# set_magic_quotes_runtime(0)
@FontFiles.each_pair do |file, info|
@font_files.each_pair do |file, info|
#Font file embedding
newobj()
@FontFiles[file]['n']=@n
@font_files[file]['n']=@n
if(defined('FPDF_FONTPATH'))
file=FPDF_FONTPATH+file
end
......
end
file=font['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
out(s+'>>')
out('endobj')
vendor/plugins/rfpdf/lib/fpdf/japanese.rb (working copy)
end
def GetStringWidth(s)
if(@CurrentFont['type']=='Type0')
if(@current_font['type']=='Type0')
return GetSJISStringWidth(s)
else
return super(s)
......
def GetSJISStringWidth(s)
#SJIS version of GetStringWidth()
l=0
cw=@CurrentFont['cw']
cw=@current_font['cw']
nb=s.length
i=0
while(i<nb)
......
i+=2
end
end
return l*@FontSize/1000
return l*@font_size/1000
end
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)
else
super(w,h,txt,border,align,fill)
......
def SJISMultiCell(w,h,txt,border=0,align='L',fill=0)
#Output text with automatic or explicit line breaks
cw=@CurrentFont['cw']
cw=@current_font['cw']
if(w==0)
w=@w-@rMargin-@x
w=@w-@r_margin-@x
end
wmax=(w-2*@cMargin)*1000/@FontSize
wmax=(w-2*@c_margin)*1000/@font_size
s=txt.gsub("\r",'')
nb=s.length
if(nb>0 and s[nb-1]=="\n")
......
b+='B'
end
Cell(w,h,s[j,i-j],b,2,align,fill)
@x=@lMargin
@x=@l_margin
end
def Write(h,txt,link='')
if(@CurrentFont['type']=='Type0')
if(@current_font['type']=='Type0')
SJISWrite(h,txt,link)
else
super(h,txt,link)
......
def SJISWrite(h,txt,link)
#SJIS version of Write()
cw=@CurrentFont['cw']
w=@w-@rMargin-@x
wmax=(w-2*@cMargin)*1000/@FontSize
cw=@current_font['cw']
w=@w-@r_margin-@x
wmax=(w-2*@c_margin)*1000/@font_size
s=txt.gsub("\r",'')
nb=s.length
sep=-1
......
l=0
if(nl==1)
#Go to left margin
@x=@lMargin
w=@w-@rMargin-@x
wmax=(w-2*@cMargin)*1000/@FontSize
@x=@l_margin
w=@w-@r_margin-@x
wmax=(w-2*@c_margin)*1000/@font_size
end
nl+=1
next
......
if(l>wmax)
#Automatic line break
if(sep==-1 or i==j)
if(@x>@lMargin)
if(@x>@l_margin)
#Move to next line
@x=@lMargin
@x=@l_margin
@y+=h
w=@w-@rMargin-@x
wmax=(w-2*@cMargin)*1000/@FontSize
w=@w-@r_margin-@x
wmax=(w-2*@c_margin)*1000/@font_size
i+=n
nl+=1
next
......
j=i
l=0
if(nl==1)
@x=@lMargin
w=@w-@rMargin-@x
wmax=(w-2*@cMargin)*1000/@FontSize
@x=@l_margin
w=@w-@r_margin-@x
wmax=(w-2*@c_margin)*1000/@font_size
end
nl+=1
else
......
end
#Last chunk
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
# mqr=get_magic_quotes_runtime()
# set_magic_quotes_runtime(0)
@FontFiles.each_pair do |file, info|
@font_files.each_pair do |file, info|
#Font file embedding
newobj()
@FontFiles[file]['n']=@n
@font_files[file]['n']=@n
if(defined('FPDF_FONTPATH'))
file=FPDF_FONTPATH+file
end
......
end
file=font['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
out(s+'>>')
out('endobj')
vendor/plugins/rfpdf/lib/tcpdf.rb (working copy)
# @since 1.4
# @see PageNo(), Footer()
#
def alias_nb_pages(alias_nb ='{nb}')
def AliasNbPages(alias_nb ='{nb}')
#Define an alias for total number of pages
@alias_nb_pages = escapetext(alias_nb)
end
alias_method :alias_nb_pages, :AliasNbPages
#
# This method is automatically called in case of fatal error; it simply outputs the message and halts the execution. An inherited class may override it to customize the error handling but should always halt the script, or the resulting document would probably be invalid.
......
end
else
s.each_byte do |c|
if cw[c]
w += cw[c];
elsif cw[?c]
w += cw[?c]
if cw[c.chr]
w += cw[c.chr];
elsif cw[?c.chr]
w += cw[?c.chr]
end
end
end
......
end
# try to add font (if not already added)
if (@is_unicode)
AddFont(family, style);
end
AddFont(family, style);
#Test if font is already selected
if ((@font_family == family) and (@font_style == style) and (@font_size_pt == size))
......
def putpages()
nb = @page;
if (@alias_nb_pages)
nbstr = UTF8ToUTF16BE(nb, false);
nbstr = UTF8ToUTF16BE(nb.to_s, false);
#Replace number of pages
1.upto(nb) do |n|
@pages[n].gsub!(@alias_nb_pages, nbstr)
lib/redmine/export/pdf.rb (working copy)
include ActionView::Helpers::TextHelper
include ActionView::Helpers::NumberHelper
class ITCPDF < TCPDF
class IFPDF < TCPDF
include Redmine::I18n
attr_accessor :footer_date
def initialize(lang)
super()
set_language_if_valid lang
@font_for_content = 'FreeSans'
@font_for_footer = 'FreeSans'
SetCreator(Redmine::Info.app_name)
SetFont(@font_for_content)
end
def SetFontStyle(style, size)
SetFont(@font_for_content, style, size)
end
def SetTitle(txt)
txt = begin
utf16txt = Iconv.conv('UTF-16BE', 'UTF-8', txt)
hextxt = "<FEFF" # FEFF is BOM
hextxt << utf16txt.unpack("C*").map {|x| sprintf("%02X",x) }.join
hextxt << ">"
rescue
txt
end || ''
super(txt)
end
def textstring(s)
# Format a text string
if s =~ /^</ # This means the string is hex-dumped.
return s
pdf_encoding = l(:general_pdf_encoding).upcase
if pdf_encoding == 'UTF-8'
@unicode = true
else
return '('+escape(s)+')'
@unicode = false
end
end
alias RDMCell Cell
alias RDMMultiCell MultiCell
def Footer
SetFont(@font_for_footer, 'I', 8)
SetY(-15)
SetX(15)
RDMCell(0, 5, @footer_date, 0, 0, 'L')
SetY(-15)
SetX(-30)
RDMCell(0, 5, PageNo().to_s + '/{nb}', 0, 0, 'C')
end
end
class IFPDF < FPDF
include Redmine::I18n
attr_accessor :footer_date
def initialize(lang)
super()
super('P', 'mm', 'A4', @unicode, pdf_encoding )
set_language_if_valid lang
case l(:general_pdf_encoding).upcase
case pdf_encoding
when 'UTF-8'
@font_for_content = 'FreeSans'
@font_for_footer = 'FreeSans'
when 'CP949'
extend(PDF_Korean)
AddUHCFont()
......
end
def fix_text_encoding(txt)
if (@unicode)
return txt
end
txt ||= ''
if txt.respond_to?(:force_encoding)
txt.force_encoding('UTF-8')
......
SetX(-30)
RDMCell(0, 5, PageNo().to_s + '/{nb}', 0, 0, 'C')
end
alias alias_nb_pages AliasNbPages
end
# Returns a PDF string of a list of issues
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)
end
pdf = IFPDF.new(current_language)
title = query.new_record? ? l(:label_issue_plural) : query.name
title = "#{project} - #{title}" if project
pdf.SetTitle(title)
......
# Returns a PDF string of a single 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)
end
pdf = IFPDF.new(current_language)
pdf.SetTitle("#{issue.project} - ##{issue.tracker} #{issue.id}")
pdf.alias_nb_pages
pdf.footer_date = format_date(Date.today)
lib/redmine/helpers/gantt.rb (working copy)
end if Object.const_defined?(:Magick)
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)
end
pdf = ::Redmine::Export::PDF::IFPDF.new(current_language)
pdf.SetTitle("#{l(:label_gantt)} #{project}")
pdf.alias_nb_pages
pdf.footer_date = format_date(Date.today)
    (1-1/1)