@@ -87,6 +87,9 module Redmine | |||||
87 |
|
87 | |||
88 | def initialize(lang) |
|
88 | def initialize(lang) | |
89 | super() |
|
89 | super() | |
|
90 | if RUBY_VERSION < '1.9' | |||
|
91 | @ic = Iconv.new(l(:general_pdf_encoding), 'UTF-8') | |||
|
92 | end | |||
90 | set_language_if_valid lang |
|
93 | set_language_if_valid lang | |
91 | case l(:general_pdf_encoding).upcase |
|
94 | case l(:general_pdf_encoding).upcase | |
92 | when 'CP949' |
|
95 | when 'CP949' | |
@@ -143,27 +146,7 module Redmine | |||||
143 | end |
|
146 | end | |
144 |
|
147 | |||
145 | def fix_text_encoding(txt) |
|
148 | def fix_text_encoding(txt) | |
146 | txt ||= '' |
|
149 | RDMPdfEncoding::rdm_pdf_iconv(@ic, txt) | |
147 | if txt.respond_to?(:force_encoding) |
|
|||
148 | txt.force_encoding('UTF-8') |
|
|||
149 | txt = txt.encode(l(:general_pdf_encoding), :invalid => :replace, |
|
|||
150 | :undef => :replace, :replace => '?') |
|
|||
151 | txt.force_encoding('ASCII-8BIT') |
|
|||
152 | else |
|
|||
153 | @ic ||= Iconv.new(l(:general_pdf_encoding), 'UTF-8') |
|
|||
154 | txtar = "" |
|
|||
155 | begin |
|
|||
156 | txtar += @ic.iconv(txt) |
|
|||
157 | rescue Iconv::IllegalSequence |
|
|||
158 | txtar += $!.success |
|
|||
159 | txt = '?' + $!.failed[1,$!.failed.length] |
|
|||
160 | retry |
|
|||
161 | rescue |
|
|||
162 | txtar += $!.success |
|
|||
163 | end |
|
|||
164 | txt = txtar |
|
|||
165 | end |
|
|||
166 | txt |
|
|||
167 | end |
|
150 | end | |
168 |
|
151 | |||
169 | def RDMCell(w,h=0,txt='',border=0,ln=0,align='',fill=0,link='') |
|
152 | def RDMCell(w,h=0,txt='',border=0,ln=0,align='',fill=0,link='') | |
@@ -465,6 +448,33 module Redmine | |||||
465 | end |
|
448 | end | |
466 | pdf.Output |
|
449 | pdf.Output | |
467 | end |
|
450 | end | |
|
451 | ||||
|
452 | class RDMPdfEncoding | |||
|
453 | include Redmine::I18n | |||
|
454 | def self.rdm_pdf_iconv(ic, txt) | |||
|
455 | txt ||= '' | |||
|
456 | if txt.respond_to?(:force_encoding) | |||
|
457 | txt.force_encoding('UTF-8') | |||
|
458 | txt = txt.encode(l(:general_pdf_encoding), :invalid => :replace, | |||
|
459 | :undef => :replace, :replace => '?') | |||
|
460 | txt.force_encoding('ASCII-8BIT') | |||
|
461 | else | |||
|
462 | ic ||= Iconv.new(l(:general_pdf_encoding), 'UTF-8') | |||
|
463 | txtar = "" | |||
|
464 | begin | |||
|
465 | txtar += ic.iconv(txt) | |||
|
466 | rescue Iconv::IllegalSequence | |||
|
467 | txtar += $!.success | |||
|
468 | txt = '?' + $!.failed[1,$!.failed.length] | |||
|
469 | retry | |||
|
470 | rescue | |||
|
471 | txtar += $!.success | |||
|
472 | end | |||
|
473 | txt = txtar | |||
|
474 | end | |||
|
475 | txt | |||
|
476 | end | |||
|
477 | end | |||
468 | end |
|
478 | end | |
469 | end |
|
479 | end | |
470 | end |
|
480 | end |
General Comments 0
You need to be logged in to leave comments.
Login now