-ps_document_goto_page(PSDocument * gs, gint page)
-{
- g_return_val_if_fail(gs != NULL, FALSE);
- g_return_val_if_fail(GTK_IS_GS(gs), FALSE);
-
- LOG ("Go to page %d", page);
-
- if(!gs->gs_filename) {
- return FALSE;
- }
-
- /* range checking... */
- if(page < 0)
- page = 0;
-
- if(gs->structured_doc && gs->doc) {
-
- LOG ("It's a structured document, let's send one page to gs");
-
- if(page >= gs->doc->numpages)
- page = gs->doc->numpages - 1;
-
- if(page == gs->current_page && !gs->changed)
- return TRUE;
-
- gs->current_page = page;
-
- if(gs->doc->pages[page].orientation != NONE &&
- !gs->override_orientation &&
- gs->doc->pages[page].orientation != gs->real_orientation) {
- gs->real_orientation = gs->doc->pages[page].orientation;
- gs->changed = TRUE;
- }
-
- ps_document_set_page_size(gs, -1, page);
-
- gs->changed = FALSE;
-
- if(is_interpreter_ready(gs)) {
- ps_document_next_page(gs);
- }
- else {
- ps_document_enable_interpreter(gs);
- send_ps(gs, gs->doc->beginprolog, gs->doc->lenprolog, FALSE);
- send_ps(gs, gs->doc->beginsetup, gs->doc->lensetup, FALSE);
- }
-
- send_ps(gs, gs->doc->pages[gs->current_page].begin,
- gs->doc->pages[gs->current_page].len, FALSE);
- }
- else {
- /* Unstructured document */
- /* In the case of non structured documents,
- GS read the PS from the actual file (via command
- line. Hence, ggv only send a signal next page.
- If ghostview is not running it is usually because
- the last page of the file was displayed. In that
- case, ggv restarts GS again and the first page is displayed.
- */
-
- LOG ("It's an unstructured document, gs will just read the file");
-
- if(page == gs->current_page && !gs->changed)
- return TRUE;
-
- ps_document_set_page_size(gs, -1, page);
-
- if(!is_interpreter_ready(gs))
- ps_document_enable_interpreter(gs);
-
- gs->current_page = page;
-
- ps_document_next_page(gs);
- }
- return TRUE;
-}
-
-/*
- * set pagesize sets the size from
- * if new_pagesize is -1, then it is set to either
- * a) the default settings of pageid, if they exist, or if pageid != -1.
- * b) the default setting of the document, if it exists.
- * c) the default setting of the widget.
- * otherwise, the new_pagesize is used as the pagesize
- */
-static gboolean
-ps_document_set_page_size(PSDocument * gs, gint new_pagesize, gint pageid)
-{
- gint new_llx = 0;
- gint new_lly = 0;
- gint new_urx = 0;
- gint new_ury = 0;
- GtkGSPaperSize *papersizes = gtk_gs_defaults_get_paper_sizes();
-
- LOG ("Set the page size");
-
- g_return_val_if_fail(gs != NULL, FALSE);
- g_return_val_if_fail(GTK_IS_GS(gs), FALSE);
-
- if(new_pagesize == -1) {
- if(gs->default_size > 0)
- new_pagesize = gs->default_size;
- if(!gs->override_size && 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((pageid >= 0) && (gs->doc->numpages > pageid) &&
- (gs->doc->pages) && (gs->doc->pages[pageid].size)) {
- new_pagesize = gs->doc->pages[pageid].size - gs->doc->size;
- }
- else if(gs->doc->default_page_size != NULL) {
- new_pagesize = gs->doc->default_page_size - gs->doc->size;
- }
- else if((pageid >= 0) &&
- (gs->doc->numpages > pageid) &&
- (gs->doc->pages) &&
- (gs->doc->pages[pageid].boundingbox[URX] >
- gs->doc->pages[pageid].boundingbox[LLX]) &&
- (gs->doc->pages[pageid].boundingbox[URY] >
- gs->doc->pages[pageid].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 && !gs->override_size) || new_pagesize == -1)) { /* epsf or bbox */
- if((pageid >= 0) &&
- (gs->doc->pages) &&
- (gs->doc->pages[pageid].boundingbox[URX] >
- gs->doc->pages[pageid].boundingbox[LLX])
- && (gs->doc->pages[pageid].boundingbox[URY] >
- gs->doc->pages[pageid].boundingbox[LLY])) {
- /* use page bbox */
- new_llx = gs->doc->pages[pageid].boundingbox[LLX];
- new_lly = gs->doc->pages[pageid].boundingbox[LLY];
- new_urx = gs->doc->pages[pageid].boundingbox[URX];
- new_ury = gs->doc->pages[pageid].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 = gs->default_size;
- new_llx = new_lly = 0;
- if(gs->doc && !gs->override_size && 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;
-
- /* If bounding box changed, setup for new size. */
- /* ps_document_disable_interpreter (gs); */
- if((new_llx != gs->llx) || (new_lly != gs->lly) ||
- (new_urx != gs->urx) || (new_ury != gs->ury)) {
- gs->llx = new_llx;
- gs->lly = new_lly;
- gs->urx = new_urx;
- gs->ury = new_ury;
- gs->changed = TRUE;
- }
-
- if(gs->changed) {
- set_up_page(gs);
- return TRUE;
- }
-
- return FALSE;
-}
-
-static gfloat
-ps_document_zoom_to_fit(PSDocument * gs, gboolean fit_width)