lunks_rghost 0.8.7.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,252 @@
1
+ require "rghost/ps_object"
2
+ require 'rghost/font_map'
3
+
4
+ #Rghost setup with Ghostscript.
5
+ #Ghostscript runs on a variety of platforms, this is why we recommend the non coupled install for non *nix environments.
6
+ #The gem already comes with a set of defaults but you can change the settings using the Hash RGhost::Config::GS before each use of the API. Listed below are the keys of the said hash.
7
+ #===RGhost::Config::GS[:mode]
8
+ #Operating mode
9
+ #* <tt>:gsparams</tt> In this mode RGhost just pass parameters to the Ghostscript framework.
10
+ #* <tt>:gsapi</tt> based on the exchange of data between Ruby and Ghostscript via rgengine.so using gslib.so.8 or gslib-esp.so.8.
11
+ #
12
+ #===RGhost::Config::GS[:path]
13
+ #Path to the ghostscript executable.
14
+ #====Example on windows
15
+ #RGhost::Config::GS[:path] = "C:\\gs\\bin\\gswin32c.exe"
16
+ #====Example on Linux
17
+ #RGhost::Config::GS[:path] = "/usr/bin/gs"
18
+ #
19
+ #===RGhost::Config::GS[:tmpdir]
20
+ #Temporary directory
21
+ #====Example
22
+ #RGhost::Config::GS[:tmpdir] = "/tmp"
23
+ #
24
+ #===RGhost::Config::GS[:default_params]
25
+ #Allows you to add/remove options. (use with caution!)
26
+ #====Example
27
+ #RGhost::Config::GS[:default_params] << "-dSAFER"
28
+ #
29
+ #===RGhost::Config::GS[:stack_elements]
30
+ #Defines the maximum number of elements for each matrix inside postscript's internal stack, avoiding a stack overflow error..
31
+ #====Example
32
+ #RGhost::Config::GS[:stack_elements]=5000
33
+ #
34
+ #===RGhost::Config::GS[:unit]
35
+ #Set the measure units. See Units::Unit for available units.
36
+ #====Example
37
+ #RGhost::Config::GS[:unit]=Units::Cm
38
+ #
39
+ #===RGhost::Config::GS[:charset_convert]
40
+ #Ruby to PS character conversion proxy. Necessary when the source code isn't on the same encoding of the document.
41
+ #Params is a block that returns a String. The default setting is nil.
42
+ #====Example
43
+ #RGhost::Config::GS[:charset_convert]= lambda {|text| Iconv::iconv("latin1","utf8", text).to_s}
44
+ #
45
+ #===RGhost::Config::GS[:font_encoding]
46
+ #Sets the Postscript font encoding. Default: :IsoLatin
47
+ #====Example
48
+ #RGhost::Config::GS[:font_encoding]= :IsoLatin
49
+ #
50
+ #===RGhost::Config::GS[:external_encoding]
51
+ #Sets the file-in external encoding (Ruby 1.9). Affects how data will be written and
52
+ #could help when dealing with encoding conversion errors. Default: nil
53
+ #====Example
54
+ #RGhost::Config::GS[:external_encoding]= 'ascii-8bit'
55
+ #
56
+ module RGhost::Config
57
+
58
+ DEFAULT_PORTRAIT_TEMPLATE = File.join(File.dirname(__FILE__),"ps","rghost_default_template.eps")
59
+
60
+
61
+ GS={
62
+ :mode => :gsparams,
63
+ :plugin => nil,
64
+ :path => nil,
65
+ :tmpdir => ENV["TMP"] || ENV["TMPDIR"] || ENV["TEMPDIR"] || ENV["TEMP"] || "/tmp",
66
+ :pslibdir => File.join( File.dirname(__FILE__),"ps"),
67
+ :extensions => [],
68
+ :preload => [],
69
+ :default_params=> %w(gs -dNOPAUSE -dBATCH -dQUIET -dNOPAGEPROMPT),
70
+ :stack_elements => 5000,
71
+ :font_encoding => :IsoLatin,
72
+ :charset_convert => begin
73
+ if RUBY_VERSION =~ /^1.9/
74
+ lambda { |text| text.encode('ISO-8859-1', 'UTF-8') }
75
+ else
76
+ require 'iconv'
77
+ lambda { |text| Iconv::iconv('latin1','utf-8', text).join }
78
+ end
79
+ end,
80
+ :external_encoding => nil,
81
+ :fontsize => 8,
82
+ :unit => RGhost::Units::Cm
83
+ }
84
+
85
+ def self.config_platform #:nodoc:
86
+ const= 'PLATFORM'
87
+ const = "RUBY_"+const if RUBY_VERSION =~ /^1.9/
88
+ GS[:path]=case Object.const_get(const)
89
+ when /linux/ then "/usr/bin/gs"
90
+ when /darwin/ then "/opt/local/bin/gs"
91
+ when /freebsd|bsd/ then "/usr/local/bin/gs"
92
+ when /mswin/ then "C:\\gs\\bin\\gswin32\\gswin32c.exe"
93
+ end
94
+ not_found_msg="\nGhostscript not found in your environment.\nInstall it and set the variable RGhost::Config::GS[:path] with the executable.\nExample: RGhost::Config::GS[:path]='/path/to/my/gs' #unix-style\n RGhost::Config::GS[:path]=\"C:\\\\gs\\\\bin\\\\gswin32c.exe\" #windows-style\n"
95
+ raise not_found_msg unless (File.exists? GS[:path])
96
+ end
97
+
98
+ #Test if your environment is ready to works. If yes the page below will show.
99
+ #
100
+ #link:images/is_ok.png
101
+ #
102
+ #You can generate this page with the code.
103
+ # RGhost::Config.is_ok?.render :pdf, :filename => "/tmp/mytest.pdf"
104
+ #
105
+ def self.is_ok?
106
+ d=RGhost::Document.new :margin_left => 2.3, :margin_bottom => 2.3
107
+ d.benchmark(:start)
108
+ d.before_page_create do |b|
109
+ b.image RGhost::Config::DEFAULT_PORTRAIT_TEMPLATE
110
+ end
111
+ d.define_tags do
112
+ new :bigger, :size => 150, :color => "#AAFF33"
113
+ end
114
+ d.text_in :x => 6, :y=> 15, :write => "Yes!", :with => :bigger
115
+ d.text_in :x => 10, :y=> 14, :write => "Your environment is ready!"
116
+ d.text_in :x => 10, :y=> 13, :write => "RGhost Version " + RGhost::VERSION::STRING
117
+ d.text_in :x => 10, :y=> 12, :write => "Created at " + Time.at(RGhost::VERSION::DATE).to_s
118
+ d.text_in :x => 10, :y=> 11, :write => "Now " + Time.now.to_s
119
+
120
+ d.benchmark(:stop)
121
+ d.done
122
+ d
123
+
124
+
125
+
126
+ end
127
+ #This method is a helper to gets the best encoding.
128
+ #
129
+ #link:images/encode_test.png
130
+ #
131
+ #You can generate this page with the code.
132
+ # RGhost::Config.encode_teste("Fiancé").render :pdf, :filename => "/tmp/mytest.pdf"
133
+ #
134
+ #The encode will use on Document class.
135
+ # doc=Document.new :font_encoding => 'IsoLatin'
136
+ #
137
+ def self.encode_test(value)
138
+ d=RGhost::Document.new :paper => :A4, :margin_left => 2 #, :landscape => true
139
+ d.before_page_create do |b|
140
+ b.image RGhost::Config::DEFAULT_PORTRAIT_TEMPLATE
141
+ end
142
+ exp=File.join(File.dirname(__FILE__),"ps","*.enc")
143
+ d.show "String (Using Helvetica Font)", :with => :b
144
+ d.moveto :x => 16
145
+ d.show "Encode Name", :with => :b
146
+ d.horizontal_line :bottom
147
+ d.next_row
148
+
149
+ Dir.glob(exp).sort.each do |f|
150
+ name=File.basename(f)
151
+ name.gsub!(/\.enc/,'')
152
+ d.set RGhost::Load.library(name,:enc)
153
+ d.set RGhost::Variable.new(:default_encoding,name)
154
+ d.set RGhost::FontMap.new {
155
+ new(:font_test, :name => "Helvetica",:size => 8,:color => "#FF0000", :encoding => true)
156
+ }
157
+
158
+ d.show "#{value}" , :with => :font_test
159
+ d.moveto :x => 16
160
+ d.show "#{name}", :with => :i
161
+ d.next_row
162
+
163
+ end
164
+ d
165
+ end
166
+ #Generates font catalog to use into method define_tags on Document
167
+ # RGhost::Config.enviroment_fonts.render :pdf, :filename => "mycatalog.pdf"
168
+ #link:images/environment_fonts.png
169
+ #
170
+ def self.environment_fonts(text="The quick brown fox jumps over the lazy dog")
171
+
172
+ d=RGhost::Document.new :margin_left => 2.3, :margin_bottom => 2.3
173
+ d.before_page_create do |b|
174
+ b.image RGhost::Config::DEFAULT_PORTRAIT_TEMPLATE
175
+ end
176
+ d.show "Search Path"
177
+ d.horizontal_line :bottom
178
+ d.next_row
179
+ d.raw :default_font
180
+ d.raw %Q{
181
+ LIBPATH{
182
+ limit_left current_row moveto show
183
+ nrdp
184
+ } forall
185
+
186
+ }
187
+ d.next_row
188
+ d.show "Example"
189
+ d.moveto :x=> 13
190
+ d.show "Font Name"
191
+ d.horizontal_line :bottom
192
+ d.next_row
193
+ #=begin
194
+ d.raw %Q{
195
+ Fontmap{
196
+ 50 string cvs pop dup findfont 10 scalefont setfont
197
+ limit_left current_row moveto (#{text}) show
198
+ 13 cm current_row moveto default_font 0 setgray
199
+ 50 string cvs show
200
+ nrdp
201
+ } forall
202
+ }
203
+ #=end
204
+ d.done
205
+ d
206
+ end
207
+
208
+ # .
209
+ #
210
+ #
211
+ #Preseted tags
212
+ #
213
+ #
214
+ #
215
+ #FONTMAP=RGhost::FontMap.new :name => "Helvetica", :size => 8, :encoding => false do
216
+ # new :span
217
+ # new :b, :name => "Helvetica-Bold"
218
+ # new :bold, :name => "Helvetica-Bold"
219
+ # new :normal, :name => "Helvetica"
220
+ # new :i, :name => "Helvetica-Oblique", :size => 8
221
+ # new :bi, :name => "Helvetica-BoldOblique"
222
+ # new :big, :size => 10
223
+ # new :small, :size => 7
224
+ # new :h1, :name => "Helvetica", :size => 14
225
+ # new :h2, :name => "Helvetica", :size => 13
226
+ # new :h3, :name => "Helvetica", :size => 12
227
+ # new :h4, :name => "Helvetica", :size => 11
228
+ # new :h5, :name => "Helvetica", :size => 10
229
+ # new :title, :name => "Helvetica", :size => 20
230
+ # new :pre, :name => "Courier"
231
+ # end
232
+ #
233
+ FONTMAP=RGhost::FontMap.new :name => "Helvetica", :size => 8, :encoding => true do
234
+ new :span
235
+ new :b, :name => "Helvetica-Bold"
236
+ new :bold, :name => "Helvetica-Bold"
237
+ new :normal, :name => "Helvetica"
238
+ new :i, :name => "Helvetica-Oblique", :size => 8
239
+ new :bi, :name => "Helvetica-BoldOblique"
240
+ new :big, :size => 10
241
+ new :small, :size => 7
242
+ new :h1, :name => "Helvetica", :size => 14
243
+ new :h2, :name => "Helvetica", :size => 13
244
+ new :h3, :name => "Helvetica", :size => 12
245
+ new :h4, :name => "Helvetica", :size => 11
246
+ new :h5, :name => "Helvetica", :size => 10
247
+ new :title, :name => "Helvetica", :size => 20
248
+ new :pre, :name => "Courier"
249
+ end
250
+
251
+ end
252
+
@@ -0,0 +1,174 @@
1
+ require 'rghost/ruby_ghost_config'
2
+ require "rghost/constants"
3
+
4
+ class RGhost::Engine
5
+ attr_reader :errors, :error, :output
6
+ DEFAULT_OPTIONS={:device => :pdf }
7
+
8
+ include RGhost::Constants::Devices
9
+
10
+ def initialize(document,options={})
11
+ @document=document
12
+ @options=DEFAULT_OPTIONS.merge(options)
13
+ @errors=[]
14
+ @error=false
15
+ @output=nil
16
+ @delete_input=true
17
+
18
+ end
19
+
20
+
21
+ def render(device=nil)
22
+
23
+ device||=@options[:device]
24
+ tmp_filename=@options[:filename]
25
+ unless tmp_filename
26
+ tmp_filename||="#{RGhost::Config::GS[:tmpdir]}#{File::SEPARATOR}#{self.object_id.abs}"
27
+ file_out="#{tmp_filename}.#{device}"
28
+ else
29
+ file_out=tmp_filename
30
+ end
31
+ external_encoding = RGhost::Config::GS[:external_encoding]
32
+
33
+ file_err="#{tmp_filename}.rgerr"
34
+
35
+ multipage=@options[:multipage]
36
+ file_out.gsub!(/^(.*)\./,'\1_%04d.') if multipage
37
+
38
+ params=RGhost::Config::GS[:default_params].dup #default parameters gs engine
39
+ params << @document.additional_params.join(" ") unless @options[:convert]
40
+ params << "-I#{RGhost::Config::GS[:pslibdir]}"
41
+ params << "-dPDFSETTINGS=/#{@options[:quality]}" if (@options[:device] ==:pdf && @options[:quality])
42
+ params << "-I#{RGhost::Config::GS[:extensions].join(' -I')}" if RGhost::Config::GS[:extensions]
43
+ params << "-sDEVICE=#{device_for(device)}"
44
+ params.concat format_params(@options[:d],"-d") if @options[:d]
45
+ params.concat format_params(@options[:s],"-s") if @options[:s]
46
+ params << "-r#{@options[:resolution]}" if @options[:resolution]
47
+ params << "-g#{@options[:size]}" if @options[:size]
48
+ if @options[:range]
49
+ params << "-dFirstPage=#{@options[:range].first}"
50
+ params << "-dLastPage=#{@options[:range].last}"
51
+ end
52
+ params << "-sstdout=#{file_err}"
53
+ params << @options[:raw] if @options[:raw]
54
+ params << "-sOutputFile=#{file_out}"
55
+
56
+
57
+ case @document
58
+ when RGhost::Document
59
+ file_in="#{tmp_filename}.rgin"
60
+ params.concat @document.gs_paper
61
+ mode=external_encoding.nil? ? 'w' : "w:#{external_encoding}"
62
+ fi=File.open(file_in,mode)
63
+ fi.puts @document.ps
64
+ fi.close
65
+ when File
66
+ file_in=@document.path
67
+ #@delete_input=false unless @options[:debug]
68
+ when String
69
+ file_in=@document
70
+ #@delete_input=false unless @options[:debug]
71
+ end
72
+
73
+ params << shellescape(file_in)
74
+
75
+ #puts params.inspect
76
+
77
+ if RGhost::Config::GS[:mode] == :gslib
78
+ require "rghost/rgengine"
79
+ gs=RGEngine.new
80
+ @error=!gs.render(params,params.size)
81
+ else
82
+ require 'rghost/gs_alone'
83
+ gs=RGhost::GSAlone.new(params,@options[:debug])
84
+ @error=!gs.run
85
+ end
86
+
87
+ if @error # if error
88
+ @errors=File.open(file_err).readlines if File.exists?(file_err)
89
+ else
90
+ if multipage
91
+ file_out.gsub!(/_%04d/,"_*")
92
+ @output=Dir.glob(file_out).map { |f| f }
93
+ else
94
+ @output=File.open(file_out)
95
+ end
96
+ end
97
+ begin
98
+ File.delete(file_err)
99
+ File.delete(file_in) unless (@options[:debug] || @options[:convert])
100
+ rescue
101
+ end
102
+ log(params) if @options[:logfile]
103
+ return @output
104
+ end
105
+
106
+ def clear_output
107
+ case @output
108
+ when File
109
+ @output.close
110
+ File.delete(@output.path)
111
+ when Array
112
+ @output.each do |f|
113
+ f.close
114
+ File.delete(f.path)
115
+ end
116
+ end
117
+ end
118
+ def error?
119
+ @error
120
+ end
121
+ private
122
+ def log(gp)
123
+ id=self.object_id.abs
124
+ flog=File.open(@options[:logfile], File::WRONLY|File::APPEND|File::CREAT)
125
+ flog.puts "[ID #{id}] created on #{Time.now}"
126
+ flog.puts "[#{id}] RUBY GS OPTIONS: #{@options.inspect}"
127
+ flog.puts "[#{id}] GS OPTIONS: #{gp.join(" ")}"
128
+ if @error
129
+ flog.puts "[#{id}] EXIT STATUS: ERROR"
130
+ flog.puts @errors.uniq.map {|m| "[#{id}] #{m}" }.to_s;
131
+ else
132
+ flog.puts "[#{id}] EXIT STATUS: OK"
133
+ end
134
+ end
135
+
136
+
137
+ def format_params(v,pre="-d")
138
+ r=[]
139
+ case v
140
+ when Symbol
141
+ r << "#{pre}#{v}"
142
+ when Array
143
+ v.each do |av|
144
+ r << format_params(av,pre).to_s
145
+ end
146
+ when Hash
147
+ v.each do |k,v|
148
+ r << "#{pre}#{k}=#{v.to_s.gsub(/ /,'')}"
149
+ end
150
+ else
151
+ return ""
152
+ end
153
+ return r;
154
+ end
155
+
156
+ def shellescape(str)
157
+ # An empty argument will be skipped, so return empty quotes.
158
+ return "''" if str.empty?
159
+
160
+ str = str.dup
161
+
162
+ # Process as a single byte sequence because not all shell
163
+ # implementations are multibyte aware.
164
+ str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/n, "\\\\\\1")
165
+
166
+ # A LF cannot be escaped with a backslash because a backslash + LF
167
+ # combo is regarded as line continuation and simply ignored.
168
+ str.gsub!(/\n/, "'\n'")
169
+
170
+ return str
171
+ end
172
+
173
+ end
174
+
@@ -0,0 +1,8 @@
1
+ module RGhost::VERSION #:nodoc:
2
+ MAJOR = 0
3
+ MINOR = 8
4
+ TINY = 7
5
+ DATE=1244286414
6
+ STRING = [MAJOR, MINOR, TINY].join('.')
7
+
8
+ end
@@ -0,0 +1,78 @@
1
+ #Converts Ruby types to Postscript types
2
+ module RGhost::RubyToPs
3
+
4
+
5
+ def to_string(value)
6
+ #ps escape
7
+ value=pack_string(value)
8
+ ps_str=ps_escape(value)
9
+
10
+ "(#{ps_str}) "
11
+
12
+ end
13
+
14
+ def pack_string(s)
15
+ if RGhost::Config::GS[:charset_convert]
16
+ RGhost::Config::GS[:charset_convert].call(s.to_s).to_s
17
+ else
18
+ s
19
+ end
20
+ end
21
+
22
+
23
+ def ps_escape(value)
24
+ #value.to_s.gsub(/\(/,'\\(').gsub(/\)/,"\\)").gsub(/\\/,"\134")
25
+ value.to_s.gsub(/(\(|\)|\\)/,'\\\\\1')
26
+ end
27
+
28
+ def to_bool(value)
29
+ value ? "true":"false"
30
+ end
31
+
32
+ def to_string_array(arr)
33
+
34
+ "[#{arr.map{|a| to_string(a.to_s) }}] "
35
+ end
36
+
37
+ def to_array(arr)
38
+ return "[ ]" unless arr
39
+ ps_arr=[]
40
+ arr.each do |a|
41
+ ps_arr << case a
42
+ when TrueClass,FalseClass then to_bool(a)
43
+ when Numeric then a
44
+ when Proc then a.to_s
45
+ when Array then to_array(a)
46
+ else
47
+ to_string(a.to_s)
48
+ end
49
+ end
50
+ "[#{ps_arr.join(' ')}] "
51
+ end
52
+
53
+ def hash_to_array(hash)
54
+ to_string_array(hash.values)
55
+ end
56
+
57
+ def array_to_stack(arr)
58
+ "#{arr.join(' ')} "
59
+ end
60
+
61
+ def string_eval(str)
62
+ str=pack_string(str)
63
+ return "(#{ps_escape(str)}) show " unless str =~ /%/
64
+
65
+ s=str.scan(/([^%][a-z]*[^%]|\d+%?)|(%[^\s%]+%)/).flatten.compact
66
+ #puts s
67
+ tudo=""
68
+ s.each do |v|
69
+ case v
70
+ when /^%/ then tudo << "#{v.gsub(/%/,'')} to_s show "
71
+ else
72
+ tudo << "(#{ps_escape(v)}) show "
73
+ end
74
+ end
75
+ tudo
76
+ end
77
+ end
78
+
@@ -0,0 +1,29 @@
1
+ require "rghost/ps_object"
2
+ #Scales objects
3
+
4
+ class RGhost::Scale < RGhost::PsObject
5
+ #===Examples
6
+ # doc.scale(1,1) #default document scale
7
+ #
8
+ #link:images/scale01.png
9
+ #
10
+ # doc.scale(1,3)
11
+ #
12
+ #link:images/scale02.png
13
+ #
14
+ # doc.scale(3,3)
15
+ #
16
+ #link:images/scale03.png
17
+ def initialize(sx,sy)
18
+ super("#{sx} #{sy} scale")
19
+ end
20
+ #Scale proportionally by value in percent
21
+ #===Example
22
+ # doc.zoom(300) # 300% the same that scale(3,3)
23
+ def self.zoom(value=100)
24
+
25
+ RGhost::Scale.new(value/100.0,value/100.0)
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,23 @@
1
+ #Responsible for fill shapes
2
+ class RGhost::ShapeContent < RGhost::PsObject
3
+
4
+ DEFAULT_OPTIONS={
5
+ :fill => true, :color => "#F0FFFF"
6
+
7
+ }
8
+ #You can use parameter :color(facade for Color.create) or disable using :fill => false
9
+ def initialize(options={})
10
+ super(""){}
11
+ @options = DEFAULT_OPTIONS.dup.merge(options)
12
+ end
13
+
14
+ def ps
15
+ p=RGhost::PsObject.new
16
+ p.raw :gsave
17
+ p.set RGhost::Color.create(@options[:color]) if @options[:color]
18
+ p.raw :fill if @options[:fill]
19
+ p.raw :grestore
20
+ p
21
+ end
22
+
23
+ end
@@ -0,0 +1,88 @@
1
+ require "rghost/ps_object"
2
+ require "rghost/ruby_to_ps" #to_string
3
+
4
+ #Writes a text on the current row or point with align.
5
+ class RGhost::Show < RGhost::PsObject
6
+
7
+ attr_accessor :text, :align, :tag
8
+ DEFAULT_OPTIONS={:tag => :default_font, :align => :show_left}
9
+ include RGhost::RubyToPs
10
+ #===Options
11
+ #
12
+ #* <tt>:tag or :with</tt> - Use predefined tag
13
+ #* <tt>:color</tt> - Override color of the tag
14
+ #* <tt>:align</tt> - Align of the text
15
+ #===Examples
16
+ #The vertical line is the current point. For align by point
17
+ # doc.moveto :x => 3, :y => 4
18
+ # doc.show "Foo Bar Baz", :align => :show_left #default
19
+ #link:images/show01.png
20
+ #
21
+ # doc.moveto :x => 3, :y => 4
22
+ # doc.show "Foo Bar Baz", :align => :show_center
23
+ #link:images/show02.png
24
+ #
25
+ # doc.moveto :x => 3, :y => 4
26
+ # doc.show "Foo Bar Baz", :align => :show_right
27
+ #link:images/show03.png
28
+ #
29
+ #For the the current row it's not necessary positioned using moveto. Like below
30
+ # doc.show "Foo Bar Baz", :align => :show_right
31
+ #Now justification in page
32
+ #
33
+ # doc.show "Foo Bar Baz", :align => :page_left
34
+ #
35
+ #link:images/show04.png
36
+ #
37
+ # doc.show "Foo Bar Baz", :align => :page_center
38
+ #
39
+ #link:images/show05.png
40
+ #
41
+ # doc.show "Foo Bar Baz", :align => :page_right
42
+ #
43
+ #link:images/show06.png
44
+ #
45
+ #====Overrinding tag's color
46
+ #
47
+ # doc.show "Foo Bar Baz", :with => :my_italic, :align => :page_center, :color => :red
48
+ #
49
+ #link:images/show07.png
50
+ #
51
+ #Many tags per row
52
+ # doc=Document.new
53
+ # doc.define_tags do
54
+ # tag :font1, :name => 'Helvetica', :size => 10, :color => '#F34811'
55
+ # tag :font2, :name => 'Times', :size => 14, :color => '#A4297A'
56
+ # tag :font3, :name => 'TimesBold', :size => 18, :color => '#AA3903'
57
+ # end
58
+ #
59
+ # doc.show "foo bar baz ", :with => :font1
60
+ # doc.show "qux quux ", :with => :font2
61
+ # doc.show "corge ", :with => :font3
62
+ # doc.show "grault garply ",:with => :font2
63
+ # doc.show "qux quux", :with => :font1
64
+ #
65
+ #link:images/show08.png
66
+
67
+
68
+
69
+ def initialize(text,options={ :align=>:show_left, :tag => :default_font, :color => 0 } )
70
+ @text = text
71
+ @options=DEFAULT_OPTIONS.dup.merge(options)
72
+ end
73
+
74
+ def ps
75
+ rtext=RGhost::PsObject.new
76
+ #rtext.raw Color.create(@options[:color] || 0)
77
+ if @options[:with] || @options[:tag]
78
+ f="_#{@options[:with] || @options[:tag]}"
79
+ rtext.raw f
80
+ end
81
+ rtext.raw RGhost::Color.create(@options[:color]) if @options[:color]
82
+ rtext.raw to_string(@text)
83
+ rtext.raw @options[:align]
84
+
85
+ rtext.graphic_scope
86
+ end
87
+
88
+ end
@@ -0,0 +1,18 @@
1
+ require "rghost/ps_object"
2
+ require 'rghost/function'
3
+
4
+ class RGhost::StaticDocumentCallback < RGhost::Function #:nodoc:
5
+ ACCEPT=[:before_document_create,
6
+ :first_page,
7
+ :last_page,
8
+ :after_document_create
9
+ ]
10
+
11
+ def initialize(name,&block)
12
+ raise NameError.new("#{name} no accept in #{self.class}") unless ACCEPT.include? name
13
+ super(name,&block)
14
+ end
15
+
16
+
17
+ end
18
+