From 7e9f99f41b065011de804fd06f22043d6a612872 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Thu, 24 Feb 2011 23:35:19 -0500 Subject: [PATCH] add trleft; test for trgraph --- lib/ruby-rtf/parser.rb | 4 ++++ lib/ruby-rtf/table.rb | 5 ++++- spec/parser_spec.rb | 22 ++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/ruby-rtf/parser.rb b/lib/ruby-rtf/parser.rb index 4cc7ec8..589fab6 100644 --- a/lib/ruby-rtf/parser.rb +++ b/lib/ruby-rtf/parser.rb @@ -186,6 +186,10 @@ def handle_control(name, val, src, current_pos) raise "trgraph outside of a table?" if !current_section[:modifiers][:row] current_section[:modifiers][:row].table.half_gap = RubyRTF.twips_to_points(val) + when :trleft then + raise "trleft outside of a table?" if !current_section[:modifiers][:row] + current_section[:modifiers][:row].table.left_margin = RubyRTF.twips_to_points(val) + when :cellx then raise "cellx outside of a table?" if !current_section[:modifiers][:row] current_section[:modifiers][:row].widths.push(RubyRTF.twips_to_points(val)) diff --git a/lib/ruby-rtf/table.rb b/lib/ruby-rtf/table.rb index 681e272..4b6ba3d 100644 --- a/lib/ruby-rtf/table.rb +++ b/lib/ruby-rtf/table.rb @@ -1,8 +1,11 @@ module RubyRTF class Table - attr_accessor :rows, :half_gap + attr_accessor :rows, :half_gap, :left_margin def initialize + @left_margin = 0 + @half_gap = 0 + @rows = [] add_row end diff --git a/spec/parser_spec.rb b/spec/parser_spec.rb index 4711d6e..5193226 100644 --- a/spec/parser_spec.rb +++ b/spec/parser_spec.rb @@ -641,6 +641,28 @@ def compare_table_results(table, data) compare_table_results(table, [{:widths => [72], :values => [['fee.']]}]) end + it 'parses a \trgraph180' do + src = '{\rtf1 Before Table' + + '\trowd\trgraph180\cellx1440' + + '\pard\intbl fee.\cell\row ' + + 'After table}' + d = parser.parse(src) + + table = d.sections[1][:modifiers][:table] + table.half_gap.should == 9 + end + + it 'parses a \trleft240' do + src = '{\rtf1 Before Table' + + '\trowd\trgraph180\trleft240\cellx1440' + + '\pard\intbl fee.\cell\row ' + + 'After table}' + d = parser.parse(src) + + table = d.sections[1][:modifiers][:table] + table.left_margin.should == 12 + end + it 'parses a single row with multiple columns' do src = '{\rtf1 Before Table' + '\trowd\trgraph180\cellx1440\cellx2880\cellx1000' +