Class: Redmine::Export::PDF::ITCPDF

Inherits:
RBPDF
  • 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_letter, #day_name, #find_language, #format_date, #format_hours, #format_time, included, #l, #l_hours, #l_hours_short, #l_or_humanize, #languages_options, #ll, #lu, #month_name, #set_language_if_valid, #valid_languages

Constructor Details

#initialize(lang, orientation = 'P') ⇒ ITCPDF

Returns a new instance of ITCPDF



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/redmine/export/pdf.rb', line 29

def initialize(lang, orientation='P')
  @@k_path_cache = Rails.root.join('tmp', 'pdf')
  FileUtils.mkdir_p @@k_path_cache unless File::exist?(@@k_path_cache)
  set_language_if_valid lang
  super(orientation, 'mm', 'A4')
  set_print_header(false)
  set_rtl(l(:direction) == 'rtl')

  @font_for_content = l(:general_pdf_fontname)
  @monospaced_font_for_content = l(:general_pdf_monospaced_fontname)
  @font_for_footer  = l(:general_pdf_fontname)
  set_creator(Redmine::Info.app_name)
  set_font(@font_for_content)

  set_header_font([@font_for_content, '', 10])
  set_footer_font([@font_for_content, '', 8])
  set_default_monospaced_font(@monospaced_font_for_content)
  set_display_mode('default', 'OneColumn')
end

Instance Attribute Details

Returns the value of attribute footer_date



27
28
29
# File 'lib/redmine/export/pdf.rb', line 27

def footer_date
  @footer_date
end

Instance Method Details

#fix_text_encoding(txt) ⇒ Object



64
65
66
# File 'lib/redmine/export/pdf.rb', line 64

def fix_text_encoding(txt)
  RDMPdfEncoding::rdm_from_utf8(txt, "UTF-8")
end


120
121
122
123
124
125
126
127
128
129
130
# File 'lib/redmine/export/pdf.rb', line 120

def Footer
  set_font(@font_for_footer, 'I', 8)
  set_x(15)
  if get_rtl
    RDMCell(0, 5, @footer_date, 0, 0, 'R')
  else
    RDMCell(0, 5, @footer_date, 0, 0, 'L')
  end
  set_x(-30)
  RDMCell(0, 5, get_alias_num_page() + '/' + get_alias_nb_pages(), 0, 0, 'C')
end

#formatted_text(text) ⇒ Object



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

def formatted_text(text)
  Redmine::WikiFormatting.to_html(Setting.text_formatting, text)
end

#get_image_filename(attrname) ⇒ Object



103
104
105
106
107
108
109
110
# File 'lib/redmine/export/pdf.rb', line 103

def get_image_filename(attrname)
  atta = RDMPdfEncoding.attach(@attachments, attrname, "UTF-8")
  if atta
    return atta.diskfile
  else
    return nil
  end
end

#get_sever_url(url) ⇒ Object



112
113
114
115
116
117
118
# File 'lib/redmine/export/pdf.rb', line 112

def get_sever_url(url)
  if !empty_string(url) and (url[0, 1] == '/')
    Setting.host_name.split('/')[0] + url
  else
    url
  end
end

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



72
73
74
# File 'lib/redmine/export/pdf.rb', line 72

def RDMCell(w ,h=0, txt='', border=0, ln=0, align='', fill=0, link='')
  cell(w, h, txt, border, ln, align, fill, link)
end

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



76
77
78
# File 'lib/redmine/export/pdf.rb', line 76

def RDMMultiCell(w, h=0, txt='', border=0, align='', fill=0, ln=1)
  multi_cell(w, h, txt, border, align, fill, ln)
end

#RDMwriteFormattedCell(w, h, x, y, txt = '', attachments = [], border = 0, ln = 1, fill = 0) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/redmine/export/pdf.rb', line 80

def RDMwriteFormattedCell(w, h, x, y, txt='', attachments=[], border=0, ln=1, fill=0)
  @attachments = attachments

  css_tag = ' <style>
  table, td {
    border: 2px #ff0000 solid;
  }
  th {  background-color:#EEEEEE; padding: 4px; white-space:nowrap; text-align: center;  font-style: bold;}
  pre {
    background-color: #fafafa;
  }
  </style>'

  # Strip {{toc}} tags
  txt.gsub!(/<p>\{\{([<>]?)toc\}\}<\/p>/i, '')
  writeHTMLCell(w, h, x, y, css_tag + txt, border, ln, fill)
end

#RDMwriteHTMLCell(w, h, x, y, txt = '', attachments = [], border = 0, ln = 1, fill = 0) ⇒ Object



98
99
100
101
# File 'lib/redmine/export/pdf.rb', line 98

def RDMwriteHTMLCell(w, h, x, y, txt='', attachments=[], border=0, ln=1, fill=0)
  txt = formatted_text(txt)
  RDMwriteFormattedCell(w, h, x, y, txt, attachments, border, ln, fill)
end

#SetFont(family, style = '', size = 0, fontfile = '') ⇒ Object Also known as: set_font



53
54
55
56
57
58
59
60
61
# File 'lib/redmine/export/pdf.rb', line 53

def SetFont(family, style='', size=0, fontfile='')
  # FreeSerif Bold Thai font has problem.
  style.delete!('B') if family.to_s.casecmp('freeserif') == 0
  # DejaVuSans Italic Arabic and Persian font has problem.
  style.delete!('I') if family.to_s.casecmp('dejavusans') == 0 && current_language.to_s.casecmp("vi") != 0
  # DejaVuSansMono Italic Arabic font has problem
  style.delete!('I') if family.to_s.casecmp('dejavusansmono') == 0
  super(family, style, size, fontfile)
end

#SetFontStyle(style, size) ⇒ Object



49
50
51
# File 'lib/redmine/export/pdf.rb', line 49

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