Class: WizRtf::Document
- Inherits:
-
Object
- Object
- WizRtf::Document
- Defined in:
- lib/wiz_rtf/document.rb
Instance Method Summary collapse
- #color(red, green, blue) ⇒ Object
- #font(num, family, name, character_set = 0, prq = 2) ⇒ Object
- #head ⇒ Object
- #image(file) ⇒ Object
-
#initialize(&block) ⇒ Document
constructor
A new instance of Document.
- #line_break ⇒ Object
-
#page_break ⇒ Object
writes a page interruption (new page).
- #render(io) ⇒ Object
- #save(file) ⇒ Object
- #table(rows = [], options = {}, &block) ⇒ Object
- #text(str, styles = {:align => :left}) ⇒ Object
Constructor Details
#initialize(&block) ⇒ Document
Returns a new instance of Document.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/wiz_rtf/document.rb', line 9 def initialize(&block) @fonts = [] @colors = [] @parts = [] font 0, 'fswiss', 'Arial', 0, 2 font 1, 'fmodern', 'Courier New', 0, 1 font 2, 'fnil', '宋体', 2, 2 color 0, 0, 0 color 255, 0, 0 block.arity<1 ? self.instance_eval(&block) : block.call(self) if block_given? end |
Instance Method Details
#color(red, green, blue) ⇒ Object
29 30 31 |
# File 'lib/wiz_rtf/document.rb', line 29 def color(red, green, blue) @colors << WizRtf::Color.new(red, green, blue) end |
#font(num, family, name, character_set = 0, prq = 2) ⇒ Object
25 26 27 |
# File 'lib/wiz_rtf/document.rb', line 25 def font(num, family, name, character_set = 0, prq = 2) @fonts << WizRtf::Font.new(num, family, name, character_set, prq) end |
#head ⇒ Object
21 22 23 |
# File 'lib/wiz_rtf/document.rb', line 21 def head end |
#image(file) ⇒ Object
37 38 39 |
# File 'lib/wiz_rtf/document.rb', line 37 def image(file) @parts << WizRtf::Image.new(file) end |
#line_break ⇒ Object
45 46 47 |
# File 'lib/wiz_rtf/document.rb', line 45 def line_break @parts << WizRtf::Cmd.new(:par) end |
#page_break ⇒ Object
writes a page interruption (new page)
50 51 52 |
# File 'lib/wiz_rtf/document.rb', line 50 def page_break @parts << WizRtf::Cmd.new(:page) end |
#render(io) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/wiz_rtf/document.rb', line 54 def render(io) io.group do io.cmd :rtf, 1 io.cmd :ansi io.cmd :ansicpg, 2052 io.cmd :deff, 0 io.group do io.cmd :fonttbl @fonts.each do |font| font.render(io) end end io.group do io.cmd :colortbl io.delimit @colors.each do |color| color.render(io) end end @parts.each do |part| part.render(io) end end end |
#save(file) ⇒ Object
79 80 81 |
# File 'lib/wiz_rtf/document.rb', line 79 def save(file) File.open(file, 'w') { |file| render(WizRtf::RtfIO.new(file)) } end |