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