Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ev-render-context.c
Go to the documentation of this file.
1 /* this file is part of evince, a gnome document viewer
2  *
3  * Copyright (C) 2005 Jonathan Blandford <jrb@gnome.org>
4  *
5  * Evince is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * Evince is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19 
20 #include <config.h>
21 #include "ev-render-context.h"
22 
23 static void ev_render_context_init (EvRenderContext *rc);
25 
26 G_DEFINE_TYPE (EvRenderContext, ev_render_context, G_TYPE_OBJECT);
27 
28 #define FLIP_DIMENSIONS(rc) ((rc)->rotation == 90 || (rc)->rotation == 270)
29 
30 static void ev_render_context_init (EvRenderContext *rc) { /* Do Nothing */ }
31 
32 static void
33 ev_render_context_dispose (GObject *object)
34 {
35  EvRenderContext *rc;
36 
37  rc = (EvRenderContext *) object;
38 
39  if (rc->page) {
40  g_object_unref (rc->page);
41  rc->page = NULL;
42  }
43 
44  (* G_OBJECT_CLASS (ev_render_context_parent_class)->dispose) (object);
45 }
46 
47 static void
49 {
50  GObjectClass *oclass;
51 
52  oclass = G_OBJECT_CLASS (class);
53 
54  oclass->dispose = ev_render_context_dispose;
55 }
56 
59  gint rotation,
60  gdouble scale)
61 {
62  EvRenderContext *rc;
63 
64  rc = (EvRenderContext *) g_object_new (EV_TYPE_RENDER_CONTEXT, NULL);
65 
66  rc->page = page ? g_object_ref (page) : NULL;
67  rc->rotation = rotation;
68  rc->scale = scale;
69  rc->target_width = -1;
70  rc->target_height = -1;
71 
72  return rc;
73 }
74 
75 void
77  EvPage *page)
78 {
79  g_return_if_fail (rc != NULL);
80  g_return_if_fail (EV_IS_PAGE (page));
81 
82  if (rc->page)
83  g_object_unref (rc->page);
84  rc->page = g_object_ref (page);
85 }
86 
87 void
89  int rotation)
90 {
91  g_return_if_fail (rc != NULL);
92 
93  rc->rotation = rotation;
94 }
95 
96 void
98  gdouble scale)
99 {
100  g_return_if_fail (rc != NULL);
101 
102  rc->scale = scale;
103 }
104 
105 void
107  int target_width,
108  int target_height)
109 {
110  g_return_if_fail (rc != NULL);
111 
112  rc->target_width = target_width;
113  rc->target_height = target_height;
114 }
115 
116 void
118  double width_points,
119  double height_points,
120  int *scaled_width,
121  int *scaled_height)
122 {
123  g_return_if_fail (rc != NULL);
124 
125  if (scaled_width) {
126  if (rc->target_width >= 0) {
127  *scaled_width = FLIP_DIMENSIONS (rc) ? rc->target_height : rc->target_width;
128  } else {
129  *scaled_width = (int) (width_points * rc->scale + 0.5);
130  }
131  }
132 
133  if (scaled_height) {
134  if (rc->target_height >= 0) {
135  *scaled_height = FLIP_DIMENSIONS (rc) ? rc->target_width : rc->target_height;
136  } else {
137  *scaled_height = (int) (height_points * rc->scale + 0.5);
138  }
139  }
140 }
141 
142 void
144  double width_points,
145  double height_points,
146  int *transformed_width,
147  int *transformed_height)
148 {
149  int scaled_width, scaled_height;
150 
151  g_return_if_fail (rc != NULL);
152 
153  ev_render_context_compute_scaled_size (rc, width_points, height_points,
154  &scaled_width, &scaled_height);
155 
156  if (transformed_width)
157  *transformed_width = FLIP_DIMENSIONS (rc) ? scaled_height : scaled_width;
158 
159  if (transformed_height)
160  *transformed_height = FLIP_DIMENSIONS (rc) ? scaled_width : scaled_height;
161 }
162 
163 void
165  double width_points,
166  double height_points,
167  double *scale_x,
168  double *scale_y)
169 {
170  int scaled_width, scaled_height;
171 
172  g_return_if_fail (rc != NULL);
173 
174  ev_render_context_compute_scaled_size (rc, width_points, height_points,
175  &scaled_width, &scaled_height);
176 
177  if (scale_x)
178  *scale_x = scaled_width / width_points;
179 
180  if (scale_y)
181  *scale_y = scaled_height / height_points;
182 }