]> source.dussan.org Git - redmine.git/commitdiff
PDF: fix 0x5c(backslash) escape processing in FPDF (#61).
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Fri, 29 Apr 2011 05:35:26 +0000 (05:35 +0000)
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Fri, 29 Apr 2011 05:35:26 +0000 (05:35 +0000)
Japanese CP932(Shift_JIS) and Traditional Chinese Big5 have 0x5c(backslash) problem.

Contributed Jun NAITOH.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5565 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/export/pdf.rb
test/unit/lib/redmine/export/pdf_test.rb
vendor/plugins/rfpdf/lib/rfpdf/fpdf.rb

index 24f66cebda5a02e9f6fb4cc5624916ad15482b8f..a618f6b79ac82db8d813a78d5b8f1f0b6ee06fd4 100644 (file)
@@ -163,8 +163,6 @@ module Redmine
             end
             txt = txtar
           end
-          # 0x5c char handling
-          txt.gsub(/\\/, "\\\\\\\\")
         end
 
         def RDMCell(w,h=0,txt='',border=0,ln=0,align='',fill=0,link='')
index fa3a8498ed9b7c39c6fa43df469649718c27ac32..c26c4c4b7a2fed7a19e43e786a895d8925e426f9 100644 (file)
@@ -27,46 +27,6 @@ class PdfTest < ActiveSupport::TestCase
     assert_equal '', pdf.fix_text_encoding(nil)
   end
 
-  def test_fix_text_encoding_backslash_ascii
-    set_language_if_valid 'ja'
-    pdf = Redmine::Export::PDF::IFPDF.new('ja')
-    assert pdf
-    assert_equal '\\\\abcd', pdf.fix_text_encoding('\\abcd')
-    assert_equal 'abcd\\\\', pdf.fix_text_encoding('abcd\\')
-    assert_equal 'ab\\\\cd', pdf.fix_text_encoding('ab\\cd')
-    assert_equal '\\\\abcd\\\\', pdf.fix_text_encoding('\\abcd\\')
-    assert_equal '\\\\abcd\\\\abcd\\\\',
-                 pdf.fix_text_encoding('\\abcd\\abcd\\')
-  end
-
-  def test_fix_text_encoding_double_backslash_ascii
-    set_language_if_valid 'ja'
-    pdf = Redmine::Export::PDF::IFPDF.new('ja')
-    assert pdf
-    assert_equal '\\\\\\\\abcd', pdf.fix_text_encoding('\\\\abcd')
-    assert_equal 'abcd\\\\\\\\', pdf.fix_text_encoding('abcd\\\\')
-    assert_equal 'ab\\\\\\\\cd', pdf.fix_text_encoding('ab\\\\cd')
-    assert_equal 'ab\\\\\\\\cd\\\\de', pdf.fix_text_encoding('ab\\\\cd\\de')
-    assert_equal '\\\\\\\\abcd\\\\\\\\', pdf.fix_text_encoding('\\\\abcd\\\\')
-    assert_equal '\\\\\\\\abcd\\\\\\\\abcd\\\\\\\\',
-                 pdf.fix_text_encoding('\\\\abcd\\\\abcd\\\\')
-  end
-
-  def test_fix_text_encoding_backslash_ja_cp932
-    pdf = Redmine::Export::PDF::IFPDF.new('ja')
-    assert pdf
-    assert_equal "\x83\\\\\x98A",
-                  pdf.fix_text_encoding("\xe3\x82\xbd\xe9\x80\xa3")
-    assert_equal "\x83\\\\\x98A\x91\xe3\x95\\\\",
-                  pdf.fix_text_encoding("\xe3\x82\xbd\xe9\x80\xa3\xe4\xbb\xa3\xe8\xa1\xa8")
-    assert_equal "\x91\xe3\x95\\\\\\\\",
-                  pdf.fix_text_encoding("\xe4\xbb\xa3\xe8\xa1\xa8\\")
-    assert_equal "\x91\xe3\x95\\\\\\\\\\\\",
-                  pdf.fix_text_encoding("\xe4\xbb\xa3\xe8\xa1\xa8\\\\")
-    assert_equal "\x91\xe3\x95\\\\a\\\\",
-                  pdf.fix_text_encoding("\xe4\xbb\xa3\xe8\xa1\xa8a\\")
-  end
-
   def test_fix_text_encoding_cannot_convert_ja_cp932
     pdf = Redmine::Export::PDF::IFPDF.new('ja')
     assert pdf
index 30714fa3aa9ca309a7e144f6056e3593384c371f..8b129a48d589c668330fbf404aed66257de12000 100644 (file)
@@ -642,10 +642,7 @@ class FPDF
 
     def Text(x, y, txt)
         # Output a string
-        txt.gsub!(')', '\\)')
-        txt.gsub!('(', '\\(')
-        txt.gsub!('\\', '\\\\')
-        s=sprintf('BT %.2f %.2f Td (%s) Tj ET',x*@k,(@h-y)*@k,txt);
+        s=sprintf('BT %.2f %.2f Td (%s) Tj ET',x*@k,(@h-y)*@k, escape(txt));
         s=s+' '+dounderline(x,y,txt) if @underline and txt!=''
         s='q '+@TextColor+' '+s+' Q' if @ColorFlag
         out(s)
@@ -719,14 +716,11 @@ class FPDF
             else
                 dx=@cMargin
             end
-            txt = txt.gsub(')', '\\)')
-            txt.gsub!('(', '\\(')
-            txt.gsub!('\\', '\\\\')
             if @ColorFlag
                 s=s+'q '+@TextColor+' '
             end
             s=s+sprintf('BT %.2f %.2f Td (%s) Tj ET',
-                (@x+dx)*@k,(@h-(@y+0.5*h+0.3*@FontSize))*@k,txt)
+                (@x+dx)*@k,(@h-(@y+0.5*h+0.3*@FontSize))*@k,escape(txt))
             s=s+' '+dounderline(@x+dx,@y+0.5*h+0.3*@FontSize,txt) if @underline
             s=s+' Q' if @ColorFlag
             if link and link != ''
@@ -1538,7 +1532,7 @@ class FPDF
 
     def escape(s)
         # Add \ before \, ( and )
-        s.gsub('\\','\\\\').gsub('(','\\(').gsub(')','\\)')
+        s.gsub('\\','\\\\\\').gsub('(','\\(').gsub(')','\\)')
     end
 
     def putstream(s)