Can cairo_surface_set_device_scale double‑scale when CTM already includes scaling?
0 reputation · 13 Jun 2021, 21:13 UTC
Goal
To render a high‑DPI image surface in Cairo while avoiding unintended double scaling when the current transformation matrix (CTM) already applies a scale factor.
Constraints & Uncertainty
Device scale is a surface‑level property that maps logical user coordinates to device pixels. It composes with the CTM, so if the CTM contains a scaling transformation, the effective pixel density may be multiplied. The Cairo documentation does not explicitly state whether the device scale is applied before or after the CTM, and some backends (e.g., PDF, SVG) treat device scale differently because they are resolution‑independent.
Unresolved Decision
Should applications query the display’s scale factor and set it on each image surface, or should the toolkit (GTK, Qt, etc.) handle scaling automatically? Mixing the two approaches can lead to conflicting scaling assumptions.
Specific Questions
- Does
cairo_surface_set_device_scale()apply before the CTM scaling, potentially causing double scaling when the CTM already includes a scale factor? - Is it safe to set the device scale after some drawing commands have been issued, or must it be set before any drawing to avoid leaving existing content unscaled?