rghost 0.8.7.5 → 0.8.7.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,12 +3,12 @@ require 'iconv'
3
3
  require 'rghost/font_map'
4
4
 
5
5
  #Rghost setup with Ghostscript.
6
- #Ghostscript runs on a variety of platforms, this is why we recommend the non coupled install for non *nix environments.
6
+ #Ghostscript runs on a variety of platforms, this is why we recommend the non coupled install for non *nix environments.
7
7
  #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.
8
8
  #===RGhost::Config::GS[:mode]
9
9
  #Operating mode
10
10
  #* <tt>:gsparams</tt> In this mode RGhost just pass parameters to the Ghostscript framework.
11
- #* <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
+ #* <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.
12
12
  #
13
13
  #===RGhost::Config::GS[:path]
14
14
  #Path to the ghostscript executable.
@@ -33,7 +33,7 @@ require 'rghost/font_map'
33
33
  #RGhost::Config::GS[:stack_elements]=5000
34
34
  #
35
35
  #===RGhost::Config::GS[:unit]
36
- #Set the measure units. See Units::Unit for available units.
36
+ #Set the measure units. See Units::Unit for available units.
37
37
  #====Example
38
38
  #RGhost::Config::GS[:unit]=Units::Cm
39
39
  #
@@ -48,11 +48,17 @@ require 'rghost/font_map'
48
48
  #====Example
49
49
  #RGhost::Config::GS[:font_encoding]= :IsoLatin
50
50
  #
51
+ #===RGhost::Config::GS[:external_encoding]
52
+ #Sets the file-in external encoding (Ruby 1.9). Affects how data will be written and
53
+ #could help when dealing with encoding conversion errors. Default: nil
54
+ #====Example
55
+ #RGhost::Config::GS[:external_encoding]= 'ascii-8bit'
56
+ #
51
57
  module RGhost::Config
52
-
58
+
53
59
  DEFAULT_PORTRAIT_TEMPLATE = File.join(File.dirname(__FILE__),"ps","rghost_default_template.eps")
54
-
55
-
60
+
61
+
56
62
  GS={
57
63
  :mode => :gsparams,
58
64
  :plugin => nil,
@@ -66,18 +72,19 @@ module RGhost::Config
66
72
  :font_encoding => :IsoLatin,
67
73
  :charset_convert => lambda {|text| Iconv::iconv('latin1','utf-8', text).join },
68
74
  #:charset_convert => nil,
75
+ :external_encoding => nil,
69
76
  :fontsize => 8,
70
77
  :unit => RGhost::Units::Cm
71
78
  }
72
-
73
-
74
-
75
-
76
-
79
+
80
+
81
+
82
+
83
+
77
84
  def self.config_platform #:nodoc:
78
-
85
+
79
86
  const= 'PLATFORM'
80
- const = "RUBY_"+const if RUBY_VERSION =~ /^1.9/
87
+ const = "RUBY_"+const if RUBY_VERSION =~ /^1.9/
81
88
  GS[:path]=case Object.const_get(const)
82
89
  when /linux/ then "/usr/bin/gs"
83
90
  when /darwin/ then "/opt/local/bin/gs"
@@ -108,13 +115,13 @@ module RGhost::Config
108
115
  d.text_in :x => 10, :y=> 13, :write => "RGhost Version " + RGhost::VERSION::STRING
109
116
  d.text_in :x => 10, :y=> 12, :write => "Created at " + Time.at(RGhost::VERSION::DATE).to_s
110
117
  d.text_in :x => 10, :y=> 11, :write => "Now " + Time.now.to_s
111
-
118
+
112
119
  d.benchmark(:stop)
113
120
  d.done
114
121
  d
115
-
116
-
117
-
122
+
123
+
124
+
118
125
  end
119
126
  #This method is a helper to gets the best encoding.
120
127
  #
@@ -122,7 +129,7 @@ module RGhost::Config
122
129
  #
123
130
  #You can generate this page with the code.
124
131
  # RGhost::Config.encode_teste("Fiancé").render :pdf, :filename => "/tmp/mytest.pdf"
125
- #
132
+ #
126
133
  #The encode will use on Document class.
127
134
  # doc=Document.new :font_encoding => 'IsoLatin'
128
135
  #
@@ -137,7 +144,7 @@ module RGhost::Config
137
144
  d.show "Encode Name", :with => :b
138
145
  d.horizontal_line :bottom
139
146
  d.next_row
140
-
147
+
141
148
  Dir.glob(exp).sort.each do |f|
142
149
  name=File.basename(f)
143
150
  name.gsub!(/\.enc/,'')
@@ -146,12 +153,12 @@ module RGhost::Config
146
153
  d.set RGhost::FontMap.new {
147
154
  new(:font_test, :name => "Helvetica",:size => 8,:color => "#FF0000", :encoding => true)
148
155
  }
149
-
156
+
150
157
  d.show "#{value}" , :with => :font_test
151
158
  d.moveto :x => 16
152
159
  d.show "#{name}", :with => :i
153
160
  d.next_row
154
-
161
+
155
162
  end
156
163
  d
157
164
  end
@@ -160,7 +167,7 @@ module RGhost::Config
160
167
  #link:images/environment_fonts.png
161
168
  #
162
169
  def self.environment_fonts(text="The quick brown fox jumps over the lazy dog")
163
-
170
+
164
171
  d=RGhost::Document.new :margin_left => 2.3, :margin_bottom => 2.3
165
172
  d.before_page_create do |b|
166
173
  b.image RGhost::Config::DEFAULT_PORTRAIT_TEMPLATE
@@ -171,10 +178,10 @@ module RGhost::Config
171
178
  d.raw :default_font
172
179
  d.raw %Q{
173
180
  LIBPATH{
174
- limit_left current_row moveto show
181
+ limit_left current_row moveto show
175
182
  nrdp
176
183
  } forall
177
-
184
+
178
185
  }
179
186
  d.next_row
180
187
  d.show "Example"
@@ -182,17 +189,17 @@ module RGhost::Config
182
189
  d.show "Font Name"
183
190
  d.horizontal_line :bottom
184
191
  d.next_row
185
- #=begin
192
+ #=begin
186
193
  d.raw %Q{
187
- Fontmap{
194
+ Fontmap{
188
195
  50 string cvs pop dup findfont 10 scalefont setfont
189
- limit_left current_row moveto (#{text}) show
196
+ limit_left current_row moveto (#{text}) show
190
197
  13 cm current_row moveto default_font 0 setgray
191
198
  50 string cvs show
192
- nrdp
199
+ nrdp
193
200
  } forall
194
201
  }
195
- #=end
202
+ #=end
196
203
  d.done
197
204
  d
198
205
  end
@@ -200,7 +207,7 @@ module RGhost::Config
200
207
  # .
201
208
  #
202
209
  #
203
- #Preseted tags
210
+ #Preseted tags
204
211
  #
205
212
  #
206
213
  #
@@ -239,5 +246,6 @@ module RGhost::Config
239
246
  new :title, :name => "Helvetica", :size => 20
240
247
  new :pre, :name => "Courier"
241
248
  end
242
-
249
+
243
250
  end
251
+
@@ -4,18 +4,18 @@ require "rghost/constants"
4
4
  class RGhost::Engine
5
5
  attr_reader :errors, :error, :output
6
6
  DEFAULT_OPTIONS={:device => :pdf }
7
-
7
+
8
8
  include RGhost::Constants::Devices
9
9
 
10
10
  def initialize(document,options={})
11
- @document=document
11
+ @document=document
12
12
  @options=DEFAULT_OPTIONS.merge(options)
13
13
  @errors=[]
14
14
  @error=false
15
- @output=nil
15
+ @output=nil
16
16
  @delete_input=true
17
17
 
18
- end
18
+ end
19
19
 
20
20
 
21
21
  def render(device=nil)
@@ -28,12 +28,13 @@ class RGhost::Engine
28
28
  else
29
29
  file_out=tmp_filename
30
30
  end
31
+ external_encoding = RGhost::Config::GS[:external_encoding]
31
32
 
32
33
  file_err="#{tmp_filename}.rgerr"
33
-
34
- multipage=@options[:multipage]
34
+
35
+ multipage=@options[:multipage]
35
36
  file_out.gsub!(/\./,"_%04d.") if multipage
36
-
37
+
37
38
  params=RGhost::Config::GS[:default_params].dup #default parameters gs engine
38
39
  params << @document.additional_params.join(" ") unless @options[:convert]
39
40
  params << "-I#{RGhost::Config::GS[:pslibdir]}"
@@ -41,7 +42,7 @@ class RGhost::Engine
41
42
  params << "-I#{RGhost::Config::GS[:extensions].join(' -I')}" if RGhost::Config::GS[:extensions]
42
43
  params << "-sDEVICE=#{device_for(device)}"
43
44
  params.concat format_params(@options[:d],"-d") if @options[:d]
44
- params.concat format_params(@options[:s],"-s") if @options[:s]
45
+ params.concat format_params(@options[:s],"-s") if @options[:s]
45
46
  params << "-r#{@options[:resolution]}" if @options[:resolution]
46
47
  params << "-g#{@options[:size]}" if @options[:size]
47
48
  if @options[:range]
@@ -49,39 +50,40 @@ class RGhost::Engine
49
50
  params << "-dLastPage=#{@options[:range].last}"
50
51
  end
51
52
  params << "-sstdout=#{file_err}"
52
- params << @options[:raw] if @options[:raw]
53
+ params << @options[:raw] if @options[:raw]
53
54
  params << "-sOutputFile=#{file_out}"
54
-
55
-
56
- case @document
55
+
56
+
57
+ case @document
57
58
  when RGhost::Document
58
- file_in="#{tmp_filename}.rgin"
59
+ file_in="#{tmp_filename}.rgin"
59
60
  params.concat @document.gs_paper
60
- fi=File.open(file_in,'w')
61
+ mode=external_encoding.nil? ? 'w' : "w:#{external_encoding}"
62
+ fi=File.open(file_in,mode)
61
63
  fi.puts @document.ps
62
64
  fi.close
63
65
  when File
64
- file_in=@document.path
66
+ file_in=@document.path
65
67
  #@delete_input=false unless @options[:debug]
66
68
  when String
67
- file_in=@document
69
+ file_in=@document
68
70
  #@delete_input=false unless @options[:debug]
69
71
  end
70
72
 
71
73
  params << file_in
72
-
74
+
73
75
  #puts params.inspect
74
-
76
+
75
77
  if RGhost::Config::GS[:mode] == :gslib
76
78
  require "rghost/rgengine"
77
- gs=RGEngine.new
79
+ gs=RGEngine.new
78
80
  @error=!gs.render(params,params.size)
79
81
  else
80
82
  require 'rghost/gs_alone'
81
83
  gs=RGhost::GSAlone.new(params,@options[:debug])
82
84
  @error=!gs.run
83
85
  end
84
-
86
+
85
87
  if @error # if error
86
88
  @errors=File.open(file_err).readlines if File.exists?(file_err)
87
89
  else
@@ -96,7 +98,7 @@ class RGhost::Engine
96
98
  File.delete(file_err)
97
99
  File.delete(file_in) unless (@options[:debug] || @options[:convert])
98
100
  rescue
99
- end
101
+ end
100
102
  log(params) if @options[:logfile]
101
103
  return @output
102
104
  end
@@ -106,8 +108,8 @@ class RGhost::Engine
106
108
  when File
107
109
  @output.close
108
110
  File.delete(@output.path)
109
- when Array
110
- @output.each do |f|
111
+ when Array
112
+ @output.each do |f|
111
113
  f.close
112
114
  File.delete(f.path)
113
115
  end
@@ -125,13 +127,13 @@ class RGhost::Engine
125
127
  flog.puts "[#{id}] GS OPTIONS: #{gp.join(" ")}"
126
128
  if @error
127
129
  flog.puts "[#{id}] EXIT STATUS: ERROR"
128
- flog.puts @errors.uniq.map {|m| "[#{id}] #{m}" }.to_s;
130
+ flog.puts @errors.uniq.map {|m| "[#{id}] #{m}" }.to_s;
129
131
  else
130
- flog.puts "[#{id}] EXIT STATUS: OK"
132
+ flog.puts "[#{id}] EXIT STATUS: OK"
131
133
  end
132
134
  end
133
-
134
-
135
+
136
+
135
137
  def format_params(v,pre="-d")
136
138
  r=[]
137
139
  case v
@@ -143,14 +145,13 @@ class RGhost::Engine
143
145
  end
144
146
  when Hash
145
147
  v.each do |k,v|
146
- r << "#{pre}#{k}=#{v.to_s.gsub(/ /,'')}"
148
+ r << "#{pre}#{k}=#{v.to_s.gsub(/ /,'')}"
147
149
  end
148
150
  else
149
- return ""
151
+ return ""
150
152
  end
151
- return r;
153
+ return r;
152
154
  end
153
155
 
154
156
  end
155
157
 
156
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rghost
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease: false
4
+ hash: 31
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
9
  - 7
10
- - 5
11
- version: 0.8.7.5
10
+ - 6
11
+ version: 0.8.7.6
12
12
  platform: ruby
13
13
  authors:
14
14
  - Shairon Toledo
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-02-06 00:00:00 -05:00
19
+ date: 2011-06-07 00:00:00 -03:00
20
20
  default_executable:
21
21
  dependencies: []
22
22
 
@@ -190,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
190
  requirements: []
191
191
 
192
192
  rubyforge_project: Ruby Ghostscript Engine is a document creation and conversion API, support(PDF,PS,GIF,TIF,PNG,JPG...). It uses the GhostScript framework for the format conversion, utilizes EPS templates and is optimized to work with larger documents.
193
- rubygems_version: 1.3.7
193
+ rubygems_version: 1.5.2
194
194
  signing_key:
195
195
  specification_version: 3
196
196
  summary: Ruby Ghostscript Engine is a document creation and conversion API, support(PDF,PS,GIF,TIF,PNG,JPG...). It uses the GhostScript framework for the format conversion, utilizes EPS templates and is optimized to work with larger documents.