PPTX.jl icon indicating copy to clipboard operation
PPTX.jl copied to clipboard

Referring to slide layouts by name

Open jaakkor2 opened this issue 1 year ago • 1 comments

At the moment (v0.6) PPTX.Slide argument for layout is defined like layout::Int=1 ie as an integer.

For convenience, would be nice to be able to refer to the layout by name as well.

Code sketch to extract name to number map

    layoutnamemap = Dict{String,Int}()
    layouts = readdir(raw"ppt/slideLayouts", join=true)
    for layout in layouts
        m = match(r"slideLayout(?<id>\d*).xml$", layout)
        isnothing(m) && continue
        id = parse(Int, m[:id])
        doc = readxml(layout)
        r = root(doc)
        n = findfirst("//p:cSld", r)
        push!(layoutnamemap, n["name"] => id)
    end

jaakkor2 avatar Jul 27 '23 10:07 jaakkor2

I agree this would be more intuitive to users.

Quick brainstorm

  • Make the Slide.layout field a Union{Integer, String}.
  • Upon writing the PPTX, create this layoutnamemap.
  • Pass this layoutnamemap through write_slides! to the make_slide_relationships function
  • create something like: id = get_slide_layout_id(s::Slide, layoutnamemap)

I wonder if we should make this layoutnamemap a property of the Presentation, since it's kinda part of the global state of the presentation.

matthijscox-asml avatar Aug 15 '23 07:08 matthijscox-asml