pdf-image-r7810.diff

Toshi MARUYAMA, 2011-11-15 01:53

Download (6.66 KB)

View differences:

lib/redmine/export/pdf.rb
115 115
          MultiCell(w, h, fix_text_encoding(txt), border, align, fill, ln)
116 116
        end
117 117

  
118
        def RDMwriteHTMLCell(w, h, x, y, html='', border=0, ln=1, fill=0)
119
          writeHTMLCell(w, h, x, y, fix_text_encoding(html), border, ln, fill)
118
        def RDMwriteHTMLCell(w, h, x, y, txt='', attachments=[], border=0, ln=1, fill=0)
119
          writeHTMLCell(w, h, x, y,
120
            fix_text_encoding(
121
              Redmine::WikiFormatting.to_html(Setting.text_formatting, txt)),
122
              border, ln, fill)
120 123
        end
121 124

  
122 125
        def Footer
......
358 361
        pdf.RDMCell(35+155, 5, l(:field_description), "LRT", 1)
359 362
        pdf.SetFontStyle('',9)
360 363
        pdf.RDMwriteHTMLCell(35+155, 5, 0, 0,
361
            Redmine::WikiFormatting.to_html(
362
              Setting.text_formatting, issue.description.to_s),"LRB")
364
              issue.description.to_s, issue.attachments, "LRB")
363 365

  
364 366
        # for CJK
365 367
        truncate_length = ( l(:general_pdf_encoding).upcase == "UTF-8" ? 90 : 65 )
......
421 423
            unless changeset.comments.blank?
422 424
              pdf.SetFontStyle('',8)
423 425
              pdf.RDMwriteHTMLCell(190,5,0,0,
424
                   Redmine::WikiFormatting.to_html(
425
                     Setting.text_formatting, changeset.comments.to_s), "")
426
                    changeset.comments.to_s, issue.attachments, "")
426 427
            end
427 428
            pdf.Ln
428 429
          end
......
446 447
            pdf.Ln unless journal.details.empty?
447 448
            pdf.SetFontStyle('',8)
448 449
            pdf.RDMwriteHTMLCell(190,5,0,0,
449
                  Redmine::WikiFormatting.to_html(
450
                    Setting.text_formatting, journal.notes.to_s), "")
450
                  journal.notes.to_s, issue.attachments, "")
451 451
          end
452 452
          pdf.Ln
453 453
        end
......
483 483
        pdf.SetImageScale(1.6)
484 484
        pdf.SetFontStyle('',9)
485 485
        pdf.RDMwriteHTMLCell(190,5,0,0,
486
              Redmine::WikiFormatting.to_html(
487
                Setting.text_formatting, page.content.text.to_s), "TLRB")
486
              page.content.text.to_s, page.attachments, "TLRB")
488 487
        if page.attachments.any?
489 488
          pdf.Ln
490 489
          pdf.SetFontStyle('B',9)
lib/redmine/export/pdf.rb
21 21
require 'fpdf/chinese'
22 22
require 'fpdf/japanese'
23 23
require 'fpdf/korean'
24
require 'core/rmagick'
24 25

  
25 26
module Redmine
26 27
  module Export
......
34 35
        attr_accessor :footer_date
35 36

  
36 37
        def initialize(lang)
38
          @@k_path_cache = Rails.root.join('tmp', 'pdf')
39
          FileUtils.mkdir_p @@k_path_cache unless File::exist?(@@k_path_cache)
37 40
          set_language_if_valid lang
38 41
          pdf_encoding = l(:general_pdf_encoding).upcase
39 42
          if RUBY_VERSION < '1.9'
lib/redmine/export/pdf.rb
119 119
        end
120 120

  
121 121
        def RDMwriteHTMLCell(w, h, x, y, txt='', attachments=[], border=0, ln=1, fill=0)
122
          @attachments = attachments.sort_by(&:created_on).reverse
122 123
          writeHTMLCell(w, h, x, y,
123 124
            fix_text_encoding(
124 125
              Redmine::WikiFormatting.to_html(Setting.text_formatting, txt)),
125 126
              border, ln, fill)
126 127
        end
127 128

  
129
        def getImageFilename(attrname)
130
          # attrname: general_pdf_encoding string file/uri name
131
          attrname_utf8 = Redmine::CodesetUtil.to_utf8(attrname, l(:general_pdf_encoding))
132
          if attrname_utf8 =~ /^[^\/"]+\.(gif|jpg|jpeg|png)$/i
133
            @attachments.each do |attachment|
134
              # attachment.filename  : UTF-8 string name
135
              # attachment.diskfile  : real server path file name
136
                #
137
              # Japanese Shift_JIS and Traditional Chinese Big5
138
              # are not compatible with ASCII.
139
              # So, downcase needs for UTF-8.
140
              if attachment.filename.downcase == attrname_utf8.downcase
141
                if attachment.readable? && attachment.visible?
142
                  return attachment.diskfile
143
                else
144
                  return nil
145
                end
146
              end
147
            end
148
          end
149
          nil
150
        end
151

  
128 152
        def Footer
129 153
          SetFont(@font_for_footer, 'I', 8)
130 154
          SetY(-15)
lib/redmine/export/pdf.rb
387 387
        pdf.SetFontStyle('B',9)
388 388
        pdf.RDMCell(35+155, 5, l(:field_description), "LRT", 1)
389 389
        pdf.SetFontStyle('',9)
390

  
391
        # Set resize image scale
392
        pdf.SetImageScale(1.6)
390 393
        pdf.RDMwriteHTMLCell(35+155, 5, 0, 0,
391 394
              issue.description.to_s, issue.attachments, "LRB")
392 395

  
lib/redmine/export/pdf.rb
145 145
                end
146 146
              end
147 147
            end
148
            return nil
149
          else
150
            # check of unsafe URI
151
            if attrname_utf8 =~ /[^-_.!~*'()a-zA-Z\d;\/?:@&=+$,\[\]%]/n
152
              return URI.encode(attrname_utf8)
153
            else
154
              return attrname_utf8
155
            end
148 156
          end
149
          nil
150 157
        end
151 158

  
152 159
        def Footer