Skip to content

Commit 68794b7

Browse files
committed
margins left, right, top, bottom
1 parent 1d0773d commit 68794b7

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/ruby-rtf/parser.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ def handle_control(name, val, src, current_pos)
144144
when :fi then add_section!(:first_line_indent => RubyRTF.twips_to_points(val))
145145
when :li then add_section!(:left_indent => RubyRTF.twips_to_points(val))
146146
when :ri then add_section!(:right_indent => RubyRTF.twips_to_points(val))
147+
when :margl then add_section!(:left_margin => RubyRTF.twips_to_points(val))
148+
when :margr then add_section!(:right_margin => RubyRTF.twips_to_points(val))
149+
when :margt then add_section!(:top_margin => RubyRTF.twips_to_points(val))
150+
when :margb then add_section!(:bottom_margin => RubyRTF.twips_to_points(val))
147151
when :sb then add_section!(:space_before => RubyRTF.twips_to_points(val))
148152
when :sa then add_section!(:space_after => RubyRTF.twips_to_points(val))
149153
when :cf then add_section!(:foreground_colour => @doc.colour_table[val])

spec/parser_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,28 @@
595595
end
596596
end
597597

598+
context 'margins' do
599+
it 'handles left margin' do
600+
parser.handle_control(:margl, 1000, nil, 0)
601+
parser.current_section[:modifiers][:left_margin].should == 50
602+
end
603+
604+
it 'handles right margin' do
605+
parser.handle_control(:margr, 1000, nil, 0)
606+
parser.current_section[:modifiers][:right_margin].should == 50
607+
end
608+
609+
it 'handles top margin' do
610+
parser.handle_control(:margt, 1000, nil, 0)
611+
parser.current_section[:modifiers][:top_margin].should == 50
612+
end
613+
614+
it 'handles bottom margin' do
615+
parser.handle_control(:margb, 1000, nil, 0)
616+
parser.current_section[:modifiers][:bottom_margin].should == 50
617+
end
618+
end
619+
598620
context 'paragraph spacing' do
599621
it 'handles space before' do
600622
parser.handle_control(:sb, 1000, nil, 0)

0 commit comments

Comments
 (0)