Class: WizRtf::Text
- Inherits:
-
Object
- Object
- WizRtf::Text
- Defined in:
- lib/wiz_rtf/text.rb
Overview
Represents Rtf text.
Constant Summary collapse
- TEXT_ALIGN_MAP =
{left:'ql',center:'qc',right:'qr'}
Instance Method Summary collapse
-
#initialize(str = '', styles = {}) ⇒ Text
constructor
creates a text of
str
to the document. -
#render(io) ⇒ Object
Outputs the Partial Rtf Document to a Generic Stream as a Rich Text Format (RTF).
Constructor Details
#initialize(str = '', styles = {}) ⇒ Text
creates a text of str
to the document.
Styles:
-
text-align
- sets the horizontal alignment of the text. optional values::left
,:center
,:right
-
font-family
- set the font family of the text. optional values: ‘Arial’, ‘Arial Black’, ‘Arial Narrow’,‘Bitstream Vera Sans Mono’,'Bitstream Vera Sans','Bitstream Vera Serif','Book Antiqua','Bookman Old Style','Castellar','Century Gothic', 'Comic Sans MS','Courier New','Franklin Gothic Medium','Garamond','Georgia','Haettenschweiler','Impact','Lucida Console' 'Lucida Sans Unicode','Microsoft Sans Serif','Monotype Corsiva','Palatino Linotype','Papyrus','Sylfaen','Symbol' 'Tahoma','Times New Roman','Trebuchet MS','Verdana'.
-
font-size
- set font size of the text. -
font-bold
- setting the value true for bold of the text. -
font-italic
- setting the value true for italic of the text. -
font-underline
- setting the value true for underline of the text.
Example:
WizRtf::Text.new(“A Example of Rtf Document”, ‘text-align’ => :center, ‘font-family’ => ‘Microsoft YaHei’, ‘font-size’ => 48, ‘font-bold’ => true, ‘font-italic’ => true, ‘font-underline’ => true)
29 30 31 32 |
# File 'lib/wiz_rtf/text.rb', line 29 def initialize(str = '', styles = {}) @str = str @styles = {'text-align' => :left, 'font-family' => 0, 'font-size' => 12, 'font-bold' => false, 'font-italic' => false, 'font-underline' => false, 'foreground-color' => 0, 'background-color' => 0 }.merge(styles) end |
Instance Method Details
#render(io) ⇒ Object
Outputs the Partial Rtf Document to a Generic Stream as a Rich Text Format (RTF).
-
io
- The Generic IO to Output the RTF Document.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/wiz_rtf/text.rb', line 36 def render(io) io.group do io.cmd :pard io.cmd TEXT_ALIGN_MAP[@styles['text-align']] io.cmd :f, @styles['font-family'] io.cmd :fs, @styles['font-size'] * 2 io.cmd @styles['font-bold'] ? 'b' : 'b0' io.cmd @styles['font-italic'] ? 'i' : 'i0' io.cmd @styles['font-underline'] ? 'ul' : 'ulnone' io.cmd :cf, @styles['foreground-color'] io.cmd :cb, @styles['background-color'] io.cmd :chcfpat, @styles['foreground-color'] io.cmd :chcbpat, @styles['background-color'] io.txt @str io.cmd :par end end |