File: SConscript

package info (click to toggle)
pdfposter 0.9.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 808 kB
  • sloc: python: 1,354; makefile: 45; sh: 40
file content (76 lines) | stat: -rw-r--r-- 2,965 bytes parent folder | download
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- mode: python ; coding: utf-8 -*-
#
# Copyright (C) 2008-2025 Hartmut Goebel <h.goebel@crazy-compilers.com>
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
#
# Build requirements
# - ImageMagick
#

Import('*')

def postersamples(pages_h, pages_v, which,
                  tiles_h=0,
                  numpages=0, reverse=False,
                  rotate=False, scale_to=100):
    inputfile = 'testpage-%s.pdf' % which
    geo = '%ix%ia4' % (pages_h, pages_v)
    # create pdf poster
    poster = env.Command('poster-%s-%s.pdf' % (which, geo),
                         inputfile,
                         'pdfposter -ma4 -p$POSTERSIZE $SOURCE $TARGET',
                         POSTERSIZE=geo)[0]

    # montage the ppm imgages to show how they have to be glued together
    tiles_h = tiles_h or pages_h
    rotate = rotate and ' png:- | convert png:- -rotate -90 ' or ''
    page_range = ''
    if reverse:
        # this is lazy: better way would be to get the number of pages
        # from 'poster', but this would requier an extra builder
        numpages = numpages or pages_h*pages_v
        page_range = str(list( range(numpages-1, -1, -1))).replace(' ', '')
    env.Command('poster-%s-%s.png' % (which, geo), poster,
                "montage $SOURCE$RANGE "
                " -background '#336699' -geometry ${SCALE}x+2+2 "
                " -tile $P_COLS "
                " $ROTATE $TARGET",
                P_COLS=tiles_h, ROTATE=rotate, SCALE=scale_to,
                RANGE=page_range)
env.Command(['testpage-tall.pdf', 'testpage-wide.pdf'],
            'gen-examplepages.py',
            'python $SOURCE $TARGETS')

env.Command('testpage-tall.png', 'testpage-tall.pdf',
            "convert $SOURCE -background '#336699' $TARGET")
env.Command('testpage-wide.png', 'testpage-wide.pdf',
            "convert $SOURCE -background '#336699' $TARGET")

# tall on two landscape sheets
postersamples(1, 2, 'tall', reverse=1)
# tall on two portrait sheets
postersamples(2, 1, 'tall', rotate=0)

# wide on two landscape sheets
postersamples(1, 2, 'wide', rotate=0)
# wide on two portrait sheets
postersamples(2, 1, 'wide')

# wide on landscape sheets (landscape a4 heigh)
postersamples(1, 99, 'wide', scale_to=50, rotate=1)
# wide on  portrait sheets (portrait a4 heigh)
postersamples(99, 1, 'wide', scale_to=50, tiles_h=9)