Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using internal column widths in pptx writer tables #9392

Merged
merged 3 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/Text/Pandoc/Writers/Powerpoint/Output.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1411,19 +1411,19 @@ getDefaultTableStyle = do
return $ findAttr (QName "def" Nothing Nothing) tblStyleLst

graphicToElement :: PandocMonad m => Integer -> Graphic -> P m Element
graphicToElement tableWidth (Tbl tblPr hdrCells rows) = do
let colWidths = if null hdrCells
then case rows of
r : _ | not (null r) -> replicate (length r) $
graphicToElement tableWidth (Tbl widths tblPr hdrCells rows) = do
let totalWidth = sum widths
let colWidths = if any (== 0.0) widths
then if null hdrCells
then case rows of
r@(_:_) : _ -> replicate (length r) $
tableWidth `div` toInteger (length r)
-- satisfy the compiler. This is the same as
-- saying that rows is empty, but the compiler
-- won't understand that `[]` exhausts the
-- alternatives.
_ -> []
else replicate (length hdrCells) $
tableWidth `div` toInteger (length hdrCells)

[]: _ -> []
[] -> []
else replicate (length hdrCells) $
tableWidth `div` toInteger (length hdrCells)
else map (\w -> round $ w / totalWidth * fromIntegral tableWidth) widths

let cellToOpenXML paras =
do elements <- mapM paragraphToElement paras
let elements' = if null elements
Expand Down
6 changes: 3 additions & 3 deletions src/Text/Pandoc/Writers/Powerpoint/Presentation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ data TableProps = TableProps { tblPrFirstRow :: Bool
, tblPrBandRow :: Bool
} deriving (Show, Eq)

data Graphic = Tbl TableProps [TableCell] [[TableCell]]
data Graphic = Tbl [Double] TableProps [TableCell] [[TableCell]]
deriving (Show, Eq)


Expand Down Expand Up @@ -601,7 +601,7 @@ blockToShape (Para (il:_)) | Link _ (il':_) target <- il
<$> inlinesToParElems ils
blockToShape (Figure _figattr _caption [b]) = blockToShape b
blockToShape (Table _ blkCapt specs thead tbody tfoot) = do
let (caption, algn, _, hdrCells, rows) = toLegacyTable blkCapt specs thead tbody tfoot
let (caption, algn, widths, hdrCells, rows) = toLegacyTable blkCapt specs thead tbody tfoot
caption' <- inlinesToParElems caption
hdrCells' <- rowToParagraphs algn hdrCells
rows' <- mapM (rowToParagraphs algn) rows
Expand All @@ -613,7 +613,7 @@ blockToShape (Table _ blkCapt specs thead tbody tfoot) = do
, tblPrBandRow = True
}

return $ GraphicFrame [Tbl tblPr hdrCells' rows'] caption'
return $ GraphicFrame [Tbl widths tblPr hdrCells' rows'] caption'
-- If the format isn't openxml, we fall through to blockToPargraphs
blockToShape (RawBlock (Format "openxml") str) = return $ RawOOXMLShape str
blockToShape blk = do paras <- blockToParagraphs blk
Expand Down
Binary file modified test/pptx/comparison/both-columns/templated.pptx
Binary file not shown.
Binary file modified test/pptx/comparison/extra-image/templated.pptx
Binary file not shown.
Binary file modified test/pptx/comparison/extra-text/templated.pptx
Binary file not shown.
Binary file modified test/pptx/comparison/non-text-first/templated.pptx
Binary file not shown.
Binary file modified test/pptx/comparison/one-column/templated.pptx
Binary file not shown.
Binary file modified test/pptx/footer/basic/output.pptx
Binary file not shown.
Binary file modified test/pptx/footer/fixed-date/output.pptx
Binary file not shown.
Binary file modified test/pptx/footer/higher-slide-number/output.pptx
Binary file not shown.
Binary file modified test/pptx/footer/no-title-slide/output.pptx
Binary file not shown.