lunks_rghost 0.8.7.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. data/lib/rghost/border.rb +44 -0
  2. data/lib/rghost/callback.rb +58 -0
  3. data/lib/rghost/circle.rb +102 -0
  4. data/lib/rghost/color.rb +175 -0
  5. data/lib/rghost/constants.rb +626 -0
  6. data/lib/rghost/convert.rb +43 -0
  7. data/lib/rghost/cursor.rb +124 -0
  8. data/lib/rghost/dash.rb +59 -0
  9. data/lib/rghost/document.rb +546 -0
  10. data/lib/rghost/document_callback_facade.rb +64 -0
  11. data/lib/rghost/dsc_entry.rb +20 -0
  12. data/lib/rghost/dynamic_document_callback.rb +15 -0
  13. data/lib/rghost/eps.rb +31 -0
  14. data/lib/rghost/font.rb +48 -0
  15. data/lib/rghost/font_map.rb +54 -0
  16. data/lib/rghost/frame.rb +105 -0
  17. data/lib/rghost/function.rb +38 -0
  18. data/lib/rghost/gif.rb +41 -0
  19. data/lib/rghost/graphic.rb +26 -0
  20. data/lib/rghost/grid/base_grid.rb +228 -0
  21. data/lib/rghost/grid/callback_facade.rb +136 -0
  22. data/lib/rghost/grid/csv_grid.rb +51 -0
  23. data/lib/rghost/grid/dynamic_callback.rb +12 -0
  24. data/lib/rghost/grid/field_format.rb +43 -0
  25. data/lib/rghost/grid/grid.rb +15 -0
  26. data/lib/rghost/grid/header.rb +120 -0
  27. data/lib/rghost/grid/matrix.rb +10 -0
  28. data/lib/rghost/grid/rails_grid.rb +74 -0
  29. data/lib/rghost/grid/static_callback.rb +13 -0
  30. data/lib/rghost/grid/style/border_lines.rb +44 -0
  31. data/lib/rghost/grid/style/bottom_lines.rb +28 -0
  32. data/lib/rghost/grid/style/old_forms.rb +28 -0
  33. data/lib/rghost/grid/style/style.rb +8 -0
  34. data/lib/rghost/gs_alone.rb +25 -0
  35. data/lib/rghost/helpers.rb +13 -0
  36. data/lib/rghost/horizontal_line.rb +45 -0
  37. data/lib/rghost/how_to.rb +75 -0
  38. data/lib/rghost/image.rb +29 -0
  39. data/lib/rghost/jpeg.rb +39 -0
  40. data/lib/rghost/line.rb +89 -0
  41. data/lib/rghost/line_width.rb +28 -0
  42. data/lib/rghost/load.rb +43 -0
  43. data/lib/rghost/newpath.rb +19 -0
  44. data/lib/rghost/paper.rb +147 -0
  45. data/lib/rghost/parse_text.rb +53 -0
  46. data/lib/rghost/pdf_security.rb +36 -0
  47. data/lib/rghost/point.rb +23 -0
  48. data/lib/rghost/point_with_command.rb +17 -0
  49. data/lib/rghost/polygon.rb +75 -0
  50. data/lib/rghost/ps/AdobeExpert.enc +258 -0
  51. data/lib/rghost/ps/AdobeLatinEncoding.enc +258 -0
  52. data/lib/rghost/ps/Bengali.enc +386 -0
  53. data/lib/rghost/ps/CodePage1250.enc +258 -0
  54. data/lib/rghost/ps/CodePage1251.enc +258 -0
  55. data/lib/rghost/ps/CodePage1252.enc +258 -0
  56. data/lib/rghost/ps/CodePage1253.enc +258 -0
  57. data/lib/rghost/ps/CodePage1254.enc +258 -0
  58. data/lib/rghost/ps/CodePage1256.enc +258 -0
  59. data/lib/rghost/ps/CodePage1257.enc +258 -0
  60. data/lib/rghost/ps/CodePage1258.enc +258 -0
  61. data/lib/rghost/ps/CodePage874.enc +258 -0
  62. data/lib/rghost/ps/Fontmap +5 -0
  63. data/lib/rghost/ps/IsoLatin.enc +352 -0
  64. data/lib/rghost/ps/MacCentralEuropean.enc +258 -0
  65. data/lib/rghost/ps/MacCyrillice.desnc +258 -0
  66. data/lib/rghost/ps/MacGreek.enc +258 -0
  67. data/lib/rghost/ps/MacHebrew.enc +258 -0
  68. data/lib/rghost/ps/TeX-CorkEncoding.enc +258 -0
  69. data/lib/rghost/ps/TeX-LGR-Greek.enc +258 -0
  70. data/lib/rghost/ps/TeX-T2AModified2Encoding.enc +258 -0
  71. data/lib/rghost/ps/TeX-T2BAdobeEncoding.enc +258 -0
  72. data/lib/rghost/ps/TeX-T2CAdobeEncoding.enc +258 -0
  73. data/lib/rghost/ps/TeX-X2AdobeEncoding.enc +258 -0
  74. data/lib/rghost/ps/TeX-XL2encoding.enc +258 -0
  75. data/lib/rghost/ps/TeXMathExtensionEncoding.enc +258 -0
  76. data/lib/rghost/ps/TeXMathItalicEncoding.enc +258 -0
  77. data/lib/rghost/ps/TeXMathSymbolEncoding.enc +258 -0
  78. data/lib/rghost/ps/US-ASCII.enc +258 -0
  79. data/lib/rghost/ps/UTF-8.enc +3 -0
  80. data/lib/rghost/ps/_cusor.ps +46 -0
  81. data/lib/rghost/ps/basic.ps +25 -0
  82. data/lib/rghost/ps/begin_document.ps +8 -0
  83. data/lib/rghost/ps/callbacks.ps +175 -0
  84. data/lib/rghost/ps/code128.font +344 -0
  85. data/lib/rghost/ps/code39.font +195 -0
  86. data/lib/rghost/ps/cursor.ps +106 -0
  87. data/lib/rghost/ps/datagrid.ps +55 -0
  88. data/lib/rghost/ps/developer.ps +237 -0
  89. data/lib/rghost/ps/ean.font +150 -0
  90. data/lib/rghost/ps/eps.ps +42 -0
  91. data/lib/rghost/ps/font.ps +38 -0
  92. data/lib/rghost/ps/frame.ps +16 -0
  93. data/lib/rghost/ps/gif.ps +150 -0
  94. data/lib/rghost/ps/horizontal_line.ps +4 -0
  95. data/lib/rghost/ps/i25.font +103 -0
  96. data/lib/rghost/ps/jpeg.ps +122 -0
  97. data/lib/rghost/ps/link.ps +22 -0
  98. data/lib/rghost/ps/paper.ps +8 -0
  99. data/lib/rghost/ps/rect_link.ps +17 -0
  100. data/lib/rghost/ps/rectangle.ps +5 -0
  101. data/lib/rghost/ps/rghost_default_template.eps +1532 -0
  102. data/lib/rghost/ps/row.ps +4 -0
  103. data/lib/rghost/ps/show.ps +21 -0
  104. data/lib/rghost/ps/table_callbacks.ps +96 -0
  105. data/lib/rghost/ps/text.ps +63 -0
  106. data/lib/rghost/ps/textarea.ps +11 -0
  107. data/lib/rghost/ps/type.ps +1 -0
  108. data/lib/rghost/ps/unit.ps +3 -0
  109. data/lib/rghost/ps/vertical_line.ps +12 -0
  110. data/lib/rghost/ps/virtual_pages.ps +55 -0
  111. data/lib/rghost/ps_facade.rb +253 -0
  112. data/lib/rghost/ps_object.rb +55 -0
  113. data/lib/rghost/rectangle_link.rb +65 -0
  114. data/lib/rghost/rgengine.so +0 -0
  115. data/lib/rghost/ruby_ghost_config.rb +252 -0
  116. data/lib/rghost/ruby_ghost_engine.rb +174 -0
  117. data/lib/rghost/ruby_ghost_version.rb +8 -0
  118. data/lib/rghost/ruby_to_ps.rb +78 -0
  119. data/lib/rghost/scale.rb +29 -0
  120. data/lib/rghost/shape_content.rb +23 -0
  121. data/lib/rghost/show.rb +88 -0
  122. data/lib/rghost/static_document_callback.rb +18 -0
  123. data/lib/rghost/text.rb +44 -0
  124. data/lib/rghost/text_in.rb +51 -0
  125. data/lib/rghost/text_link_in.rb +42 -0
  126. data/lib/rghost/textarea.rb +88 -0
  127. data/lib/rghost/units.rb +82 -0
  128. data/lib/rghost/variable.rb +12 -0
  129. data/lib/rghost/vertical_line.rb +37 -0
  130. data/lib/rghost/virtual_pages.rb +42 -0
  131. data/lib/rghost.rb +18 -0
  132. metadata +181 -0
@@ -0,0 +1,48 @@
1
+ require "rghost/ps_object"
2
+ require "rghost/constants"
3
+ require "rghost/helpers"
4
+
5
+
6
+ class RGhost::Font < RGhost::PsObject #:nodoc:
7
+ DEFAULT_OPTONS={ :size=> 8, :name => "Helvetica", :encoding => true }
8
+ include RGhost::Constants::Fonts
9
+
10
+ attr_reader :name
11
+
12
+ def initialize(options)
13
+
14
+ @options=DEFAULT_OPTONS.dup.merge(options)
15
+ @options.default ""
16
+ @options[:name]=@options[:font] if @options[:font]
17
+ @name=@options[:name].to_s
18
+ @name+="-encoding" if @options[:encoding]
19
+ end
20
+
21
+ def ps
22
+ o=@options
23
+ str_ret=""
24
+ # if o[:barcode]
25
+ # bc=RGhost::Barcode.new(o[:barcode])
26
+ # @name=bc.font_name
27
+ # o[:encoding]=false
28
+ # end
29
+ if o[:encoding] #define enconding
30
+ str_ret="/#{o[:name]} encoding_font\n"+
31
+ "/#{o[:name]}-encoding exch definefont pop\n"
32
+ end
33
+
34
+
35
+ size= o[:size]
36
+ str_ret+=case size
37
+ when Hash then "/#{@name} findfont [ #{size[:width]} 0 0 #{size[:height]} 0 0] makefont setfont "
38
+ when Array then "/#{@name} findfont [ #{size[0]} 0 0 #{size[1]} 0 0] makefont setfont "
39
+ when Fixnum then "/#{@name} findfont #{size} scalefont setfont "
40
+ end
41
+ str_ret
42
+ end
43
+
44
+
45
+
46
+ end
47
+
48
+
@@ -0,0 +1,54 @@
1
+ #NetDeseigners <www.ndesigners.com.br>
2
+ #Shairon Toledo <shairon.toledo@gmail.com>
3
+ require 'rghost/ps_object'
4
+ require 'rghost/font'
5
+ require 'rghost/function'
6
+
7
+
8
+ class RGhost::FontMap < RGhost::PsObject #:nodoc:
9
+ include RGhost::RubyToPs
10
+ def initialize(options={:font => "Helvetica", :size => 8},&block)
11
+
12
+ #options[:name]=options[:font]
13
+ @options=options
14
+ @fonts={}
15
+ instance_eval(&block) if block
16
+ end
17
+
18
+ def new(name,options={})
19
+ #options[:name]=options[:font]
20
+ @fonts[name]=options
21
+
22
+ end
23
+ def tag(name,options={})
24
+ new(name,options)
25
+ end
26
+
27
+
28
+ def ps
29
+ functions=[]
30
+ fonts=""
31
+ @fonts.each do |name,params|
32
+ options=@options
33
+ if params[:from]
34
+ [params[:from]].flatten.each do |font|
35
+ functions << format_custom_font(font)
36
+ end
37
+
38
+ end
39
+ functions << RGhost::Function.new("_#{name}") do
40
+ raw RGhost::Font.new(options.dup.merge(params)).ps
41
+ raw( RGhost::Color.create(params[:color] || 0) )
42
+ end
43
+ end
44
+ functions.join
45
+ end
46
+
47
+ private
48
+ def format_custom_font(font_path)
49
+ ps=RGhost::PsObject.new
50
+ ps.raw "#{to_string(font_path)} findfont pop"
51
+ ps
52
+ end
53
+ end
54
+
@@ -0,0 +1,105 @@
1
+ #Creates one rectangle or one shape with rounded corners.
2
+ #===Options
3
+ #
4
+ #* <tt>:x and :y</tt> - Coordinates to position.
5
+ #* <tt>:corners</tt> - Value for rounded corners. Use 0 to straight angle.
6
+ #* <tt>:width and :height</tt> - Size of frame
7
+ #* <tt>:content</tt> - facade to ShapeContent with same parameters.
8
+ #* <tt>:border</tt> - facade to Border with same parameters.
9
+ #===Examples using facade frame method inside of Document
10
+ # d=Document.new
11
+ # d.frame :x => 3, :width => 7, :height => 5, :content => {:fill => false}
12
+ #
13
+ #link:images/frame01.png
14
+ # d=Document.new
15
+ # d.frame :x => 3, :width => 7, :height => 5, :content => {:color => '#35F6A3' }
16
+ #
17
+ #link:images/frame02.png
18
+ #
19
+ # d=Document.new
20
+ # d.frame :x => 3, :width => 7, :height => 5, :content => {:color => '#35F6A3' }, :border =>{:width => 5, :dash => [1,3,10]}
21
+ #
22
+ #link:images/frame03.png
23
+ #
24
+ # d=Document.new
25
+ # d.frame :x => 3, :width => 7, :height => 5, :content => {:color => '#35F6A3' }, :corners => 20
26
+ #
27
+ #link:images/frame04.png
28
+ #
29
+ # d=Document.new
30
+ # d.frame :x => 3, :width => 7, :height => 5, :content => {:color => :yellow }, :border => {:color => :red, :width => 4}, :corners => 20
31
+ #
32
+ #link:images/frame05.png
33
+ class RGhost::Frame < RGhost::PsObject
34
+ DEFAULT_OPTIONS={
35
+ :x => :limit_left,
36
+ :y => :current_row,
37
+ :width => 5,
38
+ :height => 3.5,
39
+ :corners => 1,
40
+ :content => RGhost::ShapeContent::DEFAULT_OPTIONS,
41
+ :border => RGhost::Border::DEFAULT_OPTIONS
42
+
43
+
44
+ }
45
+ BACKGROUND_ROW_DEFAULT_OPTIONS={:start_in => :limit_left, :size => :area_x, :color => RGhost::ShapeContent::DEFAULT_OPTIONS[:color]}
46
+ def initialize(options={})
47
+
48
+ @options = DEFAULT_OPTIONS.dup.merge(options)
49
+
50
+ end
51
+
52
+
53
+ def ps
54
+ x=RGhost::Units::parse(@options[:x])
55
+ y=RGhost::Units::parse(@options[:y])
56
+
57
+ h=RGhost::Units::parse(@options[:height])
58
+ w=RGhost::Units::parse(@options[:width])
59
+
60
+ inside=RGhost::ShapeContent.new(@options[:content]) if @options[:content]
61
+ border=RGhost::Border.new(@options[:border]) if @options[:border]
62
+
63
+ params=%Q{
64
+ /rcorners_params{
65
+ /:x #{x} def /:y #{y} def
66
+ /:w #{w} def /:h #{h} def
67
+ /:r #{@options[:corners]} def
68
+ /:s 1 def
69
+ /:inside{
70
+ #{inside.ps if inside }
71
+ } def
72
+ /:outside{
73
+ #{border.ps if border}
74
+ }def
75
+ } def
76
+ }
77
+
78
+ "#{params} rcorners_params rcorners"
79
+
80
+ end
81
+ #Creates background of the row for current row. Example
82
+ #Here's fill the current row using width :area_x, height :row_height, and starting in :limit_left.
83
+ # doc.background_row :color => '#35F6A3'
84
+ #
85
+ #link:images/background_row01.png
86
+ #
87
+ #Specifies size and where will start of background
88
+ # doc.background_row :start_in => 2, :size => 5.5, :color => 0.8
89
+ #
90
+ #link:images/background_row02.png
91
+ def self.background_row(options=BACKGROUND_ROW_DEFAULT_OPTIONS)
92
+ #opts=BACKGROUND_ROW_DEFAULT_OPTIONS.merge(options)
93
+ #start_in,size=Units::parse(opts[:start_in]),Units::parse(opts[:size])
94
+ #return RGhost::PsObject.new("#{start_in} #{size} {#{opts[:color]}} background_row ")
95
+ options =RGhost::Frame::BACKGROUND_ROW_DEFAULT_OPTIONS.merge(options)
96
+ g=RGhost::Graphic.new
97
+ g.set RGhost::Units::parse(options[:start_in])
98
+ g.set RGhost::Units::parse(options[:size])
99
+ g.set RGhost::Color.create(options[:color]) if options[:color]
100
+ g.raw :background_row
101
+ g
102
+
103
+
104
+ end
105
+ end
@@ -0,0 +1,38 @@
1
+ require "rghost/ps_object"
2
+
3
+
4
+ #Creates postscript internal function. Example
5
+ # f=RGhost::Function.new :foo do
6
+ # set Show.new("A Test")
7
+ # end
8
+ #In ps stack will be
9
+ # /foo (A Test) show def
10
+ class RGhost::Function < RGhost::PsObject
11
+
12
+ attr_reader :name
13
+
14
+ def initialize(name,body_function=nil,&block)
15
+ if block
16
+ #super(&block)
17
+ super(&block)
18
+
19
+ else
20
+
21
+ super("")
22
+ end
23
+ @name=name
24
+ @body_function=body_function
25
+
26
+ end
27
+
28
+ def use_template(function_name)
29
+ call "_#{function_name}"
30
+
31
+ end
32
+ def ps
33
+ @body_function||=super
34
+
35
+ "\n/#{@name}{\n#{@body_function}\n} bind def \n"
36
+ end
37
+
38
+ end
data/lib/rghost/gif.rb ADDED
@@ -0,0 +1,41 @@
1
+ require "rghost/ps_object"
2
+ require "rghost/graphic"
3
+ require "rghost/cursor"
4
+ require "rghost/variable"
5
+ require "rghost/image"
6
+ require "rghost/function"
7
+ require "rghost/scale"
8
+ #Loads GIF image from file
9
+ #===Examples
10
+ # doc=Document.new
11
+ # doc.set Gif.new "../public/images/button.gif", :x => 10, :y => 3
12
+ #Using Image.for facade
13
+ # doc.set Image.for "../public/images/button.gif", :x => 10, :y => 3
14
+ #Using PsFacade or Document
15
+ # doc.image "images/button.gif", :x => 10, :y => 3
16
+ #Using zoom of the 200 percent
17
+ # doc.image "images/button.gif", :zoom => 200
18
+ #===Options
19
+ #
20
+ #* <tt>:x and :y</tt> - Coordinates to position.
21
+ #* <tt>:rotate</tt> - Angle to image rotation if there is one.
22
+ #* <tt>:zoom</tt> - Resize proportionally the image
23
+ class RGhost::Gif < RGhost::Image
24
+
25
+ def ps
26
+ s=@options[:zoom]/100.0
27
+
28
+ g=RGhost::Graphic.new
29
+
30
+ params=RGhost::Function.new(:gif_params)
31
+ params.set RGhost::Cursor.translate(@options)
32
+ params.set RGhost::Cursor.rotate(@options[:rotate])
33
+ params.set RGhost::Scale.new(s,s)
34
+
35
+ g.set params
36
+ g.set RGhost::PsObject.new("(#{@file}) viewGIF")
37
+ g.ps
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,26 @@
1
+ require "rghost/ps_object"
2
+ require "rghost/cursor"
3
+ require "rghost/point"
4
+ require "rghost/line_width"
5
+ #Creates a new graphic state between gsave and grestore postscript primitives. Example
6
+ # doc=Document.new
7
+ # doc.graphic do
8
+ # set LineWidth.new(0)
9
+ # set Line.lineto(5,7)
10
+ # end
11
+ class RGhost::Graphic < RGhost::PsObject
12
+
13
+ def ps
14
+ "gsave #{super} grestore"
15
+ end
16
+
17
+
18
+ end
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
@@ -0,0 +1,228 @@
1
+ require 'enumerator'
2
+ # RGhost::Grid::Base is a helper object to create a tabular
3
+ # representations, composed of rows, columns and a title. This
4
+ # prototype used to join the common attributes for data grids. To use
5
+ # a Grid you must first setup the columns, then load the data.
6
+ #
7
+ # Example:
8
+ # grid=Grid::Matrix.new
9
+ # grid.column :title => "Code", :width => 1
10
+ # grid.column :title => "Name", :width => 3, :align => :center
11
+ # grid.column :title => "Date", :width => 3, :align => :center
12
+ #
13
+ # Note that both the width and align of the last two columns are
14
+ # identical. To avoid repetition, you can specify a default width upon
15
+ # creating the DataGrid::Grid object. Any columns that do not specify
16
+ # an explicit width and align property will inherit the defaults.
17
+ #
18
+ # Example:
19
+ #
20
+ # grid=Grid::Matrix.new :width => 3, :align => :center
21
+ # grid.column :title => "Code", :width => 1 #:width => 1, :align => :center
22
+ # grid.column :title => "Name" #:width => 3, :align => :center
23
+ # grid.column :title => "Date" #:width => 3, :align => :center
24
+ #
25
+ # The actual content needs to be passed in as an array of arrays
26
+ #
27
+ # values=[
28
+ # [1,"Name 1", Time.now],
29
+ # [2,"Name 2", Time.now],
30
+ # [3,"Name 3", Time.now],
31
+ # [4,"Name 4", Time.now],
32
+ # [5,"Name 5", Time.now]
33
+ # ]
34
+ #
35
+ # Bind the content to the grid:
36
+ # grid.data(values)
37
+ # Add the Grid to a document
38
+ # d=Document.new
39
+ # d.set grid
40
+ #
41
+ class RGhost::Grid::Base < RGhost::PsObject
42
+ attr_reader :header
43
+ attr_accessor :column_padding
44
+ include RGhost::RubyToPs
45
+ include RGhost::Grid::CallbackFacade
46
+
47
+ #===Options
48
+ #* <tt>:headings</tt> - To disable headers set this attribute to false.
49
+ #* <tt>:column_padding</tt> - Padding between column content and its edge.
50
+ #* <tt>:width</tt> - Width for all columns.
51
+ #* <tt>:align</tt> - Align for all data(:left, :center and :right).
52
+ #* <tt>:title_align</tt> - Align for all the header's name(:left, :center and :right).
53
+ def initialize(options={})
54
+
55
+ @header=RGhost::Grid::Header.new( (options[:headings] == false)?false:true )
56
+ @header.default_options(options)
57
+ @callbacks=RGhost::PsObject.new
58
+ @column_padding= options[:column_padding] || 0.1
59
+ @record_count=1
60
+ @data=[]
61
+ @data[0]=[]
62
+ @data_index=0
63
+ @max_stack=RGhost::Config::GS[:stack_elements]
64
+ end
65
+
66
+
67
+ # Defines properties of a column. Parameters are the same as for new,
68
+ # plus some additional ones like :format.
69
+ # * <tt>:format</tt> - Format of the data. You can format data in four
70
+ # different ways with Rghost, passing in a Symbol
71
+ # a String a Class or Proc.
72
+ #
73
+ # ==== :format Parameters type
74
+ # * Symbol - Searches for a method defined as Grid::FieldFormat::method_name
75
+ # :format => :eurodate
76
+ # * Class - A class that inherits Grid::FieldFormat::Custom with a overridden format method.
77
+ # :format => MyFormat
78
+ # * String - Formats using the same parameters used in sprintf
79
+ # :format => "%0.2f"
80
+ # * Proc - A block. In the example a text limited to 9 characters.
81
+ # :format => lambda {|s| s.gsub(/^(.{9}).*$/,'\1...')}
82
+ # ====Customizing formats
83
+ # Replace spaces with a double dash.
84
+ # class MyFormat < DataGrid::FieldFormat::Custom
85
+ # def format
86
+ # @value.to_s.gsub(/ /,'--')
87
+ # end
88
+ # end
89
+ #
90
+ # Using
91
+ #
92
+ # grid.column :title => "Name", :format => MyFormat
93
+ #
94
+ # Below, the columns with their proper formats.
95
+ #
96
+ # grid.column :title => "Code",:format => "(%d)", :width => 1
97
+ # grid.column :title => "Name", :format => MyFormat
98
+ # grid.column :title => "Date", :format => lambda {|date| date.strftime("%d/%m/%Y") }
99
+ # values=[
100
+ # [1,"Name 1", Time.now],
101
+ # [2,"Name 2", Time.now],
102
+ # [3,"Name 3", Time.now],
103
+ # [4,"Name 4", Time.now],
104
+ # [5,"Name 5", Time.now]
105
+ # ]
106
+ # grid.data(values)
107
+ # Add the Grid to a document
108
+ #
109
+ # d=Document.new
110
+ # d.set grid
111
+ # link:images/format01.png
112
+ def col(title="", options={})
113
+ if title.is_a? Hash
114
+
115
+ @header.col(title[:title],title)
116
+ else
117
+
118
+ @header.col(title,options)
119
+ end
120
+ end
121
+ #Alias for col
122
+ def column(title="", options={})
123
+ col(title,options)
124
+
125
+ end
126
+
127
+ def format_field(value,type) #:nodoc:
128
+ case type
129
+ when Symbol
130
+ RGhost::Grid::FieldFormat.send(type,value)
131
+ when String
132
+ RGhost::Grid::FieldFormat.string(type % value)
133
+ when NilClass
134
+ RGhost::Grid::FieldFormat.string(value)
135
+ when Class
136
+ type.new(value).gs_format
137
+ when Proc
138
+ RGhost::Grid::FieldFormat.string(type.call(value))
139
+
140
+ else raise TypeError.new("type=#{type}, value type=#{value.class}")
141
+ end
142
+
143
+ end
144
+ def width
145
+ @header.size
146
+ end
147
+ def proc_line(line) #:nodoc:
148
+ h=@header.data_types
149
+ rec=[]
150
+ line.each_with_index do |v,i|
151
+ #puts "#{i} == #{h[i]} = #{v}, #{format_field(v,h[i])}"
152
+ rec << format_field(v,h[i])
153
+ end
154
+ @data[@data_index] << "[#{rec.join(' ')}]\n"
155
+
156
+
157
+ if @record_count == @max_stack
158
+ @record_count=0
159
+ @data_index+=1
160
+ @data[@data_index]=[]
161
+ end
162
+ @record_count+=1
163
+
164
+
165
+ end
166
+ #Defines data to grid processor.
167
+ def data(data)
168
+
169
+ end
170
+ public
171
+
172
+ def ps
173
+
174
+
175
+ grid_names=[]
176
+ p=RGhost::PsObject.new
177
+ p.set RGhost::Variable.new(:col_padding,RGhost::Units::parse(@column_padding))
178
+ @data.each do |ary|
179
+ r=(rand*99999).to_i
180
+ p.raw "/data#{r}[\n#{ary.join('')}\n] def"
181
+ grid_names << r
182
+ end
183
+ p.raw "#{@header.ps} #{@callbacks}"
184
+
185
+ g=RGhost::Graphic.new do
186
+ raw :before_table_create
187
+ raw grid_names.map{|m| " data#{m} table_proc \n" }.join('')
188
+ raw :after_table_create
189
+ end
190
+ p.set g
191
+ p.raw :nrdp
192
+ p
193
+
194
+
195
+ end
196
+
197
+ # Grid has 3 preset styles :bottom_lines, :border_lines and
198
+ # old_forms. To set any of them, use:
199
+ #
200
+ # grid.style(:border_lines)
201
+ #
202
+ # :border_lines - instance of Grid::Style::BorderLines
203
+ #
204
+ # link:images/setstyle01.png
205
+ #
206
+ # :bottom_lines - instance of Grid::Style::BottomLines
207
+ #
208
+ # link:images/setstyle02.png
209
+ #
210
+ # :old_forms - instance of Grid::Style::OldForms
211
+ #
212
+ # link:images/setstyle03.png
213
+ def style(type=:border_lines)
214
+ st=case type
215
+ when :border_lines
216
+ RGhost::Grid::Style::BorderLines.new
217
+ when :old_forms
218
+ RGhost::Grid::Style::OldForms.new
219
+ when :bottom_lines
220
+ RGhost::Grid::Style::BottomLines.new
221
+ else raise NameError.new("Why? #{type} ?")
222
+ end
223
+
224
+ st.set_style(self)
225
+
226
+ end
227
+
228
+ end
@@ -0,0 +1,136 @@
1
+
2
+ module RGhost::Grid
3
+ # The callbacks for the grid are defined here. Let's see them in action.
4
+ # ===Grid::CallbackFacade examples
5
+ # grid=Grid::Matrix.new :column_padding => 1
6
+ # grid.column :title => "Id", :width => 1
7
+ # grid.column :title => "Name", :width => 3, :align => :center
8
+ # grid.column :title => "Date", :width => 3, :align => :right, :title_align => :center, :format => lambda{|v| v.strftime("%d/%m/%Y")}
9
+ # values=('A'..'E').to_a.map{|v| [v,"Name #{v}", Time.now]}
10
+ #
11
+ # even_row:
12
+ # grid.even_row do |e|
13
+ # e.background_row(:size => grid.width)
14
+ # end
15
+ # link:images/grid01.png
16
+ #
17
+ # Now before_row to create a top and bottom line:
18
+ # grid.before_row do |b|
19
+ # b.horizontal_line(:top, :size => grid.width )
20
+ # b.horizontal_line(:bottom, :size => grid.width)
21
+ # end
22
+ #
23
+ # link:images/grid02.png
24
+ #
25
+ # before_column:
26
+ # grid.before_column do |v|
27
+ # v.vertical_line_row
28
+ # end
29
+ #
30
+ # link:images/grid03.png
31
+ #
32
+ # after_column:
33
+ # grid.after_column {|c| c.vertical_line_row }
34
+ #
35
+ #
36
+ # link:images/grid04.png
37
+ #
38
+ # Moving to the header
39
+ # grid.header.before_create do |b|
40
+ # b.horizontal_line(:top, :size => grid.width)
41
+ # end
42
+ #
43
+ # link:images/grid05.png
44
+ #
45
+ # Finishing the grid lines:
46
+ # grid.header.before_column do |b|
47
+ # b.vertical_line_row
48
+ # end
49
+ #
50
+ #
51
+ # grid.header.after_column do |b|
52
+ # b.vertical_line_row
53
+ # end
54
+ #
55
+ # link:images/grid06.png
56
+ #
57
+ # Now a adding a bold font to the header
58
+ # grid.header.before_create do |b|
59
+ # b.horizontal_line(:top, :size => grid.width)
60
+ # b.use_tag :bold
61
+ # end
62
+ #
63
+ # link:images/grid07.png
64
+ #
65
+ # Oops. Not quite what we expected, the entire grid used bold
66
+ # face. We need to use a header callback to reset the font.
67
+ #
68
+ # grid.header.after_create do
69
+ # b.use_tag :normal
70
+ # end
71
+ #
72
+ # link:images/grid08.png
73
+ #
74
+ # Don't forget
75
+ #
76
+ # doc=Document.new
77
+ # doc.set grid
78
+ module CallbackFacade
79
+
80
+ # Executes before processing row. Responds to :only and :except
81
+ # options.
82
+ def before_row(options={},&block)
83
+ new_dynamic_callback(:before_row,options,&block)
84
+ end
85
+
86
+ # Executes on creating an odd rows. Responds to :only and :except
87
+ # options.
88
+ def odd_row(options={},&block)
89
+ new_dynamic_callback(:odd_row,options,&block)
90
+ end
91
+
92
+ # Executes upon creating even rows. Responds to :only and :except
93
+ # options.
94
+ def even_row(options={},&block)
95
+ new_dynamic_callback(:even_row,options,&block)
96
+ end
97
+
98
+ # Executes before creating a column. Responds to :only and :except
99
+ # options.
100
+ def before_column(options={},&block)
101
+ new_dynamic_callback(:before_column,options,&block)
102
+ end
103
+
104
+ # Executes after a column was created. Responds to :only and
105
+ # :except options.
106
+ def after_column(options={},&block)
107
+ new_dynamic_callback(:after_column,options,&block)
108
+ end
109
+
110
+ # Executes when creating an odd column. Responds to :only and
111
+ # :except options.
112
+ def odd_column(options={},&block)
113
+ new_dynamic_callback(:odd_column,options,&block)
114
+ end
115
+
116
+ # Executes upon creating an even column. Responds to :only and
117
+ # :except options.
118
+ def even_column(options={},&block)
119
+ new_dynamic_callback(:even_column,options,&block)
120
+ end
121
+
122
+
123
+ private
124
+
125
+ def new_dynamic_callback(name,options={},&block)
126
+ @callbacks.set RGhost::Callback.new(name,options,&block)
127
+ end
128
+ def new_static_callback(name,&block)
129
+
130
+ callback_body= RGhost::PsFacade.new(&block)
131
+ @callbacks.set RGhost::Function.new(name,callback_body)
132
+ end
133
+
134
+
135
+ end
136
+ end