gitbrent / PptxGenJS

Create PowerPoint presentations with a powerful, concise JavaScript API.
https://gitbrent.github.io/PptxGenJS/
MIT License
2.84k stars 625 forks source link

Fix placeholder text formatting issues #1247

Open mikemeerschaert opened 1 year ago

mikemeerschaert commented 1 year ago

This PR fixes several bugs related to placeholders on master slides that can be observed in this minimal demo repo

Valign and Margin in master slides

When creating a placeholder on a master slide, the valign and margin options are disregarded on the layout slide (in ppt, go to View > Slide Master and examine the items added to the layout slide, even if you specify valign and/or margin, the items on the layout slide will still have the default values.

This issue is somewhat related to #640. The fix for that issue fixed the generated slides that use the master and placeholders from within the library, but unfortunately, it didn't fix the issue on the master slides themselves.

This causes issues when you generate a pptx and then you want to add more slides to that file manually in PowerPoint using the generated master slides.

Bullets in master slides

This one is very specific and probably doesn't come up much, but it came up for me, and since I was already in the library fixing the above issue, I decided to also developed a fix for this one.

When you supply type: "bullet" and a custom characterCode to bulleted text in a placeholder, the placeholder still uses the default bullet code 2022. The easy workaround is to just not supply a type and it will default to bullet, but it is very confusing when you run into it.

e.g.

presentation.defineSlideMaster({
  title: "Bullet point demo",
  background: { color: "FFFFFF" },
  objects: [
    {
      placeholder: {
        options: {
          name: "Bullets",
          type: "body",
          bullet: {
            type: "bullet",
            characterCode: "25CF",
          },
          x: 0.5,
          y: 0.1,
          w: 9,
          h: 1,
          fontSize: 12,
          fontFace: "Arial",
        },
        text: "bullet 1\nbullet 2\nbullet 3",
      },
    },
  ],
})