From 901359bf460246861418ae1b96aa912920c86d35 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 8 Dec 2023 13:16:59 -0800 Subject: Docx writer: allow embedded fonts to be used in reference.docx. Closes #6728. --- src/Text/Pandoc/Writers/Docx.hs | 20 +++++++++++++++----- test/docx/golden/block_quotes.docx | Bin 10062 -> 10082 bytes test/docx/golden/codeblock.docx | Bin 9874 -> 9897 bytes test/docx/golden/comments.docx | Bin 10212 -> 10235 bytes test/docx/golden/custom_style_no_reference.docx | Bin 9973 -> 9996 bytes test/docx/golden/custom_style_preserve.docx | Bin 10602 -> 10625 bytes test/docx/golden/custom_style_reference.docx | Bin 12368 -> 12388 bytes test/docx/golden/definition_list.docx | Bin 9874 -> 9897 bytes .../docx/golden/document-properties-short-desc.docx | Bin 9880 -> 9904 bytes test/docx/golden/document-properties.docx | Bin 10364 -> 10389 bytes test/docx/golden/headers.docx | Bin 10013 -> 10036 bytes test/docx/golden/image.docx | Bin 26757 -> 26778 bytes test/docx/golden/inline_code.docx | Bin 9813 -> 9836 bytes test/docx/golden/inline_formatting.docx | Bin 9993 -> 10016 bytes test/docx/golden/inline_images.docx | Bin 26755 -> 26776 bytes test/docx/golden/link_in_notes.docx | Bin 10035 -> 10058 bytes test/docx/golden/links.docx | Bin 10206 -> 10229 bytes test/docx/golden/lists.docx | Bin 10272 -> 10295 bytes test/docx/golden/lists_continuing.docx | Bin 10068 -> 10091 bytes test/docx/golden/lists_div_bullets.docx | Bin 9921 -> 9944 bytes test/docx/golden/lists_multiple_initial.docx | Bin 10150 -> 10173 bytes test/docx/golden/lists_restarting.docx | Bin 10066 -> 10089 bytes test/docx/golden/nested_anchors_in_header.docx | Bin 10206 -> 10229 bytes test/docx/golden/notes.docx | Bin 9982 -> 10005 bytes test/docx/golden/raw-blocks.docx | Bin 9914 -> 9937 bytes test/docx/golden/raw-bookmarks.docx | Bin 10048 -> 10071 bytes test/docx/golden/table_one_row.docx | Bin 9892 -> 9926 bytes test/docx/golden/table_with_list_cell.docx | Bin 10210 -> 10245 bytes test/docx/golden/tables-default-widths.docx | Bin 10249 -> 10272 bytes test/docx/golden/tables.docx | Bin 10251 -> 10287 bytes .../docx/golden/tables_separated_with_rawblock.docx | Bin 9899 -> 9922 bytes test/docx/golden/track_changes_deletion.docx | Bin 9857 -> 9880 bytes test/docx/golden/track_changes_insertion.docx | Bin 9840 -> 9863 bytes test/docx/golden/track_changes_move.docx | Bin 9874 -> 9897 bytes .../golden/track_changes_scrubbed_metadata.docx | Bin 9986 -> 10009 bytes test/docx/golden/unicode.docx | Bin 9799 -> 9822 bytes test/docx/golden/verbatim_subsuper.docx | Bin 9846 -> 9869 bytes 37 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs index f2e26322b..0178cec17 100644 --- a/src/Text/Pandoc/Writers/Docx.hs +++ b/src/Text/Pandoc/Writers/Docx.hs @@ -307,10 +307,13 @@ writeDocx opts doc = do | e <- zEntries refArchive , "word/media/" `isPrefixOf` eRelativePath e ] - let defaultnodes = [mknode "Default" - [("Extension","xml"),("ContentType","application/xml")] (), - mknode "Default" - [("Extension","rels"),("ContentType","application/vnd.openxmlformats-package.relationships+xml")] ()] + let mkDefaultNode (ext, mt) = + mknode "Default" [("Extension",ext),("ContentType",mt)] () + let defaultnodes = map mkDefaultNode + [("xml", "application/xml"), + ("rels", "application/vnd.openxmlformats-package.relationships+xml"), + ("odttf", + "application/vnd.openxmlformats-officedocument.obfuscatedFont")] let contentTypesDoc = mknode "Types" [("xmlns","http://schemas.openxmlformats.org/package/2006/content-types")] $ defaultnodes ++ overrides let contentTypesEntry = toEntry "[Content_Types].xml" epochtime $ renderXml contentTypesDoc @@ -538,6 +541,11 @@ writeDocx opts doc = do docPropsAppEntry <- entryFromArchive refArchive "docProps/app.xml" themeEntry <- entryFromArchive refArchive "word/theme/theme1.xml" fontTableEntry <- entryFromArchive refArchive "word/fontTable.xml" + let fontTableRelsEntries = maybeToList $ + findEntryByPath "word/_rels/fontTable.xml.rels" refArchive + let fontEntries = [entry | entry <- zEntries refArchive + , "word/fonts/" `isPrefixOf` (eRelativePath entry)] + -- or parse fontTable.xml.rels? webSettingsEntry <- entryFromArchive refArchive "word/webSettings.xml" headerFooterEntries <- mapM (entryFromArchive refArchive . ("word/" ++)) $ mapMaybe (fmap T.unpack . extractTarget) @@ -557,7 +565,9 @@ writeDocx opts doc = do commentsEntry : docPropsEntry : docPropsAppEntry : customPropsEntry : themeEntry : - fontTableEntry : settingsEntry : webSettingsEntry : + settingsEntry : webSettingsEntry : + fontTableEntry : + fontTableRelsEntries ++ fontEntries ++ imageEntries ++ headerFooterEntries ++ miscRelEntries ++ otherMediaEntries return $ fromArchive archive diff --git a/test/docx/golden/block_quotes.docx b/test/docx/golden/block_quotes.docx index 5d75e8302..29bf27d91 100644 Binary files a/test/docx/golden/block_quotes.docx and b/test/docx/golden/block_quotes.docx differ diff --git a/test/docx/golden/codeblock.docx b/test/docx/golden/codeblock.docx index 0baa090c1..30262ffea 100644 Binary files a/test/docx/golden/codeblock.docx and b/test/docx/golden/codeblock.docx differ diff --git a/test/docx/golden/comments.docx b/test/docx/golden/comments.docx index 6015d07bb..51c3cba34 100644 Binary files a/test/docx/golden/comments.docx and b/test/docx/golden/comments.docx differ diff --git a/test/docx/golden/custom_style_no_reference.docx b/test/docx/golden/custom_style_no_reference.docx index c50cc9883..be41860cd 100644 Binary files a/test/docx/golden/custom_style_no_reference.docx and b/test/docx/golden/custom_style_no_reference.docx differ diff --git a/test/docx/golden/custom_style_preserve.docx b/test/docx/golden/custom_style_preserve.docx index 034ab3863..8bb277cd0 100644 Binary files a/test/docx/golden/custom_style_preserve.docx and b/test/docx/golden/custom_style_preserve.docx differ diff --git a/test/docx/golden/custom_style_reference.docx b/test/docx/golden/custom_style_reference.docx index e7da8f06d..a514d1a59 100644 Binary files a/test/docx/golden/custom_style_reference.docx and b/test/docx/golden/custom_style_reference.docx differ diff --git a/test/docx/golden/definition_list.docx b/test/docx/golden/definition_list.docx index 7191805b5..e77b1b780 100644 Binary files a/test/docx/golden/definition_list.docx and b/test/docx/golden/definition_list.docx differ diff --git a/test/docx/golden/document-properties-short-desc.docx b/test/docx/golden/document-properties-short-desc.docx index 685761550..72f0f83b9 100644 Binary files a/test/docx/golden/document-properties-short-desc.docx and b/test/docx/golden/document-properties-short-desc.docx differ diff --git a/test/docx/golden/document-properties.docx b/test/docx/golden/document-properties.docx index 99ba3993c..2c611e160 100644 Binary files a/test/docx/golden/document-properties.docx and b/test/docx/golden/document-properties.docx differ diff --git a/test/docx/golden/headers.docx b/test/docx/golden/headers.docx index 90b618d69..8369364c8 100644 Binary files a/test/docx/golden/headers.docx and b/test/docx/golden/headers.docx differ diff --git a/test/docx/golden/image.docx b/test/docx/golden/image.docx index 1d6b5fa8b..9e0ac7b42 100644 Binary files a/test/docx/golden/image.docx and b/test/docx/golden/image.docx differ diff --git a/test/docx/golden/inline_code.docx b/test/docx/golden/inline_code.docx index a0052fa30..3edef3049 100644 Binary files a/test/docx/golden/inline_code.docx and b/test/docx/golden/inline_code.docx differ diff --git a/test/docx/golden/inline_formatting.docx b/test/docx/golden/inline_formatting.docx index 4ded6d1aa..6c8440441 100644 Binary files a/test/docx/golden/inline_formatting.docx and b/test/docx/golden/inline_formatting.docx differ diff --git a/test/docx/golden/inline_images.docx b/test/docx/golden/inline_images.docx index ed39308ff..7976632d7 100644 Binary files a/test/docx/golden/inline_images.docx and b/test/docx/golden/inline_images.docx differ diff --git a/test/docx/golden/link_in_notes.docx b/test/docx/golden/link_in_notes.docx index 0cd236321..7e511bf88 100644 Binary files a/test/docx/golden/link_in_notes.docx and b/test/docx/golden/link_in_notes.docx differ diff --git a/test/docx/golden/links.docx b/test/docx/golden/links.docx index 86605fc75..1cd265d9e 100644 Binary files a/test/docx/golden/links.docx and b/test/docx/golden/links.docx differ diff --git a/test/docx/golden/lists.docx b/test/docx/golden/lists.docx index 7e6be666a..f872965d5 100644 Binary files a/test/docx/golden/lists.docx and b/test/docx/golden/lists.docx differ diff --git a/test/docx/golden/lists_continuing.docx b/test/docx/golden/lists_continuing.docx index 6173d5716..23e881342 100644 Binary files a/test/docx/golden/lists_continuing.docx and b/test/docx/golden/lists_continuing.docx differ diff --git a/test/docx/golden/lists_div_bullets.docx b/test/docx/golden/lists_div_bullets.docx index ee53db559..1b21303b0 100644 Binary files a/test/docx/golden/lists_div_bullets.docx and b/test/docx/golden/lists_div_bullets.docx differ diff --git a/test/docx/golden/lists_multiple_initial.docx b/test/docx/golden/lists_multiple_initial.docx index e15a8eb40..4bdc1ec85 100644 Binary files a/test/docx/golden/lists_multiple_initial.docx and b/test/docx/golden/lists_multiple_initial.docx differ diff --git a/test/docx/golden/lists_restarting.docx b/test/docx/golden/lists_restarting.docx index d650e2830..6d9a67ad3 100644 Binary files a/test/docx/golden/lists_restarting.docx and b/test/docx/golden/lists_restarting.docx differ diff --git a/test/docx/golden/nested_anchors_in_header.docx b/test/docx/golden/nested_anchors_in_header.docx index 6497dfe8c..d95ebd303 100644 Binary files a/test/docx/golden/nested_anchors_in_header.docx and b/test/docx/golden/nested_anchors_in_header.docx differ diff --git a/test/docx/golden/notes.docx b/test/docx/golden/notes.docx index a78129145..e933eeeeb 100644 Binary files a/test/docx/golden/notes.docx and b/test/docx/golden/notes.docx differ diff --git a/test/docx/golden/raw-blocks.docx b/test/docx/golden/raw-blocks.docx index af332bcf2..829b83635 100644 Binary files a/test/docx/golden/raw-blocks.docx and b/test/docx/golden/raw-blocks.docx differ diff --git a/test/docx/golden/raw-bookmarks.docx b/test/docx/golden/raw-bookmarks.docx index 26f3c5dbf..447dcbec7 100644 Binary files a/test/docx/golden/raw-bookmarks.docx and b/test/docx/golden/raw-bookmarks.docx differ diff --git a/test/docx/golden/table_one_row.docx b/test/docx/golden/table_one_row.docx index 47083b176..b135a99b1 100644 Binary files a/test/docx/golden/table_one_row.docx and b/test/docx/golden/table_one_row.docx differ diff --git a/test/docx/golden/table_with_list_cell.docx b/test/docx/golden/table_with_list_cell.docx index 6ce56eadd..f1b9c59a0 100644 Binary files a/test/docx/golden/table_with_list_cell.docx and b/test/docx/golden/table_with_list_cell.docx differ diff --git a/test/docx/golden/tables-default-widths.docx b/test/docx/golden/tables-default-widths.docx index 0a5449a7b..02a0c21ab 100644 Binary files a/test/docx/golden/tables-default-widths.docx and b/test/docx/golden/tables-default-widths.docx differ diff --git a/test/docx/golden/tables.docx b/test/docx/golden/tables.docx index dedc6d587..fa96b80d1 100644 Binary files a/test/docx/golden/tables.docx and b/test/docx/golden/tables.docx differ diff --git a/test/docx/golden/tables_separated_with_rawblock.docx b/test/docx/golden/tables_separated_with_rawblock.docx index f9ec90b19..cd289cdcb 100644 Binary files a/test/docx/golden/tables_separated_with_rawblock.docx and b/test/docx/golden/tables_separated_with_rawblock.docx differ diff --git a/test/docx/golden/track_changes_deletion.docx b/test/docx/golden/track_changes_deletion.docx index 543c55068..94ec7705c 100644 Binary files a/test/docx/golden/track_changes_deletion.docx and b/test/docx/golden/track_changes_deletion.docx differ diff --git a/test/docx/golden/track_changes_insertion.docx b/test/docx/golden/track_changes_insertion.docx index 8127f6c26..c3535ce2b 100644 Binary files a/test/docx/golden/track_changes_insertion.docx and b/test/docx/golden/track_changes_insertion.docx differ diff --git a/test/docx/golden/track_changes_move.docx b/test/docx/golden/track_changes_move.docx index d8fe769c0..b1866a375 100644 Binary files a/test/docx/golden/track_changes_move.docx and b/test/docx/golden/track_changes_move.docx differ diff --git a/test/docx/golden/track_changes_scrubbed_metadata.docx b/test/docx/golden/track_changes_scrubbed_metadata.docx index 539d25815..bf742b5c5 100644 Binary files a/test/docx/golden/track_changes_scrubbed_metadata.docx and b/test/docx/golden/track_changes_scrubbed_metadata.docx differ diff --git a/test/docx/golden/unicode.docx b/test/docx/golden/unicode.docx index 0504b13df..bf6cd1bc5 100644 Binary files a/test/docx/golden/unicode.docx and b/test/docx/golden/unicode.docx differ diff --git a/test/docx/golden/verbatim_subsuper.docx b/test/docx/golden/verbatim_subsuper.docx index 99d2bd8b2..8996d8491 100644 Binary files a/test/docx/golden/verbatim_subsuper.docx and b/test/docx/golden/verbatim_subsuper.docx differ -- cgit v1.2.3