Project

General

Profile

Defect #6505 » pdf.rb_utf8.patch

Jun NAITOH, 2011-03-22 22:24

View differences:

lib/redmine/export/pdf.rb 2011-03-07 14:44:40.000000000 -0500 → lib/redmine/export/pdf.rb 2011-03-20 15:23:09.000000000 -0400
88 88
          end
89 89
        end
90 90
          
91
        def Cell(w,h=0,txt='',border=0,ln=0,align='',fill=0,link='')
91
        def fix_text_encoding(txt)
92 92
          @ic ||= Iconv.new(l(:general_pdf_encoding), 'UTF-8')
93 93
          # these quotation marks are not correctly rendered in the pdf
94 94
          txt = txt.gsub(/[“�]/, '"') if txt
......
100 100
          rescue
101 101
            txt
102 102
          end || ''
103
          super w,h,txt,border,ln,align,fill,link
103
          return txt
104 104
        end
105 105
        
106
        def UTF8Cell(w,h=0,txt='',border=0,ln=0,align='',fill=0,link='')
107
          Cell(w,h,fix_text_encoding(txt),border,ln,align,fill,link)
108
        end
109

  
110
        def UTF8MultiCell(w,h=0,txt='',border=0,align='',fill=0)
111
          MultiCell(w,h,fix_text_encoding(txt),border,align,fill)
112
        end
113

  
106 114
        def Footer
107 115
          SetFont(@font_for_footer, 'I', 8)
108 116
          SetY(-15)
109 117
          SetX(15)
110
          Cell(0, 5, @footer_date, 0, 0, 'L')
118
          UTF8Cell(0, 5, @footer_date, 0, 0, 'L')
111 119
          SetY(-15)
112 120
          SetX(-30)
113
          Cell(0, 5, PageNo().to_s + '/{nb}', 0, 0, 'C')
121
          UTF8Cell(0, 5, PageNo().to_s + '/{nb}', 0, 0, 'C')
114 122
        end
115 123
      end
116 124
      
......
134 142
        
135 143
        # title
136 144
        pdf.SetFontStyle('B',11)    
137
        pdf.Cell(190,10, title)
145
        pdf.UTF8Cell(190,10, title)
138 146
        pdf.Ln
139 147
        
140 148
        # headers
141 149
        pdf.SetFontStyle('B',8)
142 150
        pdf.SetFillColor(230, 230, 230)
143
        pdf.Cell(15, row_height, "#", 1, 0, 'L', 1)
151
        pdf.UTF8Cell(15, row_height, "#", 1, 0, 'L', 1)
144 152
        query.columns.each_with_index do |column, i|
145
          pdf.Cell(col_width[i], row_height, column.caption, 1, 0, 'L', 1)
153
          pdf.UTF8Cell(col_width[i], row_height, column.caption, 1, 0, 'L', 1)
146 154
        end
147 155
        pdf.Ln
148 156
        
......
153 161
        issues.each do |issue|
154 162
          if query.grouped? && (group = query.group_by_column.value(issue)) != previous_group
155 163
            pdf.SetFontStyle('B',9)
156
            pdf.Cell(277, row_height, 
164
            pdf.UTF8Cell(277, row_height, 
157 165
              (group.blank? ? 'None' : group.to_s) + " (#{query.issue_count_by_group[group]})",
158 166
              1, 1, 'L')
159 167
            pdf.SetFontStyle('',8)
160 168
            previous_group = group
161 169
          end
162
          pdf.Cell(15, row_height, issue.id.to_s, 1, 0, 'L', 1)
170
          pdf.UTF8Cell(15, row_height, issue.id.to_s, 1, 0, 'L', 1)
163 171
          query.columns.each_with_index do |column, i|
164 172
            s = if column.is_a?(QueryCustomFieldColumn)
165 173
              cv = issue.custom_values.detect {|v| v.custom_field_id == column.custom_field.id}
......
174 182
                value
175 183
              end
176 184
            end
177
            pdf.Cell(col_width[i], row_height, s.to_s, 1, 0, 'L', 1)
185
            pdf.UTF8Cell(col_width[i], row_height, s.to_s, 1, 0, 'L', 1)
178 186
          end
179 187
          pdf.Ln
180 188
        end
181 189
        if issues.size == Setting.issues_export_limit.to_i
182 190
          pdf.SetFontStyle('B',10)
183
          pdf.Cell(0, row_height, '...')
191
          pdf.UTF8Cell(0, row_height, '...')
184 192
        end
185 193
        pdf.Output
186 194
      end
......
194 202
        pdf.AddPage
195 203
        
196 204
        pdf.SetFontStyle('B',11)    
197
        pdf.Cell(190,10, "#{issue.project} - #{issue.tracker} # #{issue.id}: #{issue.subject}")
205
        pdf.UTF8Cell(190,10, "#{issue.project} - #{issue.tracker} # #{issue.id}: #{issue.subject}")
198 206
        pdf.Ln
199 207
        
200 208
        y0 = pdf.GetY
201 209
        
202 210
        pdf.SetFontStyle('B',9)
203
        pdf.Cell(35,5, l(:field_status) + ":","LT")
211
        pdf.UTF8Cell(35,5, l(:field_status) + ":","LT")
204 212
        pdf.SetFontStyle('',9)
205
        pdf.Cell(60,5, issue.status.to_s,"RT")
213
        pdf.UTF8Cell(60,5, issue.status.to_s,"RT")
206 214
        pdf.SetFontStyle('B',9)
207
        pdf.Cell(35,5, l(:field_priority) + ":","LT")
215
        pdf.UTF8Cell(35,5, l(:field_priority) + ":","LT")
208 216
        pdf.SetFontStyle('',9)
209
        pdf.Cell(60,5, issue.priority.to_s,"RT")        
217
        pdf.UTF8Cell(60,5, issue.priority.to_s,"RT")        
210 218
        pdf.Ln
211 219
        
212 220
        pdf.SetFontStyle('B',9)
213
        pdf.Cell(35,5, l(:field_author) + ":","L")
221
        pdf.UTF8Cell(35,5, l(:field_author) + ":","L")
214 222
        pdf.SetFontStyle('',9)
215
        pdf.Cell(60,5, issue.author.to_s,"R")
223
        pdf.UTF8Cell(60,5, issue.author.to_s,"R")
216 224
        pdf.SetFontStyle('B',9)
217
        pdf.Cell(35,5, l(:field_category) + ":","L")
225
        pdf.UTF8Cell(35,5, l(:field_category) + ":","L")
218 226
        pdf.SetFontStyle('',9)
219
        pdf.Cell(60,5, issue.category.to_s,"R")
227
        pdf.UTF8Cell(60,5, issue.category.to_s,"R")
220 228
        pdf.Ln   
221 229
        
222 230
        pdf.SetFontStyle('B',9)
223
        pdf.Cell(35,5, l(:field_created_on) + ":","L")
231
        pdf.UTF8Cell(35,5, l(:field_created_on) + ":","L")
224 232
        pdf.SetFontStyle('',9)
225
        pdf.Cell(60,5, format_date(issue.created_on),"R")
233
        pdf.UTF8Cell(60,5, format_date(issue.created_on),"R")
226 234
        pdf.SetFontStyle('B',9)
227
        pdf.Cell(35,5, l(:field_assigned_to) + ":","L")
235
        pdf.UTF8Cell(35,5, l(:field_assigned_to) + ":","L")
228 236
        pdf.SetFontStyle('',9)
229
        pdf.Cell(60,5, issue.assigned_to.to_s,"R")
237
        pdf.UTF8Cell(60,5, issue.assigned_to.to_s,"R")
230 238
        pdf.Ln
231 239
        
232 240
        pdf.SetFontStyle('B',9)
233
        pdf.Cell(35,5, l(:field_updated_on) + ":","LB")
241
        pdf.UTF8Cell(35,5, l(:field_updated_on) + ":","LB")
234 242
        pdf.SetFontStyle('',9)
235
        pdf.Cell(60,5, format_date(issue.updated_on),"RB")
243
        pdf.UTF8Cell(60,5, format_date(issue.updated_on),"RB")
236 244
        pdf.SetFontStyle('B',9)
237
        pdf.Cell(35,5, l(:field_due_date) + ":","LB")
245
        pdf.UTF8Cell(35,5, l(:field_due_date) + ":","LB")
238 246
        pdf.SetFontStyle('',9)
239
        pdf.Cell(60,5, format_date(issue.due_date),"RB")
247
        pdf.UTF8Cell(60,5, format_date(issue.due_date),"RB")
240 248
        pdf.Ln
241 249
        
242 250
        for custom_value in issue.custom_field_values
243 251
          pdf.SetFontStyle('B',9)
244
          pdf.Cell(35,5, custom_value.custom_field.name + ":","L")
252
          pdf.UTF8Cell(35,5, custom_value.custom_field.name + ":","L")
245 253
          pdf.SetFontStyle('',9)
246
          pdf.MultiCell(155,5, (show_value custom_value),"R")
254
          pdf.UTF8MultiCell(155,5, (show_value custom_value),"R")
247 255
        end
248 256
        
249 257
        pdf.SetFontStyle('B',9)
250
        pdf.Cell(35,5, l(:field_subject) + ":","LTB")
258
        pdf.UTF8Cell(35,5, l(:field_subject) + ":","LTB")
251 259
        pdf.SetFontStyle('',9)
252
        pdf.Cell(155,5, issue.subject,"RTB")
260
        pdf.UTF8Cell(155,5, issue.subject,"RTB")
253 261
        pdf.Ln    
254 262
        
255 263
        pdf.SetFontStyle('B',9)
256
        pdf.Cell(35,5, l(:field_description) + ":")
264
        pdf.UTF8Cell(35,5, l(:field_description) + ":")
257 265
        pdf.SetFontStyle('',9)
258
        pdf.MultiCell(155,5, issue.description.to_s,"BR")
266
        pdf.UTF8MultiCell(155,5, issue.description.to_s,"BR")
259 267
        
260 268
        pdf.Line(pdf.GetX, y0, pdf.GetX, pdf.GetY)
261 269
        pdf.Line(pdf.GetX, pdf.GetY, 170, pdf.GetY)
......
263 271
        
264 272
        if issue.changesets.any? && User.current.allowed_to?(:view_changesets, issue.project)
265 273
          pdf.SetFontStyle('B',9)
266
          pdf.Cell(190,5, l(:label_associated_revisions), "B")
274
          pdf.UTF8Cell(190,5, l(:label_associated_revisions), "B")
267 275
          pdf.Ln
268 276
          for changeset in issue.changesets
269 277
            pdf.SetFontStyle('B',8)
270
            pdf.Cell(190,5, format_time(changeset.committed_on) + " - " + changeset.author.to_s)
278
            pdf.UTF8Cell(190,5, format_time(changeset.committed_on) + " - " + changeset.author.to_s)
271 279
            pdf.Ln
272 280
            unless changeset.comments.blank?
273 281
              pdf.SetFontStyle('',8)
274
              pdf.MultiCell(190,5, changeset.comments.to_s)
282
              pdf.UTF8MultiCell(190,5, changeset.comments.to_s)
275 283
            end   
276 284
            pdf.Ln
277 285
          end
278 286
        end
279 287
        
280 288
        pdf.SetFontStyle('B',9)
281
        pdf.Cell(190,5, l(:label_history), "B")
289
        pdf.UTF8Cell(190,5, l(:label_history), "B")
282 290
        pdf.Ln  
283 291
        for journal in issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
284 292
          pdf.SetFontStyle('B',8)
285
          pdf.Cell(190,5, format_time(journal.created_on) + " - " + journal.user.name)
293
          pdf.UTF8Cell(190,5, format_time(journal.created_on) + " - " + journal.user.name)
286 294
          pdf.Ln
287 295
          pdf.SetFontStyle('I',8)
288 296
          for detail in journal.details
289
            pdf.Cell(190,5, "- " + show_detail(detail, true))
297
            pdf.UTF8Cell(190,5, "- " + show_detail(detail, true))
290 298
            pdf.Ln
291 299
          end
292 300
          if journal.notes?
293 301
            pdf.SetFontStyle('',8)
294
            pdf.MultiCell(190,5, journal.notes.to_s)
302
            pdf.UTF8MultiCell(190,5, journal.notes.to_s)
295 303
          end   
296 304
          pdf.Ln
297 305
        end
298 306
        
299 307
        if issue.attachments.any?
300 308
          pdf.SetFontStyle('B',9)
301
          pdf.Cell(190,5, l(:label_attachment_plural), "B")
309
          pdf.UTF8Cell(190,5, l(:label_attachment_plural), "B")
302 310
          pdf.Ln
303 311
          for attachment in issue.attachments
304 312
            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")
313
            pdf.UTF8Cell(80,5, attachment.filename)
314
            pdf.UTF8Cell(20,5, number_to_human_size(attachment.filesize),0,0,"R")
315
            pdf.UTF8Cell(25,5, format_date(attachment.created_on),0,0,"R")
316
            pdf.UTF8Cell(65,5, attachment.author.name,0,0,"R")
309 317
            pdf.Ln
310 318
          end
311 319
        end
(5-5/9)