Mark some Calc slots as inactive in readonly mode
[LibreOffice.git] / bin / diff-pdf-page.py
blobfced5c84da7739047c4261085c138864fb0b3208
1 #!/usr/bin/env python3
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 # Diffs two PDF pages: a reference and our own output. Red output means some to fix: the amount of
8 # red is meant to reduce as fixing progresses. Sample usage:
10 # bin/diff-pdf-page.py reference.pdf test.pdf diff.png
12 # using the ImageMagick tooling
14 import argparse
15 import tempfile
16 import subprocess
18 def run(argv):
19 print(" ".join(argv))
20 subprocess.run(argv, check=True)
22 def main():
23 parser = argparse.ArgumentParser(description="Diffs two PDF pages, first is painted red instead of black, the second is painted on top of the first.")
24 parser.add_argument("-d", "--density", default="384")
25 parser.add_argument("-p", "--page", default="0")
26 parser.add_argument("a_pdf")
27 parser.add_argument("b_pdf")
28 parser.add_argument("diff_png")
29 args = parser.parse_args()
31 CONVERT_CMD="convert" # use "magick" if Windows has installed ImageMagick and GhostScript
33 a_png = tempfile.NamedTemporaryFile(suffix=".png")
34 a_pdf = args.a_pdf + "[" + args.page + "]"
35 run([CONVERT_CMD, "-density", args.density, a_pdf, "-colorspace", "RGB", "-transparent", "white", "-fuzz", "95%", "-fill", "red", "-opaque", "black", a_png.name])
36 b_png = tempfile.NamedTemporaryFile(suffix=".png")
37 b_pdf = args.b_pdf + "[" + args.page + "]"
38 run([CONVERT_CMD, "-density", args.density, b_pdf, "-colorspace", "RGB", "-transparent", "white", b_png.name])
39 run([CONVERT_CMD, a_png.name, b_png.name, "-composite", "-background", "white", "-flatten", args.diff_png])
41 if __name__ == "__main__":
42 main()
44 # vim:set shiftwidth=4 softtabstop=4 expandtab: