diff --git a/src/Slide.jl b/src/Slide.jl index 917480e..28b6be1 100644 --- a/src/Slide.jl +++ b/src/Slide.jl @@ -73,10 +73,11 @@ function Slide(; end function new_rid(slide::Slide) - if isempty(shapes(slide)) + # When there is no rid shapes the new rid should be 2 + if isempty(slide.shapes) return 2 - else - return maximum(rid.(shapes(slide))) + 1 + else # default 2, or it should be the at least 1 bigger than the shape with the higest rid + return max(2, maximum(rid.(shapes(slide))) + 1) end end diff --git a/test/testConstructors.jl b/test/testConstructors.jl index fde5184..12eb4db 100644 --- a/test/testConstructors.jl +++ b/test/testConstructors.jl @@ -67,7 +67,7 @@ using Test picture_path = joinpath(PPTX.ASSETS_DIR, "cauliflower.jpg") p = Presentation([Slide([TextBox(),Picture(picture_path)])]) @test rid(p.slides[1].shapes[1]) == 0 - @test rid(p.slides[1].shapes[2]) == 1 + @test rid(p.slides[1].shapes[2]) == 2 end @testset "Slide" begin slide = Slide() diff --git a/test/testSlideXML.jl b/test/testSlideXML.jl index 578a171..e4e2481 100644 --- a/test/testSlideXML.jl +++ b/test/testSlideXML.jl @@ -33,6 +33,16 @@ end @test layout_relationship["Target"] == "../slideLayouts/slideLayout2.xml" end +@testset "rId always bigger than 1 updating on push!" begin + s = Slide() + push!(s, TextBox("Some text")) + @test PPTX.rid(s.shapes[1]) == 0 # textboxes have no rid, so set to 0 + push!(s, Picture(joinpath(PPTX.ASSETS_DIR,"julia_logo.png"))) + @test PPTX.rid(s.shapes[2]) == 2 + push!(s, Picture(joinpath(PPTX.ASSETS_DIR,"cauliflower.jpg"))) + @test PPTX.rid(s.shapes[3]) == 3 +end + @testset "update title in XML" begin template = ZipBufferReader(read(joinpath(PPTX.TEMPLATE_DIR,"no-slides.pptx")))