rghost 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. data/History.txt +4 -0
  2. data/Manifest.txt +101 -0
  3. data/README.txt +3 -0
  4. data/Rakefile +93 -0
  5. data/lib/rghost.rb +3 -0
  6. data/lib/rghost/arc.rb +39 -0
  7. data/lib/rghost/barcode.rb +40 -0
  8. data/lib/rghost/callback.rb +55 -0
  9. data/lib/rghost/color.rb +118 -0
  10. data/lib/rghost/constants.rb +616 -0
  11. data/lib/rghost/convert.rb +24 -0
  12. data/lib/rghost/cursor.rb +82 -0
  13. data/lib/rghost/data_grid/basic_grid.rb +136 -0
  14. data/lib/rghost/data_grid/csv_grid.rb +27 -0
  15. data/lib/rghost/data_grid/data_grid.rb +14 -0
  16. data/lib/rghost/data_grid/dynamic_callback.rb +12 -0
  17. data/lib/rghost/data_grid/field_format.rb +60 -0
  18. data/lib/rghost/data_grid/grid.rb +18 -0
  19. data/lib/rghost/data_grid/header.rb +111 -0
  20. data/lib/rghost/data_grid/rails_grid.rb +37 -0
  21. data/lib/rghost/data_grid/static_callback.rb +13 -0
  22. data/lib/rghost/data_grid/style/border_lines.rb +47 -0
  23. data/lib/rghost/data_grid/style/bottom_lines.rb +30 -0
  24. data/lib/rghost/data_grid/style/old_forms.rb +30 -0
  25. data/lib/rghost/data_grid/style/style.rb +8 -0
  26. data/lib/rghost/document.rb +380 -0
  27. data/lib/rghost/dsc_entry.rb +20 -0
  28. data/lib/rghost/dynamic_document_callback.rb +27 -0
  29. data/lib/rghost/eps.rb +22 -0
  30. data/lib/rghost/font.rb +52 -0
  31. data/lib/rghost/function.rb +36 -0
  32. data/lib/rghost/gif.rb +28 -0
  33. data/lib/rghost/graphic.rb +28 -0
  34. data/lib/rghost/gs_alone.rb +17 -0
  35. data/lib/rghost/helpers.rb +13 -0
  36. data/lib/rghost/horizontal_line.rb +29 -0
  37. data/lib/rghost/image.rb +26 -0
  38. data/lib/rghost/jpeg.rb +26 -0
  39. data/lib/rghost/line.rb +40 -0
  40. data/lib/rghost/line_width.rb +17 -0
  41. data/lib/rghost/load.rb +37 -0
  42. data/lib/rghost/newpath.rb +20 -0
  43. data/lib/rghost/paper.rb +88 -0
  44. data/lib/rghost/point.rb +22 -0
  45. data/lib/rghost/point_with_command.rb +17 -0
  46. data/lib/rghost/ps/basic.ps +14 -0
  47. data/lib/rghost/ps/begin_document.ps +7 -0
  48. data/lib/rghost/ps/callbacks.ps +146 -0
  49. data/lib/rghost/ps/code128.font +344 -0
  50. data/lib/rghost/ps/code39.font +195 -0
  51. data/lib/rghost/ps/cursor.ps +41 -0
  52. data/lib/rghost/ps/datagrid.ps +52 -0
  53. data/lib/rghost/ps/ean.font +150 -0
  54. data/lib/rghost/ps/eps.ps +42 -0
  55. data/lib/rghost/ps/font.ps +31 -0
  56. data/lib/rghost/ps/functions.ps +646 -0
  57. data/lib/rghost/ps/gif.ps +150 -0
  58. data/lib/rghost/ps/horizontal_line.ps +3 -0
  59. data/lib/rghost/ps/i25.font +103 -0
  60. data/lib/rghost/ps/jpeg.ps +122 -0
  61. data/lib/rghost/ps/paper.ps +8 -0
  62. data/lib/rghost/ps/rectangle.ps +5 -0
  63. data/lib/rghost/ps/row.ps +4 -0
  64. data/lib/rghost/ps/show.ps +20 -0
  65. data/lib/rghost/ps/table_callbacks.ps +96 -0
  66. data/lib/rghost/ps/textarea.ps +11 -0
  67. data/lib/rghost/ps/type.ps +1 -0
  68. data/lib/rghost/ps/unit.ps +3 -0
  69. data/lib/rghost/ps/vertical_line.ps +14 -0
  70. data/lib/rghost/ps_object.rb +51 -0
  71. data/lib/rghost/rectangle.rb +39 -0
  72. data/lib/rghost/rgengine.so +0 -0
  73. data/lib/rghost/rghost.rb +3 -0
  74. data/lib/rghost/ruby_ghost_config.rb +25 -0
  75. data/lib/rghost/ruby_ghost_engine.rb +175 -0
  76. data/lib/rghost/ruby_to_ps.rb +92 -0
  77. data/lib/rghost/scale.rb +14 -0
  78. data/lib/rghost/show.rb +31 -0
  79. data/lib/rghost/static_document_callback.rb +22 -0
  80. data/lib/rghost/text_in.rb +29 -0
  81. data/lib/rghost/textarea.rb +115 -0
  82. data/lib/rghost/units.rb +81 -0
  83. data/lib/rghost/variable.rb +12 -0
  84. data/lib/rghost/version.rb +9 -0
  85. data/lib/rghost/vertical_line.rb +29 -0
  86. data/scripts/txt2html +67 -0
  87. data/setup.rb +1585 -0
  88. data/test/test_helper.rb +2 -0
  89. data/test/test_rghost.rb +11 -0
  90. data/website/index.html +11 -0
  91. data/website/index.txt +30 -0
  92. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  93. data/website/stylesheets/screen.css +129 -0
  94. data/website/template.rhtml +48 -0
  95. metadata +145 -0
@@ -0,0 +1,11 @@
1
+ /textarea_defaults {
2
+ /space ( ) def
3
+ /spacecount { 0 exch ( ) { search { pop 3 -1 roll 1 add 3 1 roll } { pop exit } ifelse } loop } def
4
+ /ssp { space search pop } def
5
+ /dsp { dup stringwidth pop } def
6
+ /cpp { currentpoint pop } def
7
+ /S { dup spacecount {ssp dsp cpp add rm gt { L s s }{ s s } ifelse } repeat pop } def
8
+ /n { show newline } def /s { show } def /L { newline } def
9
+ /centre { dup stringwidth pop 2 div rm 2 div exch sub lm add tm moveto } def
10
+ /c{ centre n} def
11
+ } def
@@ -0,0 +1 @@
1
+ %!
@@ -0,0 +1,3 @@
1
+ /cm { 72 mul 2.545 div } def
2
+ /inch{ 72 mul } def
3
+ /unit{ cm } def
@@ -0,0 +1,14 @@
1
+ /vertical_line{ exch gsave current_row moveto 0 exch neg rlineto stroke grestore } def
2
+ /vlr {
3
+ gsave
4
+ 0 row_height rlineto
5
+ stroke
6
+ grestore
7
+ } def
8
+ /vlrf {
9
+ gsave
10
+ X Y row_padding sub moveto
11
+ 0 row_height row_padding add rlineto
12
+ stroke
13
+ grestore
14
+ } def
@@ -0,0 +1,51 @@
1
+ #Wrapper Postscript
2
+ class PsObject
3
+ #PS_VERSION=3
4
+ #Nova inst�ncia de PsObject
5
+ # PsObject.new("/my_proc { 33 45 2 10 sub mul div} bind def")
6
+ #Por bloco
7
+ # PsObject.new do
8
+ # set PsObject.new("(A test) show")
9
+ # raw "(Other Test in raw) show "
10
+ # end
11
+ def initialize(body="",&block)
12
+ @body=if body.is_a? PsObject
13
+ body.ps
14
+ else
15
+ "#{body} "
16
+ end
17
+
18
+ instance_eval(&block) if block
19
+
20
+ end
21
+ #Idem ps
22
+ def to_s
23
+ ps
24
+ end
25
+ #Obtem os comandos em Postscript
26
+ def ps
27
+ @body.to_s
28
+ end
29
+ #Adiciona comando postscript diretamenta na pilha
30
+ def raw(value)
31
+ @body << "#{value} "
32
+ end
33
+ #Seta um PsObject na pilha
34
+ def set(value)
35
+
36
+ raise TypeError.new("can't convert #{value.class} into PsObject") unless value.is_a? PsObject
37
+ @body << "#{value.ps} "
38
+
39
+ end
40
+ #Idem de set, n�o funciona dentro de blocos
41
+ def <<(value)
42
+ set value
43
+
44
+ end
45
+
46
+ #chama um comando,fun��o ou valor internamento dentro da pilha Postscipt
47
+ def call(name)
48
+ set PsObject.new(name)
49
+ end
50
+
51
+ end
@@ -0,0 +1,39 @@
1
+ require "ps_object"
2
+ require "units"
3
+ require "color"
4
+ #Respons�vel pela cria��o de ret�ngulos
5
+ class Rectangle < PsObject
6
+ DEFAULT_OPTIONS={:fill => false, :x => :limit_left, :y=> :current_row, :width => :area_x, :height => :row_height}
7
+ BACKGROUND_ROW_DEFAULT_OPTIONS={:start_in => :limit_left, :size => :area_x, :color => Gray.new(0.95)}
8
+ #Nova inst�ncia de Rectangle.
9
+ # Retangle.new(:x => 1, :y => 5, :height => 5, :width => 5) #um quadrado
10
+ #O Rectangle desenha apenas as bordas(default) mas pode-se utilizar :fill => true para preenche-lo.
11
+ # Retangle.new(:x => 1, :y => 5, :width => 3, :fill => true )
12
+ def initialize(options={})
13
+ @options=DEFAULT_OPTIONS.dup.merge(options)
14
+ end
15
+
16
+ def ps
17
+ x,y=@options[:x], @options[:y]
18
+ w,h,=@options[:width], @options[:height]
19
+ #with parse
20
+ x,y=Units::parse(x),Units::parse(y)
21
+ w,h=Units::parse(w),Units::parse(h)
22
+ cmd=@options[:fill] ? :fill : :stroke
23
+ "#{x} #{y} #{w} #{h} rect#{cmd}"
24
+ end
25
+
26
+ #Desenha um ret�ngulo ao fundo da faixa corrente
27
+ # Rectangle.background_row(:start_in => 2, :size => 10, :color => Color.create("FFAAFF"))
28
+ #Default
29
+ # Rectangle.background_row(:start_in => :limit_left, :size => :area_x, :color => Gray.new(0.95))
30
+ #O mesmo que
31
+ # Rectangle.background_row
32
+ def Rectangle.background_row(options={})
33
+ opts=BACKGROUND_ROW_DEFAULT_OPTIONS.merge(options)
34
+ start_in,size=Units::parse(opts[:start_in]),Units::parse(opts[:size])
35
+ return PsObject.new("#{start_in} #{size} {#{opts[:color]}} background_row ")
36
+
37
+ end
38
+
39
+ end
Binary file
@@ -0,0 +1,3 @@
1
+ $LOAD_PATH << File.dirname(__FILE__)+File::SEPARATOR+"rghost"
2
+ require 'document'
3
+ require 'data_grid/data_grid'
@@ -0,0 +1,25 @@
1
+ require "ps_object"
2
+
3
+
4
+ module RubyGhostConfig
5
+ GS={
6
+ :mode => :gsparams,
7
+ :path => "/usr/bin/gs",
8
+ :tmpdir => ENV["TMP"] || ENV["TMPDIR"] || ENV["TEMPDIR"] || ENV["TEMP"] || "/tmp",
9
+ :pslibdir => File.dirname(__FILE__)+File::SEPARATOR+"ps",
10
+ :default_params=> %w(gs -dNOPAUSE -dBATCH -dQUIET -dNOPAGEPROMPT),
11
+ :stack_elements => 50,
12
+ :unit => Units::Cm
13
+ }
14
+
15
+
16
+
17
+ def RubyGhostConfig.config_platform
18
+
19
+ GS[:path]=case PLATFORM
20
+ when /linux|darwin|freebsd/: "/usr/bin/gs"
21
+ when /mswin/: "C:\\gs\\bin\\gswin32\\gswin32c.exe"
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,175 @@
1
+ require 'ruby_ghost_config'
2
+ require "constants"
3
+ #Motor do RubyGhost. Trata parametros e arquivos tempor�rios para a compila��o do Postscript.
4
+ #
5
+ class RubyGhostEngine
6
+ attr_reader :errors, :error, :output
7
+ DEFAULT_OPTIONS={:device => :pdf }
8
+
9
+ include Constants::Devices
10
+ #Nova inst�ncia de RubyGhostEngine
11
+ # d=Document.new
12
+ # rge=RubyGhostEngine.new(d, :logfile => "/var/log/rgengine.log")
13
+ # img=rge.render(:gif)
14
+ # if rge.error
15
+ # puts rge.errors
16
+ # else
17
+ # FileUtils.cp(img,"/local/my/dir/")
18
+ # end
19
+ def initialize(document,options={})
20
+ @document=document
21
+ @options=DEFAULT_OPTIONS.merge(options)
22
+ @errors=[]
23
+ @error=false
24
+ @output=nil
25
+ @delete_input=true
26
+
27
+ end
28
+
29
+ #Renderiza o documento.
30
+ #Valores v�lidos para options.
31
+ #
32
+ # :logfile => "/var/log/rghost.log"
33
+ # :multipage=> true # Para imagens em v�rios arquivos
34
+ # :resolution => 72 # Resolu��o
35
+ # :size => "200x180" # Para crop da imagem de sa�da
36
+ # :range =>2..3 # Range de p�ginas(PDF only)
37
+ #Array contendo um Hash para op��es em modo raw do Ghostscript :d ou :s
38
+ # :s => [{:GenericResourceDir, :DEFAULTPAPERSIZE=> "a3"}]
39
+ # :d => [ {:TextAlphaBits => 2} ]
40
+ #
41
+ #Exemplo:
42
+ # d=Document.new
43
+ # #fa�a o documento ....
44
+ #
45
+ # d.render :pdf # Sa�da em pdf
46
+ # d.render :jpeg # Sa�da em jpeg
47
+ # d.render :png, :multipage => true # Uma imagem por arquivo
48
+ # d.render :tiff, :resolution => 300 # Imagem com resolu��o de 300 dpi
49
+ def render(device=nil)
50
+ puts @options.inspect
51
+ device||=@options[:device]
52
+ tmp_filename=@options[:filename]
53
+ unless tmp_filename
54
+ tmp_filename||="#{RubyGhostConfig::GS[:tmpdir]}#{File::SEPARATOR}#{self.object_id.abs}"
55
+ file_out="#{tmp_filename}.#{device}"
56
+ else
57
+ file_out=tmp_filename
58
+ end
59
+ puts file_out
60
+ file_err="#{tmp_filename}.rgerr"
61
+
62
+ multipage=@options[:multipage]
63
+ file_out.gsub!(/\./,"_%04d.") if multipage
64
+
65
+ params=RubyGhostConfig::GS[:default_params].dup #default parameters gs engine
66
+ params << "-I#{RubyGhostConfig::GS[:pslibdir]}"
67
+ params << "-sDEVICE=#{device_for(device)}"
68
+ params.concat format_params(@options[:d],"-d") if @options[:d]
69
+ params.concat format_params(@options[:s],"-s") if @options[:s]
70
+ params << "-r#{@options[:resolution]}" if @options[:resolution]
71
+ params << "-g#{@options[:size]}" if @options[:size]
72
+ if @options[:range]
73
+ params << "-dFirstPage=#{@options[:range].first}"
74
+ params << "-dLastPage=#{@options[:range].last}"
75
+ end
76
+ params << "-sstdout=#{file_err}"
77
+ params << @options[:raw] if @options[:raw]
78
+ params << "-sOutputFile=#{file_out}"
79
+
80
+
81
+ case @document
82
+ when Document:
83
+ file_in="#{tmp_filename}.rgin"
84
+ params.concat @document.gs_paper
85
+ fi=File.open(file_in,'w')
86
+ fi.puts @document.ps
87
+ fi.close
88
+ when File:
89
+ file_in=@document.path
90
+ @delete_input=false
91
+ when String:
92
+ file_in=@document
93
+ @delete_input=false
94
+ end
95
+
96
+
97
+
98
+
99
+ params << file_in
100
+
101
+
102
+ puts params.inspect
103
+
104
+ if RubyGhostConfig::GS[:mode] == :gslib
105
+ require "rgengine"
106
+ gs=RGEngine.new
107
+ @error=!gs.render(params,params.size)
108
+ else
109
+ require 'gs_alone'
110
+ gs=GSAlone.new(params)
111
+ @error=!gs.run
112
+ end
113
+
114
+ if @error # if error
115
+ @errors=File.open(file_err).readlines
116
+ else
117
+ if multipage
118
+ file_out.gsub!(/_%04d/,"_*")
119
+ @output=Dir.glob(file_out).map { |f| File.open(f) }
120
+ else
121
+ @output=File.open(file_out)
122
+ end
123
+ end
124
+ File.delete(file_err)
125
+ File.delete(file_in) if @delete_input
126
+
127
+ log(params) if @options[:logfile]
128
+ return @output
129
+ end
130
+
131
+ def clear_output
132
+ case @output
133
+ when File: File.delete(@output.path)
134
+ when Array: @output.each {|f| File.delete(f.path)}
135
+ end
136
+ end
137
+
138
+ private
139
+ def log(gp)
140
+ id=self.object_id.abs
141
+ flog=File.open(@options[:logfile], File::WRONLY|File::APPEND|File::CREAT)
142
+ flog.puts "[ID #{id}] created on #{Time.now}"
143
+ flog.puts "[#{id}] RUBY GS OPTIONS: #{@options.inspect}"
144
+ flog.puts "[#{id}] GS OPTIONS: #{gp.join(" ")}"
145
+ if @error
146
+ flog.puts "[#{id}] EXIT STATUS: ERROR"
147
+ flog.puts @errors.uniq.map {|m| "[#{id}] #{m}" }.to_s;
148
+ else
149
+ flog.puts "[#{id}] EXIT STATUS: OK"
150
+ end
151
+ end
152
+
153
+
154
+ def format_params(v,pre="-d")
155
+ r=[]
156
+ case v
157
+ when Symbol:
158
+ r << "#{pre}#{v}"
159
+ when Array:
160
+ v.each do |av|
161
+ r << format_params(av,pre).to_s
162
+ end
163
+ when Hash:
164
+ v.each do |k,v|
165
+ r << "#{pre}#{k}=#{v.to_s.gsub(/ /,'')}"
166
+ end
167
+ else
168
+ return ""
169
+ end
170
+ return r;
171
+ end
172
+
173
+ end
174
+
175
+
@@ -0,0 +1,92 @@
1
+ #Modulo de convers�o e tratamento de valores de Ruby para Postscript
2
+ module RubyToPs
3
+
4
+ #Converte uma string Ruby para string Postscript
5
+ def to_string(value)
6
+ #ps escape
7
+ ps_str=ps_escape(value)
8
+ "(#{ps_str}) "
9
+
10
+ end
11
+ #Escapa ( e ) para string postscript
12
+ def ps_escape(value)
13
+ value.to_s.gsub(/(\(|\))/,'\\\\\1')
14
+ end
15
+ #Converte para ps bool
16
+ def to_bool(value)
17
+ value ? "true":"false"
18
+ end
19
+ #Converte para um array de string ps
20
+ def to_string_array(arr)
21
+
22
+ "[#{arr.map{|a| to_string(a.to_s) }}] "
23
+ end
24
+ #Converte para um array ps
25
+ def to_array(arr)
26
+ return "[ ]" unless arr
27
+ ps_arr=[]
28
+ arr.each do |a|
29
+ ps_arr << case a
30
+ when TrueClass,FalseClass: to_bool(a)
31
+ when Numeric: a
32
+ when Proc: a.to_s
33
+ when Array: to_array(a)
34
+ else
35
+ to_string(a.to_s)
36
+ end
37
+ end
38
+ "[#{ps_arr.join(' ')}] "
39
+ end
40
+ #Converte um hash para string array ps
41
+ def hash_to_array(hash)
42
+ to_string_array(hash.values)
43
+ end
44
+ #'aload' converte um array para dados em pilha
45
+ def array_to_stack(arr)
46
+ "#{arr.join(' ')} "
47
+ end
48
+ #Eval para dados internos de postscript.
49
+ # s=string_eval("Page: %current_page% of %count_pages%")
50
+ #As vari�veis s�o delimitadas por %
51
+ def string_eval(str)
52
+ return "(#{ps_escape(str)}) show " unless str =~ /%/
53
+
54
+ s=str.scan(/([^%][a-z]*[^%]|\d+%?)|(%[^\s%]+%)/).flatten.compact
55
+ #puts s
56
+ tudo=""
57
+ s.each do |v|
58
+ case v
59
+ when /^%/: tudo << "#{v.gsub(/%/,'')} to_s show "
60
+ else
61
+ tudo << "(#{ps_escape(v)}) show "
62
+ end
63
+ end
64
+ tudo
65
+ end
66
+ end
67
+
68
+
69
+
70
+ #class Teste
71
+ # include RubyToPs
72
+
73
+ #end
74
+ #Teste.new.string_eval("diga %current_row oi")
75
+
76
+ #
77
+ #class Ligacoes < ActiveRecord::Base
78
+ #
79
+ #end
80
+ #
81
+ #ActiveRecord::Base.establish_connection(:adapter => "postgresql",:database => "fonip", :host => 'solaris', :username => 'fonip', :password=>'qwe123')
82
+ #
83
+ #t=Teste.new
84
+ #liga=Ligacoes.find(:all, :limit => 50, :conditions => "id > 100")
85
+ #
86
+ #puts liga.class
87
+ #
88
+ #liga.each do |l|
89
+ #
90
+ #puts t.hash_to_array(l.attributes)
91
+ #
92
+ #end
@@ -0,0 +1,14 @@
1
+ require "ps_object"
2
+ #Escala dos objetos
3
+
4
+ class Scale < PsObject
5
+ #Nova inst�ncia de Scale
6
+ # Scale.new(1,1) # default postscript
7
+ # Scale.new(0.5,0.5) # zoom de 50%
8
+ # Scale.new(2,2) # zoom de 200%
9
+ def initialize(sx,sy)
10
+ super("#{sx} #{sy} scale")
11
+ end
12
+
13
+
14
+ end