Beispiel #1
0
static int executeJump(void)
{
	/*
	 * 0 = No jump pending, nothing done.
	 * 1 = Jump succeeded.
	 * 2 = Jump was pending, but target page invalid.
	 */
	int retval = 0;

	/* Jump? */
	if (target_page >= 0)
	{
		
		int label = 0;
		int runs = 0;
		int page_number = target_page-1;
		while (runs < doc_n_pages && page_number >= 0 && page_number < doc_n_pages) {
		    PopplerPage *page = poppler_document_get_page(doc, page_number);
		    label = atoi(poppler_page_get_label(page));
		    if (label == target_page)
		        break;
		    if (label < target_page)
		        page_number++;
		    else if (label > target_page)
		        page_number--;
		    runs++;
		    g_object_unref(G_OBJECT(page));
		}
		
		target_page = page_number;

		/* Restrict to valid range. */
		if (target_page >= 0 && target_page < doc_n_pages)
		{
			doc_page = target_page;
			doc_page_beamer = target_page;
			setStatusText_strdup("Ready.");
			retval = 1;
		}
		else
		{
			setStatusText_strdup("Invalid page.");
			retval = 2;
		}

		/* Reset value to: "no jump pending". */
		target_page = -1;
	}

	return retval;
}
Beispiel #2
0
int main(int argc, char **argv)
{
	int i = 0, numframes;
	char *filename = NULL;
	gchar *notefile = NULL;
	FILE *fp = NULL;
	struct stat statbuf;
	char *databuf = NULL;
	GError *err = NULL;

	gtk_init(&argc, &argv);

	/* Load preferences first. Command line options will override those
	 * preferences. */
	loadPreferences();

	/* Read defaults from preferences. */
	filename = NULL;
	numframes = 2 * prefs.slide_context + 1;
	runpref.do_wrapping = prefs.do_wrapping;
	runpref.do_notectrl = prefs.do_notectrl;
	runpref.fit_mode = prefs.initial_fit_mode;

	/* get options via getopt */
	while ((i = getopt(argc, argv, "s:wnN:CTv")) != -1)
	{
		switch (i)
		{
			case 's':
				numframes = 2 * atoi(optarg) + 1;
				if (numframes <= 1)
				{
					fprintf(stderr, "Invalid slide count specified.\n");
					usage(argv[0]);
					exit(EXIT_FAILURE);
				}
				break;

			case 'w':
				runpref.do_wrapping = TRUE;
				break;

			case 'n':
				runpref.do_notectrl = TRUE;
				break;

			case 'N':
				notefile = g_strdup(optarg);
				break;

			case 'C':
				/* Force the timer to be a clock. */
				prefs.timer_is_clock = TRUE;
				break;

			case 'T':
				/* Force the timer to be a timer (not a clock). */
				prefs.timer_is_clock = FALSE;
				break;

			case 'v':
				printf("pdfpres version: %s\n", PDFPRES_VERSION);
				exit(EXIT_SUCCESS);
				break;

			case '?':
				exit(EXIT_FAILURE);
				break;
		}
	}

	/* retrieve file name via first non-option argument */
	if (optind < argc)
	{
		filename = argv[optind];
	}

	if (filename == NULL)
	{
		fprintf(stderr, "Invalid file path specified.\n");
		usage(argv[0]);
		exit(EXIT_FAILURE);
	}

	/* try to load the file */
	if (stat(filename, &statbuf) == -1)
	{
		perror("Could not stat file");
		exit(EXIT_FAILURE);
	}

	/* note: this buffer must not be freed, it'll be used by poppler
	 * later on. */
	databuf = (char *)malloc(statbuf.st_size);
	g_assert(databuf);

	fp = fopen(filename, "rb");
	if (!fp)
	{
		perror("Could not open file");
		exit(EXIT_FAILURE);
	}

	/* Read 1 element of size "statbuf.st_size". fread() returns the
	 * number of items successfully read. Thus, a return value of "1"
	 * means "success" and anything else is an error. */
	if (fread(databuf, statbuf.st_size, 1, fp) != 1)
	{
		fprintf(stderr, "Unexpected end of file.\n");
		exit(EXIT_FAILURE);
	}

	fclose(fp);

	/* get document from data */
	doc = poppler_document_new_from_data(databuf, statbuf.st_size,
			NULL, &err);
	if (!doc)
	{
		fprintf(stderr, "%s\n", err->message);
		g_error_free(err);
		exit(EXIT_FAILURE);
	}

	doc_n_pages = poppler_document_get_n_pages(doc);
	
	if (doc_n_pages <= 0)
	{
		fprintf(stderr, "Huh, no pages in that document.\n");
		exit(EXIT_FAILURE);
	}
	
	PopplerPage *page = poppler_document_get_page(doc, doc_n_pages-1);
	doc_last_page = atoi(poppler_page_get_label(page));
	g_object_unref(G_OBJECT(page));

	initGUI(numframes, notefile);

	gtk_main();
	exit(EXIT_SUCCESS);
}
Beispiel #3
0
static void
pgd_page_set_page (PgdPageDemo *demo,
		   PopplerPage *page)
{
#ifdef POPPLER_WITH_GDK
	GdkPixbuf *thumbnail;
#else
	cairo_surface_t *thumbnail;
#endif
	gchar     *str;

	str = page ? g_strdup_printf ("%d", poppler_page_get_index (page)) : NULL;
	gtk_label_set_text (GTK_LABEL (demo->index), str);
	g_free (str);

	if (page) {
		str = poppler_page_get_label (page);
		gtk_label_set_text (GTK_LABEL (demo->label), str);
		g_free (str);
	} else {
		gtk_label_set_text (GTK_LABEL (demo->label), NULL);
	}

	if (page) {
		gdouble width, height;

		poppler_page_get_size (page, &width, &height);
		str = g_strdup_printf ("%.2f x %.2f", width, height);
		gtk_label_set_text (GTK_LABEL (demo->size), str);
		g_free (str);
	} else {
		gtk_label_set_text (GTK_LABEL (demo->size), NULL);
	}

	str = page ? g_strdup_printf ("%.2f seconds", poppler_page_get_duration (page)) : NULL;
	gtk_label_set_text (GTK_LABEL (demo->duration), str);
	g_free (str);

#ifdef POPPLER_WITH_GDK
	thumbnail = page ? poppler_page_get_thumbnail_pixbuf (page) : NULL;
#else
	thumbnail = page ? poppler_page_get_thumbnail (page) : NULL;
#endif
	if (thumbnail) {
		gint width, height;
		
		poppler_page_get_thumbnail_size (page, &width, &height);
		str = g_strdup_printf ("%d x %d", width, height);
		gtk_label_set_text (GTK_LABEL (demo->thumbnail_size), str);
		g_free (str);
		
#ifdef POPPLER_WITH_GDK
		gtk_image_set_from_pixbuf (GTK_IMAGE (demo->thumbnail), thumbnail);
		g_object_unref (thumbnail);
#else
		image_set_from_surface (GTK_IMAGE (demo->thumbnail), thumbnail);
		cairo_surface_destroy (thumbnail);
#endif
	} else {
		str = g_strdup ("<i>No thumbnail found</i>");
		gtk_label_set_markup (GTK_LABEL (demo->thumbnail_size), str);
		g_free (str);

		gtk_image_set_from_icon_name (GTK_IMAGE (demo->thumbnail),
					      "image-missing",
					      GTK_ICON_SIZE_DIALOG);
	}
}
Beispiel #4
0
static gboolean onCanvasDraw(GtkWidget *widget, cairo_t *cr,
		struct viewport *pp)
{
	(void)widget;

	int mypage_i, myfitmode = -1;
	gdouble w = 0, h = 0;
	gchar *title = NULL;
	gdouble popwidth, popheight;
	gdouble tx, ty;
	gdouble screen_ratio, page_ratio, scale;
	PopplerPage *page = NULL;

	/* no valid target size? */
	if (pp->width <= 0 || pp->height <= 0)
		return TRUE;

	/* decide which page to render - if any */
	mypage_i = pagenumForPort(pp);

	if (mypage_i < 0 || mypage_i >= doc_n_pages)
	{
		/* We don't do any drawing and set the frame's title to "X".
		 * Thus, we'll end up with an "empty" frame. */
		if (pp->frame != NULL)
			gtk_frame_set_label(GTK_FRAME(pp->frame), "X");

		return TRUE;
	}
	else
	{
		/* update frame title */
		if (pp->frame != NULL)
		{
			title = g_strdup_printf("Slide %d / %d", mypage_i + 1,
					doc_n_pages);
			gtk_frame_set_label(GTK_FRAME(pp->frame), title);
			g_free(title);
		}
	}

	/* if note-control is active, print current page number if on
	 * "main" frame. (don't do this on the beamer because it could be
	 * locked.)
	 * this allows you to attach any kind of other program or script
	 * which can show notes for a specific slide. simply pipe the
	 * output of pdfpres to your other tool.
	 */
	if (pp->offset == 0 && !pp->isBeamer)
	{
		printNote(doc_page + 1);
		if (runpref.do_notectrl)
		{
			printf("%d\n", doc_page + 1);
			fflush(stdout);
		}
	}

	/* Get the page and it's size from the document. */
	page = poppler_document_get_page(doc, mypage_i);
	poppler_page_get_size(page, &popwidth, &popheight);
	
	/* Set page number */
	if (pp->isBeamer)
	{
	    gtk_label_set_text(GTK_LABEL(curPageLabel), 
	        g_strdup_printf("%s/%d", poppler_page_get_label(page), doc_last_page));
	}

	/* Select fit mode. */
	page_ratio = popwidth / popheight;
	screen_ratio = (double)pp->width / (double)pp->height;

	if (runpref.fit_mode == FIT_PAGE)
	{
		/* That's it: Compare screen and page ratio. This
		 * will cover all 4 cases that could happen. */
		if (screen_ratio > page_ratio)
			myfitmode = FIT_HEIGHT;
		else
			myfitmode = FIT_WIDTH;
	}
	else
		myfitmode = runpref.fit_mode;

	switch (myfitmode)
	{
		case FIT_HEIGHT:
			/* Fit size. */
			h = pp->height;
			w = h * page_ratio;
			scale = h / popheight;
			/* Center page. */
			tx = (pp->width - popwidth * scale) * 0.5;
			ty = 0;
			break;

		case FIT_WIDTH:
			w = pp->width;
			h = w / page_ratio;
			scale = w / popwidth;
			tx = 0;
			ty = (pp->height - popheight * scale) * 0.5;
			break;
	}

	/* A black background on beamer frame. Push and pop cairo contexts, so we have a
	 * clean state afterwards. */
	if (pp->isBeamer) {
	    cairo_save(cr);
	    cairo_set_source_rgb(cr, 0, 0, 0);
	    cairo_rectangle(cr, 0, 0, pp->width, pp->height);
	    cairo_fill(cr);
	    cairo_restore(cr);
	    
	    /* center page on beamer */
	    cairo_translate(cr, tx, ty);
	} else {
	    cairo_translate(cr, tx, 0);
	}

	/* Render the page */
	cairo_scale(cr, scale, scale);
	poppler_page_render(page, cr);

	/* We no longer need that page. */
	g_object_unref(G_OBJECT(page));

	/* Nobody else draws to this widget. */
	return TRUE;
}
Beispiel #5
0
static void emPdfOpen(const char * args)
{
	const char * filePath;
	const char * label;
	char genericLabel[256];
	char uri[64+PATH_MAX];
	GError * err;
	emPdfInst * inst;
	PopplerPage * page;
	double width,height;
	int i,instId;

	filePath=args;
	if (!*filePath) {
		fprintf(stderr,"emPdfServerProc: emPdfOpen: illegal arguments.\n");
		exit(1);
	}

	strcpy(uri,"file:");
	if (!realpath(filePath,uri+strlen(uri))) {
		printf(
			"error: Failed to read %s (%s)\n",
			filePath,
			strerror(errno)
		);
		return;
	}

	inst=(emPdfInst*)malloc(sizeof(emPdfInst));
	memset(inst,0,sizeof(emPdfInst));

	err=NULL;
	inst->doc=poppler_document_new_from_file(uri,NULL,&err);
	if (!inst->doc) {
		printf(
			"error: Failed to read %s (%s)\n",
			filePath,
			(err && err->message && err->message[0]) ? err->message : "unknown error"
		);
		if (err) g_error_free(err);
		free(inst);
		return;
	}

	for (instId=0; ; instId++) {
		if (instId==emPdfInstArraySize) {
			emPdfInstArraySize+=256;
			emPdfInstArray=(emPdfInst**)realloc(
				emPdfInstArray,
				emPdfInstArraySize*sizeof(emPdfInst*)
			);
			memset(
				emPdfInstArray+instId,
				0,
				(emPdfInstArraySize-instId)*sizeof(emPdfInst*)
			);
		}
		if (!emPdfInstArray[instId]) break;
	}
	emPdfInstArray[instId]=inst;

	printf("instance: %d\n",instId);

#if 0
	/* ???: Not in old version. */
	printf("title: %s\n",poppler_document_get_title(inst->doc));
	printf("author: %s\n",poppler_document_get_author(inst->doc));
	printf("subject: %s\n",poppler_document_get_subject(inst->doc));
	printf("keyword: %s\n",poppler_document_get_keyword(inst->doc));
	printf("creator: %s\n",poppler_document_get_creator(inst->doc));
	printf("producer: %s\n",poppler_document_get_produer(inst->doc));
	time_t t1=poppler_document_get_creation_date(inst->doc);
	time_t t2=poppler_document_get_modification_date(inst->doc);
	gboolean lin=poppler_document_is_linearized(inst->doc);
	PopplerPageLayout layout=poppler_document_get_page_layout(inst->doc);
	PopplerPageMode pageMode=poppler_document_get_page_mode(inst->doc);
	PopplerPermissions perm=poppler_document_get_permissions(inst->doc);
	gchar * metadata=poppler_document_get_metadata(inst->doc);
#endif

	inst->pageCount=poppler_document_get_n_pages(inst->doc);

	printf("pages: %d\n",inst->pageCount);

	for (i=0; i<inst->pageCount; i++) {
		sprintf(genericLabel,"%d",i+1);
		page = poppler_document_get_page(inst->doc,i);
		if (page) {
			poppler_page_get_size(page,&width,&height);
#if 0
			/* ???: Not in old version. */
			label=poppler_page_get_label(page);
#else
			label=NULL;
#endif
			if (!label || !*label) label=genericLabel;
			g_object_unref(page);
		}
		else {
			width=1000;
			height=1000;
			label=genericLabel;
		}
		printf("pageinfo: %d %.16lg %.16lg ",i,width,height);
		emPdfPrintQuoted(label);
		putchar('\n');
	}
	printf("ok\n");
}