File: onepage.lua

package info (click to toggle)
ipe 7.2.30-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,844 kB
  • sloc: cpp: 42,635; makefile: 664; sh: 44; xml: 17; ansic: 14; python: 7
file content (45 lines) | stat: -rw-r--r-- 1,154 bytes parent folder | download | duplicates (3)
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
39
40
41
42
43
44
45
#!/usr/bin/env ipescript 
-- -*- lua -*-
----------------------------------------------------------------------
-- Collapse pages of an Ipe document into a single page
----------------------------------------------------------------------
--
-- Running this script as "ipescript onepage <input> <output>" will
-- create <output> as a copy of the Ipe document <input>, but with
-- all pages of <input> collapsed into layers of a single page in
-- <output>.
--
----------------------------------------------------------------------

if #argv ~= 2 then
  io.stderr:write("Usage: ipescript onepage <input> <output>\n")
  return
end

local inname = argv[1]
local outname = argv[2]

local doc = assert(ipe.Document(inname))
local ndoc = ipe.Document()

local s = doc:sheets()
ndoc:replaceSheets(s:clone())

local t = doc:properties()
ndoc:setProperties(t)

local np = ndoc[1]

for pno = 1,#doc do
  print("Page: ", pno)
  local layer = "page_" .. pno
  np:addLayer(layer)
  np:setVisible(1, layer, true)
  local p = doc[pno]
  for _, obj, _, _ in p:objects() do
    np:insert(nil, obj:clone(), nil, layer)
  end
end

np:removeLayer("alpha")
ndoc:save(outname)