From 44ed963a467b070f591a8f74d6a7dcf58fd92256 Mon Sep 17 00:00:00 2001 From: Toshi MARUYAMA Date: Thu, 9 Jun 2011 05:29:23 +0000 Subject: [PATCH] Merged r6024 from trunk. PDF: replace all non ASCII characters to '?' if Iconv error raise in JRuby. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.2-stable@6027 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/redmine/export/pdf.rb | 7 +++++++ test/unit/lib/redmine/export/pdf_test.rb | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/lib/redmine/export/pdf.rb b/lib/redmine/export/pdf.rb index 3203c19a8..97176a7f9 100644 --- a/lib/redmine/export/pdf.rb +++ b/lib/redmine/export/pdf.rb @@ -408,6 +408,13 @@ module Redmine txt = Redmine::CodesetUtil.replace_invalid_utf8(txt) end txt.force_encoding('ASCII-8BIT') + elsif RUBY_PLATFORM == 'java' + begin + ic ||= Iconv.new(l(:general_pdf_encoding), 'UTF-8') + txt = ic.iconv(txt) + rescue + txt = txt.gsub(%r{[^\r\n\t\x20-\x7e]}, '?') + end else ic ||= Iconv.new(l(:general_pdf_encoding), 'UTF-8') txtar = "" diff --git a/test/unit/lib/redmine/export/pdf_test.rb b/test/unit/lib/redmine/export/pdf_test.rb index acb46ca69..ec1f3fd7b 100644 --- a/test/unit/lib/redmine/export/pdf_test.rb +++ b/test/unit/lib/redmine/export/pdf_test.rb @@ -57,6 +57,13 @@ class PdfTest < ActiveSupport::TestCase assert_equal "ASCII-8BIT", txt_1.encoding.to_s assert_equal "ASCII-8BIT", txt_2.encoding.to_s assert_equal "ASCII-8BIT", txt_3.encoding.to_s + elsif RUBY_PLATFORM == 'java' + assert_equal "??", + Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, utf8_txt_1) + assert_equal "???", + Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, utf8_txt_2) + assert_equal "????", + Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, utf8_txt_3) else assert_equal "???\x91\xd4", Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, utf8_txt_1) -- 2.39.5