diff --git a/DESCRIPTION b/DESCRIPTION index b0eda1bb..1a3b6188 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: officer Type: Package Title: Manipulation of Microsoft Word and PowerPoint Documents -Version: 0.4.5.013 +Version: 0.4.5.014 Authors@R: c( person("David", "Gohel", role = c("aut", "cre"), email = "david.gohel@ardata.fr"), diff --git a/NEWS.md b/NEWS.md index 5d55e603..ff443c4c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -15,6 +15,8 @@ associated with a Word character style. a match in the document. - add function `docx_current_block_xml()` to let developpers access the xml content where the cursor is. +- `ph_with.xml_document` now manages images paths in slide and +treats them in the relevant documents. ## Issues diff --git a/R/ppt_classes.R b/R/ppt_classes.R index 30b45747..36095e63 100644 --- a/R/ppt_classes.R +++ b/R/ppt_classes.R @@ -231,6 +231,13 @@ slide <- R6Class( xml_attr( cnvpr[[i]], "id") <- i self }, + reference_img = function(src, dir_name){ + src <- unique( src ) + private$rels_doc$add_img(src, root_target = "../media") + dir.create(dir_name, recursive = TRUE, showWarnings = FALSE) + file.copy(from = src, to = file.path(dir_name, basename(src))) + self + }, reference_slide = function(slide_file){ diff --git a/R/ppt_ph_with_methods.R b/R/ppt_ph_with_methods.R index f60735d8..bf94b63b 100644 --- a/R/ppt_ph_with_methods.R +++ b/R/ppt_ph_with_methods.R @@ -489,7 +489,7 @@ ph_with.empty_content <- function( x, value, location, ... ){ -xml_to_slide <- function(slide, location, value){ +xml_to_slide <- function(slide, location, value, package_dir){ node <- xml_find_first( value, as_xpath_content_sel("//") ) if(xml_name(node) == "grpSp"){ node_sppr <- xml_child(node, "p:grpSpPr") @@ -558,9 +558,10 @@ ph_with.xml_document <- function( x, value, location, ... ){ location <- fortify_location(location, doc = x) - xml_to_slide(slide, location, value) + xml_to_slide(slide, location, value, x$package_dir) xml_add_child(xml_find_first(slide$get(), "//p:spTree"), value) + process_images(slide, slide$relationship(), x$package_dir, media_dir = "ppt/media", media_rel_dir = "../media") slide$fortify_id() x