Modify input stream from files to have LF line endings

Convert line endings from CRLF to LF in input stream for .fragment, .js,
.in and xml files so that generated PDF files occupy less space.

Fixed: pdfium:1479
Change-Id: I429639322056523e393c24432beb02ed0f4fce48
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/68612
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue:  Ankit Kumar 🌪️ <ankk@microsoft.com>
diff --git a/testing/tools/fixup_pdf_template.py b/testing/tools/fixup_pdf_template.py
index f723203..808c0bb 100755
--- a/testing/tools/fixup_pdf_template.py
+++ b/testing/tools/fixup_pdf_template.py
@@ -23,6 +23,18 @@
 import re
 import sys
 
+# Line Endings.
+WINDOWS_LINE_ENDING = b'\r\n'
+UNIX_LINE_ENDING = b'\n'
+
+# List of extensions whose line endings should be modified after parsing.
+EXTENSION_OVERRIDE_LINE_ENDINGS = [
+    '.js',
+    '.fragment',
+    '.in',
+    '.xml',
+]
+
 
 class StreamLenState:
   START = 1
@@ -152,6 +164,10 @@
               os.path.join(os.path.dirname(input_path), match.group(1)),
               output_file, visited_set)
         else:
+          # Replace CRLF with LF line endings for .in files.
+          _, file_extension = os.path.splitext(input_path)
+          if file_extension in EXTENSION_OVERRIDE_LINE_ENDINGS:
+            line = line.replace(WINDOWS_LINE_ENDING, UNIX_LINE_ENDING)
           output_file.write(line)
   except IOError:
     print >> sys.stderr, 'failed to include %s' % input_path