Closed andersone1 closed 2 months ago
maybe we just open the and the old in the browser
This may be helpful at some pt:
https://search.r-project.org/CRAN/refmans/gdiff/html/samePDF.html
Some promise to going with the gif approach - does work with multi page pdfs, although ordering is maybe not as useful
getOrigModify <- function(.file) {
svnInfo <- svnProjInfo()
.org_tmp_dir <- file.path(tempdir(), "reviewOrig")
if(fs::dir_exists(.org_tmp_dir)){
fs::dir_delete(.org_tmp_dir)
}
fs::dir_create(.org_tmp_dir)
.orig_tmp_file <-
review:::svnExport(.file = .file,
.revision = svnInfo$rev,
.output_dir =.org_tmp_dir,
.return_file = TRUE,
.quiet = TRUE)
list(
orig = .orig_tmp_file,
modify = .file
)
}
diffPDF <- function(.file) {
paths <- getOrigModify(.file)
img_list <- lapply(paths, magick::image_read)
## join the images together
img_joined <- magick::image_join(img_list)
## animate at 2 frames per second
img_animated <- magick::image_animate(img_joined, fps = 1)
## view animated image
img_animated
}
A couple areas for improvement:
diffPDF <- function(.file, .fps = 1) {
get_current_prev <-
getPreviousCurrent(.file,
.previous_revision = svnProjInfo()[["rev"]],
.current_revision = NULL)
paths <- list(previous = get_current_prev$.previous_revision_temp_file,
current = get_current_prev$.current_revision_temp_file)
img_list <- lapply(paths, magick::image_read)
if(length(img_list[["previous"]]) != length(img_list[["current"]])){
stop("must have same num pages")
}
img_list[["previous"]] <- magick::image_annotate(img_list[["previous"]], text = "OLD", gravity = "south", color = "red")
img_list[["current"]]<- magick::image_annotate(img_list[["current"]], text = "NEW", gravity = "south", color = "blue")
for(i in 1:length(img_list[["previous"]])){
this_page.i <-
image_join(
img_list[["previous"]][i],
img_list[["current"]][i]
)
img_list_all_pg <-
if(i == 1){
this_page.i
} else {
image_join(img_list_all_pg, this_page.i)
}
}
img_animated <- magick::image_animate(image = img_list_all_pg, fps = .fps)
img_animated
}
Determine the checked out revision & export that version of the file. We will compare that version to the locally modified pdf. (Either side by side or some visual)