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.



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

def initialize(lang, orientation='P')
  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.



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

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


130
131
132
133
134
135
136
137
138
139
140
# File 'lib/redmine/export/pdf.rb', line 130

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
111
112
113
114
115
116
117
118
119
120
# 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
  # rubocop:disable Lint/DuplicateBranch
  elsif %r{/attachments/download/(?<id>[^/]+)/} =~ attrname and
        atta = @attachments.find{|a| a.id.to_s == id} and
        atta.readable? and atta.visible?
    return atta.diskfile
  # rubocop:enable Lint/DuplicateBranch
  elsif %r{/attachments/thumbnail/(?<id>[^/]+)/(?<size>\d+)} =~ attrname and
        atta = @attachments.find{|a| a.id.to_s == id} and
        atta.readable? and atta.visible?
    return atta.thumbnail(size: size)
  else
    return nil
  end
end

#get_sever_url(url) ⇒ Object



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

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 = txt.gsub(/<p>\{\{((<|&lt;)|(>|&gt;))?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



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

def SetFont(family, style='', size=0, fontfile='')
  style = +style
  # 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



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

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