Project

General

Profile

Defect #61 » prawn.patch

Heejong Lee, 2008-11-27 10:53

View differences:

app/helpers/pdf_helper.rb (wersja 0)
1
# redMine - project management software
2
# Copyright (C) 2006  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
# 
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
# 
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

  
18
module PdfHelper  
19
  def PdfHelper.font_for_lang(lang)
20
      case lang.to_s
21
      when 'ko'
22
        return "#{Prawn::BASEDIR}/data/fonts/UnBatang.ttf"
23
      when 'ja'
24
        return "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
25
      when 'zh'
26
        return "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
27
      when 'zh-tw'
28
        return "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
29
      else
30
        return "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
31
      end
32
  end
33
end
app/controllers/issues_controller.rb (kopia robocza)
67 67
        format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? }
68 68
        format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
69 69
        format.csv  { send_data(issues_to_csv(@issues, @project).read, :type => 'text/csv; header=present', :filename => 'export.csv') }
70
        format.pdf  { send_data(render(:template => 'issues/index.rfpdf', :layout => false), :type => 'application/pdf', :filename => 'export.pdf') }
70
        format.pdf  { send_data(render(:template => 'issues/index.pdf.prawn', :layout => false), :type => 'application/pdf', :filename => 'export.pdf') }
71 71
      end
72 72
    else
73 73
      # Send html if the query is not valid
app/views/issues/index.pdf.prawn (wersja 0)
1
Prawn::Document.new(:page_layout => :landscape) do |pdf|
2
pdf.font(PdfHelper.font_for_lang(current_language))
3
title = @project ? "#{@project.name} - #{l(:label_issue_plural)}" : "#{l(:label_issue_plural)}"
4

  
5
pdf.header pdf.margin_box.top_left do
6
   pdf.text title , :size => 12, :align => :left
7
   pdf.stroke_horizontal_rule
8
end
9

  
10
pdf.footer [pdf.margin_box.left, pdf.margin_box.bottom + 20] do
11
    pdf.stroke_horizontal_rule
12
    pdf.text format_date(Date.today), :size => 12
13
end
14

  
15
pdf.move_down 25
16

  
17
#rows
18
	rows=[]
19
        i=0
20
	@issues.each do |issue|		
21
	   	rows[i] = [issue.id.to_s, issue.tracker.name, issue.status.name,
22
                          issue.priority.name, issue.assigned_to ? issue.assigned_to.name : '',
23
                          format_date(issue.updated_on),
24
                          @project == issue.project ? issue.subject : "#{issue.project.name} - #{issue.subject}"]
25
	i=i+1
26
        end
27

  
28

  
29
pdf.table rows,     
30
    :font_size  => 11, 
31
    :horizontal_padding => 10,
32
    :vertical_padding   => 3,
33
    :border_width       => 1,
34
    :position           => :left,
35
    :headers            => ["#", l(:field_tracker), l(:field_status), l(:field_priority), l(:field_assigned_to), l(:field_updated_on), l(:field_subject)],
36
    :align              => {0 => :center},
37
    :align_headers      => :left,
38
    :widths             => {6 => 250},
39
    :row_colors         => ["ffffff","cccccc"]
40
                            
41
end
(11-11/46)