Sha256: bb2b22665325ccc3fa0b086ac9897ea4f66e5b3e6551b5e09dbeed464a3f1b67

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

# encoding: utf-8

# WizRft:  A gem for exporting Word Documents in ruby
# using the Microsoft Rich Text Format (RTF) Specification
# Copyright (C) 2015 by sgzhe@163.com

module WizRtf
  class Text
    TEXT_ALIGN_MAP = {left:'ql',center:'qc',right:'qr'}

    def initialize(str = '', styles = {})
      @str = str
      @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 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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wiz_rtf-0.5.5 lib/wiz_rtf/text.rb