git.iko.soy/typeable/pandoc
on master help sign in
Powerpoint writer: Move image sizing into picProps.

Rather than passing around attributes, we can have image sizing in the picProps and then pass it along to write to XML.

commit0482edadbd87f7d981c965f8b3ec04c4b9d102d0 authorJesse Rosenthal <jrosenthal@jhu.edu> dateMon 15 Jan 2018, 12:36 (9 years ago) parentc101416
2 files changed+27−12
src/Text/Pandoc/Writers/Powerpoint/Output.hs+3−4 src/Text/Pandoc/Writers/Powerpoint/Presentation.hs+24−8
src/Text/Pandoc/Writers/Powerpoint/Output.hs+3−4
@@ -616,10 +616,9 @@ makePicElements :: PandocMonad m
616616 => Element
617617 -> PicProps
618618 -> MediaInfo
619− -> Text.Pandoc.Definition.Attr
620619 -> [ParaElem]
621620 -> P m [Element]
622−makePicElements layout picProps mInfo _ alt = do
621+makePicElements layout picProps mInfo alt = do
623622 opts <- asks envOpts
624623 (pageWidth, pageHeight) <- asks envPresentationSize
625624 -- hasHeader <- asks envSlideHasHeader
@@ -826,11 +825,11 @@ shapeToElement layout (TextBox paras)
826825shapeToElement _ _ = return $ mknode "p:sp" [] ()
827826
828827shapeToElements :: PandocMonad m => Element -> Shape -> P m [Element]
829−shapeToElements layout (Pic picProps fp attr alt) = do
828+shapeToElements layout (Pic picProps fp alt) = do
830829 mInfo <- registerMedia fp alt
831830 case mInfoExt mInfo of
832831 Just _ -> do
833− makePicElements layout picProps mInfo attr alt
832+ makePicElements layout picProps mInfo alt
834833 Nothing -> shapeToElements layout $ TextBox [Paragraph def alt]
835834shapeToElements layout (GraphicFrame tbls cptn) =
836835 graphicFrameToElements layout tbls cptn
src/Text/Pandoc/Writers/Powerpoint/Presentation.hs+24−8
@@ -58,6 +58,7 @@ import Control.Monad.State
5858import Data.List (intercalate)
5959import Data.Default
6060import Text.Pandoc.Definition
61+import Text.Pandoc.ImageSize
6162import Text.Pandoc.Slides (getSlideLevel)
6263import Text.Pandoc.Options
6364import Text.Pandoc.Logging
@@ -138,7 +139,7 @@ data Slide = MetadataSlide { metadataSlideTitle :: [ParaElem]
138139 }
139140 deriving (Show, Eq)
140141
141−data Shape = Pic PicProps FilePath Text.Pandoc.Definition.Attr [ParaElem]
142+data Shape = Pic PicProps FilePath [ParaElem]
142143 | GraphicFrame [Graphic] [ParaElem]
143144 | TextBox [Paragraph]
144145 deriving (Show, Eq)
@@ -230,10 +231,14 @@ instance Default RunProps where
230231 }
231232
232233data PicProps = PicProps { picPropLink :: Maybe LinkTarget
234+ , picWidth :: Maybe Dimension
235+ , picHeight :: Maybe Dimension
233236 } deriving (Show, Eq)
234237
235238instance Default PicProps where
236239 def = PicProps { picPropLink = Nothing
240+ , picWidth = Nothing
241+ , picHeight = Nothing
237242 }
238243
239244--------------------------------------------------
@@ -407,17 +412,28 @@ rowToParagraphs algns tblCells = do
407412 let pairs = zip (algns ++ repeat AlignDefault) tblCells
408413 mapM (\(a, tc) -> cellToParagraphs a tc) pairs
409414
415+withAttr :: Attr -> Shape -> Shape
416+withAttr attr (Pic picPr url caption) =
417+ let picPr' = picPr { picWidth = dimension Width attr
418+ , picHeight = dimension Height attr
419+ }
420+ in
421+ Pic picPr' url caption
422+withAttr _ sp = sp
423+
410424blockToShape :: Block -> Pres Shape
411425blockToShape (Plain (il:_)) | Image attr ils (url, _) <- il =
412− Pic def url attr <$> (inlinesToParElems ils)
426+ (withAttr attr . Pic def url) <$> (inlinesToParElems ils)
413427blockToShape (Para (il:_)) | Image attr ils (url, _) <- il =
414− Pic def url attr <$> (inlinesToParElems ils)
428+ (withAttr attr . Pic def url) <$> (inlinesToParElems ils)
415429blockToShape (Plain (il:_)) | Link _ (il':_) target <- il
416430 , Image attr ils (url, _) <- il' =
417− Pic def{picPropLink = Just $ ExternalTarget target} url attr <$> (inlinesToParElems ils)
431+ (withAttr attr . Pic def {picPropLink = Just $ ExternalTarget target} url) <$>
432+ (inlinesToParElems ils)
418433blockToShape (Para (il:_)) | Link _ (il':_) target <- il
419434 , Image attr ils (url, _) <- il' =
420− Pic def{picPropLink = Just $ ExternalTarget target} url attr <$> (inlinesToParElems ils)
435+ (withAttr attr . Pic def{picPropLink = Just $ ExternalTarget target} url) <$>
436+ (inlinesToParElems ils)
421437blockToShape (Table caption algn _ hdrCells rows) = do
422438 caption' <- inlinesToParElems caption
423439 hdrCells' <- rowToParagraphs algn hdrCells
@@ -438,7 +454,7 @@ blockToShape blk = do paras <- blockToParagraphs blk
438454combineShapes :: [Shape] -> [Shape]
439455combineShapes [] = []
440456combineShapes (s : []) = [s]
441−combineShapes (pic@(Pic _ _ _ _) : ss) = pic : combineShapes ss
457+combineShapes (pic@(Pic _ _ _) : ss) = pic : combineShapes ss
442458combineShapes ((TextBox []) : ss) = combineShapes ss
443459combineShapes (s : TextBox [] : ss) = combineShapes (s : ss)
444460combineShapes ((TextBox (p:ps)) : (TextBox (p':ps')) : ss) =
@@ -650,9 +666,9 @@ applyToParagraph f para = do
650666 return $ para {paraElems = paraElems'}
651667
652668applyToShape :: Monad m => (ParaElem -> m ParaElem) -> Shape -> m Shape
653−applyToShape f (Pic pPr fp attr pes) = do
669+applyToShape f (Pic pPr fp pes) = do
654670 pes' <- mapM f pes
655− return $ Pic pPr fp attr pes'
671+ return $ Pic pPr fp pes'
656672applyToShape f (GraphicFrame gfx pes) = do
657673 pes' <- mapM f pes
658674 return $ GraphicFrame gfx pes'