| 1 |
1 |
# encoding: utf-8
|
| 2 |
2 |
#
|
| 3 |
3 |
# Redmine - project management software
|
| 4 |
|
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
|
4 |
# Copyright (C) 2006-2011 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 'iconv'
|
| 21 |
21 |
require 'rfpdf/fpdf'
|
| 22 |
|
require 'rfpdf/chinese'
|
|
22 |
require 'fpdf/chinese'
|
|
23 |
require 'fpdf/japanese'
|
|
24 |
require 'fpdf/korean'
|
| 23 |
25 |
|
| 24 |
26 |
module Redmine
|
| 25 |
27 |
module Export
|
| 26 |
28 |
module PDF
|
| 27 |
29 |
include ActionView::Helpers::TextHelper
|
| 28 |
30 |
include ActionView::Helpers::NumberHelper
|
| 29 |
|
|
| 30 |
|
class IFPDF < FPDF
|
|
31 |
|
|
32 |
class ITCPDF < TCPDF
|
| 31 |
33 |
include Redmine::I18n
|
| 32 |
34 |
attr_accessor :footer_date
|
| 33 |
|
|
|
35 |
|
| 34 |
36 |
def initialize(lang)
|
| 35 |
|
super()
|
| 36 |
37 |
set_language_if_valid lang
|
| 37 |
|
case current_language.to_s.downcase
|
| 38 |
|
when 'ko'
|
|
38 |
pdf_encoding = l(:general_pdf_encoding).upcase
|
|
39 |
if RUBY_VERSION < '1.9'
|
|
40 |
@ic = Iconv.new(pdf_encoding, 'UTF-8')
|
|
41 |
end
|
|
42 |
super('P', 'mm', 'A4', (pdf_encoding == 'UTF-8'), pdf_encoding)
|
|
43 |
case pdf_encoding
|
|
44 |
when 'UTF-8'
|
|
45 |
@font_for_content = 'FreeSans'
|
|
46 |
@font_for_footer = 'FreeSans'
|
|
47 |
when 'CP949'
|
| 39 |
48 |
extend(PDF_Korean)
|
| 40 |
49 |
AddUHCFont()
|
| 41 |
50 |
@font_for_content = 'UHC'
|
| 42 |
|
@font_for_footer = 'UHC'
|
| 43 |
|
when 'ja'
|
|
51 |
@font_for_footer = 'UHC'
|
|
52 |
when 'CP932'
|
| 44 |
53 |
extend(PDF_Japanese)
|
| 45 |
54 |
AddSJISFont()
|
| 46 |
55 |
@font_for_content = 'SJIS'
|
| 47 |
|
@font_for_footer = 'SJIS'
|
| 48 |
|
when 'zh'
|
|
56 |
@font_for_footer = 'SJIS'
|
|
57 |
when 'GB18030'
|
| 49 |
58 |
extend(PDF_Chinese)
|
| 50 |
59 |
AddGBFont()
|
| 51 |
60 |
@font_for_content = 'GB'
|
| 52 |
|
@font_for_footer = 'GB'
|
| 53 |
|
when 'zh-tw'
|
|
61 |
@font_for_footer = 'GB'
|
|
62 |
when 'BIG5'
|
| 54 |
63 |
extend(PDF_Chinese)
|
| 55 |
64 |
AddBig5Font()
|
| 56 |
65 |
@font_for_content = 'Big5'
|
| 57 |
|
@font_for_footer = 'Big5'
|
|
66 |
@font_for_footer = 'Big5'
|
| 58 |
67 |
else
|
| 59 |
68 |
@font_for_content = 'Arial'
|
| 60 |
|
@font_for_footer = 'Helvetica'
|
|
69 |
@font_for_footer = 'Helvetica'
|
| 61 |
70 |
end
|
| 62 |
71 |
SetCreator(Redmine::Info.app_name)
|
| 63 |
72 |
SetFont(@font_for_content)
|
| 64 |
73 |
end
|
| 65 |
|
|
|
74 |
|
| 66 |
75 |
def SetFontStyle(style, size)
|
| 67 |
76 |
SetFont(@font_for_content, style, size)
|
| 68 |
77 |
end
|
| 69 |
|
|
|
78 |
|
| 70 |
79 |
def SetTitle(txt)
|
| 71 |
80 |
txt = begin
|
| 72 |
81 |
utf16txt = Iconv.conv('UTF-16BE', 'UTF-8', txt)
|
| ... | ... | |
| 78 |
87 |
end || ''
|
| 79 |
88 |
super(txt)
|
| 80 |
89 |
end
|
| 81 |
|
|
|
90 |
|
| 82 |
91 |
def textstring(s)
|
| 83 |
92 |
# Format a text string
|
| 84 |
93 |
if s =~ /^</ # This means the string is hex-dumped.
|
| ... | ... | |
| 87 |
96 |
return '('+escape(s)+')'
|
| 88 |
97 |
end
|
| 89 |
98 |
end
|
| 90 |
|
|
| 91 |
|
def Cell(w,h=0,txt='',border=0,ln=0,align='',fill=0,link='')
|
| 92 |
|
@ic ||= Iconv.new(l(:general_pdf_encoding), 'UTF-8')
|
| 93 |
|
# these quotation marks are not correctly rendered in the pdf
|
| 94 |
|
txt = txt.gsub(/[“�]/, '"') if txt
|
| 95 |
|
txt = begin
|
| 96 |
|
# 0x5c char handling
|
| 97 |
|
txtar = txt.split('\\')
|
| 98 |
|
txtar << '' if txt[-1] == ?\\
|
| 99 |
|
txtar.collect {|x| @ic.iconv(x)}.join('\\').gsub(/\\/, "\\\\\\\\")
|
| 100 |
|
rescue
|
| 101 |
|
txt
|
| 102 |
|
end || ''
|
| 103 |
|
super w,h,txt,border,ln,align,fill,link
|
|
99 |
|
|
100 |
def fix_text_encoding(txt)
|
|
101 |
RDMPdfEncoding::rdm_pdf_iconv(@ic, txt)
|
| 104 |
102 |
end
|
| 105 |
|
|
|
103 |
|
|
104 |
def RDMCell(w,h=0,txt='',border=0,ln=0,align='',fill=0,link='')
|
|
105 |
Cell(w,h,fix_text_encoding(txt),border,ln,align,fill,link)
|
|
106 |
end
|
|
107 |
|
|
108 |
def RDMMultiCell(w,h=0,txt='',border=0,align='',fill=0)
|
|
109 |
MultiCell(w,h,fix_text_encoding(txt),border,align,fill)
|
|
110 |
end
|
|
111 |
|
| 106 |
112 |
def Footer
|
| 107 |
113 |
SetFont(@font_for_footer, 'I', 8)
|
| 108 |
114 |
SetY(-15)
|
| 109 |
115 |
SetX(15)
|
| 110 |
|
Cell(0, 5, @footer_date, 0, 0, 'L')
|
|
116 |
RDMCell(0, 5, @footer_date, 0, 0, 'L')
|
| 111 |
117 |
SetY(-15)
|
| 112 |
118 |
SetX(-30)
|
| 113 |
|
Cell(0, 5, PageNo().to_s + '/{nb}', 0, 0, 'C')
|
|
119 |
RDMCell(0, 5, PageNo().to_s + '/{nb}', 0, 0, 'C')
|
| 114 |
120 |
end
|
| 115 |
121 |
end
|
| 116 |
|
|
|
122 |
|
| 117 |
123 |
# Returns a PDF string of a list of issues
|
| 118 |
124 |
def issues_to_pdf(issues, project, query)
|
| 119 |
|
pdf = IFPDF.new(current_language)
|
|
125 |
pdf = ITCPDF.new(current_language)
|
| 120 |
126 |
title = query.new_record? ? l(:label_issue_plural) : query.name
|
| 121 |
127 |
title = "#{project} - #{title}" if project
|
| 122 |
128 |
pdf.SetTitle(title)
|
| 123 |
|
pdf.AliasNbPages
|
|
129 |
pdf.alias_nb_pages
|
| 124 |
130 |
pdf.footer_date = format_date(Date.today)
|
|
131 |
pdf.SetAutoPageBreak(false)
|
| 125 |
132 |
pdf.AddPage("L")
|
| 126 |
|
|
| 127 |
|
row_height = 6
|
|
133 |
|
|
134 |
# Landscape A4 = 210 x 297 mm
|
|
135 |
page_height = 210
|
|
136 |
page_width = 297
|
|
137 |
right_margin = 10
|
|
138 |
bottom_margin = 20
|
|
139 |
col_id_width = 10
|
|
140 |
row_height = 5
|
|
141 |
|
|
142 |
# column widths
|
|
143 |
table_width = page_width - right_margin - 10 # fixed left margin
|
| 128 |
144 |
col_width = []
|
| 129 |
145 |
unless query.columns.empty?
|
| 130 |
|
col_width = query.columns.collect {|column| column.name == :subject ? 4.0 : 1.0 }
|
| 131 |
|
ratio = 262.0 / col_width.inject(0) {|s,w| s += w}
|
|
146 |
col_width = query.columns.collect do |c|
|
|
147 |
(c.name == :subject || (c.is_a?(QueryCustomFieldColumn) && ['string', 'text'].include?(c.custom_field.field_format)))? 4.0 : 1.0
|
|
148 |
end
|
|
149 |
ratio = (table_width - col_id_width) / col_width.inject(0) {|s,w| s += w}
|
| 132 |
150 |
col_width = col_width.collect {|w| w * ratio}
|
| 133 |
151 |
end
|
| 134 |
|
|
|
152 |
|
| 135 |
153 |
# title
|
| 136 |
|
pdf.SetFontStyle('B',11)
|
| 137 |
|
pdf.Cell(190,10, title)
|
|
154 |
pdf.SetFontStyle('B',11)
|
|
155 |
pdf.RDMCell(190,10, title)
|
| 138 |
156 |
pdf.Ln
|
| 139 |
|
|
|
157 |
|
| 140 |
158 |
# headers
|
| 141 |
159 |
pdf.SetFontStyle('B',8)
|
| 142 |
160 |
pdf.SetFillColor(230, 230, 230)
|
| 143 |
|
pdf.Cell(15, row_height, "#", 1, 0, 'L', 1)
|
| 144 |
|
query.columns.each_with_index do |column, i|
|
| 145 |
|
pdf.Cell(col_width[i], row_height, column.caption, 1, 0, 'L', 1)
|
| 146 |
|
end
|
| 147 |
|
pdf.Ln
|
| 148 |
|
|
|
161 |
|
|
162 |
# render it background to find the max height used
|
|
163 |
base_x = pdf.GetX
|
|
164 |
base_y = pdf.GetY
|
|
165 |
max_height = issues_to_pdf_write_cells(pdf, query.columns, col_width, row_height, true)
|
|
166 |
pdf.Rect(base_x, base_y, table_width, max_height, 'FD');
|
|
167 |
pdf.SetXY(base_x, base_y);
|
|
168 |
|
|
169 |
# write the cells on page
|
|
170 |
pdf.RDMCell(col_id_width, row_height, "#", "T", 0, 'C', 1)
|
|
171 |
issues_to_pdf_write_cells(pdf, query.columns, col_width, row_height, true)
|
|
172 |
issues_to_pdf_draw_borders(pdf, base_x, base_y, base_y + max_height, col_id_width, col_width)
|
|
173 |
pdf.SetY(base_y + max_height);
|
|
174 |
|
| 149 |
175 |
# rows
|
| 150 |
176 |
pdf.SetFontStyle('',8)
|
| 151 |
177 |
pdf.SetFillColor(255, 255, 255)
|
| 152 |
178 |
previous_group = false
|
| 153 |
179 |
issues.each do |issue|
|
| 154 |
|
if query.grouped? && (group = query.group_by_column.value(issue)) != previous_group
|
|
180 |
if query.grouped? &&
|
|
181 |
(group = query.group_by_column.value(issue)) != previous_group
|
| 155 |
182 |
pdf.SetFontStyle('B',9)
|
| 156 |
|
pdf.Cell(277, row_height,
|
|
183 |
pdf.RDMCell(277, row_height,
|
| 157 |
184 |
(group.blank? ? 'None' : group.to_s) + " (#{query.issue_count_by_group[group]})",
|
| 158 |
185 |
1, 1, 'L')
|
| 159 |
186 |
pdf.SetFontStyle('',8)
|
| 160 |
187 |
previous_group = group
|
| 161 |
188 |
end
|
| 162 |
|
pdf.Cell(15, row_height, issue.id.to_s, 1, 0, 'L', 1)
|
| 163 |
|
query.columns.each_with_index do |column, i|
|
|
189 |
# fetch all the row values
|
|
190 |
col_values = query.columns.collect do |column|
|
| 164 |
191 |
s = if column.is_a?(QueryCustomFieldColumn)
|
| 165 |
192 |
cv = issue.custom_values.detect {|v| v.custom_field_id == column.custom_field.id}
|
| 166 |
193 |
show_value(cv)
|
| ... | ... | |
| 174 |
201 |
value
|
| 175 |
202 |
end
|
| 176 |
203 |
end
|
| 177 |
|
pdf.Cell(col_width[i], row_height, s.to_s, 1, 0, 'L', 1)
|
|
204 |
s.to_s
|
| 178 |
205 |
end
|
| 179 |
|
pdf.Ln
|
|
206 |
|
|
207 |
# render it off-page to find the max height used
|
|
208 |
base_x = pdf.GetX
|
|
209 |
base_y = pdf.GetY
|
|
210 |
pdf.SetY(2 * page_height)
|
|
211 |
max_height = issues_to_pdf_write_cells(pdf, col_values, col_width, row_height)
|
|
212 |
pdf.SetXY(base_x, base_y)
|
|
213 |
|
|
214 |
# make new page if it doesn't fit on the current one
|
|
215 |
space_left = page_height - base_y - bottom_margin
|
|
216 |
if max_height > space_left
|
|
217 |
pdf.AddPage("L")
|
|
218 |
base_x = pdf.GetX
|
|
219 |
base_y = pdf.GetY
|
|
220 |
end
|
|
221 |
|
|
222 |
# write the cells on page
|
|
223 |
pdf.RDMCell(col_id_width, row_height, issue.id.to_s, "T", 0, 'C', 1)
|
|
224 |
issues_to_pdf_write_cells(pdf, col_values, col_width, row_height)
|
|
225 |
issues_to_pdf_draw_borders(pdf, base_x, base_y, base_y + max_height, col_id_width, col_width)
|
|
226 |
pdf.SetY(base_y + max_height);
|
| 180 |
227 |
end
|
|
228 |
|
| 181 |
229 |
if issues.size == Setting.issues_export_limit.to_i
|
| 182 |
230 |
pdf.SetFontStyle('B',10)
|
| 183 |
|
pdf.Cell(0, row_height, '...')
|
|
231 |
pdf.RDMCell(0, row_height, '...')
|
| 184 |
232 |
end
|
| 185 |
233 |
pdf.Output
|
| 186 |
234 |
end
|
| 187 |
235 |
|
|
236 |
# Renders MultiCells and returns the maximum height used
|
|
237 |
def issues_to_pdf_write_cells(pdf, col_values, col_widths,
|
|
238 |
row_height, head=false)
|
|
239 |
base_y = pdf.GetY
|
|
240 |
max_height = row_height
|
|
241 |
col_values.each_with_index do |column, i|
|
|
242 |
col_x = pdf.GetX
|
|
243 |
if head == true
|
|
244 |
pdf.RDMMultiCell(col_widths[i], row_height, column.caption, "T", 'L', 1)
|
|
245 |
else
|
|
246 |
pdf.RDMMultiCell(col_widths[i], row_height, column, "T", 'L', 1)
|
|
247 |
end
|
|
248 |
max_height = (pdf.GetY - base_y) if (pdf.GetY - base_y) > max_height
|
|
249 |
pdf.SetXY(col_x + col_widths[i], base_y);
|
|
250 |
end
|
|
251 |
return max_height
|
|
252 |
end
|
|
253 |
|
|
254 |
# Draw lines to close the row (MultiCell border drawing in not uniform)
|
|
255 |
def issues_to_pdf_draw_borders(pdf, top_x, top_y, lower_y,
|
|
256 |
id_width, col_widths)
|
|
257 |
col_x = top_x + id_width
|
|
258 |
pdf.Line(col_x, top_y, col_x, lower_y) # id right border
|
|
259 |
col_widths.each do |width|
|
|
260 |
col_x += width
|
|
261 |
pdf.Line(col_x, top_y, col_x, lower_y) # columns right border
|
|
262 |
end
|
|
263 |
pdf.Line(top_x, top_y, top_x, lower_y) # left border
|
|
264 |
pdf.Line(top_x, lower_y, col_x, lower_y) # bottom border
|
|
265 |
end
|
|
266 |
|
| 188 |
267 |
# Returns a PDF string of a single issue
|
| 189 |
268 |
def issue_to_pdf(issue)
|
| 190 |
|
pdf = IFPDF.new(current_language)
|
|
269 |
pdf = ITCPDF.new(current_language)
|
| 191 |
270 |
pdf.SetTitle("#{issue.project} - ##{issue.tracker} #{issue.id}")
|
| 192 |
|
pdf.AliasNbPages
|
|
271 |
pdf.alias_nb_pages
|
| 193 |
272 |
pdf.footer_date = format_date(Date.today)
|
| 194 |
273 |
pdf.AddPage
|
| 195 |
|
|
| 196 |
|
pdf.SetFontStyle('B',11)
|
| 197 |
|
pdf.Cell(190,10, "#{issue.project} - #{issue.tracker} # #{issue.id}: #{issue.subject}")
|
|
274 |
pdf.SetFontStyle('B',11)
|
|
275 |
pdf.RDMMultiCell(190,5,
|
|
276 |
"#{issue.project} - #{issue.tracker} # #{issue.id}: #{issue.subject}")
|
| 198 |
277 |
pdf.Ln
|
| 199 |
|
|
|
278 |
|
| 200 |
279 |
y0 = pdf.GetY
|
| 201 |
|
|
|
280 |
|
| 202 |
281 |
pdf.SetFontStyle('B',9)
|
| 203 |
|
pdf.Cell(35,5, l(:field_status) + ":","LT")
|
|
282 |
pdf.RDMCell(35,5, l(:field_status) + ":","LT")
|
| 204 |
283 |
pdf.SetFontStyle('',9)
|
| 205 |
|
pdf.Cell(60,5, issue.status.to_s,"RT")
|
|
284 |
pdf.RDMCell(60,5, issue.status.to_s,"RT")
|
| 206 |
285 |
pdf.SetFontStyle('B',9)
|
| 207 |
|
pdf.Cell(35,5, l(:field_priority) + ":","LT")
|
|
286 |
pdf.RDMCell(35,5, l(:field_priority) + ":","LT")
|
| 208 |
287 |
pdf.SetFontStyle('',9)
|
| 209 |
|
pdf.Cell(60,5, issue.priority.to_s,"RT")
|
|
288 |
pdf.RDMCell(60,5, issue.priority.to_s,"RT")
|
| 210 |
289 |
pdf.Ln
|
| 211 |
|
|
|
290 |
|
| 212 |
291 |
pdf.SetFontStyle('B',9)
|
| 213 |
|
pdf.Cell(35,5, l(:field_author) + ":","L")
|
|
292 |
pdf.RDMCell(35,5, l(:field_author) + ":","L")
|
| 214 |
293 |
pdf.SetFontStyle('',9)
|
| 215 |
|
pdf.Cell(60,5, issue.author.to_s,"R")
|
|
294 |
pdf.RDMCell(60,5, issue.author.to_s,"R")
|
| 216 |
295 |
pdf.SetFontStyle('B',9)
|
| 217 |
|
pdf.Cell(35,5, l(:field_category) + ":","L")
|
|
296 |
pdf.RDMCell(35,5, l(:field_category) + ":","L")
|
| 218 |
297 |
pdf.SetFontStyle('',9)
|
| 219 |
|
pdf.Cell(60,5, issue.category.to_s,"R")
|
| 220 |
|
pdf.Ln
|
| 221 |
|
|
|
298 |
pdf.RDMCell(60,5, issue.category.to_s,"R")
|
|
299 |
pdf.Ln
|
|
300 |
|
| 222 |
301 |
pdf.SetFontStyle('B',9)
|
| 223 |
|
pdf.Cell(35,5, l(:field_created_on) + ":","L")
|
|
302 |
pdf.RDMCell(35,5, l(:field_created_on) + ":","L")
|
| 224 |
303 |
pdf.SetFontStyle('',9)
|
| 225 |
|
pdf.Cell(60,5, format_date(issue.created_on),"R")
|
|
304 |
pdf.RDMCell(60,5, format_date(issue.created_on),"R")
|
| 226 |
305 |
pdf.SetFontStyle('B',9)
|
| 227 |
|
pdf.Cell(35,5, l(:field_assigned_to) + ":","L")
|
|
306 |
pdf.RDMCell(35,5, l(:field_assigned_to) + ":","L")
|
| 228 |
307 |
pdf.SetFontStyle('',9)
|
| 229 |
|
pdf.Cell(60,5, issue.assigned_to.to_s,"R")
|
|
308 |
pdf.RDMCell(60,5, issue.assigned_to.to_s,"R")
|
| 230 |
309 |
pdf.Ln
|
| 231 |
|
|
|
310 |
|
| 232 |
311 |
pdf.SetFontStyle('B',9)
|
| 233 |
|
pdf.Cell(35,5, l(:field_updated_on) + ":","LB")
|
|
312 |
pdf.RDMCell(35,5, l(:field_updated_on) + ":","LB")
|
| 234 |
313 |
pdf.SetFontStyle('',9)
|
| 235 |
|
pdf.Cell(60,5, format_date(issue.updated_on),"RB")
|
|
314 |
pdf.RDMCell(60,5, format_date(issue.updated_on),"RB")
|
| 236 |
315 |
pdf.SetFontStyle('B',9)
|
| 237 |
|
pdf.Cell(35,5, l(:field_due_date) + ":","LB")
|
|
316 |
pdf.RDMCell(35,5, l(:field_due_date) + ":","LB")
|
| 238 |
317 |
pdf.SetFontStyle('',9)
|
| 239 |
|
pdf.Cell(60,5, format_date(issue.due_date),"RB")
|
|
318 |
pdf.RDMCell(60,5, format_date(issue.due_date),"RB")
|
| 240 |
319 |
pdf.Ln
|
| 241 |
|
|
|
320 |
|
| 242 |
321 |
for custom_value in issue.custom_field_values
|
| 243 |
322 |
pdf.SetFontStyle('B',9)
|
| 244 |
|
pdf.Cell(35,5, custom_value.custom_field.name + ":","L")
|
|
323 |
pdf.RDMCell(35,5, custom_value.custom_field.name + ":","L")
|
| 245 |
324 |
pdf.SetFontStyle('',9)
|
| 246 |
|
pdf.MultiCell(155,5, (show_value custom_value),"R")
|
|
325 |
pdf.RDMMultiCell(155,5, (show_value custom_value),"R")
|
| 247 |
326 |
end
|
| 248 |
|
|
|
327 |
|
| 249 |
328 |
pdf.SetFontStyle('B',9)
|
| 250 |
|
pdf.Cell(35,5, l(:field_subject) + ":","LTB")
|
|
329 |
pdf.RDMCell(35,5, l(:field_subject) + ":","LT")
|
| 251 |
330 |
pdf.SetFontStyle('',9)
|
| 252 |
|
pdf.Cell(155,5, issue.subject,"RTB")
|
| 253 |
|
pdf.Ln
|
| 254 |
|
|
|
331 |
pdf.RDMMultiCell(155,5, issue.subject,"RT")
|
|
332 |
|
| 255 |
333 |
pdf.SetFontStyle('B',9)
|
| 256 |
|
pdf.Cell(35,5, l(:field_description) + ":")
|
|
334 |
pdf.RDMCell(35,5, l(:field_description) + ":","LT")
|
| 257 |
335 |
pdf.SetFontStyle('',9)
|
| 258 |
|
pdf.MultiCell(155,5, issue.description.to_s,"BR")
|
| 259 |
|
|
|
336 |
pdf.RDMMultiCell(155,5, issue.description.to_s,"RT")
|
|
337 |
|
| 260 |
338 |
pdf.Line(pdf.GetX, y0, pdf.GetX, pdf.GetY)
|
| 261 |
|
pdf.Line(pdf.GetX, pdf.GetY, 170, pdf.GetY)
|
|
339 |
pdf.Line(pdf.GetX, pdf.GetY, pdf.GetX + 190, pdf.GetY)
|
| 262 |
340 |
pdf.Ln
|
| 263 |
|
|
| 264 |
|
if issue.changesets.any? && User.current.allowed_to?(:view_changesets, issue.project)
|
|
341 |
|
|
342 |
if issue.changesets.any? &&
|
|
343 |
User.current.allowed_to?(:view_changesets, issue.project)
|
| 265 |
344 |
pdf.SetFontStyle('B',9)
|
| 266 |
|
pdf.Cell(190,5, l(:label_associated_revisions), "B")
|
|
345 |
pdf.RDMCell(190,5, l(:label_associated_revisions), "B")
|
| 267 |
346 |
pdf.Ln
|
| 268 |
347 |
for changeset in issue.changesets
|
| 269 |
348 |
pdf.SetFontStyle('B',8)
|
| 270 |
|
pdf.Cell(190,5, format_time(changeset.committed_on) + " - " + changeset.author.to_s)
|
|
349 |
pdf.RDMCell(190,5,
|
|
350 |
format_time(changeset.committed_on) + " - " + changeset.author.to_s)
|
| 271 |
351 |
pdf.Ln
|
| 272 |
352 |
unless changeset.comments.blank?
|
| 273 |
353 |
pdf.SetFontStyle('',8)
|
| 274 |
|
pdf.MultiCell(190,5, changeset.comments.to_s)
|
| 275 |
|
end
|
|
354 |
pdf.RDMMultiCell(190,5, changeset.comments.to_s)
|
|
355 |
end
|
| 276 |
356 |
pdf.Ln
|
| 277 |
357 |
end
|
| 278 |
358 |
end
|
| 279 |
|
|
|
359 |
|
| 280 |
360 |
pdf.SetFontStyle('B',9)
|
| 281 |
|
pdf.Cell(190,5, l(:label_history), "B")
|
| 282 |
|
pdf.Ln
|
| 283 |
|
for journal in issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
|
|
361 |
pdf.RDMCell(190,5, l(:label_history), "B")
|
|
362 |
pdf.Ln
|
|
363 |
for journal in issue.journals.find(
|
|
364 |
:all, :include => [:user, :details],
|
|
365 |
:order => "#{Journal.table_name}.created_on ASC")
|
| 284 |
366 |
pdf.SetFontStyle('B',8)
|
| 285 |
|
pdf.Cell(190,5, format_time(journal.created_on) + " - " + journal.user.name)
|
|
367 |
pdf.RDMCell(190,5,
|
|
368 |
format_time(journal.created_on) + " - " + journal.user.name)
|
| 286 |
369 |
pdf.Ln
|
| 287 |
370 |
pdf.SetFontStyle('I',8)
|
| 288 |
371 |
for detail in journal.details
|
| 289 |
|
pdf.Cell(190,5, "- " + show_detail(detail, true))
|
| 290 |
|
pdf.Ln
|
|
372 |
pdf.RDMMultiCell(190,5, "- " + show_detail(detail, true))
|
| 291 |
373 |
end
|
| 292 |
374 |
if journal.notes?
|
|
375 |
pdf.Ln unless journal.details.empty?
|
| 293 |
376 |
pdf.SetFontStyle('',8)
|
| 294 |
|
pdf.MultiCell(190,5, journal.notes.to_s)
|
| 295 |
|
end
|
|
377 |
pdf.RDMMultiCell(190,5, journal.notes.to_s)
|
|
378 |
end
|
| 296 |
379 |
pdf.Ln
|
| 297 |
380 |
end
|
| 298 |
|
|
|
381 |
|
| 299 |
382 |
if issue.attachments.any?
|
| 300 |
383 |
pdf.SetFontStyle('B',9)
|
| 301 |
|
pdf.Cell(190,5, l(:label_attachment_plural), "B")
|
|
384 |
pdf.RDMCell(190,5, l(:label_attachment_plural), "B")
|
| 302 |
385 |
pdf.Ln
|
| 303 |
386 |
for attachment in issue.attachments
|
| 304 |
387 |
pdf.SetFontStyle('',8)
|
| 305 |
|
pdf.Cell(80,5, attachment.filename)
|
| 306 |
|
pdf.Cell(20,5, number_to_human_size(attachment.filesize),0,0,"R")
|
| 307 |
|
pdf.Cell(25,5, format_date(attachment.created_on),0,0,"R")
|
| 308 |
|
pdf.Cell(65,5, attachment.author.name,0,0,"R")
|
|
388 |
pdf.RDMCell(80,5, attachment.filename)
|
|
389 |
pdf.RDMCell(20,5, number_to_human_size(attachment.filesize),0,0,"R")
|
|
390 |
pdf.RDMCell(25,5, format_date(attachment.created_on),0,0,"R")
|
|
391 |
pdf.RDMCell(65,5, attachment.author.name,0,0,"R")
|
| 309 |
392 |
pdf.Ln
|
| 310 |
393 |
end
|
| 311 |
394 |
end
|
| 312 |
395 |
pdf.Output
|
| 313 |
396 |
end
|
| 314 |
397 |
|
|
398 |
class RDMPdfEncoding
|
|
399 |
include Redmine::I18n
|
|
400 |
def self.rdm_pdf_iconv(ic, txt)
|
|
401 |
txt ||= ''
|
|
402 |
if txt.respond_to?(:force_encoding)
|
|
403 |
txt.force_encoding('UTF-8')
|
|
404 |
if l(:general_pdf_encoding).upcase != 'UTF-8'
|
|
405 |
txt = txt.encode(l(:general_pdf_encoding), :invalid => :replace,
|
|
406 |
:undef => :replace, :replace => '?')
|
|
407 |
else
|
|
408 |
txt = Redmine::CodesetUtil.replace_invalid_utf8(txt)
|
|
409 |
end
|
|
410 |
txt.force_encoding('ASCII-8BIT')
|
|
411 |
else
|
|
412 |
ic ||= Iconv.new(l(:general_pdf_encoding), 'UTF-8')
|
|
413 |
txtar = ""
|
|
414 |
begin
|
|
415 |
txtar += ic.iconv(txt)
|
|
416 |
rescue Iconv::IllegalSequence
|
|
417 |
txtar += $!.success
|
|
418 |
txt = '?' + $!.failed[1,$!.failed.length]
|
|
419 |
retry
|
|
420 |
rescue
|
|
421 |
txtar += $!.success
|
|
422 |
end
|
|
423 |
txt = txtar
|
|
424 |
end
|
|
425 |
txt
|
|
426 |
end
|
|
427 |
end
|
| 315 |
428 |
end
|
| 316 |
429 |
end
|
| 317 |
430 |
end
|