Class: Redmine::Export::PDF::IFPDF

Inherits:
FPDF
  • Object
show all
Includes:
I18n
Defined in:
lib/redmine/export/pdf.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from I18n

#current_language, #day_name, #find_language, #format_date, #format_time, included, #l, #l_hours, #l_or_humanize, #ll, #month_name, #set_language_if_valid, #valid_languages

Constructor Details

#initialize(lang) ⇒ IFPDF

Returns a new instance of IFPDF.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/redmine/export/pdf.rb', line 36

def initialize(lang)
  super()
  set_language_if_valid lang
  case current_language.to_s.downcase
  when 'ko'
    extend(PDF_Korean)
    AddUHCFont()
    @font_for_content = 'UHC'
    @font_for_footer = 'UHC'
  when 'ja'
    extend(PDF_Japanese)
    AddSJISFont()
    @font_for_content = 'SJIS'
    @font_for_footer = 'SJIS'
  when 'zh'
    extend(PDF_Chinese)
    AddGBFont()
    @font_for_content = 'GB'
    @font_for_footer = 'GB'
  when 'zh-tw'
    extend(PDF_Chinese)
    AddBig5Font()
    @font_for_content = 'Big5'
    @font_for_footer = 'Big5'
  else
    @font_for_content = 'Arial'
    @font_for_footer = 'Helvetica'              
  end
  SetCreator(Redmine::Info.app_name)
  SetFont(@font_for_content)
end

Instance Attribute Details

Returns the value of attribute footer_date.



34
35
36
# File 'lib/redmine/export/pdf.rb', line 34

def footer_date
  @footer_date
end

Instance Method Details

#Cell(w, h = 0, txt = '', border = 0, ln = 0, align = '', fill = 0, link = '') ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/redmine/export/pdf.rb', line 93

def Cell(w,h=0,txt='',border=0,ln=0,align='',fill=0,link='')
  @ic ||= Iconv.new(l(:general_pdf_encoding), 'UTF-8')
  # these quotation marks are not correctly rendered in the pdf
  txt = txt.gsub(/[“�]/, '"') if txt
  txt = begin
    # 0x5c char handling
    txtar = txt.split('\\')
    txtar << '' if txt[-1] == ?\\
    txtar.collect {|x| @ic.iconv(x)}.join('\\').gsub(/\\/, "\\\\\\\\")
  rescue
    txt
  end || ''
  super w,h,txt,border,ln,align,fill,link
end


108
109
110
111
112
113
114
115
116
# File 'lib/redmine/export/pdf.rb', line 108

def Footer
  SetFont(@font_for_footer, 'I', 8)
  SetY(-15)
  SetX(15)
  Cell(0, 5, @footer_date, 0, 0, 'L')
  SetY(-15)
  SetX(-30)
  Cell(0, 5, PageNo().to_s + '/{nb}', 0, 0, 'C')
end

#SetFontStyle(style, size) ⇒ Object



68
69
70
# File 'lib/redmine/export/pdf.rb', line 68

def SetFontStyle(style, size)
  SetFont(@font_for_content, style, size)
end

#SetTitle(txt) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/redmine/export/pdf.rb', line 72

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

#textstring(s) ⇒ Object



84
85
86
87
88
89
90
91
# File 'lib/redmine/export/pdf.rb', line 84

def textstring(s)
  # Format a text string
  if s =~ /^</  # This means the string is hex-dumped.
    return s
  else
    return '('+escape(s)+')'
  end
end