Module: RGhost::Config
- Defined in:
- lib/rghost/ruby_ghost_config.rb
Overview
Rghost setup with Ghostscript. Ghostscript runs on a variety of platforms, this is why we recommend the non coupled install for non *nix environments. 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.
RGhost::Config::GS
Operating mode
-
:gsparams
In this mode RGhost just pass parameters to the Ghostscript framework. -
:gsapi
based on the exchange of data between Ruby and Ghostscript via rgengine.so using gslib.so.8 or gslib-esp.so.8.
RGhost::Config::GS
Path to the ghostscript executable.
Example on windows
RGhost::Config::GS = “C:\gs\bin\gswin32c.exe”
Example on Linux
RGhost::Config::GS = “/usr/bin/gs”
RGhost::Config::GS
Temporary directory
Example
RGhost::Config::GS = “/tmp”
RGhost::Config::GS
Allows you to add/remove options. (use with caution!)
Example
RGhost::Config::GS << “-dSAFER”
RGhost::Config::GS
Defines the maximum number of elements for each matrix inside postscript’s internal stack, avoiding a stack overflow error..
Example
RGhost::Config::GS=5000
RGhost::Config::GS
Set the measure units. See Units::Unit for available units.
Example
RGhost::Config::GS=Units::Cm
RGhost::Config::GS
Ruby to PS character conversion proxy. Necessary when the source code isn’t on the same encoding of the document. Params is a block that returns a String. The default setting is nil.
Example
RGhost::Config::GS= lambda {|text| Iconv::iconv(“latin1”,“utf8”, text).to_s}
RGhost::Config::GS
Sets the Postscript font encoding. Default: :IsoLatin
Example
RGhost::Config::GS= :IsoLatin
RGhost::Config::GS
Sets the file-in external encoding (Ruby 1.9). Affects how data will be written and could help when dealing with encoding conversion errors. Default: nil
Example
RGhost::Config::GS= ‘ascii-8bit’
Constant Summary collapse
- DEFAULT_PORTRAIT_TEMPLATE =
File.join(File.dirname(__FILE__),"ps","rghost_default_template.eps")
- GS =
{ :mode => :gsparams, :plugin => nil, :path => nil, :tmpdir => ENV["TMP"] || ENV["TMPDIR"] || ENV["TEMPDIR"] || ENV["TEMP"] || "/tmp", :pslibdir => File.join( File.dirname(__FILE__),"ps"), :extensions => [], :preload => [], :default_params=> %w(gs -dNOPAUSE -dBATCH -dQUIET -dNOPAGEPROMPT), :stack_elements => 5000, :font_encoding => :IsoLatin, :charset_convert => begin if RUBY_VERSION =~ /^1.9/ lambda { |text| text.encode('ISO-8859-1', 'UTF-8') } else require 'iconv' lambda { |text| Iconv::iconv('latin1','utf-8', text).join } end end, :external_encoding => nil, :fontsize => 8, :unit => RGhost::Units::Cm }
- FONTMAP =
.
Preseted tags
FONTMAP=RGhost::FontMap.new :name => “Helvetica”, :size => 8, :encoding => false do
new :span new :b, :name => "Helvetica-Bold" new :bold, :name => "Helvetica-Bold" new :normal, :name => "Helvetica" new :i, :name => "Helvetica-Oblique", :size => 8 new :bi, :name => "Helvetica-BoldOblique" new :big, :size => 10 new :small, :size => 7 new :h1, :name => "Helvetica", :size => 14 new :h2, :name => "Helvetica", :size => 13 new :h3, :name => "Helvetica", :size => 12 new :h4, :name => "Helvetica", :size => 11 new :h5, :name => "Helvetica", :size => 10 new :title, :name => "Helvetica", :size => 20 new :pre, :name => "Courier" end
RGhost::FontMap.new :name => "Helvetica", :size => 8, :encoding => true do new :span new :b, :name => "Helvetica-Bold" new :bold, :name => "Helvetica-Bold" new :normal, :name => "Helvetica" new :i, :name => "Helvetica-Oblique", :size => 8 new :bi, :name => "Helvetica-BoldOblique" new :big, :size => 10 new :small, :size => 7 new :h1, :name => "Helvetica", :size => 14 new :h2, :name => "Helvetica", :size => 13 new :h3, :name => "Helvetica", :size => 12 new :h4, :name => "Helvetica", :size => 11 new :h5, :name => "Helvetica", :size => 10 new :title, :name => "Helvetica", :size => 20 new :pre, :name => "Courier" end
Class Method Summary collapse
-
.config_platform ⇒ Object
:nodoc:.
-
.encode_test(value) ⇒ Object
This method is a helper to gets the best encoding.
-
.environment_fonts(text = "The quick brown fox jumps over the lazy dog") ⇒ Object
Generates font catalog to use into method define_tags on Document RGhost::Config.enviroment_fonts.render :pdf, :filename => “mycatalog.pdf” .
-
.is_ok? ⇒ Boolean
Test if your environment is ready to works.
Class Method Details
.config_platform ⇒ Object
:nodoc:
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/rghost/ruby_ghost_config.rb', line 85 def self.config_platform #:nodoc: const= 'PLATFORM' const = "RUBY_"+const if RUBY_VERSION =~ /^1.9/ GS[:path]=case Object.const_get(const) when /linux/ then "/usr/bin/gs" when /darwin/ then "/opt/local/bin/gs" when /freebsd|bsd/ then "/usr/local/bin/gs" when /mswin/ then "C:\\gs\\bin\\gswin32\\gswin32c.exe" end not_found_msg="\nGhostscript not found in your environment.\nInstall it and set the variable RGhost::Config::GS[:path] with the executable.\nExample: RGhost::Config::GS[:path]='/path/to/my/gs' #unix-style\n RGhost::Config::GS[:path]=\"C:\\\\gs\\\\bin\\\\gswin32c.exe\" #windows-style\n" raise not_found_msg unless (File.exists? GS[:path]) end |
.encode_test(value) ⇒ Object
This method is a helper to gets the best encoding.
You can generate this page with the code. RGhost::Config.encode_teste(“Fiancé”).render :pdf, :filename => “/tmp/mytest.pdf”
The encode will use on Document class. doc=Document.new :font_encoding => ‘IsoLatin’
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/rghost/ruby_ghost_config.rb', line 137 def self.encode_test(value) d=RGhost::Document.new :paper => :A4, :margin_left => 2 #, :landscape => true d.before_page_create do |b| b.image RGhost::Config::DEFAULT_PORTRAIT_TEMPLATE end exp=File.join(File.dirname(__FILE__),"ps","*.enc") d.show "String (Using Helvetica Font)", :with => :b d.moveto :x => 16 d.show "Encode Name", :with => :b d.horizontal_line :bottom d.next_row Dir.glob(exp).sort.each do |f| name=File.basename(f) name.gsub!(/\.enc/,'') d.set RGhost::Load.library(name,:enc) d.set RGhost::Variable.new(:default_encoding,name) d.set RGhost::FontMap.new { new(:font_test, :name => "Helvetica",:size => 8,:color => "#FF0000", :encoding => true) } d.show "#{value}" , :with => :font_test d.moveto :x => 16 d.show "#{name}", :with => :i d.next_row end d end |
.environment_fonts(text = "The quick brown fox jumps over the lazy dog") ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/rghost/ruby_ghost_config.rb', line 170 def self.environment_fonts(text="The quick brown fox jumps over the lazy dog") d=RGhost::Document.new :margin_left => 2.3, :margin_bottom => 2.3 d.before_page_create do |b| b.image RGhost::Config::DEFAULT_PORTRAIT_TEMPLATE end d.show "Search Path" d.horizontal_line :bottom d.next_row d.raw :default_font d.raw %Q{ LIBPATH{ limit_left current_row moveto show nrdp } forall } d.next_row d.show "Example" d.moveto :x=> 13 d.show "Font Name" d.horizontal_line :bottom d.next_row #=begin d.raw %Q{ Fontmap{ 50 string cvs pop dup findfont 10 scalefont setfont limit_left current_row moveto (#{text}) show 13 cm current_row moveto default_font 0 setgray 50 string cvs show nrdp } forall } #=end d.done d end |
.is_ok? ⇒ Boolean
Test if your environment is ready to works. If yes the page below will show.
You can generate this page with the code. RGhost::Config.is_ok?.render :pdf, :filename => “/tmp/mytest.pdf”
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/rghost/ruby_ghost_config.rb', line 105 def self.is_ok? d=RGhost::Document.new :margin_left => 2.3, :margin_bottom => 2.3 d.benchmark(:start) d.before_page_create do |b| b.image RGhost::Config::DEFAULT_PORTRAIT_TEMPLATE end d. do new :bigger, :size => 150, :color => "#AAFF33" end d.text_in :x => 6, :y=> 15, :write => "Yes!", :with => :bigger d.text_in :x => 10, :y=> 14, :write => "Your environment is ready!" d.text_in :x => 10, :y=> 13, :write => "RGhost Version " + RGhost::VERSION::STRING d.text_in :x => 10, :y=> 12, :write => "Created at " + Time.at(RGhost::VERSION::DATE).to_s d.text_in :x => 10, :y=> 11, :write => "Now " + Time.now.to_s d.benchmark(:stop) d.done d end |