File: show.rb

package info (click to toggle)
ruby-rghost 0.9.9-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,188 kB
  • sloc: ruby: 3,374; makefile: 6; sh: 1
file content (84 lines) | stat: -rw-r--r-- 2,566 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
require "rghost/ps_object"
require "rghost/ruby_to_ps"  # to_string

# Writes a text on the current row or point with align.
class RGhost::Show < RGhost::PsObject
  attr_accessor :text, :align, :tag
  DEFAULT_OPTIONS = {tag: :default_font, align: :show_left}
  include RGhost::RubyToPs
  #===Options
  #
  # * <tt>:tag or :with</tt> - Use predefined tag
  # * <tt>:color</tt> - Override color of the tag
  # * <tt>:align</tt> - Align of the text
  #===Examples
  # The vertical line is the current point. For align by point
  # doc.moveto :x => 3, :y => 4
  # doc.show "Foo Bar Baz", :align => :show_left      #default
  # link:images/show01.png
  #
  # doc.moveto :x => 3, :y => 4
  # doc.show "Foo Bar Baz", :align => :show_center
  # link:images/show02.png
  #
  # doc.moveto :x => 3, :y => 4
  # doc.show "Foo Bar Baz", :align => :show_right
  # link:images/show03.png
  #
  # For the the current row it's not necessary positioned using moveto. Like below
  # doc.show "Foo Bar Baz", :align => :show_right
  # Now justification in page
  #
  # doc.show "Foo Bar Baz", :align => :page_left
  #
  # link:images/show04.png
  #
  # doc.show "Foo Bar Baz", :align => :page_center
  #
  # link:images/show05.png
  #
  # doc.show "Foo Bar Baz", :align => :page_right
  #
  # link:images/show06.png
  #
  #====Overrinding tag's color
  #
  # doc.show "Foo Bar Baz", :with => :my_italic, :align => :page_center, :color => :red
  #
  # link:images/show07.png
  #
  # Many tags per row
  #  doc=Document.new
  #  doc.define_tags do
  #    tag :font1, :name => 'Helvetica', :size => 10, :color => '#F34811'
  #    tag :font2, :name => 'Times',     :size => 14, :color => '#A4297A'
  #    tag :font3, :name => 'TimesBold', :size => 18, :color => '#AA3903'
  #  end
  #
  #  doc.show "foo bar baz ",  :with => :font1
  #  doc.show "qux quux ",     :with => :font2
  #  doc.show "corge ",        :with => :font3
  #  doc.show "grault garply ",:with => :font2
  #  doc.show "qux quux",      :with => :font1
  #
  # link:images/show08.png

  def initialize(text, options = {align: :show_left, tag: :default_font, color: 0})
    @text = text
    @options = DEFAULT_OPTIONS.dup.merge(options)
  end

  def ps
    rtext = RGhost::PsObject.new
    # rtext.raw Color.create(@options[:color] || 0)
    if @options[:with] || @options[:tag]
      f = "_#{@options[:with] || @options[:tag]}"
      rtext.raw f
    end
    rtext.raw RGhost::Color.create(@options[:color]) if @options[:color]
    rtext.raw to_string(@text)
    rtext.raw @options[:align]

    rtext.graphic_scope
  end
end