Esempio n. 1
0
static void
print_operation_set_name (GtkPrintOperation *operation,
                          gint               image_ID)
{
  gchar *name = gimp_image_get_name (image_ID);

  gtk_print_operation_set_job_name (operation, name);

  g_free (name);
}
Esempio n. 2
0
File: print.c Progetto: pwmt/zathura
void
print(zathura_t* zathura)
{
  g_return_if_fail(zathura           != NULL);
  g_return_if_fail(zathura->document != NULL);

  GtkPrintOperation* print_operation = gtk_print_operation_new();

  /* print operation settings */
  gtk_print_operation_set_job_name(print_operation, zathura_document_get_path(zathura->document));
  gtk_print_operation_set_allow_async(print_operation, TRUE);
  gtk_print_operation_set_n_pages(print_operation, zathura_document_get_number_of_pages(zathura->document));
  gtk_print_operation_set_current_page(print_operation, zathura_document_get_current_page_number(zathura->document));
  gtk_print_operation_set_use_full_page(print_operation, TRUE);

  if (zathura->print.settings != NULL) {
    gtk_print_operation_set_print_settings(print_operation,
                                           zathura->print.settings);
  }

  if (zathura->print.page_setup != NULL) {
    gtk_print_operation_set_default_page_setup(print_operation,
                                               zathura->print.page_setup);
  }
  gtk_print_operation_set_embed_page_setup(print_operation, TRUE);

  /* print operation signals */
  g_signal_connect(print_operation, "draw-page",          G_CALLBACK(cb_print_draw_page),          zathura);
  g_signal_connect(print_operation, "end-print",          G_CALLBACK(cb_print_end),                zathura);
  g_signal_connect(print_operation, "request-page-setup", G_CALLBACK(cb_print_request_page_setup), zathura);

  /* print */
  GError* error = NULL;
  GtkPrintOperationResult result = gtk_print_operation_run(print_operation,
                                   GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
                                   GTK_WINDOW(zathura->ui.session->gtk.window), &error);

  if (result == GTK_PRINT_OPERATION_RESULT_ERROR) {
    girara_notify(zathura->ui.session, GIRARA_ERROR, _("Printing failed: %s"),
                  error->message);
    g_error_free(error);
  } else if (result == GTK_PRINT_OPERATION_RESULT_APPLY) {
    g_clear_object(&zathura->print.settings);
    g_clear_object(&zathura->print.page_setup);

    /* save previous settings */
    zathura->print.settings   = g_object_ref(gtk_print_operation_get_print_settings(print_operation));
    zathura->print.page_setup = g_object_ref(gtk_print_operation_get_default_page_setup(print_operation));
  }

  g_object_unref(print_operation);
}
static void
photos_print_operation_constructed (GObject *object)
{
  PhotosPrintOperation *self = PHOTOS_PRINT_OPERATION (object);
  GeglRectangle bbox;
  GtkPageSetup *page_setup;
  gchar *name;

  G_OBJECT_CLASS (photos_print_operation_parent_class)->constructed (object);

  page_setup = gtk_page_setup_new ();
  gtk_print_operation_set_default_page_setup (GTK_PRINT_OPERATION (self), page_setup);

  bbox = gegl_node_get_bounding_box (self->node);
  if (bbox.height >= bbox.width)
    gtk_page_setup_set_orientation (page_setup, GTK_PAGE_ORIENTATION_PORTRAIT);
  else
    gtk_page_setup_set_orientation (page_setup, GTK_PAGE_ORIENTATION_LANDSCAPE);

  g_object_unref (page_setup);

  name = g_strdup (photos_base_item_get_name (self->item));
  if (name == NULL || name[0] == '\0')
    {
      GFile *file;
      const gchar *uri;
      gchar *basename;

      uri = photos_base_item_get_uri (self->item);
      file = g_file_new_for_uri (uri);
      basename = g_file_get_basename (file);

      if (g_utf8_validate (basename, -1, NULL))
        name = g_strdup (basename);
      else
        name = g_filename_to_utf8 (basename, -1, NULL, NULL, NULL);

      g_free (basename);
      g_object_unref (file);
    }

  gtk_print_operation_set_job_name (GTK_PRINT_OPERATION (self), name);
  g_free (name);
}
Esempio n. 4
0
void
gnc_print_operation_init(GtkPrintOperation *op, const gchar* jobname)
{
    g_return_if_fail(op);

    /* Restore print settings */
    G_LOCK(print_settings);
    if (print_settings)
        gtk_print_operation_set_print_settings(op, print_settings);
    G_UNLOCK(print_settings);

    /* Restore page setup */
    G_LOCK(page_setup);
    if (page_setup)
        gtk_print_operation_set_default_page_setup(op, page_setup);
    G_UNLOCK(page_setup);

    gtk_print_operation_set_job_name ( op, jobname);
}
Esempio n. 5
0
GtkPrintOperation *
biorhythm_print_operation_new (BiorhythmChart *chart)
{
	GtkPrintOperation *print;
	GtkPageSetup *page_setup;

	print = gtk_print_operation_new ();
	gtk_print_operation_set_n_pages (print, 1);
	gtk_print_operation_set_job_name (print, "Print Biorhythm");
	gtk_print_operation_set_embed_page_setup (print, FALSE);

	page_setup = gtk_page_setup_new ();
	gtk_page_setup_set_orientation (page_setup, GTK_PAGE_ORIENTATION_LANDSCAPE);
	gtk_print_operation_set_default_page_setup (print, page_setup);

	g_signal_connect (print, "draw_page", G_CALLBACK (biorhythm_print_draw_page), chart);

	return print;
}
Esempio n. 6
0
GtkPrintOperation *
create_print_operation (DiagramData *data, const char *name)
{
  PrintData *print_data;
  GtkPrintOperation *operation;
  GtkPageSetup * setup;
  int num_pages;

  /* gets deleted in end_print */
  print_data = g_new0 (PrintData, 1);
  print_data->data = g_object_ref (data);
  print_data->renderer = g_object_new (DIA_TYPE_CAIRO_RENDERER, NULL);
  
  operation = gtk_print_operation_new ();
  
  gtk_print_operation_set_job_name (operation, name);

  setup = gtk_print_operation_get_default_page_setup (operation);
  if (!setup)
    setup = gtk_page_setup_new ();
  _dia_to_gtk_page_setup (print_data->data, setup);
  gtk_print_operation_set_default_page_setup (operation, setup);
  g_object_unref (setup);

  /* similar logic draw_page() but we need to set the total pages in advance */
  if (data->paper.fitto) {
    num_pages = data->paper.fitwidth * data->paper.fitheight;
  } else {
    int nx = ceil((data->extents.right - data->extents.left) / data->paper.width);
    int ny = ceil((data->extents.bottom - data->extents.top) / data->paper.height);
    num_pages = nx * ny;
  }
  gtk_print_operation_set_n_pages (operation, num_pages);

  gtk_print_operation_set_unit (operation, GTK_UNIT_MM);

  g_signal_connect (operation, "draw_page", G_CALLBACK (draw_page), print_data);
  g_signal_connect (operation, "begin_print", G_CALLBACK (begin_print), print_data);
  g_signal_connect (operation, "end_print", G_CALLBACK (end_print), print_data);
  
  return operation;
}
Esempio n. 7
0
Print::Print(SPDocument *doc, SPItem *base) :
    _doc (doc),
    _base (base)
{
    g_assert (_doc);
    g_assert (_base);

    _printop = gtk_print_operation_new ();

    // set up dialog title, based on document name
    gchar *jobname = _doc->name ? _doc->name : _("SVG Document");
    Glib::ustring title = _("Print");
    title += " ";
    title += jobname;
    gtk_print_operation_set_job_name (_printop, title.c_str());

    // set up paper size to match the document size
    gtk_print_operation_set_unit (_printop, GTK_UNIT_POINTS);
    GtkPageSetup *page_setup = gtk_page_setup_new();
    gdouble doc_width = sp_document_width(_doc) * PT_PER_PX;
    gdouble doc_height = sp_document_height(_doc) * PT_PER_PX;
    GtkPaperSize *paper_size = gtk_paper_size_new_custom("custom", "custom",
                                doc_width, doc_height, GTK_UNIT_POINTS);
    gtk_page_setup_set_paper_size (page_setup, paper_size);
#ifndef WIN32
    gtk_print_operation_set_default_page_setup (_printop, page_setup);
#endif
    gtk_print_operation_set_use_full_page (_printop, TRUE);

    // set up signals
    _workaround._doc = _doc;
    _workaround._base = _base;
    _workaround._tab = &_tab;
    g_signal_connect (_printop, "create-custom-widget", G_CALLBACK (create_custom_widget), _tab.gobj());
    g_signal_connect (_printop, "begin-print", G_CALLBACK (begin_print), NULL);
    g_signal_connect (_printop, "draw-page", G_CALLBACK (draw_page), &_workaround);

    // build custom preferences tab
    gtk_print_operation_set_custom_tab_label (_printop, _("Rendering"));
}
Esempio n. 8
0
gint
yad_print_run (void)
{
  GtkWidget *dlg;
  GtkWidget *box, *img, *lbl;
  gchar *uri, *job_name = NULL;
  GtkPrintCapabilities pcap;
  GtkPrintOperationAction act = GTK_PRINT_OPERATION_ACTION_PRINT;
  gint resp, ret = 0;
  GError *err = NULL;

  /* check if file is exists */
  if (options.common_data.uri && options.common_data.uri[0])
    {
      if (!g_file_test (options.common_data.uri, G_FILE_TEST_EXISTS))
        {
          g_printerr (_("File %s not found.\n"), options.common_data.uri);
          return 1;
        }
    }
  else
    {
      g_printerr (_("Filename is not specified.\n"));
      return 1;
    }

  /* create print dialog */
  dlg = gtk_print_unix_dialog_new (options.data.dialog_title, NULL);
  gtk_window_set_type_hint (GTK_WINDOW (dlg), GDK_WINDOW_TYPE_HINT_NORMAL);
  gtk_print_unix_dialog_set_embed_page_setup (GTK_PRINT_UNIX_DIALOG (dlg), TRUE);
  pcap = GTK_PRINT_CAPABILITY_PAGE_SET | GTK_PRINT_CAPABILITY_COPIES |
    GTK_PRINT_CAPABILITY_COLLATE | GTK_PRINT_CAPABILITY_REVERSE |
    GTK_PRINT_CAPABILITY_NUMBER_UP | GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT;
  if (options.common_data.preview && options.print_data.type != YAD_PRINT_RAW)
    pcap |= GTK_PRINT_CAPABILITY_PREVIEW;
  gtk_print_unix_dialog_set_manual_capabilities (GTK_PRINT_UNIX_DIALOG (dlg), pcap);

  if (!settings.print_settings)
    settings.print_settings = gtk_print_unix_dialog_get_settings (GTK_PRINT_UNIX_DIALOG (dlg));

  uri = g_build_filename (g_get_current_dir (), "yad.pdf", NULL);
  gtk_print_settings_set (settings.print_settings, "output-uri", g_filename_to_uri (uri, NULL, NULL));
  g_free (uri);

  gtk_print_unix_dialog_set_settings (GTK_PRINT_UNIX_DIALOG (dlg), settings.print_settings);

  if (settings.page_setup)
    gtk_print_unix_dialog_set_page_setup (GTK_PRINT_UNIX_DIALOG (dlg), settings.page_setup);

  /* set window behavior */
  gtk_widget_set_name (dlg, "yad-dialog-window");
  if (options.data.sticky)
    gtk_window_stick (GTK_WINDOW (dlg));
  gtk_window_set_resizable (GTK_WINDOW (dlg), !options.data.fixed);
  gtk_window_set_keep_above (GTK_WINDOW (dlg), options.data.ontop);
  gtk_window_set_decorated (GTK_WINDOW (dlg), !options.data.undecorated);
  gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dlg), options.data.skip_taskbar);
  gtk_window_set_skip_pager_hint (GTK_WINDOW (dlg), options.data.skip_taskbar);

  /* set window size and position */
  if (!options.data.geometry)
    {
      gtk_window_set_default_size (GTK_WINDOW (dlg), options.data.width, options.data.height);
      if (options.data.center)
        gtk_window_set_position (GTK_WINDOW (dlg), GTK_WIN_POS_CENTER);
      else if (options.data.mouse)
        gtk_window_set_position (GTK_WINDOW (dlg), GTK_WIN_POS_MOUSE);
    }
  else
    {
      /* parse geometry, if given. must be after showing widget */
      gtk_widget_realize (dlg);
      gtk_window_parse_geometry (GTK_WINDOW (dlg), options.data.geometry);
    }

  /* create yad's top box */
  if (options.data.dialog_text || options.data.dialog_image)
    {
#if !GTK_CHECK_VERSION(3,0,0)
      box = gtk_hbox_new (FALSE, 0);
#else
      box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
#endif

      if (options.data.dialog_image)
        {
          GdkPixbuf *pb = NULL;

          pb = get_pixbuf (options.data.dialog_image, YAD_BIG_ICON);
          img = gtk_image_new_from_pixbuf (pb);
          if (pb)
            g_object_unref (pb);

          gtk_widget_set_name (img, "yad-dialog-image");
          gtk_box_pack_start (GTK_BOX (box), img, FALSE, FALSE, 2);
        }
      if (options.data.dialog_text)
        {
          gchar *buf = g_strcompress (options.data.dialog_text);

          lbl = gtk_label_new (NULL);
          if (!options.data.no_markup)
            gtk_label_set_markup (GTK_LABEL (lbl), buf);
          else
            gtk_label_set_text (GTK_LABEL (lbl), buf);
          gtk_widget_set_name (lbl, "yad-dialog-label");
          gtk_label_set_selectable (GTK_LABEL (lbl), options.data.selectable_labels);
          gtk_misc_set_alignment (GTK_MISC (lbl), options.data.text_align, 0.5);
          if (options.data.geometry || options.data.width != -1)
            gtk_label_set_line_wrap (GTK_LABEL (lbl), TRUE);
          gtk_box_pack_start (GTK_BOX (box), lbl, TRUE, TRUE, 2);
          g_signal_connect (G_OBJECT (lbl), "size-allocate", G_CALLBACK (size_allocate_cb), NULL);
          g_free (buf);
        }

      /* add tob box to dialog */
      gtk_widget_show_all (box);
      gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), box, TRUE, TRUE, 5);
      gtk_box_reorder_child (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), box, 0);
    }

  do
    {
      resp = gtk_dialog_run (GTK_DIALOG (dlg));
      switch (resp)
        {
        case GTK_RESPONSE_APPLY:   /* ask for preview */
          act = GTK_PRINT_OPERATION_ACTION_PREVIEW;
        case GTK_RESPONSE_OK:      /* run print */
          settings.print_settings = gtk_print_unix_dialog_get_settings (GTK_PRINT_UNIX_DIALOG (dlg));
          settings.page_setup = gtk_print_unix_dialog_get_page_setup (GTK_PRINT_UNIX_DIALOG (dlg));
          job_name = g_strdup_printf ("yad-%s-%d", g_path_get_basename (options.common_data.uri), getpid ());
          if (options.print_data.type != YAD_PRINT_RAW)
            {
              /* print text or image */
              GtkPrintOperation *op = gtk_print_operation_new ();
              gtk_print_operation_set_unit (op, GTK_UNIT_POINTS);
              gtk_print_operation_set_print_settings (op, settings.print_settings);
              gtk_print_operation_set_default_page_setup (op, settings.page_setup);
              gtk_print_operation_set_job_name (op, job_name);

              switch (options.print_data.type)
                {
                case YAD_PRINT_TEXT:
                  g_signal_connect (G_OBJECT (op), "begin-print", G_CALLBACK (begin_print_text), NULL);
                  g_signal_connect (G_OBJECT (op), "draw-page", G_CALLBACK (draw_page_text), NULL);
                  break;
                case YAD_PRINT_IMAGE:
                  gtk_print_operation_set_n_pages (op, 1);
                  g_signal_connect (G_OBJECT (op), "draw-page", G_CALLBACK (draw_page_image), NULL);
                  break;
                default:;
                }

              if (gtk_print_operation_run (op, act, NULL, &err) == GTK_PRINT_OPERATION_RESULT_ERROR)
                {
                  g_printerr (_("Printing failed: %s\n"), err->message);
                  ret = 1;
                }
            }
          else
            {
              /* print raw ps or pdf data */
              GtkPrinter *prnt;
              GtkPrintJob *job;

              prnt = gtk_print_unix_dialog_get_selected_printer (GTK_PRINT_UNIX_DIALOG (dlg));

              if (g_str_has_suffix (options.common_data.uri, ".ps"))
                {
                  if (!gtk_printer_accepts_ps (prnt))
                    {
                      g_printerr (_("Printer doesn't support ps format.\n"));
                      ret = 1;
                    }
                }
              else if (g_str_has_suffix (options.common_data.uri, ".pdf"))
                {
                  if (!gtk_printer_accepts_pdf (prnt))
                    {
                      g_printerr (_("Printer doesn't support pdf format.\n"));
                      ret = 1;
                    }
                }
              else
                {
                  g_printerr (_("This file type is not supported for raw printing.\n"));
                  ret = 1;
                }
              if (ret == 1)
                break;

              job = gtk_print_job_new (job_name, prnt, settings.print_settings, settings.page_setup);
              if (gtk_print_job_set_source_file (job, options.common_data.uri, &err))
                {
                  gtk_print_job_send (job, (GtkPrintJobCompleteFunc) raw_print_done, &ret, NULL);
                  gtk_main ();
                }
              else
                {
                  g_printerr (_("Load source file failed: %s\n"), err->message);
                  ret = 1;
                }
            }
          break;
        default:
          ret = 1;
          break;
        }
    }
  while (resp == GTK_RESPONSE_APPLY);

  gtk_widget_destroy (dlg);
  write_settings ();
  return ret;
}
Esempio n. 9
0
GtkPrintOperation *
xviewer_print_operation_new (XviewerImage *image,
                             GtkPrintSettings *print_settings,
                             GtkPageSetup *page_setup)
{
    GtkPrintOperation *print;
    XviewerPrintData *data;
    gint width, height;

    xviewer_debug (DEBUG_PRINTING);

    print = gtk_print_operation_new ();

    data = g_slice_new0 (XviewerPrintData);

    data->left_margin = 0;
    data->top_margin = 0;
    data->scale_factor = 100;
    data->image = g_object_ref (image);
    data->unit = GTK_UNIT_INCH;

    xviewer_image_get_size (image, &width, &height);

    if (page_setup == NULL)
        page_setup = gtk_page_setup_new ();

    if (height >= width) {
        gtk_page_setup_set_orientation (page_setup,
                                        GTK_PAGE_ORIENTATION_PORTRAIT);
    } else {
        gtk_page_setup_set_orientation (page_setup,
                                        GTK_PAGE_ORIENTATION_LANDSCAPE);
    }

    gtk_print_operation_set_print_settings (print, print_settings);
    gtk_print_operation_set_default_page_setup (print,
            page_setup);
    gtk_print_operation_set_n_pages (print, 1);
    gtk_print_operation_set_job_name (print,
                                      xviewer_image_get_caption (image));
    gtk_print_operation_set_embed_page_setup (print, TRUE);

    g_signal_connect (print, "draw_page",
                      G_CALLBACK (xviewer_print_draw_page),
                      data);
    g_signal_connect (print, "create-custom-widget",
                      G_CALLBACK (xviewer_print_create_custom_widget),
                      data);
    g_signal_connect (print, "custom-widget-apply",
                      G_CALLBACK (xviewer_print_custom_widget_apply),
                      data);
    g_signal_connect (print, "end-print",
                      G_CALLBACK (xviewer_print_end_print),
                      data);
    g_signal_connect (print, "update-custom-widget",
                      G_CALLBACK (xviewer_print_image_setup_update),
                      data);

    gtk_print_operation_set_custom_tab_label (print, _("Image Settings"));

    return print;
}
Esempio n. 10
0
 int PrintText(const char *name, gchar *text)
 {
	GKeyFile			*conf	= GetConf();
 	GtkPrintOperation	*prt;
 	const gchar		*font;
	GtkPageSetup 		*page_setup = NULL;
	GtkPrintSettings 	*print_settings = NULL;

 	if(!text)
		return -EINVAL;

 	prt = gtk_print_operation_new();

 	if(!prt)
 		return -1;

	// Set job parameters
	g_object_set_data_full(G_OBJECT(prt),"3270Text",g_strsplit(g_strchomp(text),"\n",-1),(void (*)(gpointer)) g_strfreev);

	// Set print
	font = GetString("Print","Font","");
	if(!*font)
		font = GetString("Terminal","Font","Courier");

	g_object_set_data_full(G_OBJECT(prt),"3270FontName",g_strdup(font),g_free);

	// Configure print operation
	gtk_print_operation_set_job_name(prt,name);
	gtk_print_operation_set_allow_async(prt,0);
	gtk_print_operation_set_show_progress(prt,1);

	gtk_print_operation_set_custom_tab_label(prt,_( "Font" ));
	g_signal_connect(prt, "begin-print",    		G_CALLBACK(begin_print), 			0);
    g_signal_connect(prt, "draw-page",      		G_CALLBACK(draw_page),   			0);
#ifdef HAVE_PRINT_FONT_DIALOG
	g_signal_connect(prt, "create-custom-widget",   G_CALLBACK(create_custom_widget),	0);
	g_signal_connect(prt, "custom-widget-apply",   	G_CALLBACK(custom_widget_apply),	0);
#endif
    g_signal_connect(prt, "done",      				G_CALLBACK(print_done),	 			0);

	if(conf)
	{
#if GTK_CHECK_VERSION(2,12,0)
		gchar *ptr = g_key_file_get_string(conf,"Print Settings","output-uri",NULL);
		if(ptr)
		{
			gchar *uri = NULL;

			switch(*(ptr++))
			{
			case '$':
				if(g_str_has_prefix(ptr,"home/"))
					uri = g_strdup_printf("file:///%s/%s",g_get_home_dir(),ptr+5);
#if GTK_CHECK_VERSION(2,14,0)
				else if(g_str_has_prefix(ptr,"documents/"))
					uri = g_strdup_printf("file:///%s/%s",g_get_user_special_dir(G_USER_DIRECTORY_DOCUMENTS),ptr+10);
				else if(g_str_has_prefix(ptr,"desktop/"))
					uri = g_strdup_printf("file:///%s/%s",g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP),ptr+8);
#endif
				break;

			case '~':
				uri = g_strdup_printf("file:///%s/%s",g_get_home_dir(),ptr);
				break;

			}

			if(uri)
			{
				g_key_file_set_string(conf,"Print Settings","output-uri",uri);
				g_free(uri);
			}
		}

		print_settings = gtk_print_settings_new_from_key_file(conf,NULL,NULL);
		page_setup = gtk_page_setup_new_from_key_file(conf,NULL,NULL);

		if(!page_setup)
			page_setup = gtk_page_setup_new();

#else // GTK_CHECK_VERSION(2,12,0)
		print_settings = gtk_print_settings_new();
		if(print_settings)
		{
			gchar 				**list;
			int 				f;

			list = g_key_file_get_keys(conf,"PrintSettings",NULL,NULL);
			if(list)
			{
				for(f=0;list[f];f++)
					gtk_print_settings_set(print_settings,list[f],g_key_file_get_string(conf,"PrintSettings",list[f],NULL));
				g_strfreev(list);
			}
		}
		page_setup = gtk_page_setup_new();
#endif
	}
	else
	{
		page_setup = gtk_page_setup_new();
		gtk_print_operation_set_print_settings(prt,gtk_print_settings_new());
	}

	Trace("page_setup: %p print_settings: %p",page_setup,print_settings);
	gtk_print_operation_set_print_settings(prt,print_settings);
	gtk_print_operation_set_default_page_setup(prt,page_setup);


	// Run Print dialog
	gtk_print_operation_run(prt,GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,GTK_WINDOW(topwindow),NULL);

    g_object_unref(prt);

    return 0;
 }