diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2013-01-12 21:27:36 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2013-01-12 21:27:36 +0000 |
commit | ff53a9cfe18d006c4bcc7b82755f81821c0b6476 (patch) | |
tree | 49faaaa11300924c4f0e2554c59d4605854b30c4 /lib/redmine/export | |
parent | e224d50408283f18c2703afbd73446efd73bf5b2 (diff) | |
download | redmine-ff53a9cfe18d006c4bcc7b82755f81821c0b6476.tar.gz redmine-ff53a9cfe18d006c4bcc7b82755f81821c0b6476.zip |
Don't use Iconv with ruby1.9 (#12787).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11177 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/redmine/export')
-rw-r--r-- | lib/redmine/export/pdf.rb | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/redmine/export/pdf.rb b/lib/redmine/export/pdf.rb index e650964eb..ff3993f72 100644 --- a/lib/redmine/export/pdf.rb +++ b/lib/redmine/export/pdf.rb @@ -17,12 +17,15 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require 'iconv' require 'tcpdf' require 'fpdf/chinese' require 'fpdf/japanese' require 'fpdf/korean' +if RUBY_VERSION < '1.9' + require 'iconv' +end + module Redmine module Export module PDF @@ -86,7 +89,7 @@ module Redmine def SetTitle(txt) txt = begin - utf16txt = Iconv.conv('UTF-16BE', 'UTF-8', txt) + utf16txt = to_utf16(txt) hextxt = "<FEFF" # FEFF is BOM hextxt << utf16txt.unpack("C*").map {|x| sprintf("%02X",x) }.join hextxt << ">" @@ -109,6 +112,15 @@ module Redmine RDMPdfEncoding::rdm_from_utf8(txt, l(:general_pdf_encoding)) end + # Encodes an UTF-8 string to UTF-16BE + def to_utf16(str) + if str.respond_to?(:encode) + str.encode('UTF-16BE') + else + Iconv.conv('UTF-16BE', 'UTF-8', str) + end + end + def RDMCell(w ,h=0, txt='', border=0, ln=0, align='', fill=0, link='') Cell(w, h, fix_text_encoding(txt), border, ln, align, fill, link) end @@ -154,7 +166,7 @@ module Redmine def bookmark_title(txt) txt = begin - utf16txt = Iconv.conv('UTF-16BE', 'UTF-8', txt) + utf16txt = to_utf16(txt) hextxt = "<FEFF" # FEFF is BOM hextxt << utf16txt.unpack("C*").map {|x| sprintf("%02X",x) }.join hextxt << ">" |