@@ -163,8 +163,6 module Redmine | |||
|
163 | 163 | end |
|
164 | 164 | txt = txtar |
|
165 | 165 | end |
|
166 | # 0x5c char handling | |
|
167 | txt.gsub(/\\/, "\\\\\\\\") | |
|
168 | 166 | end |
|
169 | 167 | |
|
170 | 168 | def RDMCell(w,h=0,txt='',border=0,ln=0,align='',fill=0,link='') |
@@ -27,46 +27,6 class PdfTest < ActiveSupport::TestCase | |||
|
27 | 27 | assert_equal '', pdf.fix_text_encoding(nil) |
|
28 | 28 | end |
|
29 | 29 | |
|
30 | def test_fix_text_encoding_backslash_ascii | |
|
31 | set_language_if_valid 'ja' | |
|
32 | pdf = Redmine::Export::PDF::IFPDF.new('ja') | |
|
33 | assert pdf | |
|
34 | assert_equal '\\\\abcd', pdf.fix_text_encoding('\\abcd') | |
|
35 | assert_equal 'abcd\\\\', pdf.fix_text_encoding('abcd\\') | |
|
36 | assert_equal 'ab\\\\cd', pdf.fix_text_encoding('ab\\cd') | |
|
37 | assert_equal '\\\\abcd\\\\', pdf.fix_text_encoding('\\abcd\\') | |
|
38 | assert_equal '\\\\abcd\\\\abcd\\\\', | |
|
39 | pdf.fix_text_encoding('\\abcd\\abcd\\') | |
|
40 | end | |
|
41 | ||
|
42 | def test_fix_text_encoding_double_backslash_ascii | |
|
43 | set_language_if_valid 'ja' | |
|
44 | pdf = Redmine::Export::PDF::IFPDF.new('ja') | |
|
45 | assert pdf | |
|
46 | assert_equal '\\\\\\\\abcd', pdf.fix_text_encoding('\\\\abcd') | |
|
47 | assert_equal 'abcd\\\\\\\\', pdf.fix_text_encoding('abcd\\\\') | |
|
48 | assert_equal 'ab\\\\\\\\cd', pdf.fix_text_encoding('ab\\\\cd') | |
|
49 | assert_equal 'ab\\\\\\\\cd\\\\de', pdf.fix_text_encoding('ab\\\\cd\\de') | |
|
50 | assert_equal '\\\\\\\\abcd\\\\\\\\', pdf.fix_text_encoding('\\\\abcd\\\\') | |
|
51 | assert_equal '\\\\\\\\abcd\\\\\\\\abcd\\\\\\\\', | |
|
52 | pdf.fix_text_encoding('\\\\abcd\\\\abcd\\\\') | |
|
53 | end | |
|
54 | ||
|
55 | def test_fix_text_encoding_backslash_ja_cp932 | |
|
56 | pdf = Redmine::Export::PDF::IFPDF.new('ja') | |
|
57 | assert pdf | |
|
58 | assert_equal "\x83\\\\\x98A", | |
|
59 | pdf.fix_text_encoding("\xe3\x82\xbd\xe9\x80\xa3") | |
|
60 | assert_equal "\x83\\\\\x98A\x91\xe3\x95\\\\", | |
|
61 | pdf.fix_text_encoding("\xe3\x82\xbd\xe9\x80\xa3\xe4\xbb\xa3\xe8\xa1\xa8") | |
|
62 | assert_equal "\x91\xe3\x95\\\\\\\\", | |
|
63 | pdf.fix_text_encoding("\xe4\xbb\xa3\xe8\xa1\xa8\\") | |
|
64 | assert_equal "\x91\xe3\x95\\\\\\\\\\\\", | |
|
65 | pdf.fix_text_encoding("\xe4\xbb\xa3\xe8\xa1\xa8\\\\") | |
|
66 | assert_equal "\x91\xe3\x95\\\\a\\\\", | |
|
67 | pdf.fix_text_encoding("\xe4\xbb\xa3\xe8\xa1\xa8a\\") | |
|
68 | end | |
|
69 | ||
|
70 | 30 | def test_fix_text_encoding_cannot_convert_ja_cp932 |
|
71 | 31 | pdf = Redmine::Export::PDF::IFPDF.new('ja') |
|
72 | 32 | assert pdf |
@@ -642,10 +642,7 class FPDF | |||
|
642 | 642 | |
|
643 | 643 | def Text(x, y, txt) |
|
644 | 644 | # Output a string |
|
645 | txt.gsub!(')', '\\)') | |
|
646 | txt.gsub!('(', '\\(') | |
|
647 | txt.gsub!('\\', '\\\\') | |
|
648 | s=sprintf('BT %.2f %.2f Td (%s) Tj ET',x*@k,(@h-y)*@k,txt); | |
|
645 | s=sprintf('BT %.2f %.2f Td (%s) Tj ET',x*@k,(@h-y)*@k, escape(txt)); | |
|
649 | 646 | s=s+' '+dounderline(x,y,txt) if @underline and txt!='' |
|
650 | 647 | s='q '+@TextColor+' '+s+' Q' if @ColorFlag |
|
651 | 648 | out(s) |
@@ -719,14 +716,11 class FPDF | |||
|
719 | 716 | else |
|
720 | 717 | dx=@cMargin |
|
721 | 718 | end |
|
722 | txt = txt.gsub(')', '\\)') | |
|
723 | txt.gsub!('(', '\\(') | |
|
724 | txt.gsub!('\\', '\\\\') | |
|
725 | 719 | if @ColorFlag |
|
726 | 720 | s=s+'q '+@TextColor+' ' |
|
727 | 721 | end |
|
728 | 722 | s=s+sprintf('BT %.2f %.2f Td (%s) Tj ET', |
|
729 | (@x+dx)*@k,(@h-(@y+0.5*h+0.3*@FontSize))*@k,txt) | |
|
723 | (@x+dx)*@k,(@h-(@y+0.5*h+0.3*@FontSize))*@k,escape(txt)) | |
|
730 | 724 | s=s+' '+dounderline(@x+dx,@y+0.5*h+0.3*@FontSize,txt) if @underline |
|
731 | 725 | s=s+' Q' if @ColorFlag |
|
732 | 726 | if link and link != '' |
@@ -1538,7 +1532,7 class FPDF | |||
|
1538 | 1532 | |
|
1539 | 1533 | def escape(s) |
|
1540 | 1534 | # Add \ before \, ( and ) |
|
1541 | s.gsub('\\','\\\\').gsub('(','\\(').gsub(')','\\)') | |
|
1535 | s.gsub('\\','\\\\\\').gsub('(','\\(').gsub(')','\\)') | |
|
1542 | 1536 | end |
|
1543 | 1537 | |
|
1544 | 1538 | def putstream(s) |
General Comments 0
You need to be logged in to leave comments.
Login now