- guint orientation;
- char buf[1024];
- //GdkColormap *colormap;
- GdkGC *fill;
- GdkColor white = { 0, 0xFFFF, 0xFFFF, 0xFFFF }; /* pixel, r, g, b */
- GdkColormap *colormap;
-
- LOG ("Setup the page");
-
-#ifdef HAVE_LOCALE_H
- char *savelocale;
-#endif
-
- if (gs->pstarget == NULL)
- return;
-
- /* Do we have to check if the actual geometry changed? */
-
- stop_interpreter(gs);
-
- orientation = ps_document_get_orientation(gs);
-
- if(compute_size(gs)) {
- gdk_flush();
-
- /* clear new pixmap (set to white) */
- fill = gdk_gc_new(gs->pstarget);
- if(fill) {
- colormap = gdk_drawable_get_colormap(gs->pstarget);
- gdk_color_alloc (colormap, &white);
- gdk_gc_set_foreground(fill, &white);
-
- if(gs->width > 0 && gs->height > 0) {
- if(gs->bpixmap) {
- gdk_drawable_unref(gs->bpixmap);
- gs->bpixmap = NULL;
- }
-
- LOG ("Create our internal pixmap");
- gs->bpixmap = gdk_pixmap_new(gs->pstarget, gs->width, gs->height, -1);
-
- gdk_draw_rectangle(gs->bpixmap, fill, TRUE,
- 0, 0, gs->width, gs->height);
- }
- else {
- gdk_draw_rectangle(gs->pstarget, fill, TRUE,
- 0, 0, gs->width, gs->height);
- }
- gdk_gc_unref(fill);
-
- gdk_flush();
- }
- }
-
-#ifdef HAVE_LOCALE_H
- /* gs needs floating point parameters with '.' as decimal point
- * while some (european) locales use ',' instead, so we set the
- * locale for this snprintf to "C".
- */
- savelocale = setlocale(LC_NUMERIC, "C");
-#endif
-
- g_snprintf(buf, 1024, "%ld %d %d %d %d %d %f %f %d %d %d %d",
- 0L,
- orientation * 90,
- gs->llx,
- gs->lly,
- gs->urx,
- gs->ury,
- gs->xdpi * gs->zoom_factor,
- gs->ydpi * gs->zoom_factor,
- gs->left_margin,
- gs->bottom_margin, gs->right_margin, gs->top_margin);
-
- LOG ("GS property %s", buf);
-
-#ifdef HAVE_LOCALE_H
- setlocale(LC_NUMERIC, savelocale);
-#endif
- gdk_property_change(gs->pstarget,
- gs_class->gs_atom,
- gs_class->string_atom,
- 8, GDK_PROP_MODE_REPLACE, buf, strlen(buf));
- gdk_flush();
+ GdkGC *fill;
+ GdkColor white = { 0, 0xFFFF, 0xFFFF, 0xFFFF }; /* pixel, r, g, b */
+ GdkColormap *colormap;
+ double width, height;
+ int pixmap_width, pixmap_height;
+
+ ev_document_get_page_size (EV_DOCUMENT (gs), page, &width, &height);
+
+ if (rotation == 90 || rotation == 270) {
+ pixmap_height = width * scale + 0.5;
+ pixmap_width = height * scale + 0.5;
+ } else {
+ pixmap_width = width * scale + 0.5;
+ pixmap_height = height * scale + 0.5;
+ }
+
+ if(gs->bpixmap) {
+ int w, h;
+
+ gdk_drawable_get_size (gs->bpixmap, &w, &h);
+
+ if (pixmap_width != w || h != pixmap_height) {
+ gdk_drawable_unref (gs->bpixmap);
+ gs->bpixmap = NULL;
+ stop_interpreter (gs);
+ }
+ }
+
+ if (!gs->bpixmap) {
+ LOG ("Create pixmap");
+
+ fill = gdk_gc_new (gs->pstarget);
+ colormap = gdk_drawable_get_colormap (gs->pstarget);
+ gdk_color_alloc (colormap, &white);
+ gdk_gc_set_foreground (fill, &white);
+ gs->bpixmap = gdk_pixmap_new (gs->pstarget, pixmap_width,
+ pixmap_height, -1);
+ gdk_draw_rectangle (gs->bpixmap, fill, TRUE,
+ 0, 0, pixmap_width, pixmap_height);
+ }
+}
+
+#define DEFAULT_PAGE_SIZE 1
+
+static void
+get_page_box (PSDocument *gs, int page, int *urx, int *ury, int *llx, int *lly)
+{
+ gint new_llx = 0;
+ gint new_lly = 0;
+ gint new_urx = 0;
+ gint new_ury = 0;
+ GtkGSPaperSize *papersizes = gtk_gs_defaults_get_paper_sizes ();
+ int new_pagesize = -1;
+
+ g_return_if_fail (PS_IS_DOCUMENT (gs));
+
+ if (new_pagesize == -1) {
+ new_pagesize = DEFAULT_PAGE_SIZE;
+ if (gs->doc) {
+ /* If we have a document:
+ * We use -- the page size (if specified)
+ * or the doc. size (if specified)
+ * or the page bbox (if specified)
+ * or the bounding box
+ */
+ if ((page >= 0) && (gs->doc->numpages > page) &&
+ (gs->doc->pages) && (gs->doc->pages[page].size)) {
+ new_pagesize = gs->doc->pages[page].size - gs->doc->size;
+ } else if (gs->doc->default_page_size != NULL) {
+ new_pagesize = gs->doc->default_page_size - gs->doc->size;
+ } else if ((page >= 0) &&
+ (gs->doc->numpages > page) &&
+ (gs->doc->pages) &&
+ (gs->doc->pages[page].boundingbox[URX] >
+ gs->doc->pages[page].boundingbox[LLX]) &&
+ (gs->doc->pages[page].boundingbox[URY] >
+ gs->doc->pages[page].boundingbox[LLY])) {
+ new_pagesize = -1;
+ } else if ((gs->doc->boundingbox[URX] > gs->doc->boundingbox[LLX]) &&
+ (gs->doc->boundingbox[URY] > gs->doc->boundingbox[LLY])) {
+ new_pagesize = -1;
+ }
+ }
+ }
+
+ /* Compute bounding box */
+ if (gs->doc && (gs->doc->epsf || new_pagesize == -1)) { /* epsf or bbox */
+ if ((page >= 0) &&
+ (gs->doc->pages) &&
+ (gs->doc->pages[page].boundingbox[URX] >
+ gs->doc->pages[page].boundingbox[LLX]) &&
+ (gs->doc->pages[page].boundingbox[URY] >
+ gs->doc->pages[page].boundingbox[LLY])) {
+ /* use page bbox */
+ new_llx = gs->doc->pages[page].boundingbox[LLX];
+ new_lly = gs->doc->pages[page].boundingbox[LLY];
+ new_urx = gs->doc->pages[page].boundingbox[URX];
+ new_ury = gs->doc->pages[page].boundingbox[URY];
+ } else if ((gs->doc->boundingbox[URX] > gs->doc->boundingbox[LLX]) &&
+ (gs->doc->boundingbox[URY] > gs->doc->boundingbox[LLY])) {
+ /* use doc bbox */
+ new_llx = gs->doc->boundingbox[LLX];
+ new_lly = gs->doc->boundingbox[LLY];
+ new_urx = gs->doc->boundingbox[URX];
+ new_ury = gs->doc->boundingbox[URY];
+ }
+ } else {
+ if (new_pagesize < 0)
+ new_pagesize = DEFAULT_PAGE_SIZE;
+ new_llx = new_lly = 0;
+ if (gs->doc && gs->doc->size &&
+ (new_pagesize < gs->doc->numsizes)) {
+ new_urx = gs->doc->size[new_pagesize].width;
+ new_ury = gs->doc->size[new_pagesize].height;
+ } else {
+ new_urx = papersizes[new_pagesize].width;
+ new_ury = papersizes[new_pagesize].height;
+ }
+ }
+
+ if (new_urx <= new_llx)
+ new_urx = papersizes[12].width;
+ if (new_ury <= new_lly)
+ new_ury = papersizes[12].height;
+
+ *urx = new_urx;
+ *ury = new_ury;
+ *llx = new_llx;
+ *lly = new_lly;