1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
# Defines virtual pages for the Document by method virtual_pages
class RGhost::VirtualPages < RGhost::PsObject
DEFAULT_OPTIONS = {width: 5, margin_left: 0}
include RGhost::RubyToPs
def initialize(&block)
super("") {}
@pages = []
instance_eval(&block) if block
end
def new_page(options = RGhost::VirtualPages::DEFAULT_OPTIONS)
options.merge(RGhost::VirtualPages::DEFAULT_OPTIONS)
@pages << options
end
def ps
first = true
all_pages = @pages.map do |p|
w = RGhost::Units.parse(p[:width])
if first
first = false
"[#{w}]"
else
m = RGhost::Units.parse(p[:margin_left])
"[#{w} #{m}]"
end
# "[#{m} #{w}]"
end
o = RGhost::PsObject.new
o.set RGhost::Variable.new(:has_vp?, true)
o.raw "/vp_params [ #{all_pages.join("")} ] def "
o.call :vp_proc
o
end
end
|