Skip to content

Commit 3995cc7

Browse files
brandonlukasclaude
andcommitted
Fix annotation rasterization shrinking at high raster_quality
When raster_quality > 1, the temp raster device grew in pixels but kept the default res=72, making its physical size (inches) grow proportionally. AnnotationFunction::draw() pushes a viewport with absolute units (e.g. unit(5, "mm")), which then only filled 1/raster_quality of the enlarged device, causing the annotation to appear vertically shrunken. Fix by scaling res with raster_quality so the device's physical size stays constant regardless of quality level. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent fde96f7 commit 3995cc7

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

R/utils.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,14 @@ rasterize_in_viewport = function(draw_fun,
11981198
fileext = paste0(".", device_info[2]))
11991199
device_fun = getFromNamespace(raster_device, ns = device_info[1])
12001200

1201+
# Scale res with raster_quality so the device's physical size (in inches)
1202+
# matches the original viewport. Without this, annotation draw functions
1203+
# that push viewports with absolute units (e.g. unit(5, "mm")) would only
1204+
# fill a fraction of the enlarged temp device.
1205+
if(!"res" %in% names(raster_device_param)) {
1206+
raster_device_param$res = as.integer(72 * raster_quality)
1207+
}
1208+
12011209
oe = try(do.call(device_fun, c(list(filename = temp_image,
12021210
width = temp_image_width, height = temp_image_height), raster_device_param)))
12031211
if(inherits(oe, "try-error")) {

0 commit comments

Comments
 (0)