##// END OF EJS Templates
Don't use Iconv with ruby1.9 (#12787)....
Jean-Philippe Lang -
r10947:ff53a9cfe18d
parent child
Show More
@@ -1,4 +1,6
1 require 'iconv'
1 if RUBY_VERSION < '1.9'
2 require 'iconv'
3 end
2 4
3 5 module Redmine
4 6 module CodesetUtil
@@ -100,10 +102,17 module Redmine
100 102 end
101 103 encodings = Setting.repositories_encodings.split(',').collect(&:strip)
102 104 encodings.each do |encoding|
103 begin
104 return Iconv.conv('UTF-8', encoding, str)
105 rescue Iconv::Failure
106 # do nothing here and try the next encoding
105 if str.respond_to?(:force_encoding)
106 str.force_encoding(encoding)
107 if str.valid_encoding?
108 return str.encode('UTF-8')
109 end
110 else
111 begin
112 return Iconv.conv('UTF-8', encoding, str)
113 rescue Iconv::Failure
114 # do nothing here and try the next encoding
115 end
107 116 end
108 117 end
109 118 str = self.replace_invalid_utf8(str)
@@ -17,12 +17,15
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 require 'iconv'
21 20 require 'tcpdf'
22 21 require 'fpdf/chinese'
23 22 require 'fpdf/japanese'
24 23 require 'fpdf/korean'
25 24
25 if RUBY_VERSION < '1.9'
26 require 'iconv'
27 end
28
26 29 module Redmine
27 30 module Export
28 31 module PDF
@@ -86,7 +89,7 module Redmine
86 89
87 90 def SetTitle(txt)
88 91 txt = begin
89 utf16txt = Iconv.conv('UTF-16BE', 'UTF-8', txt)
92 utf16txt = to_utf16(txt)
90 93 hextxt = "<FEFF" # FEFF is BOM
91 94 hextxt << utf16txt.unpack("C*").map {|x| sprintf("%02X",x) }.join
92 95 hextxt << ">"
@@ -109,6 +112,15 module Redmine
109 112 RDMPdfEncoding::rdm_from_utf8(txt, l(:general_pdf_encoding))
110 113 end
111 114
115 # Encodes an UTF-8 string to UTF-16BE
116 def to_utf16(str)
117 if str.respond_to?(:encode)
118 str.encode('UTF-16BE')
119 else
120 Iconv.conv('UTF-16BE', 'UTF-8', str)
121 end
122 end
123
112 124 def RDMCell(w ,h=0, txt='', border=0, ln=0, align='', fill=0, link='')
113 125 Cell(w, h, fix_text_encoding(txt), border, ln, align, fill, link)
114 126 end
@@ -154,7 +166,7 module Redmine
154 166
155 167 def bookmark_title(txt)
156 168 txt = begin
157 utf16txt = Iconv.conv('UTF-16BE', 'UTF-8', txt)
169 utf16txt = to_utf16(txt)
158 170 hextxt = "<FEFF" # FEFF is BOM
159 171 hextxt << utf16txt.unpack("C*").map {|x| sprintf("%02X",x) }.join
160 172 hextxt << ">"
@@ -17,6 +17,10
17 17
18 18 require 'cgi'
19 19
20 if RUBY_VERSION < '1.9'
21 require 'iconv'
22 end
23
20 24 module Redmine
21 25 module Scm
22 26 module Adapters
@@ -16,7 +16,6
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 require 'iconv'
20 19
21 20 class PdfTest < ActiveSupport::TestCase
22 21 fixtures :users, :projects, :roles, :members, :member_roles,
General Comments 0
You need to be logged in to leave comments. Login now