@@ -409,14 +409,72 @@ default_resolution_in_pixels_per_inch <- function() {
409
409
}
410
410
}
411
411
412
+ # ' Determines the default device `type` for png, jpeg, and tiff
413
+ # '
414
+ # ' Only applicable when ragg is not in use
412
415
default_device_type <- function () {
416
+ switch (
417
+ system_os(),
418
+ macos = default_device_type_macos(),
419
+ windows = default_device_type_windows(),
420
+ linux = default_device_type_linux(),
421
+ # Treat `other` as linux
422
+ other = default_device_type_linux()
423
+ )
424
+ }
425
+
426
+ # ' On MacOS, we prefer Quartz
427
+ # '
428
+ # ' At one point we considered preferring Cairo, but `capabilities("cairo")`
429
+ # ' isn't a reliable signal of whether or not you have Cairo support, because
430
+ # ' surprisingly you also need xquartz installed as well, i.e. with `brew install
431
+ # ' --cask xquartz`. Confusingly you don't need that to use the `"quartz"` type.
432
+ # ' https://github.com/posit-dev/positron/issues/913
433
+ # ' https://github.com/posit-dev/positron/issues/2919
434
+ # '
435
+ # ' From https://cran.r-project.org/doc/manuals/r-release/R-admin.html#Installing-R-under-macOS-1:
436
+ # ' "Various parts of the build require XQuartz to be installed...This is also
437
+ # ' needed for some builds of the cairographics-based devices...such as
438
+ # ' png(type = "cairo") and svg()..."
439
+ # '
440
+ # ' To avoid this issue for Mac users, we don't even consider Cairo in our
441
+ # ' fallback path. It seems unlikely we'd ever get past `"quartz"` as the
442
+ # ' fallback anyways, it's probably installed on all Macs.
443
+ default_device_type_macos <- function () {
413
444
if (has_aqua()) {
414
445
" quartz"
415
- } else if (has_cairo()) {
446
+ } else if (has_x11()) {
447
+ " Xlib"
448
+ } else {
449
+ stop_no_plotting_capabilities()
450
+ }
451
+ }
452
+
453
+ # ' On Windows, we prefer Cairo
454
+ # '
455
+ # ' According to Thomas, this is much preferred over the default on Windows,
456
+ # ' which uses the Windows GDI. We don't even offer that as a fallback.
457
+ default_device_type_windows <- function () {
458
+ if (has_cairo()) {
459
+ " cairo"
460
+ } else {
461
+ stop_no_plotting_capabilities()
462
+ }
463
+ }
464
+
465
+ # ' On Linux, we prefer Cairo
466
+ # '
467
+ # ' This is the default there, and we have no reason to move away from it.
468
+ default_device_type_linux <- function () {
469
+ if (has_cairo()) {
416
470
" cairo"
417
471
} else if (has_x11()) {
418
472
" Xlib"
419
473
} else {
420
- stop( " This version of R wasn't built with plotting capabilities " )
474
+ stop_no_plotting_capabilities( )
421
475
}
422
476
}
477
+
478
+ stop_no_plotting_capabilities <- function () {
479
+ stop(" This version of R wasn't built with plotting capabilities" )
480
+ }
0 commit comments