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.
- data/lib/rghost/border.rb +44 -0
- data/lib/rghost/callback.rb +58 -0
- data/lib/rghost/circle.rb +102 -0
- data/lib/rghost/color.rb +175 -0
- data/lib/rghost/constants.rb +626 -0
- data/lib/rghost/convert.rb +43 -0
- data/lib/rghost/cursor.rb +124 -0
- data/lib/rghost/dash.rb +59 -0
- data/lib/rghost/document.rb +546 -0
- data/lib/rghost/document_callback_facade.rb +64 -0
- data/lib/rghost/dsc_entry.rb +20 -0
- data/lib/rghost/dynamic_document_callback.rb +15 -0
- data/lib/rghost/eps.rb +31 -0
- data/lib/rghost/font.rb +48 -0
- data/lib/rghost/font_map.rb +54 -0
- data/lib/rghost/frame.rb +105 -0
- data/lib/rghost/function.rb +38 -0
- data/lib/rghost/gif.rb +41 -0
- data/lib/rghost/graphic.rb +26 -0
- data/lib/rghost/grid/base_grid.rb +228 -0
- data/lib/rghost/grid/callback_facade.rb +136 -0
- data/lib/rghost/grid/csv_grid.rb +51 -0
- data/lib/rghost/grid/dynamic_callback.rb +12 -0
- data/lib/rghost/grid/field_format.rb +43 -0
- data/lib/rghost/grid/grid.rb +15 -0
- data/lib/rghost/grid/header.rb +120 -0
- data/lib/rghost/grid/matrix.rb +10 -0
- data/lib/rghost/grid/rails_grid.rb +74 -0
- data/lib/rghost/grid/static_callback.rb +13 -0
- data/lib/rghost/grid/style/border_lines.rb +44 -0
- data/lib/rghost/grid/style/bottom_lines.rb +28 -0
- data/lib/rghost/grid/style/old_forms.rb +28 -0
- data/lib/rghost/grid/style/style.rb +8 -0
- data/lib/rghost/gs_alone.rb +25 -0
- data/lib/rghost/helpers.rb +13 -0
- data/lib/rghost/horizontal_line.rb +45 -0
- data/lib/rghost/how_to.rb +75 -0
- data/lib/rghost/image.rb +29 -0
- data/lib/rghost/jpeg.rb +39 -0
- data/lib/rghost/line.rb +89 -0
- data/lib/rghost/line_width.rb +28 -0
- data/lib/rghost/load.rb +43 -0
- data/lib/rghost/newpath.rb +19 -0
- data/lib/rghost/paper.rb +147 -0
- data/lib/rghost/parse_text.rb +53 -0
- data/lib/rghost/pdf_security.rb +36 -0
- data/lib/rghost/point.rb +23 -0
- data/lib/rghost/point_with_command.rb +17 -0
- data/lib/rghost/polygon.rb +75 -0
- data/lib/rghost/ps/AdobeExpert.enc +258 -0
- data/lib/rghost/ps/AdobeLatinEncoding.enc +258 -0
- data/lib/rghost/ps/Bengali.enc +386 -0
- data/lib/rghost/ps/CodePage1250.enc +258 -0
- data/lib/rghost/ps/CodePage1251.enc +258 -0
- data/lib/rghost/ps/CodePage1252.enc +258 -0
- data/lib/rghost/ps/CodePage1253.enc +258 -0
- data/lib/rghost/ps/CodePage1254.enc +258 -0
- data/lib/rghost/ps/CodePage1256.enc +258 -0
- data/lib/rghost/ps/CodePage1257.enc +258 -0
- data/lib/rghost/ps/CodePage1258.enc +258 -0
- data/lib/rghost/ps/CodePage874.enc +258 -0
- data/lib/rghost/ps/Fontmap +5 -0
- data/lib/rghost/ps/IsoLatin.enc +352 -0
- data/lib/rghost/ps/MacCentralEuropean.enc +258 -0
- data/lib/rghost/ps/MacCyrillice.desnc +258 -0
- data/lib/rghost/ps/MacGreek.enc +258 -0
- data/lib/rghost/ps/MacHebrew.enc +258 -0
- data/lib/rghost/ps/TeX-CorkEncoding.enc +258 -0
- data/lib/rghost/ps/TeX-LGR-Greek.enc +258 -0
- data/lib/rghost/ps/TeX-T2AModified2Encoding.enc +258 -0
- data/lib/rghost/ps/TeX-T2BAdobeEncoding.enc +258 -0
- data/lib/rghost/ps/TeX-T2CAdobeEncoding.enc +258 -0
- data/lib/rghost/ps/TeX-X2AdobeEncoding.enc +258 -0
- data/lib/rghost/ps/TeX-XL2encoding.enc +258 -0
- data/lib/rghost/ps/TeXMathExtensionEncoding.enc +258 -0
- data/lib/rghost/ps/TeXMathItalicEncoding.enc +258 -0
- data/lib/rghost/ps/TeXMathSymbolEncoding.enc +258 -0
- data/lib/rghost/ps/US-ASCII.enc +258 -0
- data/lib/rghost/ps/UTF-8.enc +3 -0
- data/lib/rghost/ps/_cusor.ps +46 -0
- data/lib/rghost/ps/basic.ps +25 -0
- data/lib/rghost/ps/begin_document.ps +8 -0
- data/lib/rghost/ps/callbacks.ps +175 -0
- data/lib/rghost/ps/code128.font +344 -0
- data/lib/rghost/ps/code39.font +195 -0
- data/lib/rghost/ps/cursor.ps +106 -0
- data/lib/rghost/ps/datagrid.ps +55 -0
- data/lib/rghost/ps/developer.ps +237 -0
- data/lib/rghost/ps/ean.font +150 -0
- data/lib/rghost/ps/eps.ps +42 -0
- data/lib/rghost/ps/font.ps +38 -0
- data/lib/rghost/ps/frame.ps +16 -0
- data/lib/rghost/ps/gif.ps +150 -0
- data/lib/rghost/ps/horizontal_line.ps +4 -0
- data/lib/rghost/ps/i25.font +103 -0
- data/lib/rghost/ps/jpeg.ps +122 -0
- data/lib/rghost/ps/link.ps +22 -0
- data/lib/rghost/ps/paper.ps +8 -0
- data/lib/rghost/ps/rect_link.ps +17 -0
- data/lib/rghost/ps/rectangle.ps +5 -0
- data/lib/rghost/ps/rghost_default_template.eps +1532 -0
- data/lib/rghost/ps/row.ps +4 -0
- data/lib/rghost/ps/show.ps +21 -0
- data/lib/rghost/ps/table_callbacks.ps +96 -0
- data/lib/rghost/ps/text.ps +63 -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 +12 -0
- data/lib/rghost/ps/virtual_pages.ps +55 -0
- data/lib/rghost/ps_facade.rb +253 -0
- data/lib/rghost/ps_object.rb +55 -0
- data/lib/rghost/rectangle_link.rb +65 -0
- data/lib/rghost/rgengine.so +0 -0
- data/lib/rghost/ruby_ghost_config.rb +252 -0
- data/lib/rghost/ruby_ghost_engine.rb +174 -0
- data/lib/rghost/ruby_ghost_version.rb +8 -0
- data/lib/rghost/ruby_to_ps.rb +78 -0
- data/lib/rghost/scale.rb +29 -0
- data/lib/rghost/shape_content.rb +23 -0
- data/lib/rghost/show.rb +88 -0
- data/lib/rghost/static_document_callback.rb +18 -0
- data/lib/rghost/text.rb +44 -0
- data/lib/rghost/text_in.rb +51 -0
- data/lib/rghost/text_link_in.rb +42 -0
- data/lib/rghost/textarea.rb +88 -0
- data/lib/rghost/units.rb +82 -0
- data/lib/rghost/variable.rb +12 -0
- data/lib/rghost/vertical_line.rb +37 -0
- data/lib/rghost/virtual_pages.rb +42 -0
- data/lib/rghost.rb +18 -0
- metadata +181 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#Border object render a border around of vector shapes. Its sketch can be a combination of color, dashes, line joins and line caps.
|
|
2
|
+
#Usually its use inside of object facades, such as, Document, CallbackFacade and PsFacade as parameter :border, for example:
|
|
3
|
+
# d=Document.new
|
|
4
|
+
# d.horizontal_line :middle, :border => { :color => '#058412', :dash => [1,0,2] }
|
|
5
|
+
#You can use it as a new instance of Border and set inside of Document by method set, example:
|
|
6
|
+
# d=Document.new
|
|
7
|
+
# b=Border.new :color => '#058412', :dash => [1,0,2]
|
|
8
|
+
# d.set b
|
|
9
|
+
# d.lineto :x => 2.5, :y => 5
|
|
10
|
+
#===Options
|
|
11
|
+
#* <tt>:color</tt> - Facade to Color using the same parameter.
|
|
12
|
+
#* <tt>:dash</tt> - Facade to Dash using the same parameter.
|
|
13
|
+
#* <tt>:width</tt> - Facade to LineWidth using the same parameter.
|
|
14
|
+
#* <tt>:linejoin</tt> - Sets the line join parameter in the graphics state to int, which must be one of the integers 0, 1, or 2.
|
|
15
|
+
#====:linejoin examples
|
|
16
|
+
#* <tt>Miter join</tt> link:images/linejoin0.png <tt> :linejoin => 0 </tt>
|
|
17
|
+
#* <tt>Round join</tt> link:images/linejoin1.png <tt> :linejoin => 1 </tt>
|
|
18
|
+
#* <tt>Bevel join</tt> link:images/linejoin2.png <tt> :linejoin => 2 </tt>
|
|
19
|
+
#* <tt>:linecap</tt> - Sets the line cap parameter in the graphics state to int, which must be one of the integers 0, 1, or 2
|
|
20
|
+
#====:linecap examples
|
|
21
|
+
#* <tt><tt>Butt cap</tt></tt> link:images/linecap0.png <tt> :linecap => 0 </tt>
|
|
22
|
+
#* <tt>Round cap</tt> link:images/linecap1.png <tt> :linecap => 1 </tt>
|
|
23
|
+
#* <tt>Projecting square cap</tt> link:images/linecap2.png <tt> :linecap => 2 </tt>
|
|
24
|
+
class RGhost::Border < RGhost::PsObject
|
|
25
|
+
|
|
26
|
+
DEFAULT_OPTIONS = {:color => '#49AAFA', :dash => false, :width => 0.5, :linejoin => 0, :linecap => 0 }
|
|
27
|
+
# aqui tem documentação
|
|
28
|
+
def initialize(options={})
|
|
29
|
+
super(""){}
|
|
30
|
+
@options = DEFAULT_OPTIONS.dup.merge(options)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def ps #:nodoc:
|
|
34
|
+
p=RGhost::PsObject.new
|
|
35
|
+
p.set RGhost::LineWidth.new(@options[:width]) if @options[:width]
|
|
36
|
+
p.raw "#{@options[:linejoin]} setlinejoin"
|
|
37
|
+
p.raw "#{@options[:linecap]} setlinecap"
|
|
38
|
+
p.set RGhost::Dash.new(@options[:dash]) if @options[:dash]
|
|
39
|
+
p.set RGhost::Color.create(@options[:color]) if @options[:color]
|
|
40
|
+
p
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
|
44
|
+
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require "rghost/ps_object"
|
|
2
|
+
require "rghost/ruby_to_ps"
|
|
3
|
+
|
|
4
|
+
# Callbacks are custom code blocks defined inside of Document.
|
|
5
|
+
# All callbacks received implicitly a instance of PsFacade can be creates any PsObject.
|
|
6
|
+
# The callbacks's execution depend of the algorithims predefined in Postscript core library.
|
|
7
|
+
# There are two kind of callbacks, Statics and Dynamics callbacks.
|
|
8
|
+
# A Static callback there aren't parameters to control of the inclusion and exception on current scope, usually
|
|
9
|
+
# applied for events which happen one time, for example after_document_create, "after document create" always will execute one time for each document.
|
|
10
|
+
# Otherwise Dynamic callbacks there is control of scope using conditional :only or :except, this is only difference in relation the static callbacks.
|
|
11
|
+
# The parameters of a Dynamic callbak must be one integer or one array of integer. Example:
|
|
12
|
+
# For all pages except page 3
|
|
13
|
+
# doc.before_page_create :except => 3 do |b|
|
|
14
|
+
# # do something
|
|
15
|
+
# end
|
|
16
|
+
#
|
|
17
|
+
# For just 2 and 4 pages
|
|
18
|
+
# doc.before_page_create :only => [2,4] do |b|
|
|
19
|
+
# # do something
|
|
20
|
+
# end
|
|
21
|
+
#
|
|
22
|
+
# The most of callbacks are defined in facades such as DocumentCallbackFacade and Grid::CallbackFacade
|
|
23
|
+
class RGhost::Callback < RGhost::PsObject
|
|
24
|
+
attr_accessor :only, :except, :name
|
|
25
|
+
include RGhost::RubyToPs
|
|
26
|
+
|
|
27
|
+
def initialize(name,options={},&block)
|
|
28
|
+
|
|
29
|
+
super(""){}
|
|
30
|
+
set RGhost::PsFacade.new(&block) if block
|
|
31
|
+
@name=name
|
|
32
|
+
@options=options
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def ps
|
|
37
|
+
|
|
38
|
+
@only=num_to_array(@options[:only])
|
|
39
|
+
@except=num_to_array(@options[:except])
|
|
40
|
+
|
|
41
|
+
"\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 "
|
|
42
|
+
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
def num_to_array(value)
|
|
47
|
+
case value
|
|
48
|
+
when Fixnum then
|
|
49
|
+
a=[]
|
|
50
|
+
a << value
|
|
51
|
+
when NilClass then []
|
|
52
|
+
else
|
|
53
|
+
value
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
require "rghost/ps_object"
|
|
2
|
+
require "rghost/units"
|
|
3
|
+
#Draw a circle to the current path(or current row by default).
|
|
4
|
+
#===Options
|
|
5
|
+
#
|
|
6
|
+
#* <tt>:x and :y</tt> - as center of the circle.
|
|
7
|
+
#* <tt>:radius</tt> - as radius(in points).
|
|
8
|
+
#* <tt>:ang1</tt> - the angle of a vector from (:x , :y ) of length :radius to the first endpoint of the circle.
|
|
9
|
+
#* <tt>:ang2</tt> - the angle of a vector from (:x, :y) of length :radius to the second endpoint of the circle.
|
|
10
|
+
#* <tt>:content</tt> - facade to ShapeContent with same parameters.
|
|
11
|
+
#* <tt>:border</tt> - facade to Border with same parameters.
|
|
12
|
+
#* <tt>:use</tt> - <b>:arc</b> draw counterclockwise and <b>:arcn</b> (arc negative) clockwise direction.
|
|
13
|
+
#===Examples using facade circle method inside of Document
|
|
14
|
+
# d=Document.new
|
|
15
|
+
# d.circle :x => 5, :y => 2.5 , :radius => 40
|
|
16
|
+
#
|
|
17
|
+
#link:images/circle01.png
|
|
18
|
+
# d=Document.new
|
|
19
|
+
# d.circle :x => 5, :y => 2.5 , :radius => 40, :content => {:fill => false}
|
|
20
|
+
#
|
|
21
|
+
#link:images/circle02.png
|
|
22
|
+
#
|
|
23
|
+
# d=Document.new
|
|
24
|
+
# d.circle :x => 5, :y => 2.5 , :radius => 40, :content => {:color => "#FF0000"}
|
|
25
|
+
#
|
|
26
|
+
#link:images/circle03.png
|
|
27
|
+
#
|
|
28
|
+
# d=Document.new
|
|
29
|
+
# d.circle :x => 5, :y => 2.5 , :radius => 40, :content => {:color => "#FF0000"} ,:border => {:color => "#FFFFFF"}
|
|
30
|
+
#
|
|
31
|
+
#link:images/circle04.png
|
|
32
|
+
#
|
|
33
|
+
# d=Document.new
|
|
34
|
+
# d.circle :x => 5, :y => 2.5 , :radius => 40, :content => {:color => :yellow} ,:border => {:color => :orange, :dash => [1,2,1,2], :width => 20}
|
|
35
|
+
#
|
|
36
|
+
#link:images/circle05.png
|
|
37
|
+
#
|
|
38
|
+
# d=Document.new
|
|
39
|
+
# colors=%w[#98AE09 #AFE099 #A971FF #CC1010 #FF7201 #34FEE1]
|
|
40
|
+
# 6.downto(1) do |v|
|
|
41
|
+
# d.circle :x => 5, :y => 2.5 , :radius => v*10, :content =>{:color => colors[v]}
|
|
42
|
+
# end
|
|
43
|
+
#
|
|
44
|
+
#link:images/circle06.png
|
|
45
|
+
# d=Document.new
|
|
46
|
+
# d.circle :x => 5, :y => 2.5 , :ang1 => 90, :radius => 50, :content => {:fill => false }
|
|
47
|
+
#
|
|
48
|
+
#link:images/circle07.png
|
|
49
|
+
#
|
|
50
|
+
# d=Document.new
|
|
51
|
+
# d.circle :x => 5, :y => 2.5 , :ang2 => 90, :radius => 50, :content => {:fill => false }
|
|
52
|
+
#
|
|
53
|
+
#link:images/circle08.png
|
|
54
|
+
#
|
|
55
|
+
# d=Document.new
|
|
56
|
+
# d.circle :x => 5, :y => 2.5 , :ang2 => 90, :radius => 50, :content =>{:color => :green}
|
|
57
|
+
#
|
|
58
|
+
#link:images/circle09.png
|
|
59
|
+
#
|
|
60
|
+
# d=Document.new
|
|
61
|
+
# d.circle :x => 5, :y => 2.5 , :ang2 => 90, :use => :arcn, :radius => 50, :content =>{:color => :green}
|
|
62
|
+
#
|
|
63
|
+
#link:images/circle10.png
|
|
64
|
+
#
|
|
65
|
+
#===Examples using Circle class
|
|
66
|
+
# d=Document.new
|
|
67
|
+
# d.scale(3,1)
|
|
68
|
+
# d.set Circle.new(:x => 1.5, :y => 1.5 , :ang2 => 180, :radius => 25)
|
|
69
|
+
#
|
|
70
|
+
#link:images/circle11.png
|
|
71
|
+
class RGhost::Circle < RGhost::PsObject
|
|
72
|
+
DEFAULT_OPTIONS={
|
|
73
|
+
:x => :limit_left,
|
|
74
|
+
:y=> :current_row,
|
|
75
|
+
:radius => 50,
|
|
76
|
+
:ang1 => 0,
|
|
77
|
+
:ang2 => 360 ,
|
|
78
|
+
:use => :arc,
|
|
79
|
+
:content => RGhost::ShapeContent::DEFAULT_OPTIONS,
|
|
80
|
+
:border => RGhost::Border::DEFAULT_OPTIONS
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
def initialize(options={})
|
|
84
|
+
super(''){}
|
|
85
|
+
@options=DEFAULT_OPTIONS.dup.merge(options)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def ps
|
|
89
|
+
|
|
90
|
+
x,y= RGhost::Units::parse(@options[:x]), RGhost::Units::parse(@options[:y]) #with parse
|
|
91
|
+
|
|
92
|
+
graph=RGhost::Graphic.new
|
|
93
|
+
graph.raw :newpath
|
|
94
|
+
graph.set RGhost::Border.new(@options[:border]) if @options[:border]
|
|
95
|
+
graph.raw "#{x} #{y} #{@options[:radius]} #{@options[:ang1]} #{@options[:ang2]} #{@options[:use]} "
|
|
96
|
+
graph.set RGhost::ShapeContent.new(@options[:content]) if @options[:content]
|
|
97
|
+
graph.raw :stroke
|
|
98
|
+
graph
|
|
99
|
+
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
end
|
data/lib/rghost/color.rb
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
require "rghost/ps_object"
|
|
2
|
+
require "rghost/constants"
|
|
3
|
+
require "rghost/ruby_to_ps" #array_to_stack
|
|
4
|
+
|
|
5
|
+
#Creates color for postscript components
|
|
6
|
+
class RGhost::Color < RGhost::PsObject
|
|
7
|
+
|
|
8
|
+
include RGhost::RubyToPs
|
|
9
|
+
#The method create is a color factory depends when parameter is used. The parameter variate between 0 and 1, if value greatet that 1 will be divided by 100.0 .
|
|
10
|
+
#===Examples
|
|
11
|
+
#====Creating RGB color
|
|
12
|
+
#String HTML color converter
|
|
13
|
+
# Color.create '#FFAA33'
|
|
14
|
+
#As Symbol will be find in RGhost::Constants::Colors::RGB
|
|
15
|
+
# Color.create :red
|
|
16
|
+
#As Array with 3 elements
|
|
17
|
+
# Color.create [0.5, 0.3, 0.5]
|
|
18
|
+
#Hash with 3 pair of key/value. Valids keys :red, :green and :blue
|
|
19
|
+
# Color.create :red => 0.5, :green => 0.3, :blue => 0.5
|
|
20
|
+
#Hash with 3 pair of key/value. Valids keys :r, :g and :b
|
|
21
|
+
# Color.create :r => 0.5, :g => 0.3, :b => 0.5
|
|
22
|
+
#====Creating CMYK color
|
|
23
|
+
#Hash with 4 pair of key/value. Valids keys :cyan, :magenta, :yellow and :black
|
|
24
|
+
# Color.create :cyan=> 1 ,:magenta => 0.3, :yellow => 0, :black => 0
|
|
25
|
+
#Hash with 4 pair of key/value. Valids keys :c, :m, :y and :b
|
|
26
|
+
# Color.create :c=> 1 ,:m => 0.3, :y => 0, :b => 0
|
|
27
|
+
#====Creating CMYK Spot color
|
|
28
|
+
#Hash with 5 pair of key/value. Valids keys :cyan, :magenta, :yellow, :black, and :name
|
|
29
|
+
# Color.create :cyan=> 0, :magenta => 100, :yellow => 63, :black => 12, :name => 'Pantone 200 C'
|
|
30
|
+
#====Creating Gray color
|
|
31
|
+
#A single Numeric
|
|
32
|
+
# Color.create 0.5
|
|
33
|
+
#50 percent of black will be divided by 100.0
|
|
34
|
+
# Color.create 50
|
|
35
|
+
def self.create(color="FFAA99")
|
|
36
|
+
|
|
37
|
+
return case color
|
|
38
|
+
when String then RGhost::RGB.new(color)
|
|
39
|
+
when Symbol then
|
|
40
|
+
c=RGhost::Constants::Colors::RGB[color]
|
|
41
|
+
raise ArgumentError.new("#{color}##{color.class}") unless c
|
|
42
|
+
self.create c
|
|
43
|
+
|
|
44
|
+
when Array, Hash then
|
|
45
|
+
if color.size == 3
|
|
46
|
+
RGhost::RGB.new(color)
|
|
47
|
+
elsif color.size == 4
|
|
48
|
+
RGhost::CMYK.new(color)
|
|
49
|
+
elsif color.size == 5
|
|
50
|
+
RGhost::CMYKSpot.new(color)
|
|
51
|
+
else
|
|
52
|
+
raise ArgumentError.new("#{color}##{color.class}")
|
|
53
|
+
end
|
|
54
|
+
when Numeric then RGhost::Gray.new(color)
|
|
55
|
+
else
|
|
56
|
+
raise ArgumentError.new("#{color}##{color.class}")
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
#Creates RGB color
|
|
65
|
+
class RGhost::RGB < RGhost::Color
|
|
66
|
+
attr_accessor :red, :green, :blue
|
|
67
|
+
CONSTANTS=RGhost::Constants::Colors::RGB
|
|
68
|
+
DEFAULT_RGB={:red => 0, :green => 0, :blue => 0}
|
|
69
|
+
#String HTML color converter
|
|
70
|
+
# Color.create '#FFAA33'
|
|
71
|
+
#As Symbol will be find in RGhost::Constants::Colors::RGB
|
|
72
|
+
# Color.create :red
|
|
73
|
+
#As Array with 3 elements
|
|
74
|
+
# Color.create [0.5, 0.3, 0.5]
|
|
75
|
+
#Hash with 3 pair of key/value. Valids keys :red, :green and :blue
|
|
76
|
+
# Color.create :red => 0.5, :green => 0.3, :blue => 0.5
|
|
77
|
+
#Hash with 3 pair of key/value. Valids keys :r, :g and :b
|
|
78
|
+
# Color.create :r => 0.5, :g => 0.3, :b => 0.5
|
|
79
|
+
def initialize(color_or_red=nil,green=nil,blue=nil)
|
|
80
|
+
@color=color_or_red
|
|
81
|
+
@color=[color_or_red.to_f,green.to_f,blue.to_f] if color_or_red.is_a? Numeric
|
|
82
|
+
@color=DEFAULT_RGB.merge(color_or_red) if color_or_red.is_a? Hash
|
|
83
|
+
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def ps
|
|
87
|
+
value=color_params
|
|
88
|
+
|
|
89
|
+
array_to_stack(value.map{|n| n > 1 ? n/100.0: n})+"setrgbcolor"
|
|
90
|
+
end
|
|
91
|
+
def stack_format
|
|
92
|
+
color_params
|
|
93
|
+
end
|
|
94
|
+
def color_params
|
|
95
|
+
case @color
|
|
96
|
+
when Hash then [@color[:red] || @color[:r],@color[:green] || @color[:g],@color[:blue] || @color[:b]]
|
|
97
|
+
when Array then @color
|
|
98
|
+
when String then hex_to_rgb(@color)
|
|
99
|
+
when NilClass then [0,0,1]
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
private
|
|
106
|
+
|
|
107
|
+
def hex_to_rgb(color="#FFFFFF")
|
|
108
|
+
|
|
109
|
+
color.gsub(/#/,'').scan(/[\dA-F]{2}/).map{|h| h.hex / 255.0}
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
#Creates CMYK color space
|
|
115
|
+
class RGhost::CMYK < RGhost::Color
|
|
116
|
+
attr_accessor :cyan ,:magenta, :yellow, :black
|
|
117
|
+
CONSTANTS=RGhost::Constants::Colors::CMYK
|
|
118
|
+
|
|
119
|
+
#Hash with 4 pair of key/value. Valids keys :cyan, :magenta, :yellow and :black
|
|
120
|
+
# Color.create :cyan=> 1 ,:magenta => 0.3, :yellow => 0, :black => 0
|
|
121
|
+
#Hash with 4 pair of key/value. Valids keys :c, :m, :y and :b
|
|
122
|
+
# Color.create :c=> 1 ,:m => 0.3, :y => 0, :b => 0
|
|
123
|
+
def initialize(color={:cyan=> 1 ,:magenta => 0, :yellow => 0, :black => 0})
|
|
124
|
+
@color=color
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def ps
|
|
128
|
+
value=case @color
|
|
129
|
+
when Hash then [@color[:cyan] || @color[:c],@color[:magenta] || @color[:m],@color[:yellow] || @color[:y],@color[:black] || @color[:k]]
|
|
130
|
+
when Array then @color
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
array_to_stack(value.map{|n| n > 1 ? n/100.0: n})+"setcmykcolor"
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
#Creates CMYK Spot color space
|
|
139
|
+
class RGhost::CMYKSpot < RGhost::Color
|
|
140
|
+
attr_accessor :cyan ,:magenta, :yellow, :black, :name
|
|
141
|
+
|
|
142
|
+
def initialize(color={:name => 'spot', :cyan=> 1 ,:magenta => 0, :yellow => 0, :black => 0})
|
|
143
|
+
@name = color[:name]
|
|
144
|
+
color.delete(:name)
|
|
145
|
+
@color = color
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def ps
|
|
149
|
+
value=case @color
|
|
150
|
+
when Hash then [@color[:cyan] || @color[:c],@color[:magenta] || @color[:m],@color[:yellow] || @color[:y],@color[:black] || @color[:k]]
|
|
151
|
+
when Array then @color
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
array_to_stack(value.map{|n| n > 1 ? n/100.0: n}) + "(#{@name.to_s}) findcmykcustomcolor \n/#{@name.to_s.gsub(' ', '_')} exch def\n\n#{@name.to_s.gsub(' ', '_')} 1 setcustomcolor"
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
#Creates Gray color
|
|
159
|
+
class RGhost::Gray < RGhost::Color
|
|
160
|
+
attr_accessor :gray
|
|
161
|
+
|
|
162
|
+
#A single Numeric
|
|
163
|
+
# Color.create 0.5
|
|
164
|
+
#50 percent of black will be divided by 100.0
|
|
165
|
+
# Color.create 50
|
|
166
|
+
def initialize(gray=0.8)
|
|
167
|
+
@gray=gray
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def ps #:nodoc:
|
|
171
|
+
@gray = @gray/100.0 if @gray > 1
|
|
172
|
+
"#{@gray} setgray"
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
end
|