static gpointer
thumbnail_thread (gpointer data)
{
    ThreadData  *thread_data = data;
    gint         n_pages;
    gint         i;

    n_pages = poppler_document_get_n_pages (thread_data->document);

    for (i = 0; i < n_pages; i++)
    {
        IdleData *idle_data = g_new0 (IdleData, 1);

        idle_data->selector = thread_data->selector;
        idle_data->page_no  = i;

        /* FIXME get preferred size from somewhere? */
        idle_data->pixbuf = get_thumbnail (thread_data->document, i,
                                           THUMBNAIL_SIZE);

        g_idle_add (idle_set_thumbnail, idle_data);

        if (thread_data->stop_thumbnailing)
            break;
    }

    return NULL;
}
Beispiel #2
0
void
test_font (void)
{
  PopplerFontInfo *font_info;
  PopplerFontsIter *iter;
  gint n_pages;

  document = load_document ("slide.pdf");
  n_pages = poppler_document_get_n_pages (document);
  font_info = poppler_font_info_new (document);
  while (poppler_font_info_scan (font_info, n_pages, &iter))
    {
      if (iter)
        {
          do
            {
              actual_font_names =
                g_list_append (actual_font_names,
                               g_strdup (poppler_fonts_iter_get_name (iter)));
            } while (poppler_fonts_iter_next (iter));
          poppler_fonts_iter_free (iter);
        }
    }
  g_object_unref (font_info);

  expected_font_names = gcut_list_string_new ("IPAPMincho",
                                              "LiberationSans-Regular",
                                              NULL);
  gcut_assert_equal_list_string (expected_font_names,
                                 actual_font_names);
}
Beispiel #3
0
cairo_surface_t* get_pdf_cairo_surface(char* filename, int n_page, int width, int height) {
    if (NULL != currentDocument) {
        free_doc();
    }
    PopplerDocument* doc;
    GError* err = NULL;

    gchar* uri = g_strconcat("file:", filename, NULL);

    doc = poppler_document_new_from_file(uri, NULL, &err);

    if (NULL != err) {
        g_print(err->message);
        return NULL;
    }

    cairo_surface_t* result = cairo_image_surface_create(CAIRO_FORMAT_RGB24, width, height);
    render_pdf_page(doc, n_page, result, width, height);

    currentDocument = (document_page_t*)g_malloc(sizeof(document_page_t));
    currentDocument->doc = doc;
    currentDocument->page = 0;
    currentDocument->page_count = poppler_document_get_n_pages(doc);
    currentDocument->surface = result;
    currentDocument->width = width;
    currentDocument->height = height;

    return result;
}
Beispiel #4
0
static GString *
extract_content_text (PopplerDocument *document,
                      gsize            n_bytes)
{
	gint n_pages, i = 0;
	GString *string;
	GTimer *timer;
	gsize remaining_bytes = n_bytes;

	n_pages = poppler_document_get_n_pages (document);
	string = g_string_new ("");
	timer = g_timer_new ();

	while (i < n_pages &&
	       remaining_bytes > 0) {
		PopplerPage *page;
		gsize written_bytes = 0;
		gchar *text;

		page = poppler_document_get_page (document, i);
		i++;

		text = poppler_page_get_text (page);

		if (!text) {
			g_object_unref (page);
			continue;
		}

		if (tracker_text_validate_utf8 (text,
		                                MIN (strlen (text), remaining_bytes),
		                                &string,
		                                &written_bytes)) {
			g_string_append_c (string, ' ');
		}

		remaining_bytes -= written_bytes;

		g_debug ("Child: Extracted %" G_GSIZE_FORMAT " bytes from page %d, "
		         "%" G_GSIZE_FORMAT " bytes remaining",
		         written_bytes, i, remaining_bytes);

		g_free (text);
		g_object_unref (page);
	}

	g_debug ("Child: Content extraction finished: %d/%d pages indexed in %2.2f seconds, "
	         "%" G_GSIZE_FORMAT " bytes extracted",
	         i,
	         n_pages,
	         g_timer_elapsed (timer, NULL),
	         (n_bytes - remaining_bytes));

	g_timer_destroy (timer);

	return string;
}
Beispiel #5
0
static GtkWidget *
pgd_layers_create_viewer (PgdLayersDemo *demo)
{
	GtkWidget *vbox, *hbox;
	GtkWidget *label;
	GtkWidget *swindow;
	GtkWidget *page_selector;
	guint      n_pages;
	gchar     *str;

	vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);

	hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);

	label = gtk_label_new ("Page:");
	gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
	gtk_widget_show (label);

	n_pages = poppler_document_get_n_pages (demo->doc);
	page_selector = gtk_spin_button_new_with_range (1, n_pages, 1);
	g_signal_connect (G_OBJECT (page_selector), "value-changed",
			  G_CALLBACK (pgd_layers_page_selector_value_changed),
			  (gpointer)demo);
	gtk_box_pack_start (GTK_BOX (hbox), page_selector, FALSE, TRUE, 0);
	gtk_widget_show (page_selector);

	str = g_strdup_printf ("of %d", n_pages);
	label = gtk_label_new (str);
	gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
	gtk_widget_show (label);
	g_free (str);

	gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
	gtk_widget_show (hbox);

	demo->darea = gtk_drawing_area_new ();
	g_signal_connect (G_OBJECT (demo->darea), "draw",
			  G_CALLBACK (pgd_layers_viewer_drawing_area_draw),
			  (gpointer)demo);

	swindow = gtk_scrolled_window_new (NULL, NULL);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
					GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
#if GTK_CHECK_VERSION(3, 7, 8)
	gtk_container_add(GTK_CONTAINER(swindow), demo->darea);
#else
	gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (swindow), demo->darea);
#endif
	gtk_widget_show (demo->darea);

	gtk_box_pack_start (GTK_BOX (vbox), swindow, TRUE, TRUE, 0);
	gtk_widget_show (swindow);

	return vbox;
}
Beispiel #6
0
int main(int argc, char *argv[]) {
    PopplerDocument *document;
    PopplerPage *page;
    GError *error;
    const char *pdf_file;
    
    gchar *absolute, *dir, *uri;
    int page_num, num_pages;
    char *tmpChar;

    if (argc < 2 && argc > 3) {
        printf ("Usage: pdftomapping input_file.pdf [page]\n");
        return 0;
    }

    pdf_file = argv[1];
    g_type_init ();
    error = NULL;

	if (g_path_is_absolute(pdf_file)) {
		absolute = g_strdup (pdf_file);
	} else {
		gchar *dir = g_get_current_dir ();
		absolute = g_build_filename (dir, pdf_file, (gchar *) 0);
		free (dir);
	}
	uri = g_filename_to_uri (absolute, NULL, &error);
	free (absolute);
	if (uri == NULL) {
		printf("%s\n", error->message);
		return 1;
	}

	document = poppler_document_new_from_file (uri, NULL, &error);
	if (document == NULL) {
		printf("%s\n", error->message);
		return 1;
	}
	num_pages = poppler_document_get_n_pages (document);

	int start = 1, end = num_pages;
	if (argc >= 3) {
		start = end = atoi(argv[2]);
	}
	for (page_num = start; page_num <= end ;page_num++) {
	  page = poppler_document_get_page (document, page_num - 1);
	  if (page == NULL) {
		  printf("poppler fail: page not found\n");
		  return 1;
	  }
	  write_mapping(page_num, page);
	}

    return 0;
}
Beispiel #7
0
static void
view_page_down(struct view *view)
{
        if(!view->document ||
           view->page >= poppler_document_get_n_pages(view->document) - 1) {
                return;
        }

        view->page++;
        window_schedule_redraw(view->window);
}
Beispiel #8
0
void
test_new_from_file (void)
{
  GError *error = NULL;
  const gchar *uri;

  uri = build_uri ("multi-pages.pdf");
  document = poppler_document_new_from_file (uri, NULL, &error);
  gcut_assert_error (error);

  cut_assert_equal_int (3, poppler_document_get_n_pages (document));
}
Beispiel #9
0
int main(int argc, char const *argv[])
{
	char *path;
	PopplerDocument *doc;
	GError *err;
	gchar *gbuf;
	char *buf;
	page_t page_meta;
	int file_length, n;

	g_type_init();

	if (argc != 2) {
		return 1;
	}

	err = NULL;
	buf = open_pdf_file(argv[1], &file_length);

	sandboxify();

	doc = poppler_document_new_from_data(buf, file_length, NULL, &err);
	if (err != NULL) {
		fprintf(stderr, "Unable to open file: %s\n", err->message);
		return 2;
	}

	n = poppler_document_get_n_pages(doc);

	for (int i = 0; i < n; i++) {
		PopplerPage *page = poppler_document_get_page(doc, i);

		page_meta.pagenum = i;
		page_meta.text = poppler_page_get_text(page);
		page_meta.svg_len = 0;
		page_meta.svg = malloc(SVG_BUFLEN);
		if (!page_meta.svg)
			ERROR("Cannot allocate svg buffer, not enought memory?");
		page_meta.free_space = SVG_BUFLEN;

		render_page(&page_meta, page);

		if (page_meta.text)
			free(page_meta.text);
		g_object_unref(page);
	}

	if (munmap(buf, file_length) == -1)
		PERROR("munmap()");

	return 0;
}
Beispiel #10
0
int render_init(char *fname) {
	char *path = realpath(fname, NULL);
	if (!path) return 1;
	char *uri = malloc(strlen(path) + 8);
	sprintf(uri, "file://%s", path);
	free(path);
_pdf = realloc(_pdf, (_n + 1) * sizeof(PDF));
	_pdf[_n].doc = poppler_document_new_from_file(uri, NULL, NULL);
	_pdf[_n].npage = poppler_document_get_n_pages(_pdf[_n].doc);
++_n;
	free(uri);
	return 0;
}
Beispiel #11
0
void
test_save_a_copy (void)
{
  GError *error = NULL;
  gchar *copy_path;
  const gchar *copy_uri;

  document = load_document ("multi-pages.pdf");
  cut_assert_equal_int (3, poppler_document_get_n_pages (document));

  copy_path = g_build_filename (tmp_dir, "copied-multi-pages.pdf", NULL);
  copy_uri = cut_take_printf ("file://%s", copy_path);
  g_free (copy_path);

  poppler_document_save_a_copy (document, copy_uri, &error);
  gcut_assert_error (error);

  g_object_unref (document);
  document = poppler_document_new_from_file (copy_uri, NULL, &error);
  gcut_assert_error (error);
  cut_assert_equal_int (3, poppler_document_get_n_pages (document));
}
Beispiel #12
0
void DocumentView::drawTexImage(cairo_t* cr, TexImage* texImage)
{
	XOJ_CHECK_TYPE(DocumentView);

	cairo_matrix_t defaultMatrix = { 0 };
	cairo_get_matrix(cr, &defaultMatrix);

	PopplerDocument* pdf = texImage->getPdf();
	cairo_surface_t* img = texImage->getImage();

	if (pdf != nullptr)
	{
		if (poppler_document_get_n_pages(pdf) < 1)
		{
			g_warning("Got latex PDf without pages!: %s", texImage->getText().c_str());
			return;
		}

		PopplerPage* page = poppler_document_get_page(pdf, 0);

		double pageWidth = 0;
		double pageHeight = 0;
		poppler_page_get_size(page, &pageWidth, &pageHeight);

		double xFactor = texImage->getElementWidth() / pageWidth;
		double yFactor = texImage->getElementHeight() / pageHeight;

		cairo_translate(cr, texImage->getX(), texImage->getY());
		cairo_scale(cr, xFactor, yFactor);
		poppler_page_render(page, cr);
	}
	else if (img != nullptr)
	{
		int width = cairo_image_surface_get_width(img);
		int height = cairo_image_surface_get_height(img);

		cairo_set_operator(cr, CAIRO_OPERATOR_OVER);

		double xFactor = texImage->getElementWidth() / width;
		double yFactor = texImage->getElementHeight() / height;

		cairo_scale(cr, xFactor, yFactor);

		cairo_set_source_surface(cr, img, texImage->getX() / xFactor, texImage->getY() / yFactor);
		cairo_paint(cr);
	}

	cairo_set_matrix(cr, &defaultMatrix);
}
Beispiel #13
0
// method: draw all the pages to appropriate recording surfaces and then get ink extents
void evenodd_cropboxes(PopplerDocument *document, cairo_rectangle_t *odd_page_crop_box, cairo_rectangle_t *even_page_crop_box) {
	GError *error = NULL;
	int num_document_pages = poppler_document_get_n_pages(document);

	cairo_surface_t *odd_pages = cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, NULL);
	cairo_surface_t *even_pages = cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, NULL);
	int page_num;
	for (page_num = 0; page_num < num_document_pages; page_num++) {
		cairo_surface_t *surface = odd_pages;
		if (page_num % 2 == 1) {
			surface = even_pages;
		}
		cairo_t *cr = cairo_create(surface);

		PopplerPage *page = poppler_document_get_page(document, page_num);
		if (page == NULL) {
			printf("%s:%d: %s\n", __FILE__, __LINE__, error->message);
			exit(1);		
		}

		poppler_page_render_for_printing(page, cr);
		g_object_unref(page);

		exit_if_cairo_status_not_success(cr, __FILE__, __LINE__);
		cairo_destroy(cr);
	}

	cairo_recording_surface_ink_extents(odd_pages,
		&odd_page_crop_box->x,
		&odd_page_crop_box->y,
		&odd_page_crop_box->width,
		&odd_page_crop_box->height);
	cairo_recording_surface_ink_extents(even_pages,
		&even_page_crop_box->x,
		&even_page_crop_box->y,
		&even_page_crop_box->width,
		&even_page_crop_box->height);

	// use to check extent and crop box handling
	// write_surface_to_file_showing_crop_box("odd.pdf", odd_pages, odd_page_crop_box);
	// write_surface_to_file_showing_crop_box("even.pdf", even_pages, even_page_crop_box);

	// cleanup surfaces used to get crop boxes
	cairo_surface_destroy(odd_pages);
	exit_if_cairo_surface_status_not_success(odd_pages, __FILE__, __LINE__);
	cairo_surface_destroy(even_pages);
	exit_if_cairo_surface_status_not_success(even_pages, __FILE__, __LINE__);
}
Beispiel #14
0
struct pages_t* all_pages(PopplerDocument *document, struct options_t options) {
	struct pages_t *pages = malloc(sizeof(struct pages_t));
	
	pages->npages = poppler_document_get_n_pages(document);

	pages->pages = malloc(sizeof(struct page_t)*pages->npages);

	int page_num;
	for (page_num = 0; page_num < pages->npages; page_num++) {
		struct page_t *page = &pages->pages[page_num];

		page->num = page_num;
	}

	return pages;
}
Beispiel #15
0
void add_per_page_cropboxes(PopplerDocument *document, struct pages_t *pages) {
	GError *error = NULL;
	int num_document_pages = poppler_document_get_n_pages(document);	

	int page_num;
	for (page_num = 0; page_num < pages->npages; page_num++) {
		int document_page_num = pages->pages[page_num].num;

		printf("document_page_num: %d\n", document_page_num);

		if (document_page_num >= num_document_pages) {
			printf("ERROR: The document does not have page %d, it only has %d pages\n", document_page_num, num_document_pages);
			exit(2);
		}

		cairo_surface_t *surface = cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, NULL);
		cairo_t *cr = cairo_create(surface);

		PopplerPage *page = poppler_document_get_page(document, document_page_num);
		if (page == NULL) {
			printf("%s:%d: %s\n", __FILE__, __LINE__, error->message);
			exit(1);		
		}

		poppler_page_render_for_printing(page, cr);
		g_object_unref(page);

		exit_if_cairo_status_not_success(cr, __FILE__, __LINE__);
		cairo_destroy(cr);

		cairo_rectangle_t *crop_box = malloc(sizeof(cairo_rectangle_t));
		cairo_recording_surface_ink_extents(surface,
			&crop_box->x,
			&crop_box->y,
			&crop_box->width,
			&crop_box->height);

		// use to check extent and crop box handling
		// write_surface_to_file_showing_crop_box("per_page.pdf", surface, crop_box);

		// cleanup surfaces used to get crop boxes
		cairo_surface_destroy(surface);
		exit_if_cairo_surface_status_not_success(surface, __FILE__, __LINE__);

		pages->pages[page_num].crop_box = crop_box;
	}
}
Beispiel #16
0
void
test_new_from_data (void)
{
  GError *error = NULL;
  gchar *data;
  gsize length;
  const gchar *path;

  path = cut_take_string (cut_build_fixture_data_path ("multi-pages.pdf", NULL));
  g_file_get_contents (path, &data, &length, &error);
  gcut_assert_error (error);

  document = poppler_document_new_from_data (data, length, NULL, &error);
  g_free (data);
  gcut_assert_error (error);

  cut_assert_equal_int (3, poppler_document_get_n_pages (document));
}
Beispiel #17
0
static VALUE
rg_each(VALUE self)
{
    PopplerDocument *document;
    int i, n_pages;

    document = RVAL2DOC(self);
    n_pages = poppler_document_get_n_pages(document);
    for (i = 0; i < n_pages; i++) {
        PopplerPage *page;
        VALUE rb_page;

        page = poppler_document_get_page(document, i);
        rb_page = GOBJ2RVAL(page);
        if (page)
            g_object_unref(page);
        rb_yield(rb_page);
    }
    return self;
}
Beispiel #18
0
/* operations for doc */
struct xv_doc_t * xv_doc_new(const char * file)
{
    GError *err = NULL;
    struct xv_doc_t *xv_doc;

    xv_doc = g_malloc0(sizeof(struct xv_doc_t));
    xv_doc->doc = poppler_document_new_from_file(file, NULL, &err);

    if (!xv_doc->doc) {
        printf("%s\n", err->message);
        g_error_free(err);
        g_free(xv_doc);
        return NULL;
    }

    xv_doc->n_pages = poppler_document_get_n_pages(xv_doc->doc);

    /* initialize the pages */
    xv_doc->pages = g_malloc0(xv_doc->n_pages * sizeof(struct xv_page_t *));

    /* initial the first page */
    xv_doc->pages[0] = g_malloc0(sizeof(struct xv_page_t));
    xv_doc->pages[0]-> page = poppler_document_get_page(xv_doc->doc, 0);

    if (!xv_doc->pages[0]->page) {
        printf("Could not open page %d of document\n", 0);
        g_object_unref(xv_doc->doc);
        g_free(xv_doc->pages[0]);
        g_free(xv_doc->pages);
        g_free(xv_doc);
        return NULL;
    }

    poppler_page_get_size(xv_doc->pages[0]->page,
                          &xv_doc->pages[0]->width,
                          &xv_doc->pages[0]->height);

    return xv_doc;
}
Beispiel #19
0
void *render_threaded(void *arg) {
	Show *show = (Show *) arg;
	int i, j, n, x, y, grid = 0;
	int sw = show->w, sh = show->h;
	Pixmap thumb = 0x0;
	/* open pdf and create Show */
	PopplerDocument *pdf = poppler_document_new_from_file(show->uri,NULL,NULL);
	if (!pdf) die("\"%s\" is not a pdf file\n",show->uri);
	show->count = poppler_document_get_n_pages(pdf);
	show->slide = (Pixmap *) calloc(show->count, sizeof(Pixmap));
	show->flag = (int *) calloc(show->count, sizeof(int));
	/* scaling calculations */
	double pdfw, pdfh;
	PopplerPage *page = poppler_document_get_page(pdf,0);
	poppler_page_get_size(page,&pdfw,&pdfh);
	float hsc = show->w/pdfw, vsc = show->h/pdfh;
	if (hsc > vsc) {
		show->scale = vsc;
		show->w = pdfw * show->scale;
		show->x = (sw - show->w)/2;
	}
	else {
		show->scale = hsc;
		show->h = pdfh * show->scale;
		show->y = (sh - show->h)/2;
	}
	/* create sorter */
	if (show->sorter) {
		/* scaling calculations sorter */
		show->sorter->count = 1;
		show->sorter->slide = (Pixmap *) calloc(1, sizeof(Pixmap));
		show->sorter->flag = (int *) calloc(1,sizeof(int));
		grid = (int) ceil(sqrt(show->count)) ;
		vsc = ( (sh-10)/grid - 10) / pdfh;
		hsc = ( (sw-10)/grid - 10) / pdfw;
		show->sorter->flag[0] = grid;
		show->sorter->scale = (vsc > hsc ? hsc : vsc);
		show->sorter->h = pdfh * show->sorter->scale;
		show->sorter->w = pdfw * show->sorter->scale;
		show->sorter->x = (sw - (show->sorter->w+10)*grid + 10)/2;
		show->sorter->y = (sh - (show->sorter->h+10)*grid + 10)/2;
		/* create empty sorter frame */
		thumb = XCreatePixmap(dpy,root,show->sorter->w,
				show->sorter->h,DefaultDepth(dpy,scr));
		show->sorter->slide[0] = XCreatePixmap(dpy,root,sw,sh,
				DefaultDepth(dpy,scr));
		XFillRectangle(dpy,show->sorter->slide[0],bgc,0,0,sw,sh);
		n = 0; y = show->sorter->y;
		for (i = 0; i < grid; i++, y += show->sorter->h + 10) {
			x = show->sorter->x;
			for (j = 0; j < grid; j++, x+= show->sorter->w + 10) {
				if (++n > show->count) break;
				XFillRectangle(dpy,show->sorter->slide[0],egc,x+2,y+2,
						show->sorter->w-5,show->sorter->h-5);
			}
		}
	}	
	/* render pages */
	cairo_surface_t *target;
	cairo_t *cairo;
	n = 0; x = (show->sorter ? show->sorter->x : 0);
	y = (show->sorter ? show->sorter->y : 0);
	for (i = 0; i < show->count && !(show->flag[0] & STOP_RENDER); i++) {
		show->slide[i] = XCreatePixmap(dpy,root,show->w,show->h,
				DefaultDepth(dpy,scr));
		XFillRectangle(dpy,show->slide[i],sgc,0,0,show->w,show->h);
		page = poppler_document_get_page(pdf,i);
		target = cairo_xlib_surface_create(dpy,show->slide[i],
				DefaultVisual(dpy,scr),show->w,show->h);
		cairo = cairo_create(target);
		cairo_scale(cairo,show->scale,show->scale);
		poppler_page_render(page,cairo);
		cairo_surface_destroy(target);
		cairo_destroy(cairo);
		show->flag[i] |= RENDERED;
		if (show->sorter) {
			XFillRectangle(dpy,thumb,sgc,0,0,show->sorter->w,show->sorter->h);
			target = cairo_xlib_surface_create(dpy,thumb,DefaultVisual(dpy,scr),
					show->sorter->w,show->sorter->h);
			cairo = cairo_create(target);
			cairo_scale(cairo,show->sorter->scale,show->sorter->scale);
			poppler_page_render(page,cairo);
			cairo_surface_destroy(target);
			XCopyArea(dpy,thumb,show->sorter->slide[0],sgc,0,0,show->sorter->w,
					show->sorter->h,x,y);
			x += show->sorter->w + 10;
			if (++n == grid) {
				n = 0;
				x = show->sorter->x;
				y += show->sorter->h + 10;
			}
		}
	}
	if (show->sorter) XFreePixmap(dpy,thumb);
	return NULL;
}
Beispiel #20
0
int main(int argn, char *args[])
{
	// Poppler stuff
	PopplerDocument *pdffile;
	PopplerPage *page;

	// Initialise the GType library
	g_type_init ();

	// Get command line arguments
	if ((argn < 3)||(argn > 4)) {
		printf("Usage: pdf2svg <in file.pdf> <out file.svg> [<page no>]\n");
		return -2;
	}
	gchar *absoluteFileName = getAbsoluteFileName(args[1]);
	gchar *filename_uri = g_filename_to_uri(absoluteFileName, NULL, NULL);
	gchar *pageLabel = NULL;

	char* svgFilename = args[2];

	g_free(absoluteFileName);
	if (argn == 4) {
		// Get page number
		pageLabel = g_strdup(args[3]);
	}

	// Open the PDF file
	pdffile = poppler_document_new_from_file(filename_uri, NULL, NULL);
	g_free(filename_uri);
	if (pdffile == NULL) {
		fprintf(stderr, "Unable to open file\n");
		return -3;
	}

	int conversionErrors = 0;
	// Get the page

	if(pageLabel == NULL) {
		page = poppler_document_get_page(pdffile, 0);
		conversionErrors = convertPage(page, svgFilename);
	}
	else {
		if(strcmp(pageLabel, "all") == 0) {
			int curError;
			int pageCount = poppler_document_get_n_pages(pdffile);

			if(pageCount > 9999999) {
				fprintf(stderr, "Too many pages (>9,999,999)\n");
				return -5;
			}

			size_t svgFilenameBufLen = strlen(svgFilename) + 1;
			char *svgFilenameBuffer = (char*)malloc(svgFilenameBufLen);
			assert(svgFilenameBuffer != NULL);

			int pageInd;
			for(pageInd = 0; pageInd < pageCount; pageInd++) {
				while (1) {
					size_t _wr_len = snprintf(svgFilenameBuffer, svgFilenameBufLen, svgFilename, pageInd + 1);
					if (_wr_len >= svgFilenameBufLen) {
						svgFilenameBufLen = _wr_len + 1;
						svgFilenameBuffer = (char*)realloc(svgFilenameBuffer, svgFilenameBufLen);
						assert(svgFilenameBuffer != NULL);
						continue;
					}
					break;
				}

				page = poppler_document_get_page(pdffile, pageInd);
				curError = convertPage(page, svgFilenameBuffer);
				if(curError != 0)
					conversionErrors = -1;
			}
			free(svgFilenameBuffer);
		}
		else {
			page = poppler_document_get_page_by_label(pdffile, pageLabel);
			conversionErrors = convertPage(page, svgFilename);
			g_free(pageLabel);
		}
	}

	g_object_unref(pdffile);

	if(conversionErrors != 0) {
		return -4;
	}
	else {
		return 0;
	}

}
Beispiel #21
0
GtkWidget *
pgd_text_create_widget (PopplerDocument *document)
{
	PgdTextDemo      *demo;
	GtkWidget        *label;
	GtkWidget        *vbox, *vbox2;
	GtkWidget        *hbox, *page_selector, *area_hbox;
	GtkWidget        *button;
	GtkWidget        *swindow, *textview, *treeview;
	GtkTreeSelection *selection;
        GtkWidget        *frame, *alignment, *table;
	GtkWidget        *hpaned;
	GtkCellRenderer  *renderer;
	gchar            *str;
	gint              n_pages;
        gint              row = 0;

	demo = g_new0 (PgdTextDemo, 1);

	demo->doc = g_object_ref (document);

	n_pages = poppler_document_get_n_pages (document);

	vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
	vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);

	hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);

	label = gtk_label_new ("Page:");
	gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
	gtk_widget_show (label);

	page_selector = gtk_spin_button_new_with_range (1, n_pages, 1);
	g_signal_connect (G_OBJECT (page_selector), "value-changed",
			  G_CALLBACK (pgd_text_page_selector_value_changed),
			  (gpointer)demo);
	gtk_box_pack_start (GTK_BOX (hbox), page_selector, FALSE, TRUE, 0);
	gtk_widget_show (page_selector);

	str = g_strdup_printf ("of %d", n_pages);
	label = gtk_label_new (str);
	gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
	gtk_widget_show (label);
	g_free (str);

        gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
	gtk_widget_show (hbox);

        hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);

        area_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
	label = gtk_label_new ("X1:");
	gtk_box_pack_start (GTK_BOX (area_hbox), label, TRUE, TRUE, 0);
	gtk_widget_show (label);

	demo->area_x1 = gtk_spin_button_new_with_range (0, 0, 0.01);
	g_signal_connect (demo->area_x1, "value-changed",
			  G_CALLBACK (pgd_text_area_selector_value_changed),
			  demo);
	gtk_box_pack_start (GTK_BOX (area_hbox), demo->area_x1, TRUE, TRUE, 0);
	gtk_widget_show (demo->area_x1);

	gtk_box_pack_start (GTK_BOX (hbox), area_hbox, FALSE, TRUE, 0);
	gtk_widget_show (area_hbox);

        area_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
	label = gtk_label_new ("Y1:");
	gtk_box_pack_start (GTK_BOX (area_hbox), label, TRUE, TRUE, 0);
	gtk_widget_show (label);

	demo->area_y1 = gtk_spin_button_new_with_range (0, 0, 0.01);
        g_signal_connect (demo->area_y1, "value-changed",
			  G_CALLBACK (pgd_text_area_selector_value_changed),
			  demo);
	gtk_box_pack_start (GTK_BOX (area_hbox), demo->area_y1, TRUE, TRUE, 0);
	gtk_widget_show (demo->area_y1);

	gtk_box_pack_start (GTK_BOX (hbox), area_hbox, FALSE, TRUE, 0);
	gtk_widget_show (area_hbox);

        area_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
	label = gtk_label_new ("X2:");
	gtk_box_pack_start (GTK_BOX (area_hbox), label, TRUE, TRUE, 0);
	gtk_widget_show (label);

	demo->area_x2 = gtk_spin_button_new_with_range (0, 0, 0.01);
        g_signal_connect (demo->area_x2, "value-changed",
                          G_CALLBACK (pgd_text_area_selector_value_changed),
                          demo);
	gtk_box_pack_start (GTK_BOX (area_hbox), demo->area_x2, TRUE, TRUE, 0);
	gtk_widget_show (demo->area_x2);

	gtk_box_pack_start (GTK_BOX (hbox), area_hbox, FALSE, TRUE, 0);
	gtk_widget_show (area_hbox);

        area_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
	label = gtk_label_new ("Y2:");
	gtk_box_pack_start (GTK_BOX (area_hbox), label, TRUE, TRUE, 0);
	gtk_widget_show (label);

	demo->area_y2 = gtk_spin_button_new_with_range (0, 0, 0.01);
        g_signal_connect (demo->area_y2, "value-changed",
                          G_CALLBACK (pgd_text_area_selector_value_changed),
                          demo);
	gtk_box_pack_start (GTK_BOX (area_hbox), demo->area_y2, TRUE, TRUE, 0);
	gtk_widget_show (demo->area_y2);

	gtk_box_pack_start (GTK_BOX (hbox), area_hbox, FALSE, TRUE, 0);
	gtk_widget_show (area_hbox);

        pgd_text_area_selector_setup (demo);

	button = gtk_button_new_with_label ("Get Text");
	g_signal_connect (G_OBJECT (button), "clicked",
			  G_CALLBACK (pgd_text_get_text),
			  (gpointer)demo);
	gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
	gtk_widget_show (button);

	gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
	gtk_widget_show (hbox);

	demo->timer_label = gtk_label_new (NULL);
	gtk_label_set_markup (GTK_LABEL (demo->timer_label), "<i>No text found</i>");
	g_object_set (G_OBJECT (demo->timer_label), "xalign", 1.0, NULL);
	gtk_box_pack_start (GTK_BOX (vbox), demo->timer_label, FALSE, TRUE, 0);
	gtk_widget_show (demo->timer_label);

	hpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
	gtk_paned_set_position (GTK_PANED (hpaned), 300);

	swindow = gtk_scrolled_window_new (NULL, NULL);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
					GTK_POLICY_AUTOMATIC,
					GTK_POLICY_AUTOMATIC);

	demo->model = gtk_list_store_new (N_COLUMNS,
					  G_TYPE_STRING,
					  G_TYPE_STRING, G_TYPE_STRING,
					  G_TYPE_STRING, G_TYPE_STRING,
					  G_TYPE_POINTER);
	treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (demo->model));
        demo->treeview = treeview;

	renderer = gtk_cell_renderer_text_new ();
	gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
						     TEXT_X1_COLUMN, "X1",
						     renderer,
						     "text", TEXT_X1_COLUMN,
						     NULL);
	renderer = gtk_cell_renderer_text_new ();
	gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
						     TEXT_Y1_COLUMN, "Y1",
						     renderer,
						     "text", TEXT_Y1_COLUMN,
						     NULL);
	renderer = gtk_cell_renderer_text_new ();
	gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
						     TEXT_X2_COLUMN, "X2",
						     renderer,
						     "text", TEXT_X2_COLUMN,
						     NULL);
	renderer = gtk_cell_renderer_text_new ();
	gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
						     TEXT_Y2_COLUMN, "Y2",
						     renderer,
						     "text", TEXT_Y2_COLUMN,
						     NULL);

	renderer = gtk_cell_renderer_text_new ();
	gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
						     TEXT_OFFSET_COLUMN, "Offset",
						     renderer,
						     "text", TEXT_OFFSET_COLUMN,
						     NULL);

	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
	g_signal_connect (selection, "changed",
			  G_CALLBACK (pgd_text_selection_changed),
			  (gpointer) demo);

	gtk_container_add (GTK_CONTAINER (swindow), treeview);
	gtk_widget_show (treeview);

        gtk_box_pack_start (GTK_BOX (vbox2), swindow, TRUE, TRUE, 0);
        gtk_widget_show (swindow);

        /* Text attributes */
        frame = gtk_frame_new (NULL);
        gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
        label = gtk_label_new (NULL);
        gtk_label_set_markup (GTK_LABEL (label), "<b>Text Attributes</b>");
        gtk_frame_set_label_widget (GTK_FRAME (frame), label);
        gtk_widget_show (label);

        alignment = gtk_alignment_new (0.5, 0.5, 1, 1);
        gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 5, 5, 12, 5);
        gtk_container_add (GTK_CONTAINER (frame), alignment);
        gtk_widget_show (alignment);

        table = gtk_grid_new ();
        gtk_grid_set_column_spacing (GTK_GRID (table), 6);
        gtk_grid_set_row_spacing (GTK_GRID (table), 6);

        demo->font_name = gtk_label_new (NULL);
        pgd_table_add_property_with_custom_widget (GTK_GRID (table), "<b>Font Name:</b>", demo->font_name, &row);
        demo->font_size = gtk_label_new (NULL);
        pgd_table_add_property_with_custom_widget (GTK_GRID (table), "<b>Font Size:</b>", demo->font_size, &row);
        demo->is_underlined = gtk_label_new (NULL);
        pgd_table_add_property_with_custom_widget (GTK_GRID (table), "<b>Underlined:</b>", demo->is_underlined, &row);
        demo->text_color = gtk_image_new ();
        pgd_table_add_property_with_custom_widget (GTK_GRID (table), "<b>Color:</b>", demo->text_color, &row);

        gtk_container_add (GTK_CONTAINER (alignment), table);
        gtk_widget_show (table);

	gtk_box_pack_start (GTK_BOX (vbox2), frame, FALSE, FALSE, 12);
        gtk_widget_show (frame);
	gtk_paned_add1 (GTK_PANED (hpaned), vbox2);
	gtk_widget_show (vbox2);

	swindow = gtk_scrolled_window_new (NULL, NULL);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
					GTK_POLICY_AUTOMATIC,
					GTK_POLICY_AUTOMATIC);

	demo->buffer = gtk_text_buffer_new (NULL);
	textview = gtk_text_view_new_with_buffer (demo->buffer);
        g_signal_connect (textview, "query-tooltip",
                          G_CALLBACK (pgd_text_view_query_tooltip),
                          demo);
        g_signal_connect (demo->buffer, "notify::has-selection",
                          G_CALLBACK (pgd_text_buffer_selection_changed),
                          textview);

	gtk_container_add (GTK_CONTAINER (swindow), textview);
	gtk_widget_show (textview);

	gtk_paned_add2 (GTK_PANED (hpaned), swindow);
	gtk_widget_show (swindow);

	gtk_box_pack_start (GTK_BOX (vbox), hpaned, TRUE, TRUE, 0);
	gtk_widget_show (hpaned);

	g_object_weak_ref (G_OBJECT (vbox),
			   (GWeakNotify)pgd_text_free,
			   demo);

	return vbox;
}
Beispiel #22
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 #23
0
GtkWidget *
pgd_render_properties_selector_create (PgdRenderDemo *demo)
{
	GtkWidget *hbox, *vbox;
	GtkWidget *label;
	GtkWidget *page_hbox, *page_selector;
	GtkWidget *scale_hbox, *scale_selector;
	GtkWidget *rotate_hbox, *rotate_selector;
	GtkWidget *printing_selector;
	GtkWidget *slice_hbox;
	GtkWidget *button;
	gint       n_pages;
	gchar     *str;

	n_pages = poppler_document_get_n_pages (demo->doc);

	vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);

	hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
	gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
	gtk_widget_show (hbox);

	page_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);

	label = gtk_label_new ("Page:");
	gtk_box_pack_start (GTK_BOX (page_hbox), label, TRUE, TRUE, 0);
	gtk_widget_show (label);

	page_selector = gtk_spin_button_new_with_range (1, n_pages, 1);
	g_signal_connect (G_OBJECT (page_selector), "value-changed",
			  G_CALLBACK (pgd_render_page_selector_value_changed),
			  (gpointer)demo);
	gtk_box_pack_start (GTK_BOX (page_hbox), page_selector, TRUE, TRUE, 0);
	gtk_widget_show (page_selector);

	str = g_strdup_printf ("of %d", n_pages);
	label = gtk_label_new (str);
	gtk_box_pack_start (GTK_BOX (page_hbox), label, TRUE, TRUE, 0);
	gtk_widget_show (label);
	g_free (str);

	gtk_box_pack_start (GTK_BOX (hbox), page_hbox, FALSE, TRUE, 0);
	gtk_widget_show (page_hbox);

	scale_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);

	label = gtk_label_new ("Scale:");
	gtk_box_pack_start (GTK_BOX (scale_hbox), label, TRUE, TRUE, 0);
	gtk_widget_show (label);

	scale_selector = gtk_spin_button_new_with_range (0, 10.0, 0.1);
	gtk_spin_button_set_value (GTK_SPIN_BUTTON (scale_selector), 1.0);
	g_signal_connect (G_OBJECT (scale_selector), "value-changed",
			  G_CALLBACK (pgd_render_scale_selector_value_changed),
			  (gpointer)demo);
	gtk_box_pack_start (GTK_BOX (scale_hbox), scale_selector, TRUE, TRUE, 0);
	gtk_widget_show (scale_selector);

	gtk_box_pack_start (GTK_BOX (hbox), scale_hbox, FALSE, TRUE, 0);
	gtk_widget_show (scale_hbox);

	rotate_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);

	label = gtk_label_new ("Rotate:");
	gtk_box_pack_start (GTK_BOX (rotate_hbox), label, TRUE, TRUE, 0);
	gtk_widget_show (label);

	rotate_selector = gtk_combo_box_text_new ();
	gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (rotate_selector), "0");
	gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (rotate_selector), "90");
	gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (rotate_selector), "180");
	gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (rotate_selector), "270");
	gtk_combo_box_set_active (GTK_COMBO_BOX (rotate_selector), 0);
	g_signal_connect (G_OBJECT (rotate_selector), "changed",
			  G_CALLBACK (pgd_render_rotate_selector_changed),
			  (gpointer)demo);
	gtk_box_pack_start (GTK_BOX (rotate_hbox), rotate_selector, TRUE, TRUE, 0);
	gtk_widget_show (rotate_selector);

	gtk_box_pack_start (GTK_BOX (hbox), rotate_hbox, FALSE, TRUE, 0);
	gtk_widget_show (rotate_hbox);

	printing_selector = gtk_check_button_new_with_label ("Printing");
	g_signal_connect (printing_selector, "toggled",
			  G_CALLBACK (pgd_render_printing_selector_changed),
			  (gpointer)demo);
	gtk_box_pack_start (GTK_BOX (hbox), printing_selector, FALSE, TRUE, 0);
	gtk_widget_show (printing_selector);

	hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
	gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
	gtk_widget_show (hbox);

	slice_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);

	label = gtk_label_new ("x:");
	gtk_box_pack_start (GTK_BOX (slice_hbox), label, TRUE, TRUE, 0);
	gtk_widget_show (label);

	demo->slice_x = gtk_spin_button_new_with_range (0, 0, 1.0);
	g_signal_connect (G_OBJECT (demo->slice_x), "value-changed",
			  G_CALLBACK (pgd_render_slice_selector_value_changed),
			  (gpointer)demo);
	gtk_box_pack_start (GTK_BOX (slice_hbox), demo->slice_x, TRUE, TRUE, 0);
	gtk_widget_show (demo->slice_x);

	gtk_box_pack_start (GTK_BOX (hbox), slice_hbox, FALSE, TRUE, 0);
	gtk_widget_show (slice_hbox);

	slice_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);

	label = gtk_label_new ("y:");
	gtk_box_pack_start (GTK_BOX (slice_hbox), label, TRUE, TRUE, 0);
	gtk_widget_show (label);

	demo->slice_y = gtk_spin_button_new_with_range (0, 0, 1.0);
	g_signal_connect (G_OBJECT (demo->slice_y), "value-changed",
			  G_CALLBACK (pgd_render_slice_selector_value_changed),
			  (gpointer)demo);
	gtk_box_pack_start (GTK_BOX (slice_hbox), demo->slice_y, TRUE, TRUE, 0);
	gtk_widget_show (demo->slice_y);

	gtk_box_pack_start (GTK_BOX (hbox), slice_hbox, FALSE, TRUE, 0);
	gtk_widget_show (slice_hbox);

	slice_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);

	label = gtk_label_new ("width:");
	gtk_box_pack_start (GTK_BOX (slice_hbox), label, TRUE, TRUE, 0);
	gtk_widget_show (label);

	demo->slice_w = gtk_spin_button_new_with_range (0, 0, 1.0);
	g_signal_connect (G_OBJECT (demo->slice_w), "value-changed",
			  G_CALLBACK (pgd_render_slice_selector_value_changed),
			  (gpointer)demo);
	gtk_box_pack_start (GTK_BOX (slice_hbox), demo->slice_w, TRUE, TRUE, 0);
	gtk_widget_show (demo->slice_w);

	gtk_box_pack_start (GTK_BOX (hbox), slice_hbox, FALSE, TRUE, 0);
	gtk_widget_show (slice_hbox);

	slice_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);

	label = gtk_label_new ("height:");
	gtk_box_pack_start (GTK_BOX (slice_hbox), label, TRUE, TRUE, 0);
	gtk_widget_show (label);

	demo->slice_h = gtk_spin_button_new_with_range (0, 0, 1.0);
	g_signal_connect (G_OBJECT (demo->slice_h), "value-changed",
			  G_CALLBACK (pgd_render_slice_selector_value_changed),
			  (gpointer)demo);
	gtk_box_pack_start (GTK_BOX (slice_hbox), demo->slice_h, TRUE, TRUE, 0);
	gtk_widget_show (demo->slice_h);

	gtk_box_pack_start (GTK_BOX (hbox), slice_hbox, FALSE, TRUE, 0);
	gtk_widget_show (slice_hbox);

	pgd_render_slice_selector_setup (demo);

	button = gtk_button_new_with_label ("Render");
	g_signal_connect (G_OBJECT (button), "clicked",
			  G_CALLBACK (pgd_render_start),
			  (gpointer)demo);
	gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, TRUE, 0);
	gtk_widget_show (button);

	demo->timer_label = gtk_label_new (NULL);
	gtk_label_set_markup (GTK_LABEL (demo->timer_label), "<i>No page rendered</i>");
	g_object_set (G_OBJECT (demo->timer_label), "xalign", 1.0, NULL);
	gtk_box_pack_end (GTK_BOX (vbox), demo->timer_label, FALSE, TRUE, 0);
	gtk_widget_show (demo->timer_label);

	return vbox;
}
Beispiel #24
0
/* Main UI */
GtkWidget *
pgd_annots_create_widget (PopplerDocument *document)
{
    PgdAnnotsDemo    *demo;
    GtkWidget        *label;
    GtkWidget        *vbox, *vbox2;
    GtkWidget        *button;
    GtkWidget        *hbox, *page_selector;
    GtkWidget        *hpaned;
    GtkWidget        *swindow, *treeview;
    GtkTreeSelection *selection;
    GtkCellRenderer  *renderer;
    GtkTreeViewColumn *column;
    GtkListStore     *model;
    GtkTreeIter       iter;
    gchar            *str;
    gint              n_pages;
    gint              i;

    demo = g_new0 (PgdAnnotsDemo, 1);

    demo->doc = g_object_ref (document);
    demo->cursor = GDK_LAST_CURSOR;
    demo->mode = MODE_NORMAL;

    n_pages = poppler_document_get_n_pages (document);

    vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
    vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);

    hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);

    label = gtk_label_new ("Page:");
    gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
    gtk_widget_show (label);

    page_selector = gtk_spin_button_new_with_range (1, n_pages, 1);
    g_signal_connect (G_OBJECT (page_selector), "value-changed",
                      G_CALLBACK (pgd_annots_page_selector_value_changed),
                      (gpointer) demo);
    gtk_box_pack_start (GTK_BOX (hbox), page_selector, FALSE, TRUE, 0);
    gtk_widget_show (page_selector);

    str = g_strdup_printf ("of %d", n_pages);
    label = gtk_label_new (str);
    gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
    gtk_widget_show (label);
    g_free (str);

    demo->remove_button = gtk_button_new_with_mnemonic ("_Remove");
    gtk_widget_set_sensitive (demo->remove_button, FALSE);
    g_signal_connect (G_OBJECT (demo->remove_button), "clicked",
                      G_CALLBACK (pgd_annots_remove_annot),
                      (gpointer) demo);
    gtk_box_pack_end (GTK_BOX (hbox), demo->remove_button, FALSE, FALSE, 6);
    gtk_widget_show (demo->remove_button);

    gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);

    button = gtk_button_new_with_mnemonic ("_Add");
    g_signal_connect (G_OBJECT (button), "clicked",
                      G_CALLBACK (pgd_annots_start_add_annot),
                      (gpointer) demo);
    gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
    gtk_widget_show (button);

    model = gtk_list_store_new(SELECTED_N_COLUMNS,
                               G_TYPE_INT, G_TYPE_STRING);

    for (i = 0; i < G_N_ELEMENTS (supported_annots); i++) {
        gtk_list_store_append (model, &iter);
        gtk_list_store_set (model, &iter,
                            SELECTED_TYPE_COLUMN, supported_annots[i].type,
                            SELECTED_LABEL_COLUMN, supported_annots[i].label,
                            -1);
    }

    demo->type_selector = gtk_combo_box_new_with_model (GTK_TREE_MODEL (model));
    g_object_unref (model);

    renderer = gtk_cell_renderer_text_new ();
    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (demo->type_selector), renderer, TRUE);
    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (demo->type_selector), renderer,
                                    "text", SELECTED_LABEL_COLUMN,
                                    NULL);
    gtk_combo_box_set_active (GTK_COMBO_BOX (demo->type_selector), 0);
    gtk_box_pack_end (GTK_BOX (hbox), demo->type_selector, FALSE, FALSE, 0);
    gtk_widget_show (demo->type_selector);

    button = gtk_color_button_new ();
    demo->annot_color.red = 65535;
    demo->annot_color.alpha = 1.0;
#if GTK_CHECK_VERSION(3,4,0)
    gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (button), &demo->annot_color);
#else
    gtk_color_button_set_rgba (GTK_COLOR_BUTTON (button), &demo->annot_color);
#endif
    g_signal_connect (button, "notify::color",
                      G_CALLBACK (pgd_annot_color_changed),
                      (gpointer)demo);
    gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, TRUE, 0);
    gtk_widget_show (button);

    gtk_widget_show (hbox);

    demo->timer_label = gtk_label_new (NULL);
    gtk_label_set_markup (GTK_LABEL (demo->timer_label), "<i>No annotations found</i>");
    g_object_set (G_OBJECT (demo->timer_label), "xalign", 1.0, NULL);
    gtk_box_pack_start (GTK_BOX (vbox), demo->timer_label, FALSE, TRUE, 0);
    gtk_widget_show (demo->timer_label);

    hpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);

    demo->annot_view = pgd_annot_view_new ();

    swindow = gtk_scrolled_window_new (NULL, NULL);
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
                                    GTK_POLICY_AUTOMATIC,
                                    GTK_POLICY_AUTOMATIC);

    demo->model = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING,
                                      GDK_TYPE_PIXBUF, G_TYPE_BOOLEAN,
				      G_TYPE_BOOLEAN, G_TYPE_BOOLEAN,
				      G_TYPE_OBJECT);
    treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (demo->model));
    demo->tree_view = treeview;

    column = gtk_tree_view_column_new ();
    gtk_tree_view_column_set_title (column, "Type");
    gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);

    renderer = gtk_cell_renderer_pixbuf_new ();
    gtk_tree_view_column_pack_start (column, renderer, TRUE);
    gtk_tree_view_column_add_attribute (column, renderer, "pixbuf", ANNOTS_COLOR_COLUMN);

    renderer = gtk_cell_renderer_text_new ();
    gtk_tree_view_column_pack_start (column, renderer, TRUE);
    gtk_tree_view_column_add_attribute (column, renderer, "text", ANNOTS_TYPE_COLUMN);

    renderer = gtk_cell_renderer_toggle_new ();
    g_signal_connect (renderer, "toggled",
		      G_CALLBACK (pgd_annots_invisible_flag_toggled),
		      (gpointer) demo);
    gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
                                                 ANNOTS_FLAG_INVISIBLE_COLUMN, "Invisible",
                                                 renderer,
                                                 "active", ANNOTS_FLAG_INVISIBLE_COLUMN,
                                                 NULL);

    renderer = gtk_cell_renderer_toggle_new ();
    g_signal_connect (renderer, "toggled",
                      G_CALLBACK (pgd_annots_hidden_flag_toggled),
                      (gpointer) demo);
    gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
                                                 ANNOTS_FLAG_HIDDEN_COLUMN, "Hidden",
                                                 renderer,
                                                 "active", ANNOTS_FLAG_HIDDEN_COLUMN,
                                                 NULL);

    renderer = gtk_cell_renderer_toggle_new ();
    g_signal_connect (renderer, "toggled",
                      G_CALLBACK (pgd_annots_print_flag_toggled),
                      (gpointer) demo);
    gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
                                                 ANNOTS_FLAG_PRINT_COLUMN, "Print",
                                                 renderer,
                                                 "active", ANNOTS_FLAG_PRINT_COLUMN,
                                                 NULL);

    selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
    g_signal_connect (G_OBJECT (selection), "changed",
                      G_CALLBACK (pgd_annots_selection_changed),
                      (gpointer) demo);

    /* Annotation's list */
    gtk_container_add (GTK_CONTAINER (swindow), treeview);
    gtk_widget_show (treeview);

    gtk_box_pack_start (GTK_BOX (vbox2), swindow, TRUE, TRUE, 0);
    gtk_widget_show (swindow);

    /* Annotation Properties */
    swindow = gtk_scrolled_window_new (NULL, NULL);
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
                                    GTK_POLICY_AUTOMATIC,
                                    GTK_POLICY_AUTOMATIC);
    gtk_container_add (GTK_CONTAINER (swindow), demo->annot_view);
    gtk_widget_show (demo->annot_view);
    gtk_widget_show (swindow);

    gtk_box_pack_start (GTK_BOX (vbox2), swindow, TRUE, TRUE, 6);
    gtk_widget_show (swindow);

    gtk_paned_add1 (GTK_PANED (hpaned), vbox2);
    gtk_widget_show (vbox2);

    /* Demo Area (Render) */
    demo->darea = gtk_drawing_area_new ();
    g_signal_connect (demo->darea, "draw",
                      G_CALLBACK (pgd_annots_view_drawing_area_draw),
                      demo);
    g_signal_connect (demo->darea, "realize",
                      G_CALLBACK (pgd_annots_drawing_area_realize),
                      (gpointer)demo);
    g_signal_connect (demo->darea, "button_press_event",
                      G_CALLBACK (pgd_annots_drawing_area_button_press),
                      (gpointer)demo);
    g_signal_connect (demo->darea, "motion_notify_event",
                      G_CALLBACK (pgd_annots_drawing_area_motion_notify),
                      (gpointer)demo);
    g_signal_connect (demo->darea, "button_release_event",
                      G_CALLBACK (pgd_annots_drawing_area_button_release),
                      (gpointer)demo);

    swindow = gtk_scrolled_window_new (NULL, NULL);
#if GTK_CHECK_VERSION(3, 7, 8)
    gtk_container_add(GTK_CONTAINER(swindow), demo->darea);
#else
    gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (swindow), demo->darea);
#endif
    gtk_widget_show (demo->darea);

    gtk_paned_add2 (GTK_PANED (hpaned), swindow);
    gtk_widget_show (swindow);

    gtk_paned_set_position (GTK_PANED (hpaned), 300);

    gtk_box_pack_start (GTK_BOX (vbox), hpaned, TRUE, TRUE, 0);
    gtk_widget_show (hpaned);

    g_object_weak_ref (G_OBJECT (vbox),
                       (GWeakNotify)pgd_annots_free,
                       demo);

    pgd_annots_viewer_queue_redraw (demo);
    pgd_annots_get_annots (demo);

    demo->main_box = vbox;

    return vbox;
}
 int getNumOfPages() { return _doc ? poppler_document_get_n_pages(_doc) : 0; }
Beispiel #26
0
GtkWidget *
pgd_forms_create_widget (PopplerDocument *document)
{
	PgdFormsDemo     *demo;
	GtkWidget        *label;
	GtkWidget        *vbox;
	GtkWidget        *hbox, *page_selector;
	GtkWidget        *button;
	GtkWidget        *hpaned;
	GtkWidget        *swindow, *treeview;
	GtkTreeSelection *selection;
	GtkCellRenderer  *renderer;
	gchar            *str;
	gint              n_pages;

	demo = g_new0 (PgdFormsDemo, 1);
	
	demo->doc = g_object_ref (document);
	
	n_pages = poppler_document_get_n_pages (document);

	vbox = gtk_vbox_new (FALSE, 12);

	hbox = gtk_hbox_new (FALSE, 6);

	label = gtk_label_new ("Page:");
	gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
	gtk_widget_show (label);

	page_selector = gtk_spin_button_new_with_range (1, n_pages, 1);
	g_signal_connect (G_OBJECT (page_selector), "value-changed",
			  G_CALLBACK (pgd_forms_page_selector_value_changed),
			  (gpointer)demo);
	gtk_box_pack_start (GTK_BOX (hbox), page_selector, FALSE, TRUE, 0);
	gtk_widget_show (page_selector);

	str = g_strdup_printf ("of %d", n_pages);
	label = gtk_label_new (str);
	gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
	gtk_widget_show (label);
	g_free (str);

	button = gtk_button_new_with_label ("Get Forms Fields");
	g_signal_connect (G_OBJECT (button), "clicked",
			  G_CALLBACK (pgd_forms_get_form_fields),
			  (gpointer)demo);
	gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
	gtk_widget_show (button);

	gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
	gtk_widget_show (hbox);

	demo->timer_label = gtk_label_new (NULL);
	gtk_label_set_markup (GTK_LABEL (demo->timer_label), "<i>No form fields found</i>");
	g_object_set (G_OBJECT (demo->timer_label), "xalign", 1.0, NULL);
	gtk_box_pack_start (GTK_BOX (vbox), demo->timer_label, FALSE, TRUE, 0);
	gtk_widget_show (demo->timer_label);

	hpaned = gtk_hpaned_new ();

	demo->field_view = pgd_form_field_view_new ();

	swindow = gtk_scrolled_window_new (NULL, NULL);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
					GTK_POLICY_AUTOMATIC,
					GTK_POLICY_AUTOMATIC);
	
	demo->model = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING,
					  G_TYPE_INT, G_TYPE_BOOLEAN,
					  G_TYPE_STRING,
					  G_TYPE_STRING, G_TYPE_STRING,
					  G_TYPE_STRING, G_TYPE_OBJECT);
	treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (demo->model));

	renderer = gtk_cell_renderer_text_new ();
	gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
						     0, "Form Field Type",
						     renderer,
						     "text", FORMS_FIELD_TYPE_COLUMN,
						     NULL);
	
	renderer = gtk_cell_renderer_text_new ();
	gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
						     1, "Form Field Id",
						     renderer,
						     "text", FORMS_ID_COLUMN,
						     NULL);
	
	renderer = gtk_cell_renderer_toggle_new ();
	gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
						     2, "Read Only",
						     renderer,
						     "active", FORMS_READ_ONLY_COLUMN,
						     NULL);

	renderer = gtk_cell_renderer_text_new ();
	gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
						     3, "X1",
						     renderer,
						     "text", FORMS_X1_COLUMN,
						     NULL);
	renderer = gtk_cell_renderer_text_new ();
	gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
						     4, "Y1",
						     renderer,
						     "text", FORMS_Y1_COLUMN,
						     NULL);
	renderer = gtk_cell_renderer_text_new ();
	gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
						     5, "X2",
						     renderer,
						     "text", FORMS_X2_COLUMN,
						     NULL);
	renderer = gtk_cell_renderer_text_new ();
	gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
						     6, "Y2",
						     renderer,
						     "text", FORMS_Y2_COLUMN,
						     NULL);
	
	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
	g_signal_connect (G_OBJECT (selection), "changed",
			  G_CALLBACK (pgd_forms_selection_changed),
			  (gpointer)demo);

	gtk_container_add (GTK_CONTAINER (swindow), treeview);
	gtk_widget_show (treeview);

	gtk_paned_add1 (GTK_PANED (hpaned), swindow);
	gtk_widget_show (swindow);

	gtk_paned_add2 (GTK_PANED (hpaned), demo->field_view);
	gtk_widget_show (demo->field_view);

	gtk_paned_set_position (GTK_PANED (hpaned), 300);

	gtk_box_pack_start (GTK_BOX (vbox), hpaned, TRUE, TRUE, 0);
	gtk_widget_show (hpaned);

	g_object_weak_ref (G_OBJECT (vbox),
			   (GWeakNotify)pgd_forms_free,
			   demo);
	
	return vbox;
}
Beispiel #27
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.cache_max = prefs.cache_max;
	runpref.fit_mode = prefs.initial_fit_mode;

	/* get options via getopt */
	while ((i = getopt(argc, argv, "s:wnc:N: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 'c':
				/* don't care if that number is invalid. it'll get
				 * re-adjusted anyway if it's too small. */
				runpref.cache_max = atoi(optarg);
				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);
	}

	/* for the cache to be useful, we'll need at least "some" items.
	 * that is 2 items (prev and next) per preview viewport and 2
	 * items for the beamer port.
	 *
	 * this means that switching to the previous and next slide will
	 * always be fast.
	 *
	 * note: numframes is not negative (see above), so that cast is okay.
	 */
	if (runpref.cache_max < (guint)((numframes + 1) * 2))
		runpref.cache_max = (guint)((numframes + 1) * 2);

	/* 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);
	}

	initGUI(numframes, notefile);

	/* queue initial prerendering. */
	preQueued = TRUE;
	g_idle_add(idleFillCaches, NULL);

	gtk_main();
	exit(EXIT_SUCCESS);
}
Beispiel #28
0
GtkWidget *
pgd_text_create_widget (PopplerDocument *document)
{
	PgdTextDemo *demo;
	GtkWidget   *label;
	GtkWidget   *vbox;
	GtkWidget   *hbox, *page_selector;
	GtkWidget   *button;
	GtkWidget   *swindow, *textview;
	gchar       *str;
	gint         n_pages;

	demo = g_new0 (PgdTextDemo, 1);

	demo->doc = g_object_ref (document);

	n_pages = poppler_document_get_n_pages (document);

	vbox = gtk_vbox_new (FALSE, 12);

	hbox = gtk_hbox_new (FALSE, 6);

	label = gtk_label_new ("Page:");
	gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
	gtk_widget_show (label);

	page_selector = gtk_spin_button_new_with_range (1, n_pages, 1);
	g_signal_connect (G_OBJECT (page_selector), "value-changed",
			  G_CALLBACK (pgd_text_page_selector_value_changed),
			  (gpointer)demo);
	gtk_box_pack_start (GTK_BOX (hbox), page_selector, FALSE, TRUE, 0);
	gtk_widget_show (page_selector);

	str = g_strdup_printf ("of %d", n_pages);
	label = gtk_label_new (str);
	gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
	gtk_widget_show (label);
	g_free (str);

	button = gtk_button_new_with_label ("Get Text");
	g_signal_connect (G_OBJECT (button), "clicked",
			  G_CALLBACK (pgd_text_get_text),
			  (gpointer)demo);
	gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
	gtk_widget_show (button);

	gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
	gtk_widget_show (hbox);

	demo->timer_label = gtk_label_new (NULL);
	gtk_label_set_markup (GTK_LABEL (demo->timer_label), "<i>No text found</i>");
	g_object_set (G_OBJECT (demo->timer_label), "xalign", 1.0, NULL);
	gtk_box_pack_start (GTK_BOX (vbox), demo->timer_label, FALSE, TRUE, 0);
	gtk_widget_show (demo->timer_label);

	swindow = gtk_scrolled_window_new (NULL, NULL);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
					GTK_POLICY_AUTOMATIC,
					GTK_POLICY_AUTOMATIC);
	
	demo->buffer = gtk_text_buffer_new (NULL);
	textview = gtk_text_view_new_with_buffer (demo->buffer);

	gtk_container_add (GTK_CONTAINER (swindow), textview);
	gtk_widget_show (textview);

	gtk_box_pack_start (GTK_BOX (vbox), swindow, TRUE, TRUE, 0);
	gtk_widget_show (swindow);

	g_object_weak_ref (G_OBJECT (vbox),
			   (GWeakNotify)pgd_text_free,
			   demo);

	return vbox;
}
Beispiel #29
0
GtkWidget *
pgd_find_create_widget (PopplerDocument *document)
{
	PgdFindDemo      *demo;
	GtkWidget        *vbox, *hbox;
	GtkWidget        *button;
	GtkWidget        *swindow;
        GtkWidget        *checkbutton;
        GtkTreeModel     *model;
	GtkWidget        *treeview;
	GtkCellRenderer  *renderer;
        GtkWidget        *hpaned;
        GtkTreeSelection *selection;

	demo = g_new0 (PgdFindDemo, 1);

	demo->doc = g_object_ref (document);

	demo->n_pages = poppler_document_get_n_pages (document);
        demo->selected_page = -1;
        demo->options = POPPLER_FIND_DEFAULT;

        hpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
        gtk_paned_set_position (GTK_PANED (hpaned), 300);

	vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);

	hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);

	demo->entry = gtk_entry_new ();
	gtk_box_pack_start (GTK_BOX (hbox), demo->entry, FALSE, TRUE, 0);
	gtk_widget_show (demo->entry);

	demo->progress = gtk_progress_bar_new ();
	gtk_progress_bar_set_ellipsize (GTK_PROGRESS_BAR (demo->progress),
					PANGO_ELLIPSIZE_END);
	gtk_box_pack_start (GTK_BOX (hbox), demo->progress, TRUE, TRUE, 0);
	gtk_widget_show (demo->progress);

	button = gtk_button_new_with_label ("Find");
	gtk_widget_set_sensitive (button, FALSE);
	g_signal_connect (G_OBJECT (button), "clicked",
			  G_CALLBACK (pgd_find_button_clicked),
			  (gpointer)demo);
	g_signal_connect_swapped (G_OBJECT (demo->entry), "changed",
				  G_CALLBACK (pgd_find_button_sensitivity_cb),
				  (gpointer)button);
	gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
	gtk_widget_show (button);

	gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 6);
	gtk_widget_show (hbox);

        hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);

        checkbutton = gtk_check_button_new_with_label ("Case sensitive");
        g_signal_connect (checkbutton, "toggled",
                          G_CALLBACK (pgd_find_case_sensitive_toggled),
                          demo);
        gtk_box_pack_start (GTK_BOX (hbox), checkbutton, FALSE, FALSE, 0);
        gtk_widget_show (checkbutton);

        checkbutton = gtk_check_button_new_with_label ("Backwards");
        g_signal_connect (checkbutton, "toggled",
                          G_CALLBACK (pgd_find_backwards_toggled),
                          demo);
        gtk_box_pack_start (GTK_BOX (hbox), checkbutton, FALSE, FALSE, 0);
        gtk_widget_show (checkbutton);

        checkbutton = gtk_check_button_new_with_label ("Whole words only");
        g_signal_connect (checkbutton, "toggled",
                          G_CALLBACK (pgd_find_whole_words_toggled),
                          demo);
        gtk_box_pack_start (GTK_BOX (hbox), checkbutton, FALSE, FALSE, 0);
        gtk_widget_show (checkbutton);

        gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
        gtk_widget_show (hbox);

	swindow = gtk_scrolled_window_new (NULL, NULL);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
					GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);

	model = pgd_find_create_model ();
	treeview = gtk_tree_view_new_with_model (model);
        g_object_unref (model);
        demo->treeview = treeview;
	gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (treeview), TRUE);
        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
	gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
        g_signal_connect (selection, "changed",
                          G_CALLBACK (pgd_find_selection_changed),
                          demo);

	renderer = gtk_cell_renderer_text_new ();
	gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
						     TITLE_COLUMN, "Matches",
						     renderer,
						     "text", TITLE_COLUMN,
						     NULL);
	
	renderer = gtk_cell_renderer_text_new ();
	gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
						     X1_COLUMN, "X1",
						     renderer,
						     "text", X1_COLUMN,
						     "visible", VISIBLE_COLUMN,
						     NULL);
	renderer = gtk_cell_renderer_text_new ();
	gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
						     Y1_COLUMN, "Y1",
						     renderer,
						     "text", Y1_COLUMN,
						     "visible", VISIBLE_COLUMN,
						     NULL);
	renderer = gtk_cell_renderer_text_new ();
	gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
						     X2_COLUMN, "X2",
						     renderer,
						     "text", X2_COLUMN,
						     "visible", VISIBLE_COLUMN,
						     NULL);
	renderer = gtk_cell_renderer_text_new ();
	gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
						     Y2_COLUMN, "Y2",
						     renderer,
						     "text", Y2_COLUMN,
						     "visible", VISIBLE_COLUMN,
						     NULL);
	gtk_container_add (GTK_CONTAINER (swindow), treeview);
	gtk_widget_show (treeview);

        gtk_paned_add1 (GTK_PANED (hpaned), swindow);
        gtk_widget_show (swindow);

        demo->darea = gtk_drawing_area_new ();
        g_signal_connect (demo->darea, "draw",
                          G_CALLBACK (pgd_find_viewer_drawing_area_draw),
                          demo);

        swindow = gtk_scrolled_window_new (NULL, NULL);
#if GTK_CHECK_VERSION(3, 7, 8)
        gtk_container_add(GTK_CONTAINER(swindow), demo->darea);
#else
        gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (swindow), demo->darea);
#endif
        gtk_widget_show (demo->darea);

        gtk_paned_add2 (GTK_PANED (hpaned), swindow);
        gtk_widget_show (swindow);

        gtk_box_pack_start (GTK_BOX (vbox), hpaned, TRUE, TRUE, 0);
        gtk_widget_show (hpaned);

	g_object_weak_ref (G_OBJECT (vbox),
			   (GWeakNotify)pgd_find_free,
			   (gpointer)demo);

	return vbox;
}
Beispiel #30
0
GtkWidget *
pgd_page_create_widget (PopplerDocument *document)
{
	PgdPageDemo *demo;
	GtkWidget   *vbox;
	GtkWidget   *hbox, *page_selector;
	GtkWidget   *button;
	GtkWidget   *frame, *alignment;
	GtkWidget   *table;
	GtkWidget   *label;
	GtkWidget   *thumnail_box;
	gchar       *str;
	gint         n_pages;
	gint         row = 0;

	demo = g_new0 (PgdPageDemo, 1);

	demo->doc = g_object_ref (document);

	n_pages = poppler_document_get_n_pages (document);

	vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);

	hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);

	label = gtk_label_new ("Page:");
	gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
	gtk_widget_show (label);

	page_selector = gtk_spin_button_new_with_range (1, n_pages, 1);
	g_signal_connect (G_OBJECT (page_selector), "value-changed",
			  G_CALLBACK (pgd_page_page_selector_value_changed),
			  (gpointer)demo);
	gtk_box_pack_start (GTK_BOX (hbox), page_selector, FALSE, TRUE, 0);
	gtk_widget_show (page_selector);

	str = g_strdup_printf ("of %d", n_pages);
	label = gtk_label_new (str);
	gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
	gtk_widget_show (label);
	g_free (str);

	button = gtk_button_new_with_label ("Get Info");
	g_signal_connect (G_OBJECT (button), "clicked",
			  G_CALLBACK (pgd_page_get_info),
			  (gpointer)demo);
	gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
	gtk_widget_show (button);

	gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
	gtk_widget_show (hbox);

	hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);

	frame = gtk_frame_new (NULL);
	gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
	label = gtk_label_new (NULL);
	gtk_label_set_markup (GTK_LABEL (label), "<b>Page Properties</b>");
	gtk_frame_set_label_widget (GTK_FRAME (frame), label);
	gtk_widget_show (label);

	alignment = gtk_alignment_new (0.5, 0.5, 1, 1);
	gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 5, 5, 12, 5);
	gtk_container_add (GTK_CONTAINER (frame), alignment);
	gtk_widget_show (alignment);

	table = gtk_grid_new ();
	gtk_grid_set_column_spacing (GTK_GRID (table), 6);
	gtk_grid_set_row_spacing (GTK_GRID (table), 6);

	pgd_table_add_property_with_value_widget (GTK_GRID (table), "<b>Page Index:</b>",
						  &(demo->index), NULL, &row);
	pgd_table_add_property_with_value_widget (GTK_GRID (table), "<b>Page Label:</b>",
						  &(demo->label), NULL, &row);
	pgd_table_add_property_with_value_widget (GTK_GRID (table), "<b>Page Size:</b>",
						  &(demo->size), NULL, &row);
	pgd_table_add_property_with_value_widget (GTK_GRID (table), "<b>Page Duration:</b>",
						  &(demo->duration), NULL, &row);

	gtk_container_add (GTK_CONTAINER (alignment), table);
	gtk_widget_show (table);

	gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
	gtk_widget_show (frame);

	frame = gtk_frame_new (NULL);
	gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
	gtk_frame_set_label_align (GTK_FRAME (frame), 0.5, 0.5);
	label = gtk_label_new (NULL);
	gtk_label_set_markup (GTK_LABEL (label), "<b>Page Thumbnail</b>");
	gtk_frame_set_label_widget (GTK_FRAME (frame), label);
	gtk_widget_show (label);

	alignment = gtk_alignment_new (0.5, 0.5, 1, 1);
	gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 5, 5, 12, 5);
	gtk_container_add (GTK_CONTAINER (frame), alignment);
	gtk_widget_show (alignment);
	
	thumnail_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
	
	demo->thumbnail = gtk_image_new ();
	gtk_box_pack_start (GTK_BOX (thumnail_box), demo->thumbnail, TRUE, TRUE, 0);
	gtk_widget_show (demo->thumbnail);
	
	demo->thumbnail_size = gtk_label_new (NULL);
	g_object_set (G_OBJECT (demo->thumbnail_size), "xalign", 0.5, NULL);
	gtk_box_pack_start (GTK_BOX (thumnail_box), demo->thumbnail_size, TRUE, TRUE, 0);
	gtk_widget_show (demo->thumbnail_size);

	gtk_container_add (GTK_CONTAINER (alignment), thumnail_box);
	gtk_widget_show (thumnail_box);

	gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
	gtk_widget_show (frame);
	
	gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
	gtk_widget_show (hbox);

	g_object_weak_ref (G_OBJECT (vbox),
			   (GWeakNotify)pgd_page_free,
			   (gpointer)demo);
	
	return vbox;
}