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
}

Constants included from RubyToPs

RubyToPs::UTF8_ENCODINGS

Instance Attribute Summary collapse

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
59
# File 'lib/rghost/paper.rb', line 54

def initialize(paper=:A4, options={})
  
  @options=DEFAULT_OPTIONS.merge(options)
  @landscape = @options[:landscape] || false
  @paper=paper  
end

Instance Attribute Details

#landscapeObject (readonly)

Returns the value of attribute landscape.



24
25
26
# File 'lib/rghost/paper.rb', line 24

def landscape
  @landscape
end

#paperObject (readonly)

Returns the value of attribute paper.



24
25
26
# File 'lib/rghost/paper.rb', line 24

def paper
  @paper
end

Instance Method Details

#gs_paperObject

:nodoc:



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

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



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

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

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