git.iko.soy/typeable/pandoc
on master help sign in
Powerpoint writer: Move image sizing into picProps.
0482edaJesse Rosenthal
src/Text/Pandoc/Writers/Powerpoint/Output.hs+3−4
@@ -616,10 +616,9 @@ makePicElements :: PandocMonad m
616 => Element
616 => Element
617 -> PicProps
617 -> PicProps
618 -> MediaInfo
618 -> MediaInfo
619− -> Text.Pandoc.Definition.Attr
620 -> [ParaElem]
619 -> [ParaElem]
621 -> P m [Element]
620 -> P m [Element]
622−makePicElements layout picProps mInfo _ alt = do
621+makePicElements layout picProps mInfo alt = do
623 opts <- asks envOpts
622 opts <- asks envOpts
624 (pageWidth, pageHeight) <- asks envPresentationSize
623 (pageWidth, pageHeight) <- asks envPresentationSize
625 -- hasHeader <- asks envSlideHasHeader
624 -- hasHeader <- asks envSlideHasHeader
@@ -826,11 +825,11 @@ shapeToElement layout (TextBox paras)
826shapeToElement _ _ = return $ mknode "p:sp" [] ()
825shapeToElement _ _ = return $ mknode "p:sp" [] ()
827
826
828shapeToElements :: PandocMonad m => Element -> Shape -> P m [Element]
827shapeToElements :: PandocMonad m => Element -> Shape -> P m [Element]
829−shapeToElements layout (Pic picProps fp attr alt) = do
828+shapeToElements layout (Pic picProps fp alt) = do
830 mInfo <- registerMedia fp alt
829 mInfo <- registerMedia fp alt
831 case mInfoExt mInfo of
830 case mInfoExt mInfo of
832 Just _ -> do
831 Just _ -> do
833− makePicElements layout picProps mInfo attr alt
832+ makePicElements layout picProps mInfo alt
834 Nothing -> shapeToElements layout $ TextBox [Paragraph def alt]
833 Nothing -> shapeToElements layout $ TextBox [Paragraph def alt]
835shapeToElements layout (GraphicFrame tbls cptn) =
834shapeToElements layout (GraphicFrame tbls cptn) =
836 graphicFrameToElements layout tbls cptn
835 graphicFrameToElements layout tbls cptn
src/Text/Pandoc/Writers/Powerpoint/Presentation.hs+24−8
@@ -58,6 +58,7 @@ import Control.Monad.State
58import Data.List (intercalate)
58import Data.List (intercalate)
59import Data.Default
59import Data.Default
60import Text.Pandoc.Definition
60import Text.Pandoc.Definition
61+import Text.Pandoc.ImageSize
61import Text.Pandoc.Slides (getSlideLevel)
62import Text.Pandoc.Slides (getSlideLevel)
62import Text.Pandoc.Options
63import Text.Pandoc.Options
63import Text.Pandoc.Logging
64import Text.Pandoc.Logging
@@ -138,7 +139,7 @@ data Slide = MetadataSlide { metadataSlideTitle :: [ParaElem]
138 }
139 }
139 deriving (Show, Eq)
140 deriving (Show, Eq)
140
141
141−data Shape = Pic PicProps FilePath Text.Pandoc.Definition.Attr [ParaElem]
142+data Shape = Pic PicProps FilePath [ParaElem]
142 | GraphicFrame [Graphic] [ParaElem]
143 | GraphicFrame [Graphic] [ParaElem]
143 | TextBox [Paragraph]
144 | TextBox [Paragraph]
144 deriving (Show, Eq)
145 deriving (Show, Eq)
@@ -230,10 +231,14 @@ instance Default RunProps where
230 }
231 }
231
232
232data PicProps = PicProps { picPropLink :: Maybe LinkTarget
233data PicProps = PicProps { picPropLink :: Maybe LinkTarget
234+ , picWidth :: Maybe Dimension
235+ , picHeight :: Maybe Dimension
233 } deriving (Show, Eq)
236 } deriving (Show, Eq)
234
237
235instance Default PicProps where
238instance Default PicProps where
236 def = PicProps { picPropLink = Nothing
239 def = PicProps { picPropLink = Nothing
240+ , picWidth = Nothing
241+ , picHeight = Nothing
237 }
242 }
238
243
239--------------------------------------------------
244--------------------------------------------------
@@ -407,17 +412,28 @@ rowToParagraphs algns tblCells = do
407 let pairs = zip (algns ++ repeat AlignDefault) tblCells
412 let pairs = zip (algns ++ repeat AlignDefault) tblCells
408 mapM (\(a, tc) -> cellToParagraphs a tc) pairs
413 mapM (\(a, tc) -> cellToParagraphs a tc) pairs
409
414
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+
410blockToShape :: Block -> Pres Shape
424blockToShape :: Block -> Pres Shape
411blockToShape (Plain (il:_)) | Image attr ils (url, _) <- il =
425blockToShape (Plain (il:_)) | Image attr ils (url, _) <- il =
412− Pic def url attr <$> (inlinesToParElems ils)
426+ (withAttr attr . Pic def url) <$> (inlinesToParElems ils)
413blockToShape (Para (il:_)) | Image attr ils (url, _) <- il =
427blockToShape (Para (il:_)) | Image attr ils (url, _) <- il =
414− Pic def url attr <$> (inlinesToParElems ils)
428+ (withAttr attr . Pic def url) <$> (inlinesToParElems ils)
415blockToShape (Plain (il:_)) | Link _ (il':_) target <- il
429blockToShape (Plain (il:_)) | Link _ (il':_) target <- il
416 , Image attr ils (url, _) <- il' =
430 , 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)
418blockToShape (Para (il:_)) | Link _ (il':_) target <- il
433blockToShape (Para (il:_)) | Link _ (il':_) target <- il
419 , Image attr ils (url, _) <- il' =
434 , 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)
421blockToShape (Table caption algn _ hdrCells rows) = do
437blockToShape (Table caption algn _ hdrCells rows) = do
422 caption' <- inlinesToParElems caption
438 caption' <- inlinesToParElems caption
423 hdrCells' <- rowToParagraphs algn hdrCells
439 hdrCells' <- rowToParagraphs algn hdrCells
@@ -438,7 +454,7 @@ blockToShape blk = do paras <- blockToParagraphs blk
438combineShapes :: [Shape] -> [Shape]
454combineShapes :: [Shape] -> [Shape]
439combineShapes [] = []
455combineShapes [] = []
440combineShapes (s : []) = [s]
456combineShapes (s : []) = [s]
441−combineShapes (pic@(Pic _ _ _ _) : ss) = pic : combineShapes ss
457+combineShapes (pic@(Pic _ _ _) : ss) = pic : combineShapes ss
442combineShapes ((TextBox []) : ss) = combineShapes ss
458combineShapes ((TextBox []) : ss) = combineShapes ss
443combineShapes (s : TextBox [] : ss) = combineShapes (s : ss)
459combineShapes (s : TextBox [] : ss) = combineShapes (s : ss)
444combineShapes ((TextBox (p:ps)) : (TextBox (p':ps')) : ss) =
460combineShapes ((TextBox (p:ps)) : (TextBox (p':ps')) : ss) =
@@ -650,9 +666,9 @@ applyToParagraph f para = do
650 return $ para {paraElems = paraElems'}
666 return $ para {paraElems = paraElems'}
651
667
652applyToShape :: Monad m => (ParaElem -> m ParaElem) -> Shape -> m Shape
668applyToShape :: 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
654 pes' <- mapM f pes
670 pes' <- mapM f pes
655− return $ Pic pPr fp attr pes'
671+ return $ Pic pPr fp pes'
656applyToShape f (GraphicFrame gfx pes) = do
672applyToShape f (GraphicFrame gfx pes) = do
657 pes' <- mapM f pes
673 pes' <- mapM f pes
658 return $ GraphicFrame gfx pes'
674 return $ GraphicFrame gfx pes'