Process XFA preamble by inclusion rather than hard-coded strings Change-Id: I44d58ce553712face3377ae24d93576a29954c4c Reviewed-on: https://pdfium-review.googlesource.com/c/45490 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 1a944b1..ba7d1cd 100644 --- a/testing/resources/pixel/xfa_specific/use_ahem/xfa_example.in +++ b/testing/resources/pixel/xfa_specific/use_ahem/xfa_example.in
@@ -1,37 +1,8 @@ {{header}} -{{object 1 0}} -<< - /AcroForm 2 0 R - /Extensions << - /ADBE << - /BaseVersion /1.7 - /ExtensionLevel 8 - >> - >> - /NeedsRendering true - /Type /Catalog ->> -endobj - -{{object 2 0}} -<< - /XFA [ - (preamble) - 3 0 R - (config) - 4 0 R - (template) - 5 0 R - (localeSet) - 6 0 R - (postamble) - 7 0 R - ] ->> -endobj - -{{xfapreamble 3 0}} +{{include ../../../xfa_catalog_1_0.fragment}} +{{include ../../../xfa_object_2_0.fragment}} +{{include ../../../xfa_preamble_3_0.fragment}} {{include ../../../xfa_config_4_0.fragment}} {{object 5 0}} @@ -61,7 +32,7 @@ endobj {{include ../../../xfa_locale_6_0.fragment}} -{{xfapostamble 7 0}} +{{include ../../../xfa_postamble_7_0.fragment}} {{xref}} {{trailer}}
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 2ad7179..5fc93db 100644 --- a/testing/resources/pixel/xfa_specific/use_ahem/xfa_textfield.in +++ b/testing/resources/pixel/xfa_specific/use_ahem/xfa_textfield.in
@@ -1,39 +1,8 @@ {{header}} -%% Original object ID: 24 0 -{{object 1 0}} -<< - /AcroForm 2 0 R - /Extensions << - /ADBE << - /BaseVersion /1.7 - /ExtensionLevel 8 - >> - >> - /NeedsRendering true - /Type /Catalog ->> -endobj - -%% Original object ID: 32 0 -{{object 2 0}} -<< - /XFA [ - (preamble) - 3 0 R - (config) - 4 0 R - (template) - 5 0 R - (localeSet) - 6 0 R - (postamble) - 7 0 R - ] ->> -endobj - -{{xfapreamble 3 0}} +{{include ../../../xfa_catalog_1_0.fragment}} +{{include ../../../xfa_object_2_0.fragment}} +{{include ../../../xfa_preamble_3_0.fragment}} {{include ../../../xfa_config_4_0.fragment}} {{object 5 0}} @@ -82,8 +51,7 @@ endobj {{include ../../../xfa_locale_6_0.fragment}} - -{{xfapostamble 7 0}} +{{include ../../../xfa_postamble_7_0.fragment}} {{xref}} {{trailer}}
diff --git a/testing/resources/pixel/xfa_specific/xfa_bmp_image.in b/testing/resources/pixel/xfa_specific/xfa_bmp_image.in index 43a0ee4..3241242 100644 --- a/testing/resources/pixel/xfa_specific/xfa_bmp_image.in +++ b/testing/resources/pixel/xfa_specific/xfa_bmp_image.in
@@ -1,39 +1,8 @@ {{header}} -%% Original object ID: 24 0 -{{object 1 0}} -<< - /AcroForm 2 0 R - /Extensions << - /ADBE << - /BaseVersion /1.7 - /ExtensionLevel 8 - >> - >> - /NeedsRendering true - /Type /Catalog ->> -endobj - -%% Original object ID: 32 0 -{{object 2 0}} -<< - /XFA [ - (preamble) - 3 0 R - (config) - 4 0 R - (template) - 5 0 R - (localeSet) - 6 0 R - (postamble) - 7 0 R - ] ->> -endobj - -{{xfapreamble 3 0}} +{{include ../../xfa_catalog_1_0.fragment}} +{{include ../../xfa_object_2_0.fragment}} +{{include ../../xfa_preamble_3_0.fragment}} {{include ../../xfa_config_4_0.fragment}} {{object 5 0}} @@ -67,7 +36,7 @@ endobj {{include ../../xfa_locale_6_0.fragment}} -{{xfapostamble 7 0}} +{{include ../../xfa_postamble_7_0.fragment}} {{xref}} {{trailer}}
diff --git a/testing/resources/pixel/xfa_specific/xfa_gif_image.in b/testing/resources/pixel/xfa_specific/xfa_gif_image.in index 74a0994..847057b 100644 --- a/testing/resources/pixel/xfa_specific/xfa_gif_image.in +++ b/testing/resources/pixel/xfa_specific/xfa_gif_image.in
@@ -1,39 +1,8 @@ {{header}} -%% Original object ID: 24 0 -{{object 1 0}} -<< - /AcroForm 2 0 R - /Extensions << - /ADBE << - /BaseVersion /1.7 - /ExtensionLevel 8 - >> - >> - /NeedsRendering true - /Type /Catalog ->> -endobj - -%% Original object ID: 32 0 -{{object 2 0}} -<< - /XFA [ - (preamble) - 3 0 R - (config) - 4 0 R - (template) - 5 0 R - (localeSet) - 6 0 R - (postamble) - 7 0 R - ] ->> -endobj - -{{xfapreamble 3 0}} +{{include ../../xfa_catalog_1_0.fragment}} +{{include ../../xfa_object_2_0.fragment}} +{{include ../../xfa_preamble_3_0.fragment}} {{include ../../xfa_config_4_0.fragment}} {{object 5 0}} @@ -67,7 +36,8 @@ endobj {{include ../../xfa_locale_6_0.fragment}} -{{xfapostamble 7 0}} +{{include ../../xfa_postamble_7_0.fragment}} + {{xref}} {{trailer}} {{startxref}}
diff --git a/testing/resources/pixel/xfa_specific/xfa_jpg_image.in b/testing/resources/pixel/xfa_specific/xfa_jpg_image.in index 152be3d..4f49636 100644 --- a/testing/resources/pixel/xfa_specific/xfa_jpg_image.in +++ b/testing/resources/pixel/xfa_specific/xfa_jpg_image.in
@@ -1,39 +1,8 @@ {{header}} -%% Original object ID: 24 0 -{{object 1 0}} -<< - /AcroForm 2 0 R - /Extensions << - /ADBE << - /BaseVersion /1.7 - /ExtensionLevel 8 - >> - >> - /NeedsRendering true - /Type /Catalog ->> -endobj - -%% Original object ID: 32 0 -{{object 2 0}} -<< - /XFA [ - (preamble) - 3 0 R - (config) - 4 0 R - (template) - 5 0 R - (localeSet) - 6 0 R - (postamble) - 7 0 R - ] ->> -endobj - -{{xfapreamble 3 0}} +{{include ../../xfa_catalog_1_0.fragment}} +{{include ../../xfa_object_2_0.fragment}} +{{include ../../xfa_preamble_3_0.fragment}} {{include ../../xfa_config_4_0.fragment}} {{object 5 0}} @@ -67,7 +36,7 @@ endobj {{include ../../xfa_locale_6_0.fragment}} -{{xfapostamble 7 0}} +{{include ../../xfa_postamble_7_0.fragment}} {{xref}} {{trailer}}
diff --git a/testing/resources/pixel/xfa_specific/xfa_png_image.in b/testing/resources/pixel/xfa_specific/xfa_png_image.in index b4ea3a3..6772f1f 100644 --- a/testing/resources/pixel/xfa_specific/xfa_png_image.in +++ b/testing/resources/pixel/xfa_specific/xfa_png_image.in
@@ -1,39 +1,8 @@ {{header}} -%% Original object ID: 24 0 -{{object 1 0}} -<< - /AcroForm 2 0 R - /Extensions << - /ADBE << - /BaseVersion /1.7 - /ExtensionLevel 8 - >> - >> - /NeedsRendering true - /Type /Catalog ->> -endobj - -%% Original object ID: 32 0 -{{object 2 0}} -<< - /XFA [ - (preamble) - 3 0 R - (config) - 4 0 R - (template) - 5 0 R - (localeSet) - 6 0 R - (postamble) - 7 0 R - ] ->> -endobj - -{{xfapreamble 3 0}} +{{include ../../xfa_catalog_1_0.fragment}} +{{include ../../xfa_object_2_0.fragment}} +{{include ../../xfa_preamble_3_0.fragment}} {{include ../../xfa_config_4_0.fragment}} {{object 5 0}} @@ -67,7 +36,7 @@ endobj {{include ../../xfa_locale_6_0.fragment}} -{{xfapostamble 7 0}} +{{include ../../xfa_postamble_7_0.fragment}} {{xref}} {{trailer}}
diff --git a/testing/resources/pixel/xfa_specific/xfa_rectangle_node.in b/testing/resources/pixel/xfa_specific/xfa_rectangle_node.in index 0bb00fa..347d4ae 100644 --- a/testing/resources/pixel/xfa_specific/xfa_rectangle_node.in +++ b/testing/resources/pixel/xfa_specific/xfa_rectangle_node.in
@@ -1,39 +1,8 @@ {{header}} -%% Original object ID: 24 0 -{{object 1 0}} -<< - /AcroForm 2 0 R - /Extensions << - /ADBE << - /BaseVersion /1.7 - /ExtensionLevel 8 - >> - >> - /NeedsRendering true - /Type /Catalog ->> -endobj - -%% Original object ID: 32 0 -{{object 2 0}} -<< - /XFA [ - (preamble) - 3 0 R - (config) - 4 0 R - (template) - 5 0 R - (localeSet) - 6 0 R - (postamble) - 7 0 R - ] ->> -endobj - -{{xfapreamble 3 0}} +{{include ../../xfa_catalog_1_0.fragment}} +{{include ../../xfa_object_2_0.fragment}} +{{include ../../xfa_preamble_3_0.fragment}} {{include ../../xfa_config_4_0.fragment}} {{object 5 0}} @@ -68,7 +37,7 @@ endobj {{include ../../xfa_locale_6_0.fragment}} -{{xfapostamble 7 0}} +{{include ../../xfa_postamble_7_0.fragment}} {{xref}} {{trailer}}
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 6c64ff9..0927583 100644 --- a/testing/resources/pixel/xfa_specific/xfa_tiff_deflate_image.in +++ b/testing/resources/pixel/xfa_specific/xfa_tiff_deflate_image.in
@@ -1,39 +1,8 @@ {{header}} -%% Original object ID: 24 0 -{{object 1 0}} -<< - /AcroForm 2 0 R - /Extensions << - /ADBE << - /BaseVersion /1.7 - /ExtensionLevel 8 - >> - >> - /NeedsRendering true - /Type /Catalog ->> -endobj - -%% Original object ID: 32 0 -{{object 2 0}} -<< - /XFA [ - (preamble) - 3 0 R - (config) - 4 0 R - (template) - 5 0 R - (localeSet) - 6 0 R - (postamble) - 7 0 R - ] ->> -endobj - -{{xfapreamble 3 0}} +{{include ../../xfa_catalog_1_0.fragment}} +{{include ../../xfa_object_2_0.fragment}} +{{include ../../xfa_preamble_3_0.fragment}} {{include ../../xfa_config_4_0.fragment}} {{object 5 0}} @@ -67,7 +36,7 @@ endobj {{include ../../xfa_locale_6_0.fragment}} -{{xfapostamble 7 0}} +{{include ../../xfa_postamble_7_0.fragment}} {{xref}} {{trailer}}
diff --git a/testing/resources/pixel/xfa_specific/xfa_tiff_image.in b/testing/resources/pixel/xfa_specific/xfa_tiff_image.in index cb9b121..c94b041 100644 --- a/testing/resources/pixel/xfa_specific/xfa_tiff_image.in +++ b/testing/resources/pixel/xfa_specific/xfa_tiff_image.in
@@ -1,39 +1,8 @@ {{header}} -%% Original object ID: 24 0 -{{object 1 0}} -<< - /AcroForm 2 0 R - /Extensions << - /ADBE << - /BaseVersion /1.7 - /ExtensionLevel 8 - >> - >> - /NeedsRendering true - /Type /Catalog ->> -endobj - -%% Original object ID: 32 0 -{{object 2 0}} -<< - /XFA [ - (preamble) - 3 0 R - (config) - 4 0 R - (template) - 5 0 R - (localeSet) - 6 0 R - (postamble) - 7 0 R - ] ->> -endobj - -{{xfapreamble 3 0}} +{{include ../../xfa_catalog_1_0.fragment}} +{{include ../../xfa_object_2_0.fragment}} +{{include ../../xfa_preamble_3_0.fragment}} {{include ../../xfa_config_4_0.fragment}} {{object 5 0}} @@ -67,7 +36,7 @@ endobj {{include ../../xfa_locale_6_0.fragment}} -{{xfapostamble 7 0}} +{{include ../../xfa_postamble_7_0.fragment}} {{xref}} {{trailer}}
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 52b5c68..85a8853 100644 --- a/testing/resources/pixel/xfa_specific/xfa_tiff_lzw_image.in +++ b/testing/resources/pixel/xfa_specific/xfa_tiff_lzw_image.in
@@ -1,39 +1,8 @@ {{header}} -%% Original object ID: 24 0 -{{object 1 0}} -<< - /AcroForm 2 0 R - /Extensions << - /ADBE << - /BaseVersion /1.7 - /ExtensionLevel 8 - >> - >> - /NeedsRendering true - /Type /Catalog ->> -endobj - -%% Original object ID: 32 0 -{{object 2 0}} -<< - /XFA [ - (preamble) - 3 0 R - (config) - 4 0 R - (template) - 5 0 R - (localeSet) - 6 0 R - (postamble) - 7 0 R - ] ->> -endobj - -{{xfapreamble 3 0}} +{{include ../../xfa_catalog_1_0.fragment}} +{{include ../../xfa_object_2_0.fragment}} +{{include ../../xfa_preamble_3_0.fragment}} {{include ../../xfa_config_4_0.fragment}} {{object 5 0}} @@ -67,7 +36,7 @@ endobj {{include ../../xfa_locale_6_0.fragment}} -{{xfapostamble 7 0}} +{{include ../../xfa_postamble_7_0.fragment}} {{xref}} {{trailer}}
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 72bd4e7..f496f1c 100644 --- a/testing/resources/pixel/xfa_specific/xfa_tiff_packbits_image.in +++ b/testing/resources/pixel/xfa_specific/xfa_tiff_packbits_image.in
@@ -1,39 +1,8 @@ {{header}} -%% Original object ID: 24 0 -{{object 1 0}} -<< - /AcroForm 2 0 R - /Extensions << - /ADBE << - /BaseVersion /1.7 - /ExtensionLevel 8 - >> - >> - /NeedsRendering true - /Type /Catalog ->> -endobj - -%% Original object ID: 32 0 -{{object 2 0}} -<< - /XFA [ - (preamble) - 3 0 R - (config) - 4 0 R - (template) - 5 0 R - (localeSet) - 6 0 R - (postamble) - 7 0 R - ] ->> -endobj - -{{xfapreamble 3 0}} +{{include ../../xfa_catalog_1_0.fragment}} +{{include ../../xfa_object_2_0.fragment}} +{{include ../../xfa_preamble_3_0.fragment}} {{include ../../xfa_config_4_0.fragment}} {{object 5 0}} @@ -67,7 +36,7 @@ endobj {{include ../../xfa_locale_6_0.fragment}} -{{xfapostamble 7 0}} +{{include ../../xfa_postamble_7_0.fragment}} {{xref}} {{trailer}}
diff --git a/testing/resources/xfa/xfa_multiline_textfield.in b/testing/resources/xfa/xfa_multiline_textfield.in index b32ac7b..dec526b 100644 --- a/testing/resources/xfa/xfa_multiline_textfield.in +++ b/testing/resources/xfa/xfa_multiline_textfield.in
@@ -1,39 +1,8 @@ {{header}} -%% Original object ID: 24 0 -{{object 1 0}} -<< - /AcroForm 2 0 R - /Extensions << - /ADBE << - /BaseVersion /1.7 - /ExtensionLevel 8 - >> - >> - /NeedsRendering true - /Type /Catalog ->> -endobj - -%% Original object ID: 32 0 -{{object 2 0}} -<< - /XFA [ - (preamble) - 3 0 R - (config) - 4 0 R - (template) - 5 0 R - (localeSet) - 6 0 R - (postamble) - 7 0 R - ] ->> -endobj - -{{xfapreamble 3 0}} +{{include ../xfa_catalog_1_0.fragment}} +{{include ../xfa_object_2_0.fragment}} +{{include ../xfa_preamble_3_0.fragment}} {{include ../xfa_config_4_0.fragment}} {{object 5 0}} @@ -64,7 +33,7 @@ endobj {{include ../xfa_locale_6_0.fragment}} -{{xfapostamble 7 0}} +{{include ../xfa_postamble_7_0.fragment}} {{xref}} {{trailer}}
diff --git a/testing/resources/xfa_catalog_1_0.fragment b/testing/resources/xfa_catalog_1_0.fragment new file mode 100644 index 0000000..13f9ee5 --- /dev/null +++ b/testing/resources/xfa_catalog_1_0.fragment
@@ -0,0 +1,12 @@ +{{object 1 0}} << + /AcroForm 2 0 R + /Extensions << + /ADBE << + /BaseVersion /1.7 + /ExtensionLevel 8 + >> + >> + /NeedsRendering true + /Type /Catalog +>> +endobj
diff --git a/testing/resources/xfa_object_2_0.fragment b/testing/resources/xfa_object_2_0.fragment new file mode 100644 index 0000000..c8b5a34 --- /dev/null +++ b/testing/resources/xfa_object_2_0.fragment
@@ -0,0 +1,15 @@ +{{object 2 0}} << + /XFA [ + (preamble) + 3 0 R + (config) + 4 0 R + (template) + 5 0 R + (localeSet) + 6 0 R + (postamble) + 7 0 R + ] +>> +endobj
diff --git a/testing/resources/xfa_postamble.xml b/testing/resources/xfa_postamble.xml new file mode 100644 index 0000000..1d90745 --- /dev/null +++ b/testing/resources/xfa_postamble.xml
@@ -0,0 +1 @@ +</xdp:xdp>
diff --git a/testing/resources/xfa_postamble_7_0.fragment b/testing/resources/xfa_postamble_7_0.fragment new file mode 100644 index 0000000..0cc197a --- /dev/null +++ b/testing/resources/xfa_postamble_7_0.fragment
@@ -0,0 +1,7 @@ +{{object 7 0}} << + {{streamlen}} +>> +stream +{{include xfa_postamble.xml}} +endstream +endobj
diff --git a/testing/resources/xfa_preamble.xml b/testing/resources/xfa_preamble.xml new file mode 100644 index 0000000..a44947f --- /dev/null +++ b/testing/resources/xfa_preamble.xml
@@ -0,0 +1 @@ +<xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/" timeStamp="2018-02-23T21:37:11Z" uuid="21482798-7bf0-40a4-bc5d-3cefdccf32b5">
diff --git a/testing/resources/xfa_preamble_3_0.fragment b/testing/resources/xfa_preamble_3_0.fragment new file mode 100644 index 0000000..0dc7939 --- /dev/null +++ b/testing/resources/xfa_preamble_3_0.fragment
@@ -0,0 +1,7 @@ +{{object 3 0}} << + {{streamlen}} +>> +stream +{{include xfa_preamble.xml}} +endstream +endobj
diff --git a/testing/tools/fixup_pdf_template.py b/testing/tools/fixup_pdf_template.py index 6978bbd..3c5ecf5 100755 --- a/testing/tools/fixup_pdf_template.py +++ b/testing/tools/fixup_pdf_template.py
@@ -15,10 +15,6 @@ {{startxref} - expands to a startxref directive followed by correct offset. {{object x y}} - expands to |x y obj| declaration, noting the offset. {{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. - {{xfapostamble x y}} - expands to an object |x y obj| containing a XML - posteamble to be used in XFA docs. """ import cStringIO @@ -60,14 +56,6 @@ STREAMLEN_TOKEN = '{{streamlen}}' STREAMLEN_REPLACEMENT = '/Length %d' - XFAPREAMBLE_PATTERN = r'\{\{xfapreamble\s+(\d+)\s+(\d+)\}\}' - XFAPREAMBLE_REPLACEMENT = '%d %d obj\n<<\n /Length %d\n>>\nstream\n%s\nendstream\nendobj\n' - XFAPREAMBLE_STREAM = '<xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/" timeStamp="2018-02-23T21:37:11Z" uuid="21482798-7bf0-40a4-bc5d-3cefdccf32b5">' - - XFAPOSTAMBLE_PATTERN = r'\{\{xfapostamble\s+(\d+)\s+(\d+)\}\}' - XFAPOSTAMBLE_REPLACEMENT = '%d %d obj\n<<\n /Length %d\n>>\nstream\n%s\nendstream\nendobj\n' - XFAPOSTAMBLE_STREAM = '</xdp:xdp>' - def __init__(self): self.streamlen_state = StreamLenState.START self.streamlens = [] @@ -126,27 +114,9 @@ if match: self.insert_xref_entry(int(match.group(1)), int(match.group(2))) line = re.sub(self.OBJECT_PATTERN, self.OBJECT_REPLACEMENT, line) - line = self.replace_xfa_tag(line, - self.XFAPREAMBLE_PATTERN, - self.XFAPREAMBLE_REPLACEMENT, - self.XFAPREAMBLE_STREAM) - line = self.replace_xfa_tag(line, - self.XFAPOSTAMBLE_PATTERN, - self.XFAPOSTAMBLE_REPLACEMENT, - self.XFAPOSTAMBLE_STREAM) - self.offset += len(line) return line - def replace_xfa_tag(self, line, pattern, replacement, stream): - match = re.match(pattern, line) - if match: - x = int(match.group(1)) - y = int(match.group(2)) - self.insert_xref_entry(x, y) - line = replacement % (x, y, len(stream), stream) - return line - def expand_file(infile, output_path): processor = TemplateProcessor()