rghost 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +101 -0
- data/README.txt +3 -0
- data/Rakefile +93 -0
- data/lib/rghost.rb +3 -0
- data/lib/rghost/arc.rb +39 -0
- data/lib/rghost/barcode.rb +40 -0
- data/lib/rghost/callback.rb +55 -0
- data/lib/rghost/color.rb +118 -0
- data/lib/rghost/constants.rb +616 -0
- data/lib/rghost/convert.rb +24 -0
- data/lib/rghost/cursor.rb +82 -0
- data/lib/rghost/data_grid/basic_grid.rb +136 -0
- data/lib/rghost/data_grid/csv_grid.rb +27 -0
- data/lib/rghost/data_grid/data_grid.rb +14 -0
- data/lib/rghost/data_grid/dynamic_callback.rb +12 -0
- data/lib/rghost/data_grid/field_format.rb +60 -0
- data/lib/rghost/data_grid/grid.rb +18 -0
- data/lib/rghost/data_grid/header.rb +111 -0
- data/lib/rghost/data_grid/rails_grid.rb +37 -0
- data/lib/rghost/data_grid/static_callback.rb +13 -0
- data/lib/rghost/data_grid/style/border_lines.rb +47 -0
- data/lib/rghost/data_grid/style/bottom_lines.rb +30 -0
- data/lib/rghost/data_grid/style/old_forms.rb +30 -0
- data/lib/rghost/data_grid/style/style.rb +8 -0
- data/lib/rghost/document.rb +380 -0
- data/lib/rghost/dsc_entry.rb +20 -0
- data/lib/rghost/dynamic_document_callback.rb +27 -0
- data/lib/rghost/eps.rb +22 -0
- data/lib/rghost/font.rb +52 -0
- data/lib/rghost/function.rb +36 -0
- data/lib/rghost/gif.rb +28 -0
- data/lib/rghost/graphic.rb +28 -0
- data/lib/rghost/gs_alone.rb +17 -0
- data/lib/rghost/helpers.rb +13 -0
- data/lib/rghost/horizontal_line.rb +29 -0
- data/lib/rghost/image.rb +26 -0
- data/lib/rghost/jpeg.rb +26 -0
- data/lib/rghost/line.rb +40 -0
- data/lib/rghost/line_width.rb +17 -0
- data/lib/rghost/load.rb +37 -0
- data/lib/rghost/newpath.rb +20 -0
- data/lib/rghost/paper.rb +88 -0
- data/lib/rghost/point.rb +22 -0
- data/lib/rghost/point_with_command.rb +17 -0
- data/lib/rghost/ps/basic.ps +14 -0
- data/lib/rghost/ps/begin_document.ps +7 -0
- data/lib/rghost/ps/callbacks.ps +146 -0
- data/lib/rghost/ps/code128.font +344 -0
- data/lib/rghost/ps/code39.font +195 -0
- data/lib/rghost/ps/cursor.ps +41 -0
- data/lib/rghost/ps/datagrid.ps +52 -0
- data/lib/rghost/ps/ean.font +150 -0
- data/lib/rghost/ps/eps.ps +42 -0
- data/lib/rghost/ps/font.ps +31 -0
- data/lib/rghost/ps/functions.ps +646 -0
- data/lib/rghost/ps/gif.ps +150 -0
- data/lib/rghost/ps/horizontal_line.ps +3 -0
- data/lib/rghost/ps/i25.font +103 -0
- data/lib/rghost/ps/jpeg.ps +122 -0
- data/lib/rghost/ps/paper.ps +8 -0
- data/lib/rghost/ps/rectangle.ps +5 -0
- data/lib/rghost/ps/row.ps +4 -0
- data/lib/rghost/ps/show.ps +20 -0
- data/lib/rghost/ps/table_callbacks.ps +96 -0
- data/lib/rghost/ps/textarea.ps +11 -0
- data/lib/rghost/ps/type.ps +1 -0
- data/lib/rghost/ps/unit.ps +3 -0
- data/lib/rghost/ps/vertical_line.ps +14 -0
- data/lib/rghost/ps_object.rb +51 -0
- data/lib/rghost/rectangle.rb +39 -0
- data/lib/rghost/rgengine.so +0 -0
- data/lib/rghost/rghost.rb +3 -0
- data/lib/rghost/ruby_ghost_config.rb +25 -0
- data/lib/rghost/ruby_ghost_engine.rb +175 -0
- data/lib/rghost/ruby_to_ps.rb +92 -0
- data/lib/rghost/scale.rb +14 -0
- data/lib/rghost/show.rb +31 -0
- data/lib/rghost/static_document_callback.rb +22 -0
- data/lib/rghost/text_in.rb +29 -0
- data/lib/rghost/textarea.rb +115 -0
- data/lib/rghost/units.rb +81 -0
- data/lib/rghost/variable.rb +12 -0
- data/lib/rghost/version.rb +9 -0
- data/lib/rghost/vertical_line.rb +29 -0
- data/scripts/txt2html +67 -0
- data/setup.rb +1585 -0
- data/test/test_helper.rb +2 -0
- data/test/test_rghost.rb +11 -0
- data/website/index.html +11 -0
- data/website/index.txt +30 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +129 -0
- data/website/template.rhtml +48 -0
- metadata +145 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
README.txt
|
4
|
+
Rakefile
|
5
|
+
lib/rghost.rb
|
6
|
+
lib/rghost/version.rb
|
7
|
+
scripts/txt2html
|
8
|
+
setup.rb
|
9
|
+
test/test_helper.rb
|
10
|
+
test/test_rghost.rb
|
11
|
+
website/index.html
|
12
|
+
website/index.txt
|
13
|
+
website/javascripts/rounded_corners_lite.inc.js
|
14
|
+
website/stylesheets/screen.css
|
15
|
+
website/template.rhtml
|
16
|
+
lib/
|
17
|
+
lib/rghost
|
18
|
+
lib/rghost/vertical_line.rb
|
19
|
+
lib/rghost/graphic.rb
|
20
|
+
lib/rghost/color.rb
|
21
|
+
lib/rghost/document.rb
|
22
|
+
lib/rghost/load.rb
|
23
|
+
lib/rghost/convert.rb
|
24
|
+
lib/rghost/function.rb
|
25
|
+
lib/rghost/jpeg.rb
|
26
|
+
lib/rghost/point_with_command.rb
|
27
|
+
lib/rghost/horizontal_line.rb
|
28
|
+
lib/rghost/ruby_to_ps.rb
|
29
|
+
lib/rghost/line_width.rb
|
30
|
+
lib/rghost/gs_alone.rb
|
31
|
+
lib/rghost/eps.rb
|
32
|
+
lib/rghost/point.rb
|
33
|
+
lib/rghost/callback.rb
|
34
|
+
lib/rghost/barcode.rb
|
35
|
+
lib/rghost/rghost.rb
|
36
|
+
lib/rghost/units.rb
|
37
|
+
lib/rghost/gif.rb
|
38
|
+
lib/rghost/font.rb
|
39
|
+
lib/rghost/text_in.rb
|
40
|
+
lib/rghost/paper.rb
|
41
|
+
lib/rghost/data_grid
|
42
|
+
lib/rghost/data_grid/style
|
43
|
+
lib/rghost/data_grid/style/bottom_lines.rb
|
44
|
+
lib/rghost/data_grid/style/style.rb
|
45
|
+
lib/rghost/data_grid/style/old_forms.rb
|
46
|
+
lib/rghost/data_grid/style/border_lines.rb
|
47
|
+
lib/rghost/data_grid/data_grid.rb
|
48
|
+
lib/rghost/data_grid/dynamic_callback.rb
|
49
|
+
lib/rghost/data_grid/rails_grid.rb
|
50
|
+
lib/rghost/data_grid/csv_grid.rb
|
51
|
+
lib/rghost/data_grid/static_callback.rb
|
52
|
+
lib/rghost/data_grid/grid.rb
|
53
|
+
lib/rghost/data_grid/basic_grid.rb
|
54
|
+
lib/rghost/data_grid/header.rb
|
55
|
+
lib/rghost/data_grid/field_format.rb
|
56
|
+
lib/rghost/rgengine.so
|
57
|
+
lib/rghost/constants.rb
|
58
|
+
lib/rghost/ps
|
59
|
+
lib/rghost/ps/horizontal_line.ps
|
60
|
+
lib/rghost/ps/rectangle.ps
|
61
|
+
lib/rghost/ps/gif.ps
|
62
|
+
lib/rghost/ps/font.ps
|
63
|
+
lib/rghost/ps/paper.ps
|
64
|
+
lib/rghost/ps/row.ps
|
65
|
+
lib/rghost/ps/functions.ps
|
66
|
+
lib/rghost/ps/code39.font
|
67
|
+
lib/rghost/ps/cursor.ps
|
68
|
+
lib/rghost/ps/textarea.ps
|
69
|
+
lib/rghost/ps/datagrid.ps
|
70
|
+
lib/rghost/ps/callbacks.ps
|
71
|
+
lib/rghost/ps/unit.ps
|
72
|
+
lib/rghost/ps/show.ps
|
73
|
+
lib/rghost/ps/vertical_line.ps
|
74
|
+
lib/rghost/ps/basic.ps
|
75
|
+
lib/rghost/ps/type.ps
|
76
|
+
lib/rghost/ps/begin_document.ps
|
77
|
+
lib/rghost/ps/i25.font
|
78
|
+
lib/rghost/ps/jpeg.ps
|
79
|
+
lib/rghost/ps/table_callbacks.ps
|
80
|
+
lib/rghost/ps/eps.ps
|
81
|
+
lib/rghost/ps/ean.font
|
82
|
+
lib/rghost/ps/code128.font
|
83
|
+
lib/rghost/cursor.rb
|
84
|
+
lib/rghost/textarea.rb
|
85
|
+
lib/rghost/variable.rb
|
86
|
+
lib/rghost/show.rb
|
87
|
+
lib/rghost/image.rb
|
88
|
+
lib/rghost/version.rb
|
89
|
+
lib/rghost/line.rb
|
90
|
+
lib/rghost/scale.rb
|
91
|
+
lib/rghost/dsc_entry.rb
|
92
|
+
lib/rghost/helpers.rb
|
93
|
+
lib/rghost/rectangle.rb
|
94
|
+
lib/rghost/dynamic_document_callback.rb
|
95
|
+
lib/rghost/static_document_callback.rb
|
96
|
+
lib/rghost/arc.rb
|
97
|
+
lib/rghost/newpath.rb
|
98
|
+
lib/rghost/ps_object.rb
|
99
|
+
lib/rghost/ruby_ghost_config.rb
|
100
|
+
lib/rghost/ruby_ghost_engine.rb
|
101
|
+
lib/rghost.rb
|
data/README.txt
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'rake/testtask'
|
5
|
+
require 'rake/packagetask'
|
6
|
+
require 'rake/gempackagetask'
|
7
|
+
require 'rake/rdoctask'
|
8
|
+
require 'rake/contrib/rubyforgepublisher'
|
9
|
+
require 'fileutils'
|
10
|
+
require 'hoe'
|
11
|
+
include FileUtils
|
12
|
+
require File.join(File.dirname(__FILE__), 'lib', 'rghost', 'version')
|
13
|
+
|
14
|
+
AUTHOR = 'shairon' # can also be an array of Authors
|
15
|
+
EMAIL = "your contact email for bug fixes and info"
|
16
|
+
DESCRIPTION = "description of gem"
|
17
|
+
GEM_NAME = 'rghost' # what ppl will type to install your gem
|
18
|
+
RUBYFORGE_PROJECT = 'rghost' # The unix name for your project
|
19
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
20
|
+
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
21
|
+
|
22
|
+
NAME = "rghost"
|
23
|
+
REV = nil # UNCOMMENT IF REQUIRED: File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
|
24
|
+
VERS = Rghost::VERSION::STRING + (REV ? ".#{REV}" : "")
|
25
|
+
CLEAN.include ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store']
|
26
|
+
RDOC_OPTS = ['--quiet', '--title', 'rghost documentation',
|
27
|
+
"--opname", "index.html",
|
28
|
+
"--line-numbers",
|
29
|
+
"--main", "README",
|
30
|
+
"--inline-source"]
|
31
|
+
|
32
|
+
class Hoe
|
33
|
+
def extra_deps
|
34
|
+
@extra_deps.reject { |x| Array(x).first == 'hoe' }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Generate all the Rake tasks
|
39
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
40
|
+
hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
41
|
+
p.author = AUTHOR
|
42
|
+
p.description = DESCRIPTION
|
43
|
+
p.email = EMAIL
|
44
|
+
p.summary = DESCRIPTION
|
45
|
+
p.url = HOMEPATH
|
46
|
+
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
47
|
+
p.test_globs = ["test/**/test_*.rb"]
|
48
|
+
p.clean_globs = CLEAN #An array of file patterns to delete on clean.
|
49
|
+
|
50
|
+
# == Optional
|
51
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
52
|
+
#p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
|
53
|
+
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
desc 'Generate website files'
|
58
|
+
task :website_generate do
|
59
|
+
Dir['website/**/*.txt'].each do |txt|
|
60
|
+
sh %{ ruby scripts/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
desc 'Upload website files to rubyforge'
|
65
|
+
task :website_upload do
|
66
|
+
config = YAML.load(File.read(File.expand_path("~/.rubyforge/user-config.yml")))
|
67
|
+
host = "#{config["username"]}@rubyforge.org"
|
68
|
+
remote_dir = "/var/www/gforge-projects/#{RUBYFORGE_PROJECT}/"
|
69
|
+
# remote_dir = "/var/www/gforge-projects/#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
70
|
+
local_dir = 'website'
|
71
|
+
sh %{rsync -av #{local_dir}/ #{host}:#{remote_dir}}
|
72
|
+
end
|
73
|
+
|
74
|
+
desc 'Generate and upload website files'
|
75
|
+
task :website => [:website_generate, :website_upload]
|
76
|
+
|
77
|
+
desc 'Release the website and new gem version'
|
78
|
+
task :deploy => [:check_version, :website, :release]
|
79
|
+
|
80
|
+
desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
|
81
|
+
task :local_deploy => [:website_generate, :install_gem]
|
82
|
+
|
83
|
+
task :check_version do
|
84
|
+
unless ENV['VERSION']
|
85
|
+
puts 'Must pass a VERSION=x.y.z release version'
|
86
|
+
exit
|
87
|
+
end
|
88
|
+
unless ENV['VERSION'] == VERS
|
89
|
+
puts "Please update your version.rb to match the release version, currently #{VERS}"
|
90
|
+
exit
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
data/lib/rghost.rb
ADDED
data/lib/rghost/arc.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "ps_object"
|
2
|
+
require "units"
|
3
|
+
# Arc representa arcos, onde ang2 acende os pontos e ang2 apaga os pontos, ambos no sentido anti-hor�rio para valores positivos.
|
4
|
+
# Para evitar surpresas no esbo�o do Arc recomenda-se o uso dentro de um bloco newpath.
|
5
|
+
#
|
6
|
+
# doc=Document.new
|
7
|
+
# doc.newpath do
|
8
|
+
# set Arc.new(:x => 3, :y => 3, :radius => 70, :ang2 => 180)
|
9
|
+
# end
|
10
|
+
class Arc < PsObject
|
11
|
+
DEFAULT_OPTIONS={:fill => false, :x => :limit_left, :y=> :current_row, :radius => 50, :ang1 => 0, :ang2 => 360 , :use => :arc }
|
12
|
+
#Nova inst�ncia de Arc
|
13
|
+
# Responde as op��es
|
14
|
+
# :x => :limit_left # Posi��o X
|
15
|
+
# :y => :current_row # Posi��o Y
|
16
|
+
# :fill => false # false - N�o preenche o arco mas desenha a borda, true - Preenche o arco
|
17
|
+
# :radius => 50 # O raio do arco, valor em pontos
|
18
|
+
# :ang1 => 0 # Apaga os pontos
|
19
|
+
# :ang2 => 360 # Acende os Pontos
|
20
|
+
# :use => :arc # Usa o comando :arc e :arcn
|
21
|
+
#
|
22
|
+
#Postscript Command: x y r ang1 ang2 arc
|
23
|
+
def initialize(options={})
|
24
|
+
@options=DEFAULT_OPTIONS.dup.merge(options)
|
25
|
+
end
|
26
|
+
|
27
|
+
def ps
|
28
|
+
x,y=@options[:x], @options[:y]
|
29
|
+
x,y=Units::parse(x),Units::parse(y) #with parse
|
30
|
+
|
31
|
+
|
32
|
+
cmd=@options[:fill] ? :fill : :stroke
|
33
|
+
"#{x} #{y} #{@options[:radius]} #{@options[:ang1]} #{@options[:ang2]} #{@options[:use]} #{cmd}"
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "ps_object"
|
2
|
+
#Trata das fontes bin�rias dispon�veis na API(GNU Barcodes)
|
3
|
+
class Barcode < PsObject
|
4
|
+
DEFAULT_BARCODES={
|
5
|
+
:ean => "EANJK",
|
6
|
+
:code128 => "Code128JK" ,
|
7
|
+
:code39 => "Code39JK",
|
8
|
+
:i25 => "Codei25JK",
|
9
|
+
}
|
10
|
+
#Nova inst�ncia de Barcode
|
11
|
+
def initialize(barcode_name)
|
12
|
+
@barcode=barcode_name
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def ps
|
17
|
+
Load.library(name,:font)
|
18
|
+
end
|
19
|
+
#Obtem o nome da real da fonte Postscript
|
20
|
+
def font_name
|
21
|
+
DEFAULT_BARCODES[@barcode]
|
22
|
+
|
23
|
+
end
|
24
|
+
#Codifica a fonte em N,n,W e w. Formato esperado pela fonte i25.
|
25
|
+
def Barcode.i25_encode(string_integers)
|
26
|
+
cd=%w(00110 10001 01001 11000 00101 10100 01100 00011 10010 01010) # binaries
|
27
|
+
hash={'00' => 'n' , '01' => 'N', '10' => 'w', '11' => 'W'}
|
28
|
+
cnv= ''
|
29
|
+
v=-1;
|
30
|
+
barcode=barcode.scan(/./).map {|c| c.to_i}
|
31
|
+
(barcode.size.div 2).times do
|
32
|
+
b1,b2=cd[barcode[v+=1]],cd[barcode[v+=1]]
|
33
|
+
0.upto(4) { |i| cnv << hash[ b1[i].chr+b2[i].chr] }
|
34
|
+
end
|
35
|
+
"<#{cnv}>"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
#puts Barcode.new(:EAN).binary_font
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "ps_object"
|
2
|
+
require "ruby_to_ps"
|
3
|
+
|
4
|
+
# Callback representa uma chamada com condi��o :only e :except para elementos inteiros.
|
5
|
+
# � gerado metac�digo em Postscript tendo como base um dict no formato abaixo.
|
6
|
+
# /dictname 3 dict def
|
7
|
+
# dictname begin
|
8
|
+
# /proc {} bind def
|
9
|
+
# /except [ ] def
|
10
|
+
# /only [ ] def
|
11
|
+
# end
|
12
|
+
# Obs: Se detectado pelo menos uma entrada para :only o :except n�o ser� executado
|
13
|
+
#
|
14
|
+
class Callback < PsObject
|
15
|
+
attr_accessor :only, :except, :name
|
16
|
+
include RubyToPs
|
17
|
+
#Nova inst�ncia de Callback
|
18
|
+
# Responde as op��es
|
19
|
+
# :only => [1,2] # Array - Callback ser� executado somente para os valores
|
20
|
+
# :except => [3,4] # Array - Callback n�o executar� para os valores
|
21
|
+
#Exemplo:
|
22
|
+
# Callback.new :only => [4,10,11]
|
23
|
+
def initialize(name,options={},&block) #((|name|)) nome do callback
|
24
|
+
super(&block)
|
25
|
+
@name=name
|
26
|
+
@options=options
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
def ps
|
31
|
+
|
32
|
+
|
33
|
+
@only=num_to_array(@options[:only])
|
34
|
+
@except=num_to_array(@options[:except])
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
"\n/#{@name} 3 dict def #{@name} begin \n/proc { #{super} } bind def \n/except #{to_array(@except)} def \n/only #{to_array(@only)} def \nend "
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def num_to_array(value)
|
44
|
+
case value
|
45
|
+
when Fixnum:
|
46
|
+
a=[]
|
47
|
+
a << value
|
48
|
+
when NilClass: []
|
49
|
+
else
|
50
|
+
value
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
data/lib/rghost/color.rb
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
require "ps_object"
|
2
|
+
require "constants"
|
3
|
+
require "ruby_to_ps" #array_to_stack
|
4
|
+
|
5
|
+
#Prototype de Colores
|
6
|
+
#Os valores no intevalo de 0.0 a 1.0 se o valor for maior que 1 ser� dividido por 100.
|
7
|
+
class Color < PsObject
|
8
|
+
|
9
|
+
include RubyToPs
|
10
|
+
#Cria uma cor RGB ou CMYK ou Gray dependendo do tipo do valor de entrada(factory).
|
11
|
+
# Para o tipo
|
12
|
+
# String => RGB valor em Hexa color='#FFAA33'
|
13
|
+
# Array => CMYK com 4 elementos color=[0.5, 0, 0, 1]
|
14
|
+
# Array => RGB com 3 elementos color=[0.5, 0, 0]
|
15
|
+
# Hash => CMYK - color={:cyan=> 1 ,:magenta => 0, :yellow => 0, :black => 0}
|
16
|
+
# Hash => RGB - color={:red => 0, :green => 0, :blue => 0}
|
17
|
+
# Numeric => Gray - color=0.5
|
18
|
+
#Exemplos:
|
19
|
+
# Color.create("#03D5F2") #RGB
|
20
|
+
# Color.create([0.3, 0.4, 0.2, 0.9]) #CMYK
|
21
|
+
# Color.create(0.9) #Gray
|
22
|
+
def Color.create(color='#000000')
|
23
|
+
|
24
|
+
return case color
|
25
|
+
when String: RGB.new(color)
|
26
|
+
when Array, Hash:
|
27
|
+
if color.size == 3
|
28
|
+
RGB.new(color)
|
29
|
+
elsif color.size == 4
|
30
|
+
CMYK.new(color)
|
31
|
+
else
|
32
|
+
raise ArgumentError.new
|
33
|
+
end
|
34
|
+
when Numeric: Gray.new(color)
|
35
|
+
else
|
36
|
+
raise ArgumentError.new
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
#Espa�o de cor RGB
|
45
|
+
class RGB < Color
|
46
|
+
attr_accessor :red, :green, :blue
|
47
|
+
CONSTANTS=Constants::Colors::RGB
|
48
|
+
DEFAULT_RGB={:red => 0, :green => 0, :blue => 0}
|
49
|
+
#Nova inst�ncia de RGB
|
50
|
+
#Por sequ�ncia de parametros
|
51
|
+
# RGB.new(0.5,1,0)
|
52
|
+
# #ou Hash
|
53
|
+
# RGB.new(:red => 0.5, :green => 1, :blue => 0)
|
54
|
+
# #ou String
|
55
|
+
# RGB.new('#F0FF00')
|
56
|
+
def initialize(color_or_red=nil,green=nil,blue=nil)
|
57
|
+
@color=color_or_red
|
58
|
+
@color=[color_or_red.to_f,green.to_f,blue.to_f] if color_or_red.is_a? Numeric
|
59
|
+
@color=DEFAULT_RGB.merge(color_or_red) if color_or_red.is_a? Hash
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
def ps
|
64
|
+
|
65
|
+
value=case @color
|
66
|
+
when Hash: [@color[:red],@color[:green],@color[:blue]]
|
67
|
+
when Array: @color
|
68
|
+
when String: hex_to_rgb(@color)
|
69
|
+
when NilClass: [0,0,1]
|
70
|
+
end
|
71
|
+
array_to_stack(value.map{|n| n > 1 ? n/100.0: n})+"setrgbcolor"
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def hex_to_rgb(color="#FFFFFF")
|
77
|
+
|
78
|
+
color.gsub(/#/,'').scan(/[\dA-F]{2}/).map{|h| h.hex / 255.0}
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
#Espa�o de cor CMYK
|
84
|
+
class CMYK < Color
|
85
|
+
attr_accessor :cyan ,:magenta, :yellow, :black
|
86
|
+
CONSTANTS=Constants::Colors::CMYK
|
87
|
+
#Nova inst�ncia de CMYK
|
88
|
+
# CMYK.new(:cyan=> 1 ,:magenta => 0, :yellow => 0, :black => 0)
|
89
|
+
def initialize(color={:cyan=> 1 ,:magenta => 0, :yellow => 0, :black => 0})
|
90
|
+
@color=color
|
91
|
+
end
|
92
|
+
|
93
|
+
def ps
|
94
|
+
|
95
|
+
value=case @color
|
96
|
+
when Hash: [@color[:cyan],@color[:magenta],@color[:yellow],@color[:black]]
|
97
|
+
when Array: @color
|
98
|
+
end
|
99
|
+
array_to_stack(value.map{|n| n > 1 ? n/100.0: n})+"setcmykcolor"
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
#Espa�o de cor Gray
|
105
|
+
class Gray < Color
|
106
|
+
attr_accessor :gray
|
107
|
+
#Nova inst�ncia de Gray
|
108
|
+
# Gray.new(0.7)
|
109
|
+
def initialize(gray=0.8)
|
110
|
+
@gray=gray
|
111
|
+
end
|
112
|
+
|
113
|
+
def ps
|
114
|
+
@gray = @gray/100.0 if @gray > 1
|
115
|
+
"#{@gray} setgray"
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|