##// END OF EJS Templates
revert r14907 (#19017)...
Toshi MARUYAMA -
r14529:12ede7d07f5e
parent child
Show More
@@ -1,154 +1,154
1 # encoding: utf-8
1 # encoding: utf-8
2 #
2 #
3 # Redmine - project management software
3 # Redmine - project management software
4 # Copyright (C) 2006-2015 Jean-Philippe Lang
4 # Copyright (C) 2006-2015 Jean-Philippe Lang
5 #
5 #
6 # This program is free software; you can redistribute it and/or
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
9 # of the License, or (at your option) any later version.
10 #
10 #
11 # This program is distributed in the hope that it will be useful,
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
14 # GNU General Public License for more details.
15 #
15 #
16 # You should have received a copy of the GNU General Public License
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
19
20 require 'rbpdf'
20 require 'rbpdf'
21
21
22 module Redmine
22 module Redmine
23 module Export
23 module Export
24 module PDF
24 module PDF
25 class ITCPDF < RBPDF
25 class ITCPDF < RBPDF
26 include Redmine::I18n
26 include Redmine::I18n
27 attr_accessor :footer_date
27 attr_accessor :footer_date
28
28
29 def initialize(lang, orientation='P')
29 def initialize(lang, orientation='P')
30 @@k_path_cache = Rails.root.join('tmp', 'pdf')
30 @@k_path_cache = Rails.root.join('tmp', 'pdf')
31 FileUtils.mkdir_p @@k_path_cache unless File::exist?(@@k_path_cache)
31 FileUtils.mkdir_p @@k_path_cache unless File::exist?(@@k_path_cache)
32 set_language_if_valid lang
32 set_language_if_valid lang
33 super(orientation, 'mm', 'A4')
33 super(orientation, 'mm', 'A4')
34 set_print_header(false)
34 set_print_header(false)
35 set_rtl(l(:direction) == 'rtl')
35 set_rtl(l(:direction) == 'rtl')
36
36
37 @font_for_content = l(:general_pdf_fontname)
37 @font_for_content = l(:general_pdf_fontname)
38 @monospaced_font_for_content = l(:general_pdf_monospaced_fontname)
38 @monospaced_font_for_content = l(:general_pdf_monospaced_fontname)
39 @font_for_footer = l(:general_pdf_fontname)
39 @font_for_footer = l(:general_pdf_fontname)
40 set_creator(Redmine::Info.app_name)
40 set_creator(Redmine::Info.app_name)
41 set_font(@font_for_content)
41 set_font(@font_for_content)
42
42
43 set_header_font([@font_for_content, '', 10])
43 set_header_font([@font_for_content, '', 10])
44 set_footer_font([@font_for_content, '', 8])
44 set_footer_font([@font_for_content, '', 8])
45 set_default_monospaced_font(@monospaced_font_for_content)
45 set_default_monospaced_font(@monospaced_font_for_content)
46 set_display_mode('default', 'OneColumn')
46 set_display_mode('default', 'OneColumn')
47 end
47 end
48
48
49 def SetFontStyle(style, size)
49 def SetFontStyle(style, size)
50 set_font(@font_for_content, style, size)
50 set_font(@font_for_content, style, size)
51 end
51 end
52
52
53 def SetFont(family, style='', size=0, fontfile='')
53 def SetFont(family, style='', size=0, fontfile='')
54 # FreeSerif Bold Thai font has problem.
54 # FreeSerif Bold Thai font has problem.
55 style.delete!('B') if family == 'freeserif'
55 style.delete!('B') if l(:general_pdf_fontname) == 'freeserif'
56 # DejaVuSans Italic Arabic and Persian font has problem.
56 # DejaVuSans Italic Arabic and Persian font has problem.
57 style.delete!('I') if family == 'DejaVuSans' && current_language.to_s.casecmp("vi") != 0
57 style.delete!('I') if l(:general_pdf_fontname) == 'DejaVuSans' && current_language.to_s.casecmp("vi") != 0
58 super(family, style, size, fontfile)
58 super(family, style, size, fontfile)
59 end
59 end
60 alias_method :set_font, :SetFont
60 alias_method :set_font, :SetFont
61
61
62 def fix_text_encoding(txt)
62 def fix_text_encoding(txt)
63 RDMPdfEncoding::rdm_from_utf8(txt, "UTF-8")
63 RDMPdfEncoding::rdm_from_utf8(txt, "UTF-8")
64 end
64 end
65
65
66 def formatted_text(text)
66 def formatted_text(text)
67 Redmine::WikiFormatting.to_html(Setting.text_formatting, text)
67 Redmine::WikiFormatting.to_html(Setting.text_formatting, text)
68 end
68 end
69
69
70 def RDMCell(w ,h=0, txt='', border=0, ln=0, align='', fill=0, link='')
70 def RDMCell(w ,h=0, txt='', border=0, ln=0, align='', fill=0, link='')
71 cell(w, h, txt, border, ln, align, fill, link)
71 cell(w, h, txt, border, ln, align, fill, link)
72 end
72 end
73
73
74 def RDMMultiCell(w, h=0, txt='', border=0, align='', fill=0, ln=1)
74 def RDMMultiCell(w, h=0, txt='', border=0, align='', fill=0, ln=1)
75 multi_cell(w, h, txt, border, align, fill, ln)
75 multi_cell(w, h, txt, border, align, fill, ln)
76 end
76 end
77
77
78 def RDMwriteFormattedCell(w, h, x, y, txt='', attachments=[], border=0, ln=1, fill=0)
78 def RDMwriteFormattedCell(w, h, x, y, txt='', attachments=[], border=0, ln=1, fill=0)
79 @attachments = attachments
79 @attachments = attachments
80
80
81 css_tag = ' <style>
81 css_tag = ' <style>
82 table, td {
82 table, td {
83 border: 2px #ff0000 solid;
83 border: 2px #ff0000 solid;
84 }
84 }
85 th { background-color:#EEEEEE; padding: 4px; white-space:nowrap; text-align: center; font-style: bold;}
85 th { background-color:#EEEEEE; padding: 4px; white-space:nowrap; text-align: center; font-style: bold;}
86 pre {
86 pre {
87 background-color: #fafafa;
87 background-color: #fafafa;
88 }
88 }
89 </style>'
89 </style>'
90
90
91 # Strip {{toc}} tags
91 # Strip {{toc}} tags
92 txt.gsub!(/<p>\{\{([<>]?)toc\}\}<\/p>/i, '')
92 txt.gsub!(/<p>\{\{([<>]?)toc\}\}<\/p>/i, '')
93 writeHTMLCell(w, h, x, y, css_tag + txt, border, ln, fill)
93 writeHTMLCell(w, h, x, y, css_tag + txt, border, ln, fill)
94 end
94 end
95
95
96 def RDMwriteHTMLCell(w, h, x, y, txt='', attachments=[], border=0, ln=1, fill=0)
96 def RDMwriteHTMLCell(w, h, x, y, txt='', attachments=[], border=0, ln=1, fill=0)
97 txt = formatted_text(txt)
97 txt = formatted_text(txt)
98 RDMwriteFormattedCell(w, h, x, y, txt, attachments, border, ln, fill)
98 RDMwriteFormattedCell(w, h, x, y, txt, attachments, border, ln, fill)
99 end
99 end
100
100
101 def get_image_filename(attrname)
101 def get_image_filename(attrname)
102 atta = RDMPdfEncoding.attach(@attachments, attrname, "UTF-8")
102 atta = RDMPdfEncoding.attach(@attachments, attrname, "UTF-8")
103 if atta
103 if atta
104 return atta.diskfile
104 return atta.diskfile
105 else
105 else
106 return nil
106 return nil
107 end
107 end
108 end
108 end
109
109
110 def get_sever_url(url)
110 def get_sever_url(url)
111 if !empty_string(url) and (url[0, 1] == '/')
111 if !empty_string(url) and (url[0, 1] == '/')
112 Setting.host_name.split('/')[0] + url
112 Setting.host_name.split('/')[0] + url
113 else
113 else
114 url
114 url
115 end
115 end
116 end
116 end
117
117
118 def Footer
118 def Footer
119 set_font(@font_for_footer, 'I', 8)
119 set_font(@font_for_footer, 'I', 8)
120 set_x(15)
120 set_x(15)
121 if get_rtl
121 if get_rtl
122 RDMCell(0, 5, @footer_date, 0, 0, 'R')
122 RDMCell(0, 5, @footer_date, 0, 0, 'R')
123 else
123 else
124 RDMCell(0, 5, @footer_date, 0, 0, 'L')
124 RDMCell(0, 5, @footer_date, 0, 0, 'L')
125 end
125 end
126 set_x(-30)
126 set_x(-30)
127 RDMCell(0, 5, get_alias_num_page() + '/' + get_alias_nb_pages(), 0, 0, 'C')
127 RDMCell(0, 5, get_alias_num_page() + '/' + get_alias_nb_pages(), 0, 0, 'C')
128 end
128 end
129 end
129 end
130
130
131 class RDMPdfEncoding
131 class RDMPdfEncoding
132 def self.rdm_from_utf8(txt, encoding)
132 def self.rdm_from_utf8(txt, encoding)
133 txt ||= ''
133 txt ||= ''
134 txt = Redmine::CodesetUtil.from_utf8(txt, encoding)
134 txt = Redmine::CodesetUtil.from_utf8(txt, encoding)
135 txt.force_encoding('ASCII-8BIT')
135 txt.force_encoding('ASCII-8BIT')
136 txt
136 txt
137 end
137 end
138
138
139 def self.attach(attachments, filename, encoding)
139 def self.attach(attachments, filename, encoding)
140 filename_utf8 = Redmine::CodesetUtil.to_utf8(filename, encoding)
140 filename_utf8 = Redmine::CodesetUtil.to_utf8(filename, encoding)
141 atta = nil
141 atta = nil
142 if filename_utf8 =~ /^[^\/"]+\.(gif|jpg|jpe|jpeg|png)$/i
142 if filename_utf8 =~ /^[^\/"]+\.(gif|jpg|jpe|jpeg|png)$/i
143 atta = Attachment.latest_attach(attachments, filename_utf8)
143 atta = Attachment.latest_attach(attachments, filename_utf8)
144 end
144 end
145 if atta && atta.readable? && atta.visible?
145 if atta && atta.readable? && atta.visible?
146 return atta
146 return atta
147 else
147 else
148 return nil
148 return nil
149 end
149 end
150 end
150 end
151 end
151 end
152 end
152 end
153 end
153 end
154 end
154 end
General Comments 0
You need to be logged in to leave comments. Login now