lib/wiz_rtf/text.rb in wiz_rtf-0.5.0 vs lib/wiz_rtf/text.rb in wiz_rtf-0.5.5
- old
+ new
@@ -4,22 +4,28 @@
# using the Microsoft Rich Text Format (RTF) Specification
# Copyright (C) 2015 by sgzhe@163.com
module WizRtf
class Text
- ALIGN_MAP = {left:'ql',center:'qc',right:'qr'}
- FONT_MAP = {'font-size' => :fs}
+ TEXT_ALIGN_MAP = {left:'ql',center:'qc',right:'qr'}
def initialize(str = '', styles = {})
@str = str
- @styles = {:align => :left,'font-size' => 24}.merge(styles)
+ @styles = {'text-align' => :left, 'font-size' => 24, 'font-bold' => false, 'font-italic' => false, 'font-underline' => false, 'foreground-color' => 1, 'background-color' => 0 }.merge(styles)
end
def render(io)
io.group do
io.cmd :pard
- io.cmd ALIGN_MAP[@styles[:align]]
- io.cmd FONT_MAP[@styles['font-size']]
+ io.cmd TEXT_ALIGN_MAP[@styles['text-align']]
+ io.cmd :fs, @styles['font-size']
+ 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
end