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