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

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

Constant Summary

Constants inherited from FPDF

Charwidths, FPDF_VERSION, M_EOI, M_SOF0, M_SOF1, M_SOF10, M_SOF11, M_SOF13, M_SOF14, M_SOF15, M_SOF2, M_SOF3, M_SOF5, M_SOF6, M_SOF7, M_SOF9, M_SOI, M_SOS

Instance Attribute Summary

Instance Method Summary

Methods included from Redmine::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

Methods inherited from FPDF

#AcceptPageBreak, #AddFont, #AddLink, #AddPage, #AliasNbPages, #Close, #Error, #GetStringWidth, #GetX, #GetY, #Header, #Image, #Line, #Link, #Ln, #MultiCell, #Open, #Output, #PageNo, #Rect, #SetAuthor, #SetAutoPageBreak, #SetCompression, #SetCreator, #SetDisplayMode, #SetDrawColor, #SetFillColor, #SetFont, #SetFontSize, #SetKeywords, #SetLeftMargin, #SetLineWidth, #SetLink, #SetMargins, #SetRightMargin, #SetSubject, #SetTextColor, #SetTopMargin, #SetX, #SetXY, #SetY, #Text, #Write

Constructor Details

- (IFPDF) initialize(lang)

A new instance of IFPDF



34
35
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
# File 'lib/redmine/export/pdf.rb', line 34

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



32
33
34
# File 'lib/redmine/export/pdf.rb', line 32

def footer_date
  @footer_date
end

Instance Method Details

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



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

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


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

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

- (Object) SetFontStyle(style, size)



66
67
68
# File 'lib/redmine/export/pdf.rb', line 66

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

- (Object) SetTitle(txt)



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

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

- (Object) textstring(s)



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

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