From c0f41488148f8ffd3d252e01f14a5bc06722f495 Mon Sep 17 00:00:00 2001 From: Kenshi Muto Date: Sat, 16 Apr 2016 16:28:02 +0900 Subject: [PATCH 1/3] fix wrong calcuration between pt and mm for table cell width on IDGXML. --- lib/review/configure.rb | 1 + lib/review/idgxmlbuilder.rb | 10 +++++----- test/test_idgxmlbuilder.rb | 27 ++++++++++++++++++++++----- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/lib/review/configure.rb b/lib/review/configure.rb index 03d9a830f..7b7175005 100644 --- a/lib/review/configure.rb +++ b/lib/review/configure.rb @@ -58,6 +58,7 @@ def self.values "nolf" => true, # for IDGXML "chapref" => nil, # for IDGXML "structuredxml" => nil, # for IDGXML + "pt_to_mm_unit" => 0.3528, # for IDGXML (DTP: 1pt = 0.3528mm, JIS: 1pt = 0.3514mm) "footnotetext" => nil, # for LaTeX ] conf.maker = nil diff --git a/lib/review/idgxmlbuilder.rb b/lib/review/idgxmlbuilder.rb index 520b47a37..f1e4be8dd 100644 --- a/lib/review/idgxmlbuilder.rb +++ b/lib/review/idgxmlbuilder.rb @@ -501,8 +501,8 @@ def texequation(lines) def table(lines, id = nil, caption = nil) tablewidth = nil col = 0 - unless @book.config["tableopt"].nil? - tablewidth = @book.config["tableopt"].split(",")[0].to_f / 0.351 # mm -> pt + if @book.config["tableopt"] + tablewidth = @book.config["tableopt"].split(",")[0].to_f / @book.config["pt_to_mm_unit"] end puts "" rows = [] @@ -529,7 +529,7 @@ def table(lines, id = nil, caption = nil) cellwidth = @tsize.split(/\s*,\s*/) totallength = 0 cellwidth.size.times do |n| - cellwidth[n] = cellwidth[n].to_f / 0.351 # mm -> pt + cellwidth[n] = cellwidth[n].to_f / @book.config["pt_to_mm_unit"] totallength += cellwidth[n] warn "total length exceeds limit for table: #{id}" if totallength > tablewidth end @@ -563,7 +563,7 @@ def table(lines, id = nil, caption = nil) else i = 0 rows.shift.split(/\t/).each_with_index do |cell, x| - print %Q[] + print %Q[] i += 1 end end @@ -584,7 +584,7 @@ def trputs(tablewidth, rows, cellwidth, sepidx) rows.each_with_index do |row, y| i = 0 row.split(/\t/).each_with_index do |cell, x| - print %Q[] + print %Q[] i += 1 end end diff --git a/test/test_idgxmlbuilder.rb b/test/test_idgxmlbuilder.rb index 4a788bd95..11a2d31dd 100644 --- a/test/test_idgxmlbuilder.rb +++ b/test/test_idgxmlbuilder.rb @@ -14,7 +14,6 @@ def setup @config = ReVIEW::Configure.values @config.merge!({ "secnolevel" => 2, - "nolf" => true, "tableopt" => "10" }) @book = Book::Base.new(nil) @@ -86,26 +85,44 @@ def test_inline_raw def test_inline_in_table actual = compile_block("//table{\n@{1}\t@{2}\n------------\n@{3}\t@{4}<>&\n//}\n") - assert_equal %Q|
#{cell.sub("DUMMYCELLSPLITTER", "")}#{cell.sub("DUMMYCELLSPLITTER", "")}#{cell.sub("DUMMYCELLSPLITTER", "")}#{cell.sub("DUMMYCELLSPLITTER", "")}
1234<>&
|, actual + assert_equal %Q|
1234<>&
|, actual end def test_inline_in_table_without_header actual = compile_block("//table{\n@{1}\t@{2}\n@{3}\t@{4}<>&\n//}\n") - assert_equal %Q|
1234<>&
|, actual + assert_equal %Q|
1234<>&
|, actual end def test_inline_in_table_without_cellwidth @config["tableopt"] = nil actual = compile_block("//table{\n@{1}\t@{2}\n------------\n@{3}\t@{4}<>&\n//}\n") assert_equal %Q|1\t23\t4<>&
|, actual - @config["tableopt"] = 10 end def test_inline_in_table_without_header_and_cellwidth @config["tableopt"] = nil actual = compile_block("//table{\n@{1}\t@{2}\n@{3}\t@{4}<>&\n//}\n") assert_equal %Q|1\t23\t4<>&
|, actual - @config["tableopt"] = 10 + end + + def test_customize_cellwidth + actual = compile_block("//tsize[2,3,5]\n//table{\nA\tB\tC\n//}\n") + assert_equal %Q|
ABC
|, actual + + actual = compile_block("//tsize[2,3]\n//table{\nA\tB\tC\n//}\n") + assert_equal %Q|
ABC
|, actual + + actual = compile_block("//tsize[2]\n//table{\nA\tB\tC\n//}\n") + assert_equal %Q|
ABC
|, actual + end + + def test_customize_mmtopt + actual = compile_block("//table{\nA\n//}\n") + assert_equal %Q|
A
|, actual + + @config["pt_to_mm_unit"] = 0.3514 + actual = compile_block("//table{\nA\n//}\n") + assert_equal %Q|
A
|, actual end def test_inline_br From 53237b9c8d8fb76b84a92d76f686d9db9172fd86 Mon Sep 17 00:00:00 2001 From: Kenshi Muto Date: Sat, 16 Apr 2016 16:33:12 +0900 Subject: [PATCH 2/3] assume passing value as String --- lib/review/idgxmlbuilder.rb | 4 ++-- test/test_idgxmlbuilder.rb | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/review/idgxmlbuilder.rb b/lib/review/idgxmlbuilder.rb index f1e4be8dd..e622021c3 100644 --- a/lib/review/idgxmlbuilder.rb +++ b/lib/review/idgxmlbuilder.rb @@ -502,7 +502,7 @@ def table(lines, id = nil, caption = nil) tablewidth = nil col = 0 if @book.config["tableopt"] - tablewidth = @book.config["tableopt"].split(",")[0].to_f / @book.config["pt_to_mm_unit"] + tablewidth = @book.config["tableopt"].split(",")[0].to_f / @book.config["pt_to_mm_unit"].to_f end puts "" rows = [] @@ -529,7 +529,7 @@ def table(lines, id = nil, caption = nil) cellwidth = @tsize.split(/\s*,\s*/) totallength = 0 cellwidth.size.times do |n| - cellwidth[n] = cellwidth[n].to_f / @book.config["pt_to_mm_unit"] + cellwidth[n] = cellwidth[n].to_f / @book.config["pt_to_mm_unit"].to_f totallength += cellwidth[n] warn "total length exceeds limit for table: #{id}" if totallength > tablewidth end diff --git a/test/test_idgxmlbuilder.rb b/test/test_idgxmlbuilder.rb index 11a2d31dd..937189983 100644 --- a/test/test_idgxmlbuilder.rb +++ b/test/test_idgxmlbuilder.rb @@ -123,6 +123,10 @@ def test_customize_mmtopt @config["pt_to_mm_unit"] = 0.3514 actual = compile_block("//table{\nA\n//}\n") assert_equal %Q|
A
|, actual + + @config["pt_to_mm_unit"] = "0.3514" + actual = compile_block("//table{\nA\n//}\n") + assert_equal %Q|
A
|, actual end def test_inline_br From 013cc2a8fba09a2b29917e47a10ff1c1b5fa6c66 Mon Sep 17 00:00:00 2001 From: Kenshi Muto Date: Sat, 16 Apr 2016 16:38:42 +0900 Subject: [PATCH 3/3] unnecessary spacing and , --- lib/review/configure.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/review/configure.rb b/lib/review/configure.rb index 7b7175005..c9a90b868 100644 --- a/lib/review/configure.rb +++ b/lib/review/configure.rb @@ -59,7 +59,7 @@ def self.values "chapref" => nil, # for IDGXML "structuredxml" => nil, # for IDGXML "pt_to_mm_unit" => 0.3528, # for IDGXML (DTP: 1pt = 0.3528mm, JIS: 1pt = 0.3514mm) - "footnotetext" => nil, # for LaTeX + "footnotetext" => nil # for LaTeX ] conf.maker = nil conf