bin/diff-pdf-page.py |   42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

New commits:
commit 0f77a35efd20836ec69bc08c052f1e9e8f6d611f
Author:     Miklos Vajna <[email protected]>
AuthorDate: Tue Jun 4 16:14:15 2024 +0200
Commit:     Miklos Vajna <[email protected]>
CommitDate: Fri Oct 25 09:18:21 2024 +0200

    bin: add a diff-pdf-page.py script to diff reference vs our rendering via 
PDF
    
    Thanks László Németh for the idea, the mechanism used in the tool was
    also used to generate the visual diff visible at
    
<https://wiki.documentfoundation.org/ReleaseNotes/24.2#New_line_break_algorithm_for_interoperability>.
    
    Change-Id: I51afb08c60c7134f75a54acdb94b49d2ff94befd
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168404
    Reviewed-by: Miklos Vajna <[email protected]>
    Tested-by: Jenkins
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175560
    Reviewed-by: Justin Luth <[email protected]>
    Tested-by: Jenkins CollaboraOffice <[email protected]>

diff --git a/bin/diff-pdf-page.py b/bin/diff-pdf-page.py
new file mode 100755
index 000000000000..153654d5d386
--- /dev/null
+++ b/bin/diff-pdf-page.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python3
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# Diffs two PDF pages: a reference and our own output. Red output means some 
to fix: the amount of
+# red is meant to reduce as fixing progresses. Sample usage:
+#
+# bin/diff-pdf-page.py reference.pdf test.pdf diff.png
+
+import argparse
+import tempfile
+import subprocess
+
+def run(argv):
+    print(" ".join(argv))
+    subprocess.run(argv, check=True)
+
+def main():
+    parser = argparse.ArgumentParser(description="Diffs two PDF pages, first 
is painted red instead of black, the second is painted on top of the first.")
+    parser.add_argument("-d", "--density", default="384")
+    parser.add_argument("-p", "--page", default="0")
+    parser.add_argument("a_pdf")
+    parser.add_argument("b_pdf")
+    parser.add_argument("diff_png")
+    args = parser.parse_args()
+
+    a_png = tempfile.NamedTemporaryFile(suffix=".png")
+    a_pdf = args.a_pdf + "[" + args.page + "]"
+    run(["convert", "-density", args.density, a_pdf, "-colorspace", "RGB", 
"-fuzz", "95%", "-fill", "red", "-opaque", "black", a_png.name])
+    b_png = tempfile.NamedTemporaryFile(suffix=".png")
+    b_pdf = args.b_pdf + "[" + args.page + "]"
+    run(["convert", "-density", args.density, b_pdf, "-colorspace", "RGB", 
b_png.name])
+    composite_png = tempfile.NamedTemporaryFile(suffix=".png")
+    run(["convert", "-composite", a_png.name, b_png.name, composite_png.name])
+    run(["convert", composite_png.name, "-background", "white", "-flatten", 
args.diff_png])
+
+if __name__ == "__main__":
+    main()
+
+# vim:set shiftwidth=4 softtabstop=4 expandtab:

Reply via email to