Process XFA config by inclusion in place of hard coded strings

Change-Id: I3dac79c12a5a482ab69420b68d7383efba646d81
Reviewed-on: https://pdfium-review.googlesource.com/c/45475
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/testing/resources/pixel/xfa_specific/use_ahem/xfa_example.in b/testing/resources/pixel/xfa_specific/use_ahem/xfa_example.in
index 429be9d..1a944b1 100644
--- a/testing/resources/pixel/xfa_specific/use_ahem/xfa_example.in
+++ b/testing/resources/pixel/xfa_specific/use_ahem/xfa_example.in
@@ -32,7 +32,7 @@
 endobj
 
 {{xfapreamble 3 0}}
-{{xfaconfig 4 0}}
+{{include ../../../xfa_config_4_0.fragment}}
 
 {{object 5 0}}
 <<
diff --git a/testing/resources/pixel/xfa_specific/use_ahem/xfa_textfield.in b/testing/resources/pixel/xfa_specific/use_ahem/xfa_textfield.in
index 4e42547..2ad7179 100644
--- a/testing/resources/pixel/xfa_specific/use_ahem/xfa_textfield.in
+++ b/testing/resources/pixel/xfa_specific/use_ahem/xfa_textfield.in
@@ -34,7 +34,7 @@
 endobj
 
 {{xfapreamble 3 0}}
-{{xfaconfig 4 0}}
+{{include ../../../xfa_config_4_0.fragment}}
 
 {{object 5 0}}
 <<
diff --git a/testing/resources/pixel/xfa_specific/xfa_bmp_image.in b/testing/resources/pixel/xfa_specific/xfa_bmp_image.in
index c59cff7..43a0ee4 100644
--- a/testing/resources/pixel/xfa_specific/xfa_bmp_image.in
+++ b/testing/resources/pixel/xfa_specific/xfa_bmp_image.in
@@ -34,7 +34,7 @@
 endobj
 
 {{xfapreamble 3 0}}
-{{xfaconfig 4 0}}
+{{include ../../xfa_config_4_0.fragment}}
 
 {{object 5 0}}
 <<
diff --git a/testing/resources/pixel/xfa_specific/xfa_gif_image.in b/testing/resources/pixel/xfa_specific/xfa_gif_image.in
index 74e5c20..74a0994 100644
--- a/testing/resources/pixel/xfa_specific/xfa_gif_image.in
+++ b/testing/resources/pixel/xfa_specific/xfa_gif_image.in
@@ -34,7 +34,7 @@
 endobj
 
 {{xfapreamble 3 0}}
-{{xfaconfig 4 0}}
+{{include ../../xfa_config_4_0.fragment}}
 
 {{object 5 0}}
 <<
diff --git a/testing/resources/pixel/xfa_specific/xfa_jpg_image.in b/testing/resources/pixel/xfa_specific/xfa_jpg_image.in
index cd8cff5..152be3d 100644
--- a/testing/resources/pixel/xfa_specific/xfa_jpg_image.in
+++ b/testing/resources/pixel/xfa_specific/xfa_jpg_image.in
@@ -34,7 +34,7 @@
 endobj
 
 {{xfapreamble 3 0}}
-{{xfaconfig 4 0}}
+{{include ../../xfa_config_4_0.fragment}}
 
 {{object 5 0}}
 <<
diff --git a/testing/resources/pixel/xfa_specific/xfa_png_image.in b/testing/resources/pixel/xfa_specific/xfa_png_image.in
index 10cc356..b4ea3a3 100644
--- a/testing/resources/pixel/xfa_specific/xfa_png_image.in
+++ b/testing/resources/pixel/xfa_specific/xfa_png_image.in
@@ -34,7 +34,7 @@
 endobj
 
 {{xfapreamble 3 0}}
-{{xfaconfig 4 0}}
+{{include ../../xfa_config_4_0.fragment}}
 
 {{object 5 0}}
 <<
diff --git a/testing/resources/pixel/xfa_specific/xfa_rectangle_node.in b/testing/resources/pixel/xfa_specific/xfa_rectangle_node.in
index 3bdf44c..0bb00fa 100644
--- a/testing/resources/pixel/xfa_specific/xfa_rectangle_node.in
+++ b/testing/resources/pixel/xfa_specific/xfa_rectangle_node.in
@@ -34,7 +34,7 @@
 endobj
 
 {{xfapreamble 3 0}}
-{{xfaconfig 4 0}}
+{{include ../../xfa_config_4_0.fragment}}
 
 {{object 5 0}}
 <<
diff --git a/testing/resources/pixel/xfa_specific/xfa_tiff_deflate_image.in b/testing/resources/pixel/xfa_specific/xfa_tiff_deflate_image.in
index e10159b..6c64ff9 100644
--- a/testing/resources/pixel/xfa_specific/xfa_tiff_deflate_image.in
+++ b/testing/resources/pixel/xfa_specific/xfa_tiff_deflate_image.in
@@ -34,7 +34,7 @@
 endobj
 
 {{xfapreamble 3 0}}
-{{xfaconfig 4 0}}
+{{include ../../xfa_config_4_0.fragment}}
 
 {{object 5 0}}
 <<
diff --git a/testing/resources/pixel/xfa_specific/xfa_tiff_image.in b/testing/resources/pixel/xfa_specific/xfa_tiff_image.in
index 70049a6..cb9b121 100644
--- a/testing/resources/pixel/xfa_specific/xfa_tiff_image.in
+++ b/testing/resources/pixel/xfa_specific/xfa_tiff_image.in
@@ -34,7 +34,7 @@
 endobj
 
 {{xfapreamble 3 0}}
-{{xfaconfig 4 0}}
+{{include ../../xfa_config_4_0.fragment}}
 
 {{object 5 0}}
 <<
diff --git a/testing/resources/pixel/xfa_specific/xfa_tiff_lzw_image.in b/testing/resources/pixel/xfa_specific/xfa_tiff_lzw_image.in
index 3b31f45..52b5c68 100644
--- a/testing/resources/pixel/xfa_specific/xfa_tiff_lzw_image.in
+++ b/testing/resources/pixel/xfa_specific/xfa_tiff_lzw_image.in
@@ -34,7 +34,7 @@
 endobj
 
 {{xfapreamble 3 0}}
-{{xfaconfig 4 0}}
+{{include ../../xfa_config_4_0.fragment}}
 
 {{object 5 0}}
 <<
diff --git a/testing/resources/pixel/xfa_specific/xfa_tiff_packbits_image.in b/testing/resources/pixel/xfa_specific/xfa_tiff_packbits_image.in
index 936c69f..72bd4e7 100644
--- a/testing/resources/pixel/xfa_specific/xfa_tiff_packbits_image.in
+++ b/testing/resources/pixel/xfa_specific/xfa_tiff_packbits_image.in
@@ -34,7 +34,7 @@
 endobj
 
 {{xfapreamble 3 0}}
-{{xfaconfig 4 0}}
+{{include ../../xfa_config_4_0.fragment}}
 
 {{object 5 0}}
 <<
diff --git a/testing/resources/xfa/xfa_multiline_textfield.in b/testing/resources/xfa/xfa_multiline_textfield.in
index df747fa..b32ac7b 100644
--- a/testing/resources/xfa/xfa_multiline_textfield.in
+++ b/testing/resources/xfa/xfa_multiline_textfield.in
@@ -34,7 +34,7 @@
 endobj
 
 {{xfapreamble 3 0}}
-{{xfaconfig 4 0}}
+{{include ../xfa_config_4_0.fragment}}
 
 {{object 5 0}}
 <<
diff --git a/testing/resources/xfa_config.xml b/testing/resources/xfa_config.xml
new file mode 100644
index 0000000..801fd14
--- /dev/null
+++ b/testing/resources/xfa_config.xml
@@ -0,0 +1,30 @@
+<config xmlns="http://www.xfa.org/schema/xci/3.0/">
+<agent name="designer">
+  <destination>pdf</destination>
+  <pdf>
+    <fontInfo/>
+  </pdf>
+</agent>
+<present>
+  <pdf>
+    <version>1.7</version>
+    <adobeExtensionLevel>8</adobeExtensionLevel>
+    <renderPolicy>client</renderPolicy>
+    <scriptModel>XFA</scriptModel>
+    <interactive>1</interactive>
+  </pdf>
+  <xdp>
+    <packets>*</packets>
+  </xdp>
+  <destination>pdf</destination>
+  <script>
+    <runScripts>server</runScripts>
+  </script>
+</present>
+<acrobat>
+  <acrobat7>
+    <dynamicRender>required</dynamicRender>
+  </acrobat7>
+  <validate>preSubmit</validate>
+</acrobat>
+</config>
diff --git a/testing/resources/xfa_config_4_0.fragment b/testing/resources/xfa_config_4_0.fragment
new file mode 100644
index 0000000..3d3e944
--- /dev/null
+++ b/testing/resources/xfa_config_4_0.fragment
@@ -0,0 +1,7 @@
+{{object 4 0}} <<
+  {{streamlen}}
+>>
+stream
+{{include xfa_config.xml}}
+endstream
+endobj
diff --git a/testing/tools/fixup_pdf_template.py b/testing/tools/fixup_pdf_template.py
index 3256a4c..6978bbd 100755
--- a/testing/tools/fixup_pdf_template.py
+++ b/testing/tools/fixup_pdf_template.py
@@ -17,8 +17,6 @@
   {{streamlen}} - expands to |/Length n|.
   {{xfapreamble x y}} - expands to an object |x y obj| containing a XML preamble
                         to be used in XFA docs.
-  {{xfaconfig x y}} - expands to an object |x y obj| containing a config XML
-                      block to be used in XFA docs.
   {{xfapostamble x y}} - expands to an object |x y obj| containing a XML
                          posteamble to be used in XFA docs.
 """
@@ -70,39 +68,6 @@
   XFAPOSTAMBLE_REPLACEMENT = '%d %d obj\n<<\n  /Length %d\n>>\nstream\n%s\nendstream\nendobj\n'
   XFAPOSTAMBLE_STREAM = '</xdp:xdp>'
 
-  XFACONFIG_PATTERN = r'\{\{xfaconfig\s+(\d+)\s+(\d+)\}\}'
-  XFACONFIG_REPLACEMENT = '%d %d obj\n<<\n  /Length %d\n>>\nstream\n%s\nendstream\nendobj\n'
-  XFACONFIG_STREAM = '''<config xmlns="http://www.xfa.org/schema/xci/3.0/">
-  <agent name="designer">
-    <destination>pdf</destination>
-    <pdf>
-      <fontInfo/>
-    </pdf>
-  </agent>
-  <present>
-    <pdf>
-      <version>1.7</version>
-      <adobeExtensionLevel>8</adobeExtensionLevel>
-      <renderPolicy>client</renderPolicy>
-      <scriptModel>XFA</scriptModel>
-      <interactive>1</interactive>
-    </pdf>
-    <xdp>
-      <packets>*</packets>
-    </xdp>
-    <destination>pdf</destination>
-    <script>
-      <runScripts>server</runScripts>
-    </script>
-  </present>
-  <acrobat>
-    <acrobat7>
-      <dynamicRender>required</dynamicRender>
-    </acrobat7>
-    <validate>preSubmit</validate>
-  </acrobat>
-</config>'''
-
   def __init__(self):
     self.streamlen_state = StreamLenState.START
     self.streamlens = []
@@ -166,10 +131,6 @@
                                 self.XFAPREAMBLE_REPLACEMENT,
                                 self.XFAPREAMBLE_STREAM)
     line = self.replace_xfa_tag(line,
-                                self.XFACONFIG_PATTERN,
-                                self.XFACONFIG_REPLACEMENT,
-                                self.XFACONFIG_STREAM)
-    line = self.replace_xfa_tag(line,
                                 self.XFAPOSTAMBLE_PATTERN,
                                 self.XFAPOSTAMBLE_REPLACEMENT,
                                 self.XFAPOSTAMBLE_STREAM)