Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Artifacts.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[pptx_data]
git-tree-sha1 = "4609b3887be7359885a405f7c14a53c56776d366"
[[pptx_data.download]]
url = "https://github.com/ig-or/PPTX.jl/releases/download/v0.7.0/pptx_data.tar.gz"
sha256 = "0e159a2792e49a74ff14c742b056098122f5c445ecb1191cc2be461727428a6a"




3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name = "PPTX"
uuid = "14a86994-10a4-4a7d-b9ad-ef6f3b1fac6a"
authors = ["Xander de Vries", "Matthijs Cox"]
version = "0.7.0"
version = "0.7.1"

[deps]
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
DefaultApplication = "3f0dd361-4fe0-5fc6-8523-80b14ec94d85"
EzXML = "8f5d6c58-4d21-5cfd-889c-e3ad7ee6a615"
Expand Down
5 changes: 3 additions & 2 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ You can build a presentation inside Julia:

```jldoctest
using PPTX, DataFrames
using Artifacts

# Lets make a presentation
# note: this already adds a first slide with the title
Expand All @@ -31,14 +32,14 @@ push!(s2, text2)
push!(pres, s2)

# Now lets add a picture and some text
cauli_pic = Picture(joinpath(PPTX.ASSETS_DIR,"cauliflower.jpg"))
cauli_pic = Picture(joinpath(artifact"pptx_data", "assets","cauliflower.jpg"))
text = TextBox(content="Look its a vegetable!")
s3 = Slide()
push!(s3, cauli_pic)
push!(s3, text)

# move picture 100 mm down and 100 mm right
julia_logo = Picture(joinpath(PPTX.ASSETS_DIR,"julia_logo.png"), offset_x=100, offset_y=100)
julia_logo = Picture(joinpath(artifact"pptx_data", "assets","julia_logo.png"), offset_x=100, offset_y=100)
push!(s3, julia_logo)
push!(pres, s3)

Expand Down
6 changes: 4 additions & 2 deletions src/Picture.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ Internally the sizes are converted EMUs.
# Examples
```julia
julia> using PPTX
julia> using Artifacts

julia> img = Picture(joinpath(PPTX.ASSETS_DIR, "cauliflower.jpg"))
julia> img = Picture(joinpath(artifact"pptx_data", "assets", "cauliflower.jpg"))
Picture
source is "./cauliflower.jpg"
offset_x is 0 EMUs
Expand All @@ -28,8 +29,9 @@ Picture
Optionally, you can set the `size_x` and `size_y` manually for filetypes not supported by FileIO, such as SVG.
```julia
julia> using PPTX
julia> using Artifacts

julia> img = Picture(joinpath(PPTX.ASSETS_DIR, "julia_logo.svg"); size_x=40, size_y=30)
julia> img = Picture(joinpath(artifact"pptx_data", "assets", "julia_logo.svg"); size_x=40, size_y=30)
Picture
source is "./julia_logo.svg"
offset_x is 0 EMUs
Expand Down
1 change: 0 additions & 1 deletion src/constants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const _EMUS_PER_MM = 36000
const _EMUS_PER_PT = 12700

const TEMPLATE_DIR = abspath(joinpath(@__DIR__, "..", "templates"))
const ASSETS_DIR = abspath(joinpath(@__DIR__, "..", "assets"))
const TESTDATA_DIR = abspath(joinpath(@__DIR__, "..", "test/testdata"))

# we use layoutSlide1 for the first title slide, and layoutSlide2 for all other slides
Expand Down
3 changes: 2 additions & 1 deletion src/write.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import DefaultApplication
using Artifacts

function write_presentation!(w::ZipWriter, p::Presentation)
xml = make_presentation(p)
Expand Down Expand Up @@ -137,7 +138,7 @@ function Base.write(
p::Presentation;
overwrite::Bool=false,
open_ppt::Bool=true,
template_path::String=joinpath(TEMPLATE_DIR, "no-slides.pptx"),
template_path::String=joinpath(artifact"pptx_data", "templates", "no-slides.pptx"),
)

template_path = abspath(template_path)
Expand Down
10 changes: 10 additions & 0 deletions test/testArtifacts.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using PPTX
using Test
using Artifacts

dark_template_name = "no-slides-dark.pptx"
dark_template_path = joinpath(artifact"pptx_data", "templates", dark_template_name)
isfile(dark_template_path)
pres = Presentation(;title="My Presentation")
s = Slide()
push!(pres, s)
9 changes: 5 additions & 4 deletions test/testConstructors.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using PPTX
using Test
using Artifacts

@testset "constructors" begin
@testset "TextBox" begin
Expand All @@ -22,7 +23,7 @@ using Test
@test_throws ArgumentError pic = Picture("path")
fnames = ["julia_logo.png", "julia_logo.svg", "julia_logo.emf", "julia_dots.wmf"]
for fname in fnames
logo_path = joinpath(PPTX.ASSETS_DIR, fname)
logo_path = joinpath(artifact"pptx_data", "assets", fname)
pic = Picture(logo_path)
@test pic.offset_x == 0
width = 150
Expand All @@ -47,7 +48,7 @@ using Test
end
end
@testset "Picture - custom aspect ratio" begin
logo_path = joinpath(PPTX.ASSETS_DIR,"julia_logo.svg")
logo_path = joinpath(artifact"pptx_data", "assets","julia_logo.svg")
pic = Picture(logo_path; size_x=40, size_y=30)
@test pic.size_x == 1440000
@test pic.size_y == 1080000
Expand All @@ -64,14 +65,14 @@ using Test
@testset "first slide" begin
p = Presentation()
@test rid(p.slides[1]) == 6
picture_path = joinpath(PPTX.ASSETS_DIR, "cauliflower.jpg")
picture_path = joinpath(artifact"pptx_data", "assets", "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
end
@testset "Slide" begin
slide = Slide()
picture_path = joinpath(PPTX.ASSETS_DIR, "cauliflower.jpg")
picture_path = joinpath(artifact"pptx_data", "assets", "cauliflower.jpg")
push!(slide, Picture(picture_path))
end
end
Expand Down
3 changes: 2 additions & 1 deletion test/testPresentationState.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Test
using PPTX
using Artifacts

@testset "Presentation Size" begin
template_folder = abspath(joinpath(PPTX.TEMPLATE_DIR,"no-slides"))
template_folder = abspath(joinpath(artifact"pptx_data", "templates","no-slides"))
p = Presentation()
ppt_dir = joinpath(template_folder, "ppt")
PPTX.update_presentation_state!(p, ppt_dir)
Expand Down
3 changes: 2 additions & 1 deletion test/testSlideXML.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ using Test
using PPTX
using EzXML
using ZipArchives: ZipBufferReader, zip_readentry
using Artifacts

@testset "Slide XML structure" begin
s = Slide()
Expand Down Expand Up @@ -34,7 +35,7 @@ end
end

@testset "update title in XML" begin
template = ZipBufferReader(read(joinpath(PPTX.TEMPLATE_DIR,"no-slides.pptx")))
template = ZipBufferReader(read(joinpath(artifact"pptx_data", "templates","no-slides.pptx")))

@testset "slideLayout1.xml" begin
slide = Slide(;layout=1)
Expand Down
5 changes: 3 additions & 2 deletions test/testTables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ using Test
using DataFrames
using EzXML
using ZipArchives: ZipBufferReader, zip_readentry
using Artifacts

@testset "PPTX Tables from a DataFrame" begin
df = DataFrame(a = [1,2], b = [3,4], c = [5,6])
Expand Down Expand Up @@ -51,11 +52,11 @@ using ZipArchives: ZipBufferReader, zip_readentry
end

@testset "check empty table style list" begin
tableStyles_path = abspath(joinpath(PPTX.TEMPLATE_DIR, "tableStyles.xml"))
tableStyles_path = abspath(joinpath(artifact"pptx_data", "templates", "tableStyles.xml"))
table_style_doc = EzXML.parsexml(read(tableStyles_path))
@test !PPTX.has_empty_table_list(table_style_doc)

no_slides_template = ZipBufferReader(read(joinpath(PPTX.TEMPLATE_DIR, "no-slides.pptx")))
no_slides_template = ZipBufferReader(read(joinpath(artifact"pptx_data", "templates", "no-slides.pptx")))
table_style_doc = EzXML.parsexml(zip_readentry(no_slides_template, "ppt/tableStyles.xml"))
@test PPTX.has_empty_table_list(table_style_doc)
end
15 changes: 9 additions & 6 deletions test/testWriting.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using ZipArchives:
ZipBufferReader, zip_readentry, zip_names, zip_append_archive, zip_newfile

using Artifacts

function bincompare(path::String, ref::String)
bin1 = read(path)
Expand All @@ -25,15 +27,15 @@ end

@testset "writing" begin
@testset "push same picture" begin
picture_path = joinpath(PPTX.ASSETS_DIR, "cauliflower.jpg")
picture_path = joinpath(artifact"pptx_data", "assets", "cauliflower.jpg")
p = Presentation([Slide([Picture(picture_path)]), Slide([Picture(picture_path)])])
@test write_and_remove("test.pptx", p)
end

@testset "pushing same picture twice" begin
pres = Presentation()
s1 = Slide()
julia_logo = Picture(joinpath(PPTX.ASSETS_DIR,"julia_logo.png"), top = 110, left = 110)
julia_logo = Picture(joinpath(artifact"pptx_data", "assets","julia_logo.png"), top = 110, left = 110)
push!(s1, julia_logo)
push!(pres, s1)
s2 = Slide()
Expand All @@ -48,7 +50,7 @@ end
# TODO: what if the .pptx template already has slides?
@testset "custom template" begin
dark_template_name = "no-slides-dark.pptx"
dark_template_path = joinpath(PPTX.TEMPLATE_DIR, dark_template_name)
dark_template_path = joinpath(artifact"pptx_data", "templates", dark_template_name)
pres = Presentation(;title="My Presentation")
s = Slide()
push!(pres, s)
Expand Down Expand Up @@ -93,18 +95,19 @@ end
# test for issue https://github.com/ASML-Labs/PPTX.jl/issues/20
mktempdir() do tmpdir
template_name = "no-slides.pptx"
original_template_path = joinpath(PPTX.TEMPLATE_DIR, template_name)
original_template_path = joinpath(artifact"pptx_data", "templates", template_name)
edited_template_path = joinpath(tmpdir, template_name)
write(edited_template_path, read(original_template_path))
chmod(edited_template_path, 0o0100664)
zip_append_archive(edited_template_path) do w
# add an existing media directory
zip_newfile(w, "ppt/media/foo.png")
write(w, read(joinpath(PPTX.ASSETS_DIR,"julia_logo.png")))
write(w, read(joinpath(artifact"pptx_data", "assets","julia_logo.png")))
end

pres = Presentation(;title="My Presentation")
s1 = Slide()
julia_logo = Picture(joinpath(PPTX.ASSETS_DIR,"julia_logo.png"), top = 110, left = 110)
julia_logo = Picture(joinpath(artifact"pptx_data", "assets","julia_logo.png"), top = 110, left = 110)
push!(s1, julia_logo)
push!(pres, s1)

Expand Down