Skip to content

Commit

Permalink
add trleft; test for trgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
dj2 committed Feb 25, 2011
1 parent 49fc90a commit 7e9f99f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/ruby-rtf/parser.rb
Expand Up @@ -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))
Expand Down
5 changes: 4 additions & 1 deletion 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
Expand Down
22 changes: 22 additions & 0 deletions spec/parser_spec.rb
Expand Up @@ -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' +
Expand Down

0 comments on commit 7e9f99f

Please sign in to comment.