Debian Codegraph @

toolbin/tests/make_two_pdfversions

raw
1 #!/usr/bin/env python
2 # -*- Mode: python -*-
3
4 # Copyright (C) 2001-2023 Artifex Software, Inc.
5 # All Rights Reserved.
6 #
7 # This software is provided AS-IS with no warranty, either express or
8 # implied.
9 #
10 # This software is distributed under license and may not be copied,
11 # modified or distributed except as expressly authorized under the terms
12 # of the license contained in the file LICENSE in this distribution.
13 #
14 # Refer to licensing information at http://www.artifex.com or contact
15 # Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
16 # CA 94129, USA, for further information.
17 #
18
19
20 #
21 # make_two_versions <filename> [<device> [<res>]]
22 #
23 # this script creates two versions of the file specified
24 # one from baseline, and one from head
25 # these are appropriate for a visual diff
26
27 import gstestgs
28 import gsconf
29 import rasterdb
30 import os, sys
31 import string
32
33 def make_version(ifile, ofile, device, dpi, baseline=0):
34 gs = gstestgs.Ghostscript()
35 gs.log_stdout = gsconf.log_stdout
36 gs.log_stderr = gsconf.log_stderr
37
38 if baseline:
39 gs.command = gsconf.baselinegs
40 else:
41 gs.command = gsconf.comparegs
42
43 gs.infile = gsconf.comparefiledir + ifile
44 gs.dpi = dpi
45 gs.band = 0
46
47 # make file->PDF
48
49 tfile = ofile + ".pdf"
50 gs.outfile = tfile
51 gs.device = 'pdfwrite'
52
53 if not gs.process():
54 print "error creating pdf."
55 return
56
57 gs.infile = tfile
58 gs.outfile = ofile
59 gs.device = device
60
61 if not gs.process():
62 print "error rasterizing pdf."
63 os.unlink(tfile)
64
65 if len(sys.argv) < 2:
66 print "\n usage: make_two_pdfversions filename [ device:ppmraw [ res:72 ] ]\n"
67 sys.exit()
68
69 file = os.path.basename(sys.argv[1])
70 if len(sys.argv) > 2:
71 device = sys.argv[2]
72 else:
73 device = 'ppmraw'
74 if len(sys.argv) > 3:
75 res = int(sys.argv[3])
76 else:
77 res = 72
78
79 dbfile = "%s.pdf.%s.%d.%d" % (file, device, res, 0)
80 ofile = "%s.pdf.%s.baseline.pnm" % (file, device)
81
82 # check for cached raster and use that if it exists
83 if rasterdb.exists(dbfile):
84 rasterdb.get_file(dbfile, output=ofile)
85 else:
86 make_version(file, ofile, device, res, baseline=1)
87
88 ofile = "%s.pdf.%s.compare.pnm" % (file, device)
89
90 make_version(file, ofile, device, res, baseline=0)