Class: RGhost::Paper

Inherits:
PsObject show all
Includes:
RubyToPs
Defined in:
lib/rghost/paper.rb

Overview

Constant Summary collapse

DEFAULT_OPTIONS =
{ :landscape => false, 
  :margin_top => 1, 
  :margin_right => 1, 
  :margin_bottom => 1,
  :margin_left => 1, 
  :duplex => false, 
  :tumble => false
}

Instance Method Summary collapse

Methods included from RubyToPs

#array_to_stack, #hash_to_array, #pack_string, #ps_escape, #string_eval, #to_array, #to_bool, #to_string, #to_string_array

Methods inherited from PsObject

#<<, #call, #graphic_scope, #raw, #set, #to_s

Constructor Details

#initialize(paper = :A4, options = {}) ⇒ Paper

Examples

Create paper by name

doc=Document.new :paper => :A4

Create paper by name in landscape

doc=Document.new :paper => :A4 , :landscape => true

Create custom paper

doc=Document.new :paper => [10,15]

Defining all margins

doc=Document.new :paper => :A5, :margin => 0.5

Defining custom margins

doc=Document.new :paper => :A5, :margin => [0.5, 1, 0.5, 2] #=>[top,right,bottom,left] clockwise

Defining particular margin

doc=Document.new :paper => :A5, :margin_top => 1, :margin_left => 0.3

Defining two faces document to printer

doc=Document.new :paper => :A5, :duplex => true

Parameters

  • paper - The paper parameter can be either a Symbol or a Array. If paper parameter is a Symbol its value will search in RGhost::Constants::Papers . If paper parameter is a Array(with two numeric elements) will be position [0] width and [1] height of page. Example: doc=Document.new :paper => :A3 #=> Build new A3 paper doc=Document.new :paper => [5,5] #=> Build new custom paper 5x5, using default unit defined in RGhost::Config::GS.

Configuration options:

  • :landscape - If set to true will invert width to height and height to width.

  • :margin - Specifies margins non-printable area. It can be one Numeric for all margins or Array [top,right,bottom,left] margins.

  • :duplex - Specifies two faces(for print)

  • :tumble - Specifies kind of duplex



54
55
56
57
58
# File 'lib/rghost/paper.rb', line 54

def initialize(paper=:A4, options={})
  
  @options=DEFAULT_OPTIONS.merge(options)
  @paper=paper  
end

Instance Method Details

#gs_paperObject

:nodoc:



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/rghost/paper.rb', line 71

def gs_paper #:nodoc:
  fp=format_paper
  p=fp[:gs]
  #["-dDEVICEWIDTHPOINTS=#{p[0]}", "-dDEVICEHEIGHTPOINTS=#{p[1]}"]
  if fp[:done]
    ["-dDEVICEWIDTHPOINTS=#{p[0]}", "-dDEVICEHEIGHTPOINTS=#{p[1]}"]
  else
    ["-dDEVICEWIDTHPOINTS=#{to_pt(p[0])}", "-dDEVICEHEIGHTPOINTS=#{to_pt(p[1])}"]
  end

end

#psObject



60
61
62
63
64
65
66
67
68
# File 'lib/rghost/paper.rb', line 60

def ps
  d=format_duplex
  p=format_paper[:rg]
  m=format_margin

  lib=RGhost::Load.library :paper
  
  d<< p << m << lib.ps    
end