diff --git a/backend/ps/ev-spectre.c b/backend/ps/ev-spectre.c
index 265fed3..96aaccb 100644
--- a/backend/ps/ev-spectre.c
+++ b/backend/ps/ev-spectre.c
@@ -294,20 +294,32 @@ ps_document_render (EvDocument *document,
gint rotation;
cairo_surface_t *surface;
static const cairo_user_data_key_t key;
+ double x_scale, y_scale, scale;
ps_page = (SpectrePage *)rc->page->backend_page;
spectre_page_get_size (ps_page, &width_points, &height_points);
- ev_render_context_compute_scaled_size (rc, width_points, height_points,
- &width, &height);
-
rotation = (rc->rotation + get_page_rotation (ps_page)) % 360;
+ if (rc->target_width >= 0 && rc->target_height >= 0) {
+ if (rotation == 90 || rotation == 270) {
+ x_scale = (double) rc->target_height / width_points;
+ y_scale = (double) rc->target_width / height_points;
+ } else {
+ x_scale = (double) rc->target_width / width_points;
+ y_scale = (double) rc->target_height / height_points;
+ }
+ scale = MIN (x_scale, y_scale);
+ } else {
+ scale = rc->scale;
+ }
+
+ width = (int) (width_points * scale + 0.5);
+ height = (int) (height_points * scale + 0.5);
+
src = spectre_render_context_new ();
- spectre_render_context_set_scale (src,
- (gdouble)width / width_points,
- (gdouble)height / height_points);
+ spectre_render_context_set_scale (src, scale, scale);
spectre_render_context_set_rotation (src, rotation);
spectre_page_render (ps_page, src, &data, &stride);
spectre_render_context_free (src);