From b6a65445e10d74dfe384763c37438338bd395372 Mon Sep 17 00:00:00 2001 From: mbrackeantidot <65160241+mbrackeantidot@users.noreply.github.com> Date: Thu, 29 Apr 2021 18:11:44 +0200 Subject: Docx reader: add handling of vml image objects (jgm#4735) (#7257) They represent images, the same way as other images in vml format. --- src/Text/Pandoc/Readers/Docx/Parse.hs | 11 +++++++++-- test/Tests/Readers/Docx.hs | 4 ++++ test/docx/image_vml_as_object.docx | Bin 0 -> 74199 bytes test/docx/image_vml_as_object.native | 2 ++ 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 test/docx/image_vml_as_object.docx create mode 100644 test/docx/image_vml_as_object.native diff --git a/src/Text/Pandoc/Readers/Docx/Parse.hs b/src/Text/Pandoc/Readers/Docx/Parse.hs index f8ed248d7..7325ff300 100644 --- a/src/Text/Pandoc/Readers/Docx/Parse.hs +++ b/src/Text/Pandoc/Readers/Docx/Parse.hs @@ -709,7 +709,8 @@ elemToParPart ns element case drawing of Just s -> expandDrawingId s >>= (\(fp, bs) -> return $ Drawing fp title alt bs $ elemToExtent drawingElem) Nothing -> throwError WrongElem --- The below is an attempt to deal with images in deprecated vml format. +-- The two cases below are an attempt to deal with images in deprecated vml format. +-- Todo: check out title and attr for deprecated format. elemToParPart ns element | isElem ns "w" "r" element , Just _ <- findChildByName ns "w" "pict" element = @@ -717,9 +718,15 @@ elemToParPart ns element >>= findAttrByName ns "r" "id" in case drawing of - -- Todo: check out title and attr for deprecated format. Just s -> expandDrawingId s >>= (\(fp, bs) -> return $ Drawing fp "" "" bs Nothing) Nothing -> throwError WrongElem +elemToParPart ns element + | isElem ns "w" "r" element + , Just objectElem <- findChildByName ns "w" "object" element + , Just shapeElem <- findChildByName ns "v" "shape" objectElem + , Just imagedataElem <- findChildByName ns "v" "imagedata" shapeElem + , Just drawingId <- findAttrByName ns "r" "id" imagedataElem + = expandDrawingId drawingId >>= (\(fp, bs) -> return $ Drawing fp "" "" bs Nothing) -- Chart elemToParPart ns element | isElem ns "w" "r" element diff --git a/test/Tests/Readers/Docx.hs b/test/Tests/Readers/Docx.hs index 263e04173..2cce70cc5 100644 --- a/test/Tests/Readers/Docx.hs +++ b/test/Tests/Readers/Docx.hs @@ -155,6 +155,10 @@ tests = [ testGroup "document" "VML image" "docx/image_vml.docx" "docx/image_vml.native" + , testCompare + "VML image as object" + "docx/image_vml_as_object.docx" + "docx/image_vml_as_object.native" , testCompare "inline image in links" "docx/inline_images.docx" diff --git a/test/docx/image_vml_as_object.docx b/test/docx/image_vml_as_object.docx new file mode 100644 index 000000000..7e1e4d2ca Binary files /dev/null and b/test/docx/image_vml_as_object.docx differ diff --git a/test/docx/image_vml_as_object.native b/test/docx/image_vml_as_object.native new file mode 100644 index 000000000..6e689486a --- /dev/null +++ b/test/docx/image_vml_as_object.native @@ -0,0 +1,2 @@ +[Para [Str "Test",Space,Str "with",Space,Str "object",Space,Str "as",Space,Str "image:"] +,Para [Image ("",[],[]) [] ("media/image1.emf","")]] -- cgit v1.2.3