annotate .svn/pristine/e7/e77d4ee988f0ee0cedc3ea42fee306534d1cb4e6.svn-base @ 1517:dffacf8a6908 redmine-2.5

Update to Redmine SVN revision 13367 on 2.5-stable branch
author Chris Cannam
date Tue, 09 Sep 2014 09:29:00 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 # encoding: utf-8
Chris@909 2 #
Chris@909 3 # Redmine - project management software
Chris@909 4 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 5 #
Chris@909 6 # This program is free software; you can redistribute it and/or
Chris@909 7 # modify it under the terms of the GNU General Public License
Chris@909 8 # as published by the Free Software Foundation; either version 2
Chris@909 9 # of the License, or (at your option) any later version.
Chris@909 10 #
Chris@909 11 # This program is distributed in the hope that it will be useful,
Chris@909 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 14 # GNU General Public License for more details.
Chris@909 15 #
Chris@909 16 # You should have received a copy of the GNU General Public License
Chris@909 17 # along with this program; if not, write to the Free Software
Chris@909 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 19
Chris@909 20 require 'iconv'
Chris@909 21 require 'fpdf/chinese'
Chris@909 22 require 'fpdf/japanese'
Chris@909 23 require 'fpdf/korean'
Chris@909 24 require 'core/rmagick'
Chris@909 25
Chris@909 26 module Redmine
Chris@909 27 module Export
Chris@909 28 module PDF
Chris@909 29 include ActionView::Helpers::TextHelper
Chris@909 30 include ActionView::Helpers::NumberHelper
Chris@909 31 include IssuesHelper
Chris@909 32
Chris@909 33 class ITCPDF < TCPDF
Chris@909 34 include Redmine::I18n
Chris@909 35 attr_accessor :footer_date
Chris@909 36
Chris@909 37 def initialize(lang)
Chris@909 38 @@k_path_cache = Rails.root.join('tmp', 'pdf')
Chris@909 39 FileUtils.mkdir_p @@k_path_cache unless File::exist?(@@k_path_cache)
Chris@909 40 set_language_if_valid lang
Chris@909 41 pdf_encoding = l(:general_pdf_encoding).upcase
Chris@909 42 super('P', 'mm', 'A4', (pdf_encoding == 'UTF-8'), pdf_encoding)
Chris@909 43 case current_language.to_s.downcase
Chris@909 44 when 'vi'
Chris@909 45 @font_for_content = 'DejaVuSans'
Chris@909 46 @font_for_footer = 'DejaVuSans'
Chris@909 47 else
Chris@909 48 case pdf_encoding
Chris@909 49 when 'UTF-8'
Chris@909 50 @font_for_content = 'FreeSans'
Chris@909 51 @font_for_footer = 'FreeSans'
Chris@909 52 when 'CP949'
Chris@909 53 extend(PDF_Korean)
Chris@909 54 AddUHCFont()
Chris@909 55 @font_for_content = 'UHC'
Chris@909 56 @font_for_footer = 'UHC'
Chris@909 57 when 'CP932', 'SJIS', 'SHIFT_JIS'
Chris@909 58 extend(PDF_Japanese)
Chris@909 59 AddSJISFont()
Chris@909 60 @font_for_content = 'SJIS'
Chris@909 61 @font_for_footer = 'SJIS'
Chris@909 62 when 'GB18030'
Chris@909 63 extend(PDF_Chinese)
Chris@909 64 AddGBFont()
Chris@909 65 @font_for_content = 'GB'
Chris@909 66 @font_for_footer = 'GB'
Chris@909 67 when 'BIG5'
Chris@909 68 extend(PDF_Chinese)
Chris@909 69 AddBig5Font()
Chris@909 70 @font_for_content = 'Big5'
Chris@909 71 @font_for_footer = 'Big5'
Chris@909 72 else
Chris@909 73 @font_for_content = 'Arial'
Chris@909 74 @font_for_footer = 'Helvetica'
Chris@909 75 end
Chris@909 76 end
Chris@909 77 SetCreator(Redmine::Info.app_name)
Chris@909 78 SetFont(@font_for_content)
Chris@909 79 end
Chris@909 80
Chris@909 81 def SetFontStyle(style, size)
Chris@909 82 SetFont(@font_for_content, style, size)
Chris@909 83 end
Chris@909 84
Chris@909 85 def SetTitle(txt)
Chris@909 86 txt = begin
Chris@909 87 utf16txt = Iconv.conv('UTF-16BE', 'UTF-8', txt)
Chris@909 88 hextxt = "<FEFF" # FEFF is BOM
Chris@909 89 hextxt << utf16txt.unpack("C*").map {|x| sprintf("%02X",x) }.join
Chris@909 90 hextxt << ">"
Chris@909 91 rescue
Chris@909 92 txt
Chris@909 93 end || ''
Chris@909 94 super(txt)
Chris@909 95 end
Chris@909 96
Chris@909 97 def textstring(s)
Chris@909 98 # Format a text string
Chris@909 99 if s =~ /^</ # This means the string is hex-dumped.
Chris@909 100 return s
Chris@909 101 else
Chris@909 102 return '('+escape(s)+')'
Chris@909 103 end
Chris@909 104 end
Chris@909 105
Chris@909 106 def fix_text_encoding(txt)
Chris@909 107 RDMPdfEncoding::rdm_from_utf8(txt, l(:general_pdf_encoding))
Chris@909 108 end
Chris@909 109
Chris@909 110 def RDMCell(w ,h=0, txt='', border=0, ln=0, align='', fill=0, link='')
Chris@909 111 Cell(w, h, fix_text_encoding(txt), border, ln, align, fill, link)
Chris@909 112 end
Chris@909 113
Chris@909 114 def RDMMultiCell(w, h=0, txt='', border=0, align='', fill=0, ln=1)
Chris@909 115 MultiCell(w, h, fix_text_encoding(txt), border, align, fill, ln)
Chris@909 116 end
Chris@909 117
Chris@909 118 def RDMwriteHTMLCell(w, h, x, y, txt='', attachments=[], border=0, ln=1, fill=0)
Chris@909 119 @attachments = attachments
Chris@909 120 writeHTMLCell(w, h, x, y,
Chris@909 121 fix_text_encoding(
Chris@909 122 Redmine::WikiFormatting.to_html(Setting.text_formatting, txt)),
Chris@909 123 border, ln, fill)
Chris@909 124 end
Chris@909 125
Chris@909 126 def getImageFilename(attrname)
Chris@909 127 # attrname: general_pdf_encoding string file/uri name
Chris@909 128 atta = RDMPdfEncoding.attach(@attachments, attrname, l(:general_pdf_encoding))
Chris@909 129 if atta
Chris@909 130 return atta.diskfile
Chris@909 131 else
Chris@909 132 return nil
Chris@909 133 end
Chris@909 134 end
Chris@909 135
Chris@909 136 def Footer
Chris@909 137 SetFont(@font_for_footer, 'I', 8)
Chris@909 138 SetY(-15)
Chris@909 139 SetX(15)
Chris@909 140 RDMCell(0, 5, @footer_date, 0, 0, 'L')
Chris@909 141 SetY(-15)
Chris@909 142 SetX(-30)
Chris@909 143 RDMCell(0, 5, PageNo().to_s + '/{nb}', 0, 0, 'C')
Chris@909 144 end
Chris@909 145 end
Chris@909 146
Chris@909 147 # Returns a PDF string of a list of issues
Chris@909 148 def issues_to_pdf(issues, project, query)
Chris@909 149 pdf = ITCPDF.new(current_language)
Chris@909 150 title = query.new_record? ? l(:label_issue_plural) : query.name
Chris@909 151 title = "#{project} - #{title}" if project
Chris@909 152 pdf.SetTitle(title)
Chris@909 153 pdf.alias_nb_pages
Chris@909 154 pdf.footer_date = format_date(Date.today)
Chris@909 155 pdf.SetAutoPageBreak(false)
Chris@909 156 pdf.AddPage("L")
Chris@909 157
Chris@909 158 # Landscape A4 = 210 x 297 mm
Chris@909 159 page_height = 210
Chris@909 160 page_width = 297
Chris@909 161 right_margin = 10
Chris@909 162 bottom_margin = 20
Chris@909 163 col_id_width = 10
Chris@909 164 row_height = 5
Chris@909 165
Chris@909 166 # column widths
Chris@909 167 table_width = page_width - right_margin - 10 # fixed left margin
Chris@909 168 col_width = []
Chris@909 169 unless query.columns.empty?
Chris@909 170 col_width = query.columns.collect do |c|
Chris@909 171 (c.name == :subject || (c.is_a?(QueryCustomFieldColumn) &&
Chris@909 172 ['string', 'text'].include?(c.custom_field.field_format))) ? 4.0 : 1.0
Chris@909 173 end
Chris@909 174 ratio = (table_width - col_id_width) / col_width.inject(0) {|s,w| s += w}
Chris@909 175 col_width = col_width.collect {|w| w * ratio}
Chris@909 176 end
Chris@909 177
Chris@909 178 # title
Chris@909 179 pdf.SetFontStyle('B',11)
Chris@909 180 pdf.RDMCell(190,10, title)
Chris@909 181 pdf.Ln
Chris@909 182
Chris@909 183 # headers
Chris@909 184 pdf.SetFontStyle('B',8)
Chris@909 185 pdf.SetFillColor(230, 230, 230)
Chris@909 186
Chris@909 187 # render it background to find the max height used
Chris@909 188 base_x = pdf.GetX
Chris@909 189 base_y = pdf.GetY
Chris@909 190 max_height = issues_to_pdf_write_cells(pdf, query.columns, col_width, row_height, true)
Chris@909 191 pdf.Rect(base_x, base_y, table_width, max_height, 'FD');
Chris@909 192 pdf.SetXY(base_x, base_y);
Chris@909 193
Chris@909 194 # write the cells on page
Chris@909 195 pdf.RDMCell(col_id_width, row_height, "#", "T", 0, 'C', 1)
Chris@909 196 issues_to_pdf_write_cells(pdf, query.columns, col_width, row_height, true)
Chris@909 197 issues_to_pdf_draw_borders(pdf, base_x, base_y, base_y + max_height, col_id_width, col_width)
Chris@909 198 pdf.SetY(base_y + max_height);
Chris@909 199
Chris@909 200 # rows
Chris@909 201 pdf.SetFontStyle('',8)
Chris@909 202 pdf.SetFillColor(255, 255, 255)
Chris@909 203 previous_group = false
Chris@909 204 issue_list(issues) do |issue, level|
Chris@909 205 if query.grouped? &&
Chris@909 206 (group = query.group_by_column.value(issue)) != previous_group
Chris@909 207 pdf.SetFontStyle('B',9)
Chris@909 208 pdf.RDMCell(277, row_height,
Chris@909 209 (group.blank? ? 'None' : group.to_s) + " (#{query.issue_count_by_group[group]})",
Chris@909 210 1, 1, 'L')
Chris@909 211 pdf.SetFontStyle('',8)
Chris@909 212 previous_group = group
Chris@909 213 end
Chris@909 214 # fetch all the row values
Chris@909 215 col_values = query.columns.collect do |column|
Chris@909 216 s = if column.is_a?(QueryCustomFieldColumn)
Chris@909 217 cv = issue.custom_values.detect {|v| v.custom_field_id == column.custom_field.id}
Chris@909 218 show_value(cv)
Chris@909 219 else
Chris@909 220 value = issue.send(column.name)
Chris@909 221 if column.name == :subject
Chris@909 222 value = " " * level + value
Chris@909 223 end
Chris@909 224 if value.is_a?(Date)
Chris@909 225 format_date(value)
Chris@909 226 elsif value.is_a?(Time)
Chris@909 227 format_time(value)
Chris@909 228 else
Chris@909 229 value
Chris@909 230 end
Chris@909 231 end
Chris@909 232 s.to_s
Chris@909 233 end
Chris@909 234
Chris@909 235 # render it off-page to find the max height used
Chris@909 236 base_x = pdf.GetX
Chris@909 237 base_y = pdf.GetY
Chris@909 238 pdf.SetY(2 * page_height)
Chris@909 239 max_height = issues_to_pdf_write_cells(pdf, col_values, col_width, row_height)
Chris@909 240 pdf.SetXY(base_x, base_y)
Chris@909 241
Chris@909 242 # make new page if it doesn't fit on the current one
Chris@909 243 space_left = page_height - base_y - bottom_margin
Chris@909 244 if max_height > space_left
Chris@909 245 pdf.AddPage("L")
Chris@909 246 base_x = pdf.GetX
Chris@909 247 base_y = pdf.GetY
Chris@909 248 end
Chris@909 249
Chris@909 250 # write the cells on page
Chris@909 251 pdf.RDMCell(col_id_width, row_height, issue.id.to_s, "T", 0, 'C', 1)
Chris@909 252 issues_to_pdf_write_cells(pdf, col_values, col_width, row_height)
Chris@909 253 issues_to_pdf_draw_borders(pdf, base_x, base_y, base_y + max_height, col_id_width, col_width)
Chris@909 254 pdf.SetY(base_y + max_height);
Chris@909 255 end
Chris@909 256
Chris@909 257 if issues.size == Setting.issues_export_limit.to_i
Chris@909 258 pdf.SetFontStyle('B',10)
Chris@909 259 pdf.RDMCell(0, row_height, '...')
Chris@909 260 end
Chris@909 261 pdf.Output
Chris@909 262 end
Chris@909 263
Chris@909 264 # Renders MultiCells and returns the maximum height used
Chris@909 265 def issues_to_pdf_write_cells(pdf, col_values, col_widths,
Chris@909 266 row_height, head=false)
Chris@909 267 base_y = pdf.GetY
Chris@909 268 max_height = row_height
Chris@909 269 col_values.each_with_index do |column, i|
Chris@909 270 col_x = pdf.GetX
Chris@909 271 if head == true
Chris@909 272 pdf.RDMMultiCell(col_widths[i], row_height, column.caption, "T", 'L', 1)
Chris@909 273 else
Chris@909 274 pdf.RDMMultiCell(col_widths[i], row_height, column, "T", 'L', 1)
Chris@909 275 end
Chris@909 276 max_height = (pdf.GetY - base_y) if (pdf.GetY - base_y) > max_height
Chris@909 277 pdf.SetXY(col_x + col_widths[i], base_y);
Chris@909 278 end
Chris@909 279 return max_height
Chris@909 280 end
Chris@909 281
Chris@909 282 # Draw lines to close the row (MultiCell border drawing in not uniform)
Chris@909 283 def issues_to_pdf_draw_borders(pdf, top_x, top_y, lower_y,
Chris@909 284 id_width, col_widths)
Chris@909 285 col_x = top_x + id_width
Chris@909 286 pdf.Line(col_x, top_y, col_x, lower_y) # id right border
Chris@909 287 col_widths.each do |width|
Chris@909 288 col_x += width
Chris@909 289 pdf.Line(col_x, top_y, col_x, lower_y) # columns right border
Chris@909 290 end
Chris@909 291 pdf.Line(top_x, top_y, top_x, lower_y) # left border
Chris@909 292 pdf.Line(top_x, lower_y, col_x, lower_y) # bottom border
Chris@909 293 end
Chris@909 294
Chris@909 295 # Returns a PDF string of a single issue
Chris@909 296 def issue_to_pdf(issue)
Chris@909 297 pdf = ITCPDF.new(current_language)
Chris@909 298 pdf.SetTitle("#{issue.project} - ##{issue.tracker} #{issue.id}")
Chris@909 299 pdf.alias_nb_pages
Chris@909 300 pdf.footer_date = format_date(Date.today)
Chris@909 301 pdf.AddPage
Chris@909 302 pdf.SetFontStyle('B',11)
Chris@909 303 buf = "#{issue.project} - #{issue.tracker} # #{issue.id}"
Chris@909 304 pdf.RDMMultiCell(190, 5, buf)
Chris@909 305 pdf.Ln
Chris@909 306 pdf.SetFontStyle('',8)
Chris@909 307 base_x = pdf.GetX
Chris@909 308 i = 1
Chris@909 309 issue.ancestors.each do |ancestor|
Chris@909 310 pdf.SetX(base_x + i)
Chris@909 311 buf = "#{ancestor.tracker} # #{ancestor.id} (#{ancestor.status.to_s}): #{ancestor.subject}"
Chris@909 312 pdf.RDMMultiCell(190 - i, 5, buf)
Chris@909 313 i += 1 if i < 35
Chris@909 314 end
Chris@909 315 pdf.Ln
Chris@909 316
Chris@909 317 pdf.SetFontStyle('B',9)
Chris@909 318 pdf.RDMCell(35,5, l(:field_status) + ":","LT")
Chris@909 319 pdf.SetFontStyle('',9)
Chris@909 320 pdf.RDMCell(60,5, issue.status.to_s,"RT")
Chris@909 321 pdf.SetFontStyle('B',9)
Chris@909 322 pdf.RDMCell(35,5, l(:field_priority) + ":","LT")
Chris@909 323 pdf.SetFontStyle('',9)
Chris@909 324 pdf.RDMCell(60,5, issue.priority.to_s,"RT")
Chris@909 325 pdf.Ln
Chris@909 326
Chris@909 327 pdf.SetFontStyle('B',9)
Chris@909 328 pdf.RDMCell(35,5, l(:field_author) + ":","L")
Chris@909 329 pdf.SetFontStyle('',9)
Chris@909 330 pdf.RDMCell(60,5, issue.author.to_s,"R")
Chris@909 331 pdf.SetFontStyle('B',9)
Chris@909 332 pdf.RDMCell(35,5, l(:field_category) + ":","L")
Chris@909 333 pdf.SetFontStyle('',9)
Chris@909 334 pdf.RDMCell(60,5, issue.category.to_s,"R")
Chris@909 335 pdf.Ln
Chris@909 336
Chris@909 337 pdf.SetFontStyle('B',9)
Chris@909 338 pdf.RDMCell(35,5, l(:field_created_on) + ":","L")
Chris@909 339 pdf.SetFontStyle('',9)
Chris@909 340 pdf.RDMCell(60,5, format_date(issue.created_on),"R")
Chris@909 341 pdf.SetFontStyle('B',9)
Chris@909 342 pdf.RDMCell(35,5, l(:field_assigned_to) + ":","L")
Chris@909 343 pdf.SetFontStyle('',9)
Chris@909 344 pdf.RDMCell(60,5, issue.assigned_to.to_s,"R")
Chris@909 345 pdf.Ln
Chris@909 346
Chris@909 347 pdf.SetFontStyle('B',9)
Chris@909 348 pdf.RDMCell(35,5, l(:field_updated_on) + ":","LB")
Chris@909 349 pdf.SetFontStyle('',9)
Chris@909 350 pdf.RDMCell(60,5, format_date(issue.updated_on),"RB")
Chris@909 351 pdf.SetFontStyle('B',9)
Chris@909 352 pdf.RDMCell(35,5, l(:field_due_date) + ":","LB")
Chris@909 353 pdf.SetFontStyle('',9)
Chris@909 354 pdf.RDMCell(60,5, format_date(issue.due_date),"RB")
Chris@909 355 pdf.Ln
Chris@909 356
Chris@909 357 for custom_value in issue.custom_field_values
Chris@909 358 pdf.SetFontStyle('B',9)
Chris@909 359 pdf.RDMCell(35,5, custom_value.custom_field.name + ":","L")
Chris@909 360 pdf.SetFontStyle('',9)
Chris@909 361 pdf.RDMMultiCell(155,5, (show_value custom_value),"R")
Chris@909 362 end
Chris@909 363
Chris@909 364 y0 = pdf.GetY
Chris@909 365
Chris@909 366 pdf.SetFontStyle('B',9)
Chris@909 367 pdf.RDMCell(35,5, l(:field_subject) + ":","LT")
Chris@909 368 pdf.SetFontStyle('',9)
Chris@909 369 pdf.RDMMultiCell(155,5, issue.subject,"RT")
Chris@909 370 pdf.Line(pdf.GetX, y0, pdf.GetX, pdf.GetY)
Chris@909 371
Chris@909 372 pdf.SetFontStyle('B',9)
Chris@909 373 pdf.RDMCell(35+155, 5, l(:field_description), "LRT", 1)
Chris@909 374 pdf.SetFontStyle('',9)
Chris@909 375
Chris@909 376 # Set resize image scale
Chris@909 377 pdf.SetImageScale(1.6)
Chris@909 378 pdf.RDMwriteHTMLCell(35+155, 5, 0, 0,
Chris@909 379 issue.description.to_s, issue.attachments, "LRB")
Chris@909 380
Chris@909 381 unless issue.leaf?
Chris@909 382 # for CJK
Chris@909 383 truncate_length = ( l(:general_pdf_encoding).upcase == "UTF-8" ? 90 : 65 )
Chris@909 384
Chris@909 385 pdf.SetFontStyle('B',9)
Chris@909 386 pdf.RDMCell(35+155,5, l(:label_subtask_plural) + ":", "LTR")
Chris@909 387 pdf.Ln
Chris@909 388 issue_list(issue.descendants.sort_by(&:lft)) do |child, level|
Chris@909 389 buf = truncate("#{child.tracker} # #{child.id}: #{child.subject}",
Chris@909 390 :length => truncate_length)
Chris@909 391 level = 10 if level >= 10
Chris@909 392 pdf.SetFontStyle('',8)
Chris@909 393 pdf.RDMCell(35+135,5, (level >=1 ? " " * level : "") + buf, "L")
Chris@909 394 pdf.SetFontStyle('B',8)
Chris@909 395 pdf.RDMCell(20,5, child.status.to_s, "R")
Chris@909 396 pdf.Ln
Chris@909 397 end
Chris@909 398 end
Chris@909 399
Chris@909 400 relations = issue.relations.select { |r| r.other_issue(issue).visible? }
Chris@909 401 unless relations.empty?
Chris@909 402 # for CJK
Chris@909 403 truncate_length = ( l(:general_pdf_encoding).upcase == "UTF-8" ? 80 : 60 )
Chris@909 404
Chris@909 405 pdf.SetFontStyle('B',9)
Chris@909 406 pdf.RDMCell(35+155,5, l(:label_related_issues) + ":", "LTR")
Chris@909 407 pdf.Ln
Chris@909 408 relations.each do |relation|
Chris@909 409 buf = ""
Chris@909 410 buf += "#{l(relation.label_for(issue))} "
Chris@909 411 if relation.delay && relation.delay != 0
Chris@909 412 buf += "(#{l('datetime.distance_in_words.x_days', :count => relation.delay)}) "
Chris@909 413 end
Chris@909 414 if Setting.cross_project_issue_relations?
Chris@909 415 buf += "#{relation.other_issue(issue).project} - "
Chris@909 416 end
Chris@909 417 buf += "#{relation.other_issue(issue).tracker}" +
Chris@909 418 " # #{relation.other_issue(issue).id}: #{relation.other_issue(issue).subject}"
Chris@909 419 buf = truncate(buf, :length => truncate_length)
Chris@909 420 pdf.SetFontStyle('', 8)
Chris@909 421 pdf.RDMCell(35+155-60, 5, buf, "L")
Chris@909 422 pdf.SetFontStyle('B',8)
Chris@909 423 pdf.RDMCell(20,5, relation.other_issue(issue).status.to_s, "")
Chris@909 424 pdf.RDMCell(20,5, format_date(relation.other_issue(issue).start_date), "")
Chris@909 425 pdf.RDMCell(20,5, format_date(relation.other_issue(issue).due_date), "R")
Chris@909 426 pdf.Ln
Chris@909 427 end
Chris@909 428 end
Chris@909 429 pdf.RDMCell(190,5, "", "T")
Chris@909 430 pdf.Ln
Chris@909 431
Chris@909 432 if issue.changesets.any? &&
Chris@909 433 User.current.allowed_to?(:view_changesets, issue.project)
Chris@909 434 pdf.SetFontStyle('B',9)
Chris@909 435 pdf.RDMCell(190,5, l(:label_associated_revisions), "B")
Chris@909 436 pdf.Ln
Chris@909 437 for changeset in issue.changesets
Chris@909 438 pdf.SetFontStyle('B',8)
Chris@909 439 csstr = "#{l(:label_revision)} #{changeset.format_identifier} - "
Chris@909 440 csstr += format_time(changeset.committed_on) + " - " + changeset.author.to_s
Chris@909 441 pdf.RDMCell(190, 5, csstr)
Chris@909 442 pdf.Ln
Chris@909 443 unless changeset.comments.blank?
Chris@909 444 pdf.SetFontStyle('',8)
Chris@909 445 pdf.RDMwriteHTMLCell(190,5,0,0,
Chris@909 446 changeset.comments.to_s, issue.attachments, "")
Chris@909 447 end
Chris@909 448 pdf.Ln
Chris@909 449 end
Chris@909 450 end
Chris@909 451
Chris@909 452 pdf.SetFontStyle('B',9)
Chris@909 453 pdf.RDMCell(190,5, l(:label_history), "B")
Chris@909 454 pdf.Ln
Chris@909 455 indice = 0
Chris@909 456 for journal in issue.journals.find(
Chris@909 457 :all, :include => [:user, :details],
Chris@909 458 :order => "#{Journal.table_name}.created_on ASC")
Chris@909 459 indice = indice + 1
Chris@909 460 pdf.SetFontStyle('B',8)
Chris@909 461 pdf.RDMCell(190,5,
Chris@909 462 "#" + indice.to_s +
Chris@909 463 " - " + format_time(journal.created_on) +
Chris@909 464 " - " + journal.user.name)
Chris@909 465 pdf.Ln
Chris@909 466 pdf.SetFontStyle('I',8)
Chris@909 467 for detail in journal.details
Chris@909 468 pdf.RDMMultiCell(190,5, "- " + show_detail(detail, true))
Chris@909 469 end
Chris@909 470 if journal.notes?
Chris@909 471 pdf.Ln unless journal.details.empty?
Chris@909 472 pdf.SetFontStyle('',8)
Chris@909 473 pdf.RDMwriteHTMLCell(190,5,0,0,
Chris@909 474 journal.notes.to_s, issue.attachments, "")
Chris@909 475 end
Chris@909 476 pdf.Ln
Chris@909 477 end
Chris@909 478
Chris@909 479 if issue.attachments.any?
Chris@909 480 pdf.SetFontStyle('B',9)
Chris@909 481 pdf.RDMCell(190,5, l(:label_attachment_plural), "B")
Chris@909 482 pdf.Ln
Chris@909 483 for attachment in issue.attachments
Chris@909 484 pdf.SetFontStyle('',8)
Chris@909 485 pdf.RDMCell(80,5, attachment.filename)
Chris@909 486 pdf.RDMCell(20,5, number_to_human_size(attachment.filesize),0,0,"R")
Chris@909 487 pdf.RDMCell(25,5, format_date(attachment.created_on),0,0,"R")
Chris@909 488 pdf.RDMCell(65,5, attachment.author.name,0,0,"R")
Chris@909 489 pdf.Ln
Chris@909 490 end
Chris@909 491 end
Chris@909 492 pdf.Output
Chris@909 493 end
Chris@909 494
Chris@909 495 # Returns a PDF string of a single wiki page
Chris@909 496 def wiki_to_pdf(page, project)
Chris@909 497 pdf = ITCPDF.new(current_language)
Chris@909 498 pdf.SetTitle("#{project} - #{page.title}")
Chris@909 499 pdf.alias_nb_pages
Chris@909 500 pdf.footer_date = format_date(Date.today)
Chris@909 501 pdf.AddPage
Chris@909 502 pdf.SetFontStyle('B',11)
Chris@909 503 pdf.RDMMultiCell(190,5,
Chris@909 504 "#{project} - #{page.title} - # #{page.content.version}")
Chris@909 505 pdf.Ln
Chris@909 506 # Set resize image scale
Chris@909 507 pdf.SetImageScale(1.6)
Chris@909 508 pdf.SetFontStyle('',9)
Chris@909 509 pdf.RDMwriteHTMLCell(190,5,0,0,
Chris@909 510 page.content.text.to_s, page.attachments, "TLRB")
Chris@909 511 if page.attachments.any?
Chris@909 512 pdf.Ln
Chris@909 513 pdf.SetFontStyle('B',9)
Chris@909 514 pdf.RDMCell(190,5, l(:label_attachment_plural), "B")
Chris@909 515 pdf.Ln
Chris@909 516 for attachment in page.attachments
Chris@909 517 pdf.SetFontStyle('',8)
Chris@909 518 pdf.RDMCell(80,5, attachment.filename)
Chris@909 519 pdf.RDMCell(20,5, number_to_human_size(attachment.filesize),0,0,"R")
Chris@909 520 pdf.RDMCell(25,5, format_date(attachment.created_on),0,0,"R")
Chris@909 521 pdf.RDMCell(65,5, attachment.author.name,0,0,"R")
Chris@909 522 pdf.Ln
Chris@909 523 end
Chris@909 524 end
Chris@909 525 pdf.Output
Chris@909 526 end
Chris@909 527
Chris@909 528 class RDMPdfEncoding
Chris@909 529 def self.rdm_from_utf8(txt, encoding)
Chris@909 530 txt ||= ''
Chris@909 531 txt = Redmine::CodesetUtil.from_utf8(txt, encoding)
Chris@909 532 if txt.respond_to?(:force_encoding)
Chris@909 533 txt.force_encoding('ASCII-8BIT')
Chris@909 534 end
Chris@909 535 txt
Chris@909 536 end
Chris@909 537
Chris@909 538 def self.attach(attachments, filename, encoding)
Chris@909 539 filename_utf8 = Redmine::CodesetUtil.to_utf8(filename, encoding)
Chris@909 540 atta = nil
Chris@909 541 if filename_utf8 =~ /^[^\/"]+\.(gif|jpg|jpe|jpeg|png)$/i
Chris@909 542 atta = Attachment.latest_attach(attachments, filename_utf8)
Chris@909 543 end
Chris@909 544 if atta && atta.readable? && atta.visible?
Chris@909 545 return atta
Chris@909 546 else
Chris@909 547 return nil
Chris@909 548 end
Chris@909 549 end
Chris@909 550 end
Chris@909 551 end
Chris@909 552 end
Chris@909 553 end