From ed8682d6d1f9a9ee06e99cd41614b42eddb2ed66 Mon Sep 17 00:00:00 2001 From: MartinPacker Date: Wed, 27 Dec 2023 15:52:40 +0000 Subject: [PATCH 1/2] 4.2 backgroundImage code --- md2pptx | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/md2pptx b/md2pptx index e48142e..909b2d4 100755 --- a/md2pptx +++ b/md2pptx @@ -79,8 +79,8 @@ except: have_graphviz = False -md2pptx_level = "4.1.2" -md2pptx_date = "11 July, 2023" +md2pptx_level = "4.2" +md2pptx_date = "27 December, 2023" namespaceURL = { "mc": "http://schemas.openxmlformats.org/markup-compatibility/2006", @@ -233,6 +233,16 @@ class ProcessingOptions: self.dynamicallyChangedOptions[lowerName] = True +# Add a picture stretched to cover the slide and move it to the back of the z order +def add_background(presentation, slide, picture): + # Add the picture, covering the entire slide + pic = slide.shapes.add_picture(picture,0,0,presentation.slide_width,presentation.slide_height) + + # Move the picture to the back of the z order + slide.shapes[0]._element.addprevious(pic._element) + + # return the picture shape + return pic # Find the extLst element - if it exists in presentation.xml def findExtLst(prs): @@ -246,7 +256,11 @@ def findExtLst(prs): def addSlide(presentation, slideLayout, slideInfo=None): slide = presentation.slides.add_slide(slideLayout) slide.slideInfo = slideInfo + + backgroundImage = processingOptions.getCurrentOption("backgroundImage") + if backgroundImage != "": + background = add_background(presentation, slide, backgroundImage) return slide @@ -1051,7 +1065,12 @@ def findTitleShape(slide): def findBodyShape(slide): if len(slide.shapes) > 1: - return slide.shapes[1] + if processingOptions.getCurrentOption("backgroundImage") == "": + # No background in effect + return slide.shapes[1] + else: + # Background in effect + return slide.shapes[2] elif slide.shapes.title == None: return slide.shapes[0] else: @@ -4878,9 +4897,15 @@ processingOptions.setOptionValuesArray( ] ) -processingOptions.setOptionValues("baseTextSize", 18) +processingOptions.setOptionValues("backgroundImage", "") -processingOptions.setOptionValues("baseTextDecrement", 2) +# Text size defaults +processingOptions.setOptionValuesArray( + [ + ["baseTextSize", 18], + ["baseTextDecrement", 2], + ] +) # Code defaults processingOptions.setOptionValuesArray( @@ -5185,6 +5210,11 @@ for line in metadata_lines: elif name == "basetextdecrement": processingOptions.setOptionValues(name, float(value)) + elif name == "backgroundimage": + processingOptions.setOptionValues(name, value) + + + elif name in [ "sectiontitlesize", "sectionsubtitlesize", @@ -6070,6 +6100,13 @@ for lineNumber, line in enumerate(linesAfterConcatenation): metadataKey, metadataValue, "" ) + elif metadataKey == "backgroundimage": + # Slide background image + processingOptions.dynamicallySetOption( + metadataKey, metadataValue, "" + ) + + # Note: Actual value handling prevents using dynamicallySetOption elif metadataKey == "contentsplit": # Proportions for each content element on a slide From b2eb4187e01c378c8d6d78b95db4797a8dcaba29 Mon Sep 17 00:00:00 2001 From: MartinPacker Date: Wed, 27 Dec 2023 16:23:21 +0000 Subject: [PATCH 2/2] v4.2 --- docs/user-guide.html | 20 ++++++++++++++++++++ docs/user-guide.log | 6 ++++-- docs/user-guide.md | 25 ++++++++++++++++++++++++- docs/user-guide.mdp | 27 ++++++++++++++++++++++++++- 4 files changed, 74 insertions(+), 4 deletions(-) diff --git a/docs/user-guide.html b/docs/user-guide.html index 9780bee..64ec241 100644 --- a/docs/user-guide.html +++ b/docs/user-guide.html @@ -1214,6 +1214,7 @@

Table Of ContentsSpecifying How Many Spaces Represent An Indentation Level With IndentSpaces
  • Specifying Where Temporary Files Are Stored With tempDir
  • Deleting The First (Processing Summary) Slide - with DeleteFirstSlide
  • +
  • Specifying Slide Background Images With backgroundImage
  • Table Metadata
  • @@ -1475,6 +1477,11 @@

    Change Log4.2 +27 December 2023 +Added background image support using backgroundImage. + + 4.1.2 11 July 2023 Fixed two bugs: Using <sub> & <sup> causes a crash. Also Card Slides cause a crash. @@ -3289,6 +3296,14 @@

    Delet

    The default is no.

    Note: If you don’t have a Processing Summary slide - perhaps because the slide master you used doesn’t have a slide - the first slide would still be removed if you specified removeFirstSlide: yes. This is probably not what you want to have happen.

    +

    Specifying Slide Background Images With backgroundImage

    +

    +

    You can specify a background image for slides with backgroundImage. For example:

    +
    backgroundImage: myFavouriteBackground.png
    +
    +

    The default is no background image (other than from the slide master), represented by an empty string.

    +

    You can override this value with Dynamic Metadata.

    +

    Note: python-pptx doesn’t know how to truly manipulate a slide background image. Accordingly, md2pptx places the graphic you specify behind all the other objects it creates on the slide (but in front of any real background). It covers the slide area entirely, scaling the graphic to fit. It’s a good idea to make your background image be the same size, or have the same aspect ratio, as the slide.

    Table Metadata

    Shrinking Tables With compactTables

    @@ -4180,6 +4195,11 @@

    Transition

    +

    BackgroundImage

    +

    You can override the presentation BackgroundImage specification on a slide-by-slide basis:

    +
    <!-- md2pptx: backgroundImage: myNewBackground.png -->
    +

    Modifying The Slide Template

    The included template presentation - Martin Template.pptx - is what the author tested with and gives good results. However, you probably want to develop your own template from it.

    diff --git a/docs/user-guide.log b/docs/user-guide.log index 6a521f3..5ed1691 100644 --- a/docs/user-guide.log +++ b/docs/user-guide.log @@ -5,8 +5,8 @@ mdpre Markdown Preprocessor v0.6.7 (17 December, 2023) Def mdpre_date = 17 December, 2023 Def mdpre_level = 0.6.7 Def userid = martinpacker -Def time = 10:32 -Def date = 23 December, 2023 +Def time = 16:20 +Def date = 27 December, 2023 Def TOC = Table Of Contents Def md = Markdown Def pp = Powerpoint @@ -113,6 +113,7 @@ CSV Stop ..... ..... ..... Specifying How Many Spaces Represent An Indentation Level With `IndentSpaces` ..... ..... ..... Specifying Where Temporary Files Are Stored With `tempDir` ..... ..... ..... Deleting The First (Processing Summary) Slide - with `DeleteFirstSlide` +..... ..... ..... Specifying Slide Background Images With `backgroundImage` ..... ..... ..... Table Metadata ..... ..... ..... ..... Shrinking Tables With `compactTables` ..... ..... ..... ..... Adjusting Table Heading Font Size With `tableHeadingSize` @@ -225,6 +226,7 @@ CSV Stop ..... ..... ..... `NumbersHeight` ..... ..... ..... `TableMargin` ..... ..... ..... `Transition` +..... ..... ..... `BackgroundImage` ..... Modifying The Slide Template ..... ..... Basics ..... ..... Slide Template Sequence diff --git a/docs/user-guide.md b/docs/user-guide.md index 0e030b5..cea5111 100644 --- a/docs/user-guide.md +++ b/docs/user-guide.md @@ -101,6 +101,7 @@ As you can see in the [change log](#change-log), md2pptx is frequently updated - * [Specifying How Many Spaces Represent An Indentation Level With `IndentSpaces`](#specifying-how-many-spaces-represent-an-indentation-level-with-indentspaces) * [Specifying Where Temporary Files Are Stored With `tempDir`](#specifying-where-temporary-files-are-stored-with-tempdir) * [Deleting The First (Processing Summary) Slide - with `DeleteFirstSlide`](#deleting-the-first-(processing-summary)-slide-with-deletefirstslide) + * [Specifying Slide Background Images With `backgroundImage`](#specifying-slide-background-images-with-backgroundimage) * [Table Metadata](#table-metadata) * [Shrinking Tables With `compactTables`](#shrinking-tables-with-compacttables) * [Adjusting Table Heading Font Size With `tableHeadingSize`](#adjusting-table-heading-font-size-with-tableheadingsize) @@ -207,6 +208,7 @@ As you can see in the [change log](#change-log), md2pptx is frequently updated - * [`NumbersHeight`](#numbersheight) * [`TableMargin`](#tablemargin) * [`Transition`](#transition) + * [`BackgroundImage`](#backgroundimage) * [Modifying The Slide Template](#modifying-the-slide-template) * [Basics](#basics) * [Slide Template Sequence](#slide-template-sequence) @@ -341,6 +343,7 @@ To quote from the python-pptx license statement: |Level|Date|What| |:-|-:|:-| +|4.2|27 December 2023|Added background image support using [`backgroundImage`](#specifying-slide-background-images-with-backgroundimage).| |4.1.2|11 July 2023|Fixed two bugs: Using `` & `` causes a crash. Also [Card Slides](#card-slides) cause a crash.| |4.1.1|10 July 2023|Added [`numbersFontSize`](#specifying-slide-number-font-size-with-numbersfontsize) and [`footerFontSize`](#specifying-footer-font-size-with-footerfontsize).| |4.1|28 April 2023|Added [`funnelLabelsPosition`](#funnel-labels-position-funnellabelsposition) and [`funnelWidest`](#funnel-orientation-funnelwidest). Added [`cardTitleBackground`](#card-title-background-colours-cardtitlebackground). Added quotation mark related [HTML entity references](#html-entity-references).| @@ -2029,6 +2032,20 @@ The default is `no`. **Note:** If you don't have a Processing Summary slide - perhaps because the slide master you used doesn't have a slide - the first slide would still be removed if you specified `removeFirstSlide: yes`. This is probably not what you want to have happen. + +#### Specifying Slide Background Images With `backgroundImage` + + +You can specify a background image for slides with `backgroundImage`. For example: + + backgroundImage: myFavouriteBackground.png + +The default is no background image (other than from the slide master), represented by an empty string. + +You can override this value with [Dynamic Metadata](#backgroundimage-dynamic). + +**Note:** python-pptx doesn't know how to truly manipulate a slide background *image*. Accordingly, md2pptx places the graphic you specify behind all the other objects it creates on the slide (but in front of any real background). It covers the slide area entirely, scaling the graphic to fit. It's a good idea to make your background image be the same size, or have the same aspect ratio, as the slide. + #### Table Metadata ##### Shrinking Tables With `compactTables` @@ -2045,7 +2062,6 @@ For example, to remove the margins and reduce the font size to 16pt code You can override this value with [Dynamic Metadata](#compacttables-dynamic). - ##### Adjusting Table Heading Font Size With `tableHeadingSize` @@ -3264,6 +3280,13 @@ You can override the presentation [Transition](#slide-transitions-transition) sp It's important to note that doing this will affect the transition **into** this slide. Likewise all subsequent slides - until overridden again or reverted. + +#### `BackgroundImage` + +You can override the presentation [BackgroundImage](#specifying-slide-background-images-with-backgroundimage) specification on a slide-by-slide basis: + + + ## Modifying The Slide Template diff --git a/docs/user-guide.mdp b/docs/user-guide.mdp index d2a39be..81042e2 100644 --- a/docs/user-guide.mdp +++ b/docs/user-guide.mdp @@ -154,6 +154,7 @@ To quote from the python-pptx license statement: =colalign l r l =csv Level,Date,What +4.2,27 December 2023,Added background image support using [`backgroundImage`](#specifying-slide-background-images-with-backgroundimage). 4.1.2,11 July 2023,Fixed two bugs: Using `` & `` causes a crash. Also [Card Slides](#card-slides) cause a crash. 4.1.1,10 July 2023,Added [`numbersFontSize`](#specifying-slide-number-font-size-with-numbersfontsize) and [`footerFontSize`](#specifying-footer-font-size-with-footerfontsize). 4.1,28 April 2023,Added [`funnelLabelsPosition`](#funnel-labels-position-funnellabelsposition) and [`funnelWidest`](#funnel-orientation-funnelwidest). Added [`cardTitleBackground`](#card-title-background-colours-cardtitlebackground). Added quotation mark related [HTML entity references](#html-entity-references). @@ -2040,6 +2041,24 @@ The default is `no`. If you don't have a Processing Summary slide - perhaps because the slide master you used doesn't have a slide - the first slide would still be removed if you specified `removeFirstSlide: yes`. \ This is probably not what you want to have happen. + +#### Specifying Slide Background Images With `backgroundImage` + + +You can specify a background image for slides with `backgroundImage`. For example: + + backgroundImage: myFavouriteBackground.png + +The default is no background image (other than from the slide master), represented by an empty string. + +You can override this value with [Dynamic Metadata](#backgroundimage-dynamic). + +**Note:** \ +python-pptx doesn't know how to truly manipulate a slide background *image*. \ +Accordingly, md2pptx places the graphic you specify behind all the other objects it creates on the slide (but in front of any real background). \ +It covers the slide area entirely, scaling the graphic to fit. \ +It's a good idea to make your background image be the same size, or have the same aspect ratio, as the slide. + #### Table Metadata ##### Shrinking Tables With `compactTables` @@ -2056,7 +2075,6 @@ For example, to remove the margins and reduce the font size to 16pt code You can override this value with [Dynamic Metadata](#compacttables-dynamic). - ##### Adjusting Table Heading Font Size With `tableHeadingSize` @@ -3377,6 +3395,13 @@ You can override the presentation [Transition](#slide-transitions-transition) sp It's important to note that doing this will affect the transition **into** this slide. Likewise all subsequent slides - until overridden again or reverted. + +#### `BackgroundImage` + +You can override the presentation [BackgroundImage](#specifying-slide-background-images-with-backgroundimage) specification on a slide-by-slide basis: + + + ## Modifying The Slide Template