Docx reader: add handling of vml image objects (jgm#4735) (#7257)

They represent images, the same way as other images in vml format.
This commit is contained in:
mbrackeantidot 2021-04-29 18:11:44 +02:00 committed by GitHub
parent d14c5f94df
commit b6a65445e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 2 deletions

View file

@ -709,7 +709,8 @@ elemToParPart ns element
case drawing of case drawing of
Just s -> expandDrawingId s >>= (\(fp, bs) -> return $ Drawing fp title alt bs $ elemToExtent drawingElem) Just s -> expandDrawingId s >>= (\(fp, bs) -> return $ Drawing fp title alt bs $ elemToExtent drawingElem)
Nothing -> throwError WrongElem 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 elemToParPart ns element
| isElem ns "w" "r" element | isElem ns "w" "r" element
, Just _ <- findChildByName ns "w" "pict" element = , Just _ <- findChildByName ns "w" "pict" element =
@ -717,9 +718,15 @@ elemToParPart ns element
>>= findAttrByName ns "r" "id" >>= findAttrByName ns "r" "id"
in in
case drawing of case drawing of
-- Todo: check out title and attr for deprecated format.
Just s -> expandDrawingId s >>= (\(fp, bs) -> return $ Drawing fp "" "" bs Nothing) Just s -> expandDrawingId s >>= (\(fp, bs) -> return $ Drawing fp "" "" bs Nothing)
Nothing -> throwError WrongElem 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 -- Chart
elemToParPart ns element elemToParPart ns element
| isElem ns "w" "r" element | isElem ns "w" "r" element

View file

@ -155,6 +155,10 @@ tests = [ testGroup "document"
"VML image" "VML image"
"docx/image_vml.docx" "docx/image_vml.docx"
"docx/image_vml.native" "docx/image_vml.native"
, testCompare
"VML image as object"
"docx/image_vml_as_object.docx"
"docx/image_vml_as_object.native"
, testCompare , testCompare
"inline image in links" "inline image in links"
"docx/inline_images.docx" "docx/inline_images.docx"

Binary file not shown.

View file

@ -0,0 +1,2 @@
[Para [Str "Test",Space,Str "with",Space,Str "object",Space,Str "as",Space,Str "image:"]
,Para [Image ("",[],[]) [] ("media/image1.emf","")]]