rghost 0.8.6.5 → 0.8.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,7 +27,7 @@ class RGhost::Callback < RGhost::PsObject
27
27
  def initialize(name,options={},&block)
28
28
 
29
29
  super(""){}
30
- set RGhost::PsFacade.new(&block)
30
+ set RGhost::PsFacade.new(&block) if block
31
31
  @name=name
32
32
  @options=options
33
33
 
@@ -45,11 +45,10 @@ class RGhost::Callback < RGhost::PsObject
45
45
  private
46
46
  def num_to_array(value)
47
47
  case value
48
- when Fixnum
48
+ when Fixnum:
49
49
  a=[]
50
50
  a << value
51
- when NilClass
52
- []
51
+ when NilClass: []
53
52
  else
54
53
  value
55
54
  end
data/lib/rghost/color.rb CHANGED
@@ -35,14 +35,14 @@ class RGhost::Color < RGhost::PsObject
35
35
  def self.create(color="FFAA99")
36
36
 
37
37
  return case color
38
- when String then RGhost::RGB.new(color)
39
- when Symbol
38
+ when String: RGhost::RGB.new(color)
39
+ when Symbol:
40
40
  c=RGhost::Constants::Colors::RGB[color]
41
41
  raise ArgumentError.new("#{color}##{color.class}") unless c
42
42
  self.create c
43
43
 
44
- when Array, Hash
45
- if color.size == 3
44
+ when Array, Hash:
45
+ if color.size == 3
46
46
  RGhost::RGB.new(color)
47
47
  elsif color.size == 4
48
48
  RGhost::CMYK.new(color)
@@ -51,7 +51,7 @@ class RGhost::Color < RGhost::PsObject
51
51
  else
52
52
  raise ArgumentError.new("#{color}##{color.class}")
53
53
  end
54
- when Numeric then RGhost::Gray.new(color)
54
+ when Numeric: RGhost::Gray.new(color)
55
55
  else
56
56
  raise ArgumentError.new("#{color}##{color.class}")
57
57
  end
@@ -93,14 +93,10 @@ class RGhost::RGB < RGhost::Color
93
93
  end
94
94
  def color_params
95
95
  case @color
96
- when Hash
97
- [@color[:red] || @color[:r],@color[:green] || @color[:g],@color[:blue] || @color[:b]]
98
- when Array
99
- @color
100
- when String
101
- hex_to_rgb(@color)
102
- when NilClass
103
- [0,0,1]
96
+ when Hash: [@color[:red] || @color[:r],@color[:green] || @color[:g],@color[:blue] || @color[:b]]
97
+ when Array: @color
98
+ when String: hex_to_rgb(@color)
99
+ when NilClass: [0,0,1]
104
100
  end
105
101
 
106
102
 
@@ -130,10 +126,8 @@ class RGhost::CMYK < RGhost::Color
130
126
 
131
127
  def ps
132
128
  value=case @color
133
- when Hash
134
- [@color[:cyan] || @color[:c],@color[:magenta] || @color[:m],@color[:yellow] || @color[:y],@color[:black] || @color[:k]]
135
- when Array
136
- @color
129
+ when Hash: [@color[:cyan] || @color[:c],@color[:magenta] || @color[:m],@color[:yellow] || @color[:y],@color[:black] || @color[:k]]
130
+ when Array: @color
137
131
  end
138
132
 
139
133
  array_to_stack(value.map{|n| n > 1 ? n/100.0: n})+"setcmykcolor"
@@ -153,10 +147,8 @@ class RGhost::CMYKSpot < RGhost::Color
153
147
 
154
148
  def ps
155
149
  value=case @color
156
- when Hash
157
- [@color[:cyan] || @color[:c],@color[:magenta] || @color[:m],@color[:yellow] || @color[:y],@color[:black] || @color[:k]]
158
- when Array
159
- @color
150
+ when Hash: [@color[:cyan] || @color[:c],@color[:magenta] || @color[:m],@color[:yellow] || @color[:y],@color[:black] || @color[:k]]
151
+ when Array: @color
160
152
  end
161
153
 
162
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"
@@ -75,11 +75,12 @@ class RGhost::Document < RGhost::PsFacade
75
75
  #* <tt>:row_height and row_padding</tt> - Its names say by itself :)
76
76
  #* <tt>:font_encoding</tt> - Specifies encoding of data input. You can look for supported encoding using the method RGhost::Config.encode_test
77
77
  def initialize(options={},&block)
78
- super()
78
+
79
+
79
80
  @head,@callbacks=RGhost::PsObject.new,RGhost::PsObject.new
80
81
  @head.set RGhost::Load.library(:type)
81
82
  @head.set RGhost::Load.library(:unit)
82
-
83
+ #super()
83
84
  @variables=DEFAULT_OPTIONS.dup.merge(options)
84
85
  default_encoding
85
86
  @paper=RGhost::Paper.new(options[:paper] || :A4, options)
@@ -90,7 +91,9 @@ class RGhost::Document < RGhost::PsFacade
90
91
  @additional_params=[]
91
92
 
92
93
  default_variables
93
- yield self if block
94
+ super()
95
+ #block.call(self) if block
96
+ #yield self if block
94
97
  end
95
98
 
96
99
  def gs_paper #:nodoc:
@@ -148,7 +151,7 @@ class RGhost::Document < RGhost::PsFacade
148
151
  end
149
152
 
150
153
  def ps #:nodoc:
151
- done unless @done
154
+ done
152
155
 
153
156
 
154
157
 
@@ -251,17 +254,10 @@ class RGhost::Document < RGhost::PsFacade
251
254
  # printer.write doc.render_stream(:ps)
252
255
  # printer.close
253
256
  def render_stream(device,options={})
254
- # rg=render(device,options)
255
- # out=rg.output.readlines.join
256
- # rg.clear_output
257
- # out
258
-
259
257
  rg=render(device,options)
260
- out=rg.output
261
- raise "RGhost::#{rg.errors} - #{out}" if rg.error?
262
- data=out.readlines.join
258
+ out=rg.output.readlines.join
263
259
  rg.clear_output
264
- data
260
+ out
265
261
  end
266
262
  #Facade to Function.new
267
263
  #Defines low level function to optimize repetitive piece of code.
@@ -325,16 +321,16 @@ class RGhost::Document < RGhost::PsFacade
325
321
  set RGhost::VirtualPages.new(&block)
326
322
  end
327
323
  {
328
- :base => -4,
329
- :print => -4,
330
- :modify => -8,
331
- :copy => -16,
332
- :annotate => -32,
333
- :interactive => -256,
334
- :copy_access => -512,
335
- :assemble => -1024,
336
- :high_quality_print => -2048,
337
- :all => -3904}
324
+ :base => -4,
325
+ :print => -4,
326
+ :modify => -8,
327
+ :copy => -16,
328
+ :annotate => -32,
329
+ :interactive => -256,
330
+ :copy_access => -512,
331
+ :assemble => -1024,
332
+ :high_quality_print => -2048,
333
+ :all => -3904}
338
334
 
339
335
  #Security disable the permissions and define passwords to PDF documents.
340
336
  #The password just support set of \w .
@@ -366,9 +362,9 @@ class RGhost::Document < RGhost::PsFacade
366
362
  # end
367
363
  #
368
364
  def security
369
- sec=RGhost::PdfSecurity.new
370
- yield sec
371
- @additional_params << sec.gs_params
365
+ sec=RGhost::PdfSecurity.new
366
+ yield sec
367
+ @additional_params << sec.gs_params
372
368
  end
373
369
 
374
370
  #Starts and Ends internal benckmark will write in bottom of page.
@@ -454,14 +450,18 @@ class RGhost::Document < RGhost::PsFacade
454
450
 
455
451
  #Informs is ready to converts/prints
456
452
  def done
457
- @done=true
458
- raw "\n\n"
459
- call :after_page_create
460
- call :callback
461
- call :after_document_create
462
453
 
463
- showpage
464
- raw "\n%%EOF"
454
+ unless @done
455
+ @done=true
456
+ raw "\n\n"
457
+ call :after_page_create
458
+ call :callback
459
+ call :after_document_create
460
+
461
+ showpage
462
+ raw "\n%%EOF"
463
+ end
464
+ self
465
465
  end
466
466
  def enable_virtual_pages
467
467
  set RGhost::Variable.new(:has_vp?, true)
data/lib/rghost/font.rb CHANGED
@@ -34,12 +34,9 @@ class RGhost::Font < RGhost::PsObject #:nodoc:
34
34
 
35
35
  size= o[:size]
36
36
  str_ret+=case size
37
- when Hash
38
- "/#{@name} findfont [ #{size[:width]} 0 0 #{size[:height]} 0 0] makefont setfont "
39
- when Array
40
- "/#{@name} findfont [ #{size[0]} 0 0 #{size[1]} 0 0] makefont setfont "
41
- when Fixnum
42
- "/#{@name} findfont #{size} scalefont setfont "
37
+ when Hash: "/#{@name} findfont [ #{size[:width]} 0 0 #{size[:height]} 0 0] makefont setfont "
38
+ when Array: "/#{@name} findfont [ #{size[0]} 0 0 #{size[1]} 0 0] makefont setfont "
39
+ when Fixnum: "/#{@name} findfont #{size} scalefont setfont "
43
40
  end
44
41
  str_ret
45
42
  end
@@ -3,7 +3,7 @@
3
3
  require 'ps_object'
4
4
  require 'font'
5
5
  require 'function'
6
- require 'color'
6
+
7
7
 
8
8
  class RGhost::FontMap < RGhost::PsObject #:nodoc:
9
9
  include RGhost::RubyToPs
@@ -1,7 +1,5 @@
1
1
  require "ps_object"
2
2
  require "cursor"
3
- require "color"
4
- require "point"
5
3
  require "point"
6
4
  require "line_width"
7
5
  #Creates a new graphic state between gsave and grestore postscript primitives. Example
data/lib/rghost/image.rb CHANGED
@@ -13,12 +13,9 @@ class RGhost::Image < RGhost::PsObject
13
13
  def self.for(path,options={})
14
14
 
15
15
  clazz=case path
16
- when /gif$/i
17
- RGhost::Gif
18
- when /jpe?g$/i
19
- RGhost::Jpeg
20
- when /(eps|template)$/i
21
- RGhost::Eps
16
+ when /gif$/i: RGhost::Gif
17
+ when /jpe?g$/i: RGhost::Jpeg
18
+ when /(eps|template)$/i : RGhost::Eps
22
19
  else raise NameError.new("Unsupported format")
23
20
  end
24
21
 
@@ -1,7 +1,5 @@
1
1
  require "ps_object"
2
2
  require "cursor"
3
- require "color"
4
- require "point"
5
3
  require "point"
6
4
  require "line_width"
7
5
 
data/lib/rghost/paper.rb CHANGED
@@ -87,10 +87,8 @@ class RGhost::Paper < RGhost::PsObject
87
87
 
88
88
 
89
89
  return case RGhost::Config::GS[:unit].new
90
- when RGhost::Units::Cm
91
- (value.to_f*72/2.545).to_i
92
- when RGhost::Units::Inch
93
- (value.to_f*72).to_i
90
+ when RGhost::Units::Cm: (value.to_f*72/2.545).to_i
91
+ when RGhost::Units::Inch: (value.to_f*72).to_i
94
92
  else
95
93
  value
96
94
  end
@@ -107,10 +105,9 @@ class RGhost::Paper < RGhost::PsObject
107
105
  #end
108
106
 
109
107
  case @options[:margin]
110
- when Numeric
111
- mt=mr=mb=ml=RGhost::Units::parse(@options[:margin])
112
- when Array
113
- mt=RGhost::Units::parse(@options[:margin][0] || DEFAULT_OPTIONS[:margin_top] )
108
+ when Numeric: mt=mr=mb=ml=RGhost::Units::parse(@options[:margin])
109
+ when Array:
110
+ mt=RGhost::Units::parse(@options[:margin][0] || DEFAULT_OPTIONS[:margin_top] )
114
111
  mr=RGhost::Units::parse(@options[:margin][1] || DEFAULT_OPTIONS[:margin_right])
115
112
  mb=RGhost::Units::parse(@options[:margin][2] || DEFAULT_OPTIONS[:margin_bottom])
116
113
  ml=RGhost::Units::parse(@options[:margin][3] || DEFAULT_OPTIONS[:margin_left] )
@@ -127,11 +124,12 @@ class RGhost::Paper < RGhost::PsObject
127
124
  def format_paper
128
125
 
129
126
  case @paper
130
- when Symbol
131
- p=RGhost::Constants::Papers::STANDARD[@paper.to_s.downcase.to_sym]
127
+ when Symbol:
128
+
129
+ p=RGhost::Constants::Papers::STANDARD[@paper.to_s.downcase.to_sym]
132
130
  p.reverse! if @options[:landscape]
133
131
  {:rg => "/pagesize #{to_array( p ) } def\n", :gs => p, :done => true}
134
- when Array
132
+ when Array:
135
133
  @paper.reverse! if @options[:landscape]
136
134
  {:rg => "/pagesize #{to_array( @paper.map{|v| to_pt(v) } ) } def\n", :gs => @paper, :done => false}
137
135
  end
@@ -5,10 +5,10 @@ module RGhost::ParseText #:nodoc:
5
5
 
6
6
  unless @tag_parse
7
7
  case @options[:text_align]
8
- when :center, :right
8
+ when :center, :right:
9
9
  @text.split(/\n/).map{|l| "#{to_string(l)} :text_proc_cr :nbw " }.to_s
10
10
  jump_with=':nbw'
11
- when :left,nil
11
+ when :left,nil:
12
12
  if self.class == RGhost::Text
13
13
  return @text.split(/\n/).map{|l| " :text #{to_string(l)} :text_proc nrdp " }.to_s
14
14
 
@@ -57,7 +57,7 @@ class RGhost::Polygon < RGhost::PsObject
57
57
 
58
58
  def ps
59
59
  graph=RGhost::Graphic.new
60
- graph.set Cursor.moveto(@options)
60
+ graph.set RGhost::Cursor.moveto(@options)
61
61
  graph.set RGhost::Border.new(@options[:border]) if @options[:border]
62
62
 
63
63
  @points.each{|p| graph.set RGhost::Line.rlineto(p) }
@@ -1,50 +1,19 @@
1
- require "ps_object"
2
- require "dynamic_document_callback"
3
- require "static_document_callback"
4
- require "paper"
5
- require "load"
6
- #require "function"
7
- require "font"
8
- require "cursor"
9
- require "show"
10
- require "color"
11
- require "graphic"
12
- #require "arc"
13
- require "newpath"
14
- require "line"
15
- require 'parse_text'
16
- require "line_width"
17
- require "textarea"
18
- require "variable"
19
- require "eps"
20
- require "jpeg"
21
- require "gif"
22
- require "text_in"
23
- require "text_link_in"
24
- require "ruby_ghost_engine"
25
- require "convert"
26
- require "text"
27
- require "dash"
28
- require "border"
29
- require "shape_content"
30
- #require "rectangle"
31
- require "vertical_line"
32
- require "horizontal_line"
33
- require "frame"
34
- require "polygon"
35
- require "circle"
36
- require "how_to"
37
- require 'rectangle_link'
1
+ [:ps_object, :dynamic_document_callback,:static_document_callback, :paper, :load,
2
+ :cursor,:show, :color, :graphic, :newpath, :line, :parse_text,:line_width, :textarea,
3
+ :variable, :eps, :jpeg, :gif, :text_in, :text_link_in, :ruby_ghost_engine, :convert,
4
+ :text, :dash, :border, :shape_content, :vertical_line, :horizontal_line,
5
+ :frame, :polygon, :circle, :how_to, :rectangle_link].each{|lib| require "rghost/#{lib}" }
38
6
 
39
7
 
40
8
  #PsFacade is just a big facade involving an instance of most postscript objects.
41
9
  class RGhost::PsFacade < RGhost::PsObject
42
10
  attr_reader :rows
43
11
 
44
- def initialize(&block)
12
+ def initialize #(&block)
45
13
  super(""){}
46
14
  @rows=0
47
- instance_eval(&block) if block
15
+ yield self if block_given?
16
+ #instance_eval(&block) if block
48
17
  end
49
18
 
50
19
  #A facade for the method Cursor.next_row
@@ -65,13 +34,23 @@ class RGhost::PsFacade < RGhost::PsObject
65
34
  end
66
35
 
67
36
  #A facade for the class Graphic
68
- def graphic(ps_obj=RGhost::PsObject.new,&block)
69
- set RGhost::Graphic.new(ps_obj,&block)
37
+ def graphic(&block)
38
+ psfc=RGhost::PsFacade.new
39
+ yield psfc
40
+ raw :gsave
41
+ set psfc
42
+ raw :grestore
43
+
70
44
  end
71
45
 
72
46
  #A facade for the class NewPath
73
47
  def newpath(&block)
74
- set RGhost::NewPath.new(&block)
48
+ psfc=RGhost::PsFacade.new
49
+ yield psfc
50
+ raw :newpath
51
+ set psfc
52
+ raw :closepath
53
+ #set RGhost::NewPath.new(&block)
75
54
  end
76
55
 
77
56
  #A facade for the method Cursor.showpage
@@ -54,16 +54,16 @@ class RGhost::Engine
54
54
 
55
55
 
56
56
  case @document
57
- when RGhost::Document
57
+ when RGhost::Document:
58
58
  file_in="#{tmp_filename}.rgin"
59
59
  params.concat @document.gs_paper
60
60
  fi=File.open(file_in,'w')
61
61
  fi.puts @document.ps
62
62
  fi.close
63
- when File
63
+ when File:
64
64
  file_in=@document.path
65
65
  #@delete_input=false unless @options[:debug]
66
- when String
66
+ when String:
67
67
  file_in=@document
68
68
  #@delete_input=false unless @options[:debug]
69
69
  end
@@ -87,7 +87,7 @@ class RGhost::Engine
87
87
  else
88
88
  if multipage
89
89
  file_out.gsub!(/_%04d/,"_*")
90
- @output=Dir.glob(file_out).map { |f| File.open(f) }
90
+ @output=Dir.glob(file_out).map { |f| f }
91
91
  else
92
92
  @output=File.open(file_out)
93
93
  end
@@ -103,10 +103,10 @@ class RGhost::Engine
103
103
 
104
104
  def clear_output
105
105
  case @output
106
- when File
106
+ when File:
107
107
  @output.close
108
108
  File.delete(@output.path)
109
- when Array
109
+ when Array:
110
110
  @output.each do |f|
111
111
  f.close
112
112
  File.delete(f.path)
@@ -135,13 +135,13 @@ class RGhost::Engine
135
135
  def format_params(v,pre="-d")
136
136
  r=[]
137
137
  case v
138
- when Symbol
138
+ when Symbol:
139
139
  r << "#{pre}#{v}"
140
- when Array
140
+ when Array:
141
141
  v.each do |av|
142
142
  r << format_params(av,pre).to_s
143
143
  end
144
- when Hash
144
+ when Hash:
145
145
  v.each do |k,v|
146
146
  r << "#{pre}#{k}=#{v.to_s.gsub(/ /,'')}"
147
147
  end
@@ -21,7 +21,8 @@ module RGhost::RubyToPs
21
21
 
22
22
 
23
23
  def ps_escape(value)
24
- value.to_s.gsub(/(\(|\)|\\)/,'\\\\\1')
24
+ value.to_s.gsub(/\(/,"\050").gsub(/\)/,"\051").gsub(/\\/,"\134")
25
+ #value.to_s.gsub(/(\(|\)|\\)/,'\\\\\1')
25
26
  end
26
27
 
27
28
  def to_bool(value)
@@ -38,14 +39,10 @@ module RGhost::RubyToPs
38
39
  ps_arr=[]
39
40
  arr.each do |a|
40
41
  ps_arr << case a
41
- when TrueClass,FalseClass
42
- to_bool(a)
43
- when Numeric
44
- a
45
- when Proc
46
- a.to_s
47
- when Array
48
- to_array(a)
42
+ when TrueClass,FalseClass: to_bool(a)
43
+ when Numeric: a
44
+ when Proc: a.to_s
45
+ when Array: to_array(a)
49
46
  else
50
47
  to_string(a.to_s)
51
48
  end
@@ -70,8 +67,7 @@ module RGhost::RubyToPs
70
67
  tudo=""
71
68
  s.each do |v|
72
69
  case v
73
- when /^%/
74
- tudo << "#{v.gsub(/%/,'')} to_s show "
70
+ when /^%/: tudo << "#{v.gsub(/%/,'')} to_s show "
75
71
  else
76
72
  tudo << "(#{ps_escape(v)}) show "
77
73
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rghost
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.6.5
4
+ version: 0.8.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shairon Toledo
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-20 00:00:00 -04:00
12
+ date: 2009-05-30 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15