You signed in with another tab or window. Reload
8000
to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PNG forest plots are clipped on Linux when saved with default sizing #115
This is unrelated to meta 9.0-0, just something I noticed earlier and wanted to report.
When saving the same forest plot as PDF and PNG using forest(..., filename = ...) with default sizing, the PNG is clipped on Linux while the PDF fits. Windows and macOS outputs look fine.
This happens because forest_dims_internal() measures the plot on pdf(file = NULL) using Helvetica AFM font metrics (and forest_dims() itself creates a temporary .pdf), regardless of the target format. When ragg is installed, PNG output uses ragg::agg_png(). On Windows and macOS, ragg uses Arial / Helvetica (close to PDF's Helvetica AFM), whereas on Linux it resolves sans to the wider DejaVu Sans font, making the measured width too narrow. Because each device resolves fonts differently, setting fontfamily alone does not fix this; measurement needs to run on the actual output device.
Would it be possible to let forest_dims() accept a measurement device (with the same font settings as the plot), and have forest(..., filename = ...) measure on the selected output device when autosizing?
grid::grid.grabExpr() already accepts a device function and notes in its documentation that the default PDF device is unsuitable for custom fonts:
Devices like pdf(file = NULL) and ragg::agg_record() allow measuring without writing a file, and a temporary file works for devices without an in-memory recorder.
I'd be happy to help implement this in a PR if you think it's useful.
Activity
guido-s commentedon Dec 3, 2026
@NourEdinDarwish Thank you for pointing this out. I would definitely be interested in fixing this issue, so a PR would be very welcome.