@@ -35,6 +35,7 @@ module Text.Pandoc.Readers.Docx.Parse ( Docx(..)
35 , Body(..)
35 , Body(..)
36 , BodyPart(..)
36 , BodyPart(..)
37 , TblLook(..)
37 , TblLook(..)
38 , ParPart(..)
39 , ParPart(..)
40 , RunElem(..)
41 , RunElem(..)
@@ -62,6 +63,7 @@ import Control.Monad.Reader
62import Control.Applicative ((<|>))
63import Control.Applicative ((<|>))
63import qualified Data.Map as M
64import qualified Data.Map as M
64import Text.Pandoc.Compat.Except
65import Text.Pandoc.Compat.Except
66+import Text.Pandoc.Shared (safeRead)
65import Text.TeXMath.Readers.OMML (readOMML)
67import Text.TeXMath.Readers.OMML (readOMML)
66import Text.Pandoc.Readers.Docx.Fonts (getUnicode, Font(..))
68import Text.Pandoc.Readers.Docx.Fonts (getUnicode, Font(..))
67import Text.TeXMath (Exp)
69import Text.TeXMath (Exp)
@@ -196,20 +198,23 @@ data Row = Row [Cell]
196data Cell = Cell [BodyPart]
198data Cell = Cell [BodyPart]
197 deriving Show
199 deriving Show
201+-- (width, height) in EMUs
202+type Extent = Maybe (Double, Double)
199data ParPart = PlainRun Run
204data ParPart = PlainRun Run
200 | Insertion ChangeId Author ChangeDate [Run]
205 | Insertion ChangeId Author ChangeDate [Run]
201 | Deletion ChangeId Author ChangeDate [Run]
206 | Deletion ChangeId Author ChangeDate [Run]
202 | BookMark BookMarkId Anchor
207 | BookMark BookMarkId Anchor
203 | InternalHyperLink Anchor [Run]
208 | InternalHyperLink Anchor [Run]
204 | ExternalHyperLink URL [Run]
209 | ExternalHyperLink URL [Run]
205− | Drawing FilePath B.ByteString
210+ | Drawing FilePath B.ByteString Extent
206 | PlainOMath [Exp]
211 | PlainOMath [Exp]
207 deriving Show
212 deriving Show
209data Run = Run RunStyle [RunElem]
214data Run = Run RunStyle [RunElem]
210 | Footnote [BodyPart]
215 | Footnote [BodyPart]
211 | Endnote [BodyPart]
216 | Endnote [BodyPart]
212− | InlineDrawing FilePath B.ByteString
217+ | InlineDrawing FilePath B.ByteString Extent
213 deriving Show
218 deriving Show
215data RunElem = TextRun String | LnBrk | Tab | SoftHyphen | NoBreakHyphen
220data RunElem = TextRun String | LnBrk | Tab | SoftHyphen | NoBreakHyphen
@@ -619,13 +624,13 @@ expandDrawingId s = do
619elemToParPart :: NameSpaces -> Element -> D ParPart
624elemToParPart :: NameSpaces -> Element -> D ParPart
620elemToParPart ns element
625elemToParPart ns element
621 | isElem ns "w" "r" element
626 | isElem ns "w" "r" element
622− , Just _ <- findChild (elemName ns "w" "drawing") element =
627+ , Just drawingElem <- findChild (elemName ns "w" "drawing") element =
623 let a_ns = "http://schemas.openxmlformats.org/drawingml/2006/main"
628 let a_ns = "http://schemas.openxmlformats.org/drawingml/2006/main"
624 drawing = findElement (QName "blip" (Just a_ns) (Just "a")) element
629 drawing = findElement (QName "blip" (Just a_ns) (Just "a")) element
625 >>= findAttr (QName "embed" (lookup "r" ns) (Just "r"))
630 >>= findAttr (QName "embed" (lookup "r" ns) (Just "r"))
627 case drawing of
632 case drawing of
628− Just s -> expandDrawingId s >>= (\(fp, bs) -> return $ Drawing fp bs)
633+ Just s -> expandDrawingId s >>= (\(fp, bs) -> return $ Drawing fp bs $ elemToExtent drawingElem)
629 Nothing -> throwError WrongElem
634 Nothing -> throwError WrongElem
630-- The below is an attempt to deal with images in deprecated vml format.
635-- The below is an attempt to deal with images in deprecated vml format.
631elemToParPart ns element
636elemToParPart ns element
@@ -635,7 +640,7 @@ elemToParPart ns element
635 >>= findAttr (elemName ns "r" "id")
640 >>= findAttr (elemName ns "r" "id")
637 case drawing of
642 case drawing of
638− Just s -> expandDrawingId s >>= (\(fp, bs) -> return $ Drawing fp bs)
643+ Just s -> expandDrawingId s >>= (\(fp, bs) -> return $ Drawing fp bs Nothing)
639 Nothing -> throwError WrongElem
644 Nothing -> throwError WrongElem
640elemToParPart ns element
645elemToParPart ns element
641 | isElem ns "w" "r" element =
646 | isElem ns "w" "r" element =
@@ -687,6 +692,16 @@ lookupFootnote s (Notes _ fns _) = fns >>= (M.lookup s)
687lookupEndnote :: String -> Notes -> Maybe Element
692lookupEndnote :: String -> Notes -> Maybe Element
688lookupEndnote s (Notes _ _ ens) = ens >>= (M.lookup s)
693lookupEndnote s (Notes _ _ ens) = ens >>= (M.lookup s)
695+elemToExtent :: Element -> Extent
696+elemToExtent drawingElem =
697+ case (getDim "cx", getDim "cy") of
698+ (Just w, Just h) -> Just (w, h)
701+ wp_ns = "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
702+ getDim at = findElement (QName "extent" (Just wp_ns) (Just "wp")) drawingElem
703+ >>= findAttr (QName at Nothing Nothing) >>= safeRead
690elemToRun :: NameSpaces -> Element -> D Run
705elemToRun :: NameSpaces -> Element -> D Run
691elemToRun ns element
706elemToRun ns element
692 | isElem ns "w" "r" element
707 | isElem ns "w" "r" element
@@ -697,7 +712,7 @@ elemToRun ns element
698 case drawing of
713 case drawing of
699 Just s -> expandDrawingId s >>=
714 Just s -> expandDrawingId s >>=
700− (\(fp, bs) -> return $ InlineDrawing fp bs)
715+ (\(fp, bs) -> return $ InlineDrawing fp bs $ elemToExtent drawingElem)
701 Nothing -> throwError WrongElem
716 Nothing -> throwError WrongElem
702elemToRun ns element
717elemToRun ns element
703 | isElem ns "w" "r" element
718 | isElem ns "w" "r" element