Skip to content

Commit

Permalink
fix internal bug (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
leeper committed Jun 8, 2016
1 parent 8732d9c commit f8835ec
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 39 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: tabulizer
Type: Package
Title: Bindings for Tabula PDF Table Extractor Library
Version: 0.1.19
Date: 2016-06-04
Version: 0.1.20
Date: 2016-06-08
Authors@R: c(person("Thomas J.", "Leeper", role = c("aut", "cre"),
email = "thosjleeper@gmail.com"),
person("David", "Gohel", role = "ctb",
Expand Down
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# CHANGES TO tabulizer 0.1.20 #

* Fixed bug in internal function `try_area_full()` introduced by changes in #8.

# CHANGES TO tabulizer 0.1.19 #

* Further expand the `locate_areas()` interface to use a Shiny gadget when working within RStudio, or otherwise rely on the full functionality interface (based on graphics device events) or reduced functionality interface (relying on `locator()`). (#8)
Expand Down
73 changes: 36 additions & 37 deletions R/try_area_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,28 +94,28 @@ try_area_reduced <- function(file, dims, area = NULL, warn = FALSE) {
}

try_area_full <- function(file, dims, area = NULL) {
clicked <- FALSE
lastkey <- NA_character_
if (!length(area)) {
startx <- NULL
starty <- NULL
endx <- NULL
endy <- NULL
} else {
showArea <- function() {
# convert from: top,left,bottom,right
startx <<- area[2]
starty <<- dims[2] - area[1]
endx <<- area[4]
endy <<- dims[2] - area[3]
drawRectangle()
}
showArea()

deviceUnits <- "nfc"
if (Sys.info()["sysname"] == "Darwin") {
grDevices::X11(type = "xlib")
}
if (grDevices::dev.capabilities()[["rasterImage"]] != "yes") {
stop("Graphics device does not support rasterImage() plotting")
}
thispng <- readPNG(file, native = TRUE)

devset <- function() {
if (grDevices::dev.cur() != eventEnv$which) grDevices::dev.set(eventEnv$which)
}
drawPage <- function() {
graphics::plot(c(0, dims[1]), c(0, dims[2]), type = "n", xlab = "", ylab = "", asp = 1)
graphics::rasterImage(thispng, 0, 0, dims[1], dims[2])
}
drawRectangle <- function() {
if (!is.null(endx)) {
graphics::rect(startx, starty, endx, endy, col = grDevices::rgb(1,0,0,.2) )
}
}

mousedown <- function(buttons, x, y) {
devset()
Expand All @@ -132,7 +132,6 @@ try_area_full <- function(file, dims, area = NULL) {
}
NULL
}

dragmousemove <- function(buttons, x, y) {
devset()
if (clicked) {
Expand All @@ -143,37 +142,37 @@ try_area_full <- function(file, dims, area = NULL) {
}
NULL
}

keydown <- function(key) {
devset()
eventEnv$onMouseMove <- NULL
lastkey <<- key
TRUE
}

deviceUnits <- "nfc"
if (Sys.info()["sysname"] == "Darwin") {
grDevices::X11(type = "xlib")
}
if (grDevices::dev.capabilities()[["rasterImage"]] != "yes") {
stop("Graphics device does not support rasterImage() plotting")
}
thispng <- readPNG(file, native = TRUE)
drawPage <- function() {
graphics::plot(c(0, dims[1]), c(0, dims[2]), type = "n", xlab = "", ylab = "", asp = 1)
graphics::rasterImage(thispng, 0, 0, dims[1], dims[2])
}
drawRectangle <- function() {
if (!is.null(endx)) {
graphics::rect(startx, starty, endx, endy, col = grDevices::rgb(1,0,0,.2) )
}
}

pre_par <- graphics::par(mar=c(0,0,0,0), xaxs = "i", yaxs = "i", bty = "n")
on.exit(graphics::par(pre_par), add = TRUE)
drawPage()
on.exit(grDevices::dev.off(), add = TRUE)

clicked <- FALSE
lastkey <- NA_character_
if (!length(area)) {
startx <- NULL
starty <- NULL
endx <- NULL
endy <- NULL
} else {
showArea <- function() {
# convert from: top,left,bottom,right
startx <<- area[2]
starty <<- dims[2] - area[1]
endx <<- area[4]
endy <<- dims[2] - area[3]
drawRectangle()
}
showArea()
}

p <- "Click and drag to select a table area. Press <Right> for next page or <Q> to quit."
grDevices::setGraphicsEventHandlers(prompt = p,
onMouseDown = mousedown,
Expand Down

0 comments on commit f8835ec

Please sign in to comment.