Module RGhost::Config
In: ruby_ghost_config.rb

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[:mode]

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]

Path to the ghostscript executable.

Example on windows

RGhost::Config::GS[:path] = "C:\gs\bin\gswin32c.exe"

Example on Linux

RGhost::Config::GS[:path] = "/usr/bin/gs"

RGhost::Config::GS[:tmpdir]

Temporary directory

Example

RGhost::Config::GS[:tmpdir] = "/tmp"

RGhost::Config::GS[:default_params]

Allows you to add/remove options. (use with caution!)

Example

RGhost::Config::GS[:default_params] << "-dSAFER"

RGhost::Config::GS[:stack_elements]

Defines the maximum number of elements for each matrix inside postscript‘s internal stack, avoiding a stack overflow error..

Example

RGhost::Config::GS[:stack_elements]=5000

RGhost::Config::GS[:unit]

Set the measure units. See Units::Unit for available units.

Example

RGhost::Config::GS[:unit]=Units::Cm

RGhost::Config::GS[:charset_convert]

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[:charset_convert]= lambda {|text| Iconv::iconv("latin1","utf8", text).to_s}

RGhost::Config::GS[:font_encoding]

Sets the Postscript font encoding. Default: :IsoLatin

Example

RGhost::Config::GS[:font_encoding]= :IsoLatin

Methods

Constants

DEFAULT_PORTRAIT_TEMPLATE = File.join(File.dirname(__FILE__),"ps","rghost_default_template.eps")
GS = { :mode => :gsparams, :plugin => nil, :path => "/usr/bin/gs", :tmpdir => ENV["TMP"] || ENV["TMPDIR"] || ENV["TEMPDIR"] || ENV["TEMP"] || "/tmp", :pslibdir => File.join( File.dirname(__FILE__),"ps"), :default_params=> %w(gs -dNOPAUSE -dBATCH -dQUIET -dNOPAGEPROMPT), :stack_elements => 5000, :font_encoding => :IsoLatin, :charset_convert => lambda {|text| Iconv::iconv('latin1','utf8', text) }, :fontsize => 8, :unit => RGhost::Units::Cm
FONTMAP = RGhost::FontMap.new :name => "Helvetica", :size => 8, :encoding => false do new :span  
 .
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

Public Class methods

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'

Generates font catalog to use into method define_tags on Document

  RGhost::Config.enviroment_fonts.render :pdf, :filename => "mycatalog.pdf"

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"

[Validate]