tests/testthat/test-scale.R

context("Scale")
library("grid")

# Tests requiring manual oversight are registered as such. They
# specify files that should be opened with multiple browsers to make
# sure the SVG appearance is consistent. Use open_manual_tests() after
# running testthat to open them in your default browser.

test_that("text has correct dimensions", {
  register_manual_test("test-scale-text.html")

  ttf <- fontquiver::font("Liberation", "Sans", "Regular")$ttf
  metrics <- gdtools::str_metrics("foobar", fontfile = ttf)
  w <- metrics[["width"]]
  h <- metrics[["ascent"]]

  svglite("test-scale-text.svg", width = w / 72, height = h / 72,
    user_fonts = fontquiver::font_families("Liberation"))
  on.exit(dev.off())

  grid.newpage()
  grid.rect(0, 1, width = unit(w, "bigpts"), height = unit(h, "bigpts"),
    hjust = 0, vjust = 1, gp = gpar(col = "red", lwd = 1))
  grid.text("foobar", 0, 1, hjust = 0, vjust = 1, gp = gpar(fontsize = 12))
  pushViewport(viewport())
})

test_that("lwd has correct dimensions", {
  x <- xmlSVG({
    plot.new()
    segments(0, 1, 0, 0, lwd = 96 / 72)
  })
  line <- xml_find_all(x, "//line")
  expect_equal(xml_attr(line, "style"), "stroke-width: 1.00;")
})

Try the svglite package in your browser

Any scripts or data that you put into this service are public.

svglite documentation built on Sept. 12, 2017, 1:04 a.m.