Exemplo n.º 1
0
NS_IMETHODIMP
nsPrintSettingsGTK::SetPaperName(const char16_t * aPaperName)
{
    NS_ConvertUTF16toUTF8 gtkPaperName(aPaperName);

    // Convert these Goanna names to GTK names
    if (gtkPaperName.EqualsIgnoreCase("letter"))
        gtkPaperName.AssignLiteral(GTK_PAPER_NAME_LETTER);
    else if (gtkPaperName.EqualsIgnoreCase("legal"))
        gtkPaperName.AssignLiteral(GTK_PAPER_NAME_LEGAL);

    // Try to get the display name from the name so our paper size fits in the Page Setup dialog.
    GtkPaperSize* paperSize = gtk_paper_size_new(gtkPaperName.get());
    char* displayName = strdup(gtk_paper_size_get_display_name(paperSize));
    gtk_paper_size_free(paperSize);

    paperSize = gtk_paper_size_new_custom(gtkPaperName.get(), displayName,
                                          gtk_paper_size_get_width(mPaperSize, GTK_UNIT_INCH),
                                          gtk_paper_size_get_height(mPaperSize, GTK_UNIT_INCH),
                                          GTK_UNIT_INCH);

    free(displayName);
    gtk_paper_size_free(mPaperSize);
    mPaperSize = paperSize;
    SaveNewPageSize();
    return NS_OK;
}
Exemplo n.º 2
0
static void
preview_got_page_size (GtkPrintOperationPreview *preview, 
		       GtkPrintContext          *context,
		       GtkPageSetup             *page_setup,
		       gpointer                  data)
{
  PreviewOp *pop = data;
  GtkPaperSize *paper_size;
  double w, h;
  cairo_t *cr;
  gdouble dpi_x, dpi_y;

  paper_size = gtk_page_setup_get_paper_size (page_setup);

  w = gtk_paper_size_get_width (paper_size, GTK_UNIT_INCH);
  h = gtk_paper_size_get_height (paper_size, GTK_UNIT_INCH);

  cr = gdk_cairo_create (pop->area->window);

  dpi_x = pop->area->allocation.width/w;
  dpi_y = pop->area->allocation.height/h;

  if (fabs (dpi_x - pop->dpi_x) > 0.001 ||
      fabs (dpi_y - pop->dpi_y) > 0.001)
    {
      gtk_print_context_set_cairo_context (context, cr, dpi_x, dpi_y);
      pop->dpi_x = dpi_x;
      pop->dpi_y = dpi_y;
    }

  pango_cairo_update_layout (cr, pop->data->layout);
  cairo_destroy (cr);
}
Exemplo n.º 3
0
/* attribute double paperWidth; */
NS_IMETHODIMP
nsPrintSettingsGTK::GetPaperWidth(double *aPaperWidth)
{
    NS_ENSURE_ARG_POINTER(aPaperWidth);
    *aPaperWidth = gtk_paper_size_get_width(mPaperSize, GetGTKUnit(mPaperSizeUnit));
    return NS_OK;
}
Exemplo n.º 4
0
NS_IMETHODIMP
nsPrintSettingsGTK::SetPaperHeight(double aPaperHeight)
{
    gtk_paper_size_set_size(mPaperSize,
                            gtk_paper_size_get_width(mPaperSize, GetGTKUnit(mPaperSizeUnit)),
                            aPaperHeight,
                            GetGTKUnit(mPaperSizeUnit));
    SaveNewPageSize();
    return NS_OK;
}
Exemplo n.º 5
0
static
GtkPaperSize* moz_gtk_paper_size_copy_to_new_custom(GtkPaperSize* oldPaperSize)
{
    // We make a "custom-ified" copy of the paper size so it can be changed later.
    return gtk_paper_size_new_custom(gtk_paper_size_get_name(oldPaperSize),
                                     gtk_paper_size_get_display_name(oldPaperSize),
                                     gtk_paper_size_get_width(oldPaperSize, GTK_UNIT_INCH),
                                     gtk_paper_size_get_height(oldPaperSize, GTK_UNIT_INCH),
                                     GTK_UNIT_INCH);
}
Exemplo n.º 6
0
static void
unix_start_page (GtkPrintOperation *op,
		 GtkPrintContext   *print_context,
		 GtkPageSetup      *page_setup)
{
  GtkPrintOperationUnix *op_unix;  
  GtkPaperSize *paper_size;
  cairo_surface_type_t type;
  gdouble w, h;

  op_unix = op->priv->platform_data;
  
  paper_size = gtk_page_setup_get_paper_size (page_setup);

  w = gtk_paper_size_get_width (paper_size, GTK_UNIT_POINTS);
  h = gtk_paper_size_get_height (paper_size, GTK_UNIT_POINTS);
  
  type = cairo_surface_get_type (op_unix->surface);

  if ((op->priv->manual_number_up < 2) ||
      (op->priv->page_position % op->priv->manual_number_up == 0))
    {
      if (type == CAIRO_SURFACE_TYPE_PS)
        {
          cairo_ps_surface_set_size (op_unix->surface, w, h);
          cairo_ps_surface_dsc_begin_page_setup (op_unix->surface);
          switch (gtk_page_setup_get_orientation (page_setup))
            {
              case GTK_PAGE_ORIENTATION_PORTRAIT:
              case GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT:
                cairo_ps_surface_dsc_comment (op_unix->surface, "%%PageOrientation: Portrait");
                break;

              case GTK_PAGE_ORIENTATION_LANDSCAPE:
              case GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE:
                cairo_ps_surface_dsc_comment (op_unix->surface, "%%PageOrientation: Landscape");
                break;
            }
         }
      else if (type == CAIRO_SURFACE_TYPE_PDF)
        {
          if (!op->priv->manual_orientation)
            {
              w = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_POINTS);
              h = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_POINTS);
            }
          cairo_pdf_surface_set_size (op_unix->surface, w, h);
        }
    }
}
Exemplo n.º 7
0
NS_IMETHODIMP
nsPrintSettingsGTK::SetPaperSizeUnit(int16_t aPaperSizeUnit)
{
    // Convert units internally. e.g. they might have set the values while we're still in mm but
    // they change to inch just afterwards, expecting that their sizes are in inches.
    gtk_paper_size_set_size(mPaperSize,
                            gtk_paper_size_get_width(mPaperSize, GetGTKUnit(mPaperSizeUnit)),
                            gtk_paper_size_get_height(mPaperSize, GetGTKUnit(mPaperSizeUnit)),
                            GetGTKUnit(aPaperSizeUnit));
    SaveNewPageSize();

    mPaperSizeUnit = aPaperSizeUnit;
    return NS_OK;
}
Exemplo n.º 8
0
static cairo_surface_t *
create_preview_surface_platform (GtkPaperSize *paper_size,
				 gdouble      *dpi_x,
				 gdouble      *dpi_y)
{
	gdouble width, height;

	width = gtk_paper_size_get_width (paper_size, GTK_UNIT_POINTS);
	height = gtk_paper_size_get_height (paper_size, GTK_UNIT_POINTS);

	*dpi_x = *dpi_y = PRINTER_DPI;

	return cairo_pdf_surface_create_for_stream (dummy_write_func, NULL,
						    width, height);
}
Exemplo n.º 9
0
NS_IMETHODIMP
nsPrintSettingsGTK::GetEffectivePageSize(double *aWidth, double *aHeight)
{
    *aWidth  = NS_INCHES_TO_INT_TWIPS(gtk_paper_size_get_width(mPaperSize, GTK_UNIT_INCH));
    *aHeight = NS_INCHES_TO_INT_TWIPS(gtk_paper_size_get_height(mPaperSize, GTK_UNIT_INCH));

    GtkPageOrientation gtkOrient = gtk_page_setup_get_orientation(mPageSetup);

    if (gtkOrient == GTK_PAGE_ORIENTATION_LANDSCAPE ||
            gtkOrient == GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE) {
        double temp = *aWidth;
        *aWidth = *aHeight;
        *aHeight = temp;
    }
    return NS_OK;
}
void FormatDialog::cbFormatChangedCb(GtkComboBox* widget, FormatDialog* dlg)
{
	XOJ_CHECK_TYPE_OBJ(dlg, FormatDialog);

	GtkTreeIter iter;

	if (gtk_combo_box_get_active_iter(widget, &iter))
	{
		GtkTreeModel* model = gtk_combo_box_get_model(widget);

		GValue value = { 0 };
		gtk_tree_model_get_value(model, &iter, 1, &value);

		if (G_VALUE_HOLDS_POINTER(&value))
		{
			GtkPaperSize* s = (GtkPaperSize*) g_value_get_pointer(&value);

			if (s == NULL)
			{
				return;
			}

			double width = gtk_paper_size_get_width(s, GTK_UNIT_POINTS) / dlg->scale;
			double height = gtk_paper_size_get_height(s, GTK_UNIT_POINTS) / dlg->scale;

			if (dlg->orientation == ORIENTATION_LANDSCAPE)
			{
				double tmp = width;
				width = height;
				height = tmp;
			}
			else
			{
				dlg->setOrientation(ORIENTATION_PORTRAIT);
			}

			gtk_spin_button_set_value(GTK_SPIN_BUTTON(dlg->get("spinWidth")), width);
			gtk_spin_button_set_value(GTK_SPIN_BUTTON(dlg->get("spinHeight")), height);
		}
	}
}
void FormatDialog::spinValueChangedCb(GtkSpinButton* spinbutton, FormatDialog* dlg)
{
	XOJ_CHECK_TYPE_OBJ(dlg, FormatDialog);

	double width = gtk_spin_button_get_value(GTK_SPIN_BUTTON(dlg->get("spinWidth"))) * dlg->scale;
	double height = gtk_spin_button_get_value(GTK_SPIN_BUTTON(dlg->get("spinHeight"))) * dlg->scale;

	if (width < height)
	{
		dlg->setOrientation(ORIENTATION_PORTRAIT);
	}
	else if (width > height)
	{
		dlg->setOrientation(ORIENTATION_LANDSCAPE);
	}
	else
	{
		dlg->setOrientation(ORIENTATION_NOT_DEFINED);
	}

	int i = 0;
	for (GList* l = dlg->list; l != NULL; l = l->next)
	{
		GtkPaperSize* s = (GtkPaperSize*) l->data;
		double w = gtk_paper_size_get_width(s, GTK_UNIT_POINTS);
		double h = gtk_paper_size_get_height(s, GTK_UNIT_POINTS);

		if (((int) (w - width) == 0 && (int) (h - height) == 0) || ((int) (h - width) == 0 && (int) (w - height) == 0))
		{
			gtk_combo_box_set_active(GTK_COMBO_BOX(dlg->get("cbTemplate")), i);
			return;
		}
		i++;
	}

	gtk_combo_box_set_active(GTK_COMBO_BOX(dlg->get("cbTemplate")), i);
}
Exemplo n.º 12
0
static void
unix_start_page (GtkPrintOperation *op,
		 GtkPrintContext   *print_context,
		 GtkPageSetup      *page_setup)
{
  GtkPrintOperationUnix *op_unix;  
  GtkPaperSize *paper_size;
  cairo_surface_type_t type;
  gdouble w, h;

  op_unix = op->priv->platform_data;
  
  paper_size = gtk_page_setup_get_paper_size (page_setup);

  w = gtk_paper_size_get_width (paper_size, GTK_UNIT_POINTS);
  h = gtk_paper_size_get_height (paper_size, GTK_UNIT_POINTS);
  
  type = cairo_surface_get_type (op_unix->surface);

  if (type == CAIRO_SURFACE_TYPE_PS)
    cairo_ps_surface_set_size (op_unix->surface, w, h);
  else if (type == CAIRO_SURFACE_TYPE_PDF)
    cairo_pdf_surface_set_size (op_unix->surface, w, h);
}
Exemplo n.º 13
0
static void papersize(PdfPrintContext *ppc)
{
//GList *list, *item;
const gchar *name;
GtkPaperSize *ps;

	DB( g_print("[papersize]\n") );
	
	name = gtk_paper_size_get_default();

	DB( g_print("- def paper is %s\n", name) );
	
	ps = gtk_paper_size_new(name);



  /*GtkPageSetup *new_page_setup;

  if (settings == NULL)
    settings = gtk_print_settings_new ();

  new_page_setup = gtk_print_run_page_setup_dialog (NULL,
                                                    page_setup, settings);

  if (page_setup)
    g_object_unref (page_setup);

  page_setup = new_page_setup;
*/

//#if MYDEBUG == 1
	gdouble w, h, mt, mb, ml, mr;
	w = gtk_paper_size_get_width(ps, GTK_UNIT_MM);
	h = gtk_paper_size_get_height(ps, GTK_UNIT_MM);
	mt = gtk_paper_size_get_default_top_margin(ps, GTK_UNIT_MM);
	mr = gtk_paper_size_get_default_right_margin(ps, GTK_UNIT_MM);
	mb = gtk_paper_size_get_default_bottom_margin(ps, GTK_UNIT_MM);
	ml = gtk_paper_size_get_default_left_margin(ps, GTK_UNIT_MM);
	
	DB( g_print("- name: %s\n", gtk_paper_size_get_display_name(ps)) );
	DB( g_print("- w: %f (%f)\n- h: %f (%f)\n", w, w/PANGO_SCALE, h, h/PANGO_SCALE) );
	DB( g_print("- margin: %f %f %f %f\n", mt, mr, mb, ml) );

	ppc->w = w * 2.83;
	ppc->h = h * 2.83;
	ppc->mt = mt * 2.83;
	ppc->mr = mr * 2.83;
	ppc->mb = mb * 2.83;
	ppc->ml = ml * 2.83;

//#endif

	gtk_paper_size_free(ps);

	/* list all paper size */
	/*
	list = gtk_paper_size_get_paper_sizes (FALSE);
	item = g_list_first(list);
	while(item != NULL)
	{
		ps = item->data;
		if(ps != NULL)
		{
			g_print("- name: %s\n", gtk_paper_size_get_display_name(ps));
			gtk_paper_size_free(ps);
		}
		item = g_list_next(item);
	}
	g_list_free (list);
	*/
}
FormatDialog::FormatDialog(GladeSearchpath* gladeSearchPath, Settings* settings, double width, double heigth) :
		GladeGui(gladeSearchPath, "pagesize.glade", "pagesizeDialog")
{

	XOJ_INIT_TYPE(FormatDialog);

	this->orientation = ORIENTATION_NOT_DEFINED;
	this->selectedScale = 0;
	this->settings = settings;

	SElement& format = settings->getCustomElement("format");
	string unit;

	if (format.getString("unit", unit))
	{
		for (int i = 0; i < XOJ_UNIT_COUNT; i++)
		{
			if (unit == XOJ_UNITS[i].name)
			{
				this->selectedScale = i;
				break;
			}
		}
	}

	this->scale = XOJ_UNITS[this->selectedScale].scale;
	this->origHeight = heigth;
	this->origWidth = width;

	this->width = -1;
	this->height = -1;

	gtk_spin_button_set_value(GTK_SPIN_BUTTON(get("spinWidth")), this->origWidth / this->scale);
	gtk_spin_button_set_value(GTK_SPIN_BUTTON(get("spinHeight")), this->origHeight / this->scale);

	GtkWidget* cbUnit = get("cbUnit");
	GtkListStore* store = gtk_list_store_new(1, G_TYPE_STRING);
	gtk_combo_box_set_model(GTK_COMBO_BOX(cbUnit), GTK_TREE_MODEL(store));
	g_object_unref(store);

	GtkCellRenderer* cell = gtk_cell_renderer_text_new();
	gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(cbUnit), cell, TRUE);
	gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(cbUnit), cell, "text", 0, NULL);

	for (int i = 0; i < XOJ_UNIT_COUNT; i++)
	{
		gtk_combo_box_append_text(GTK_COMBO_BOX(cbUnit), XOJ_UNITS[i].name);
	}
	gtk_combo_box_set_active(GTK_COMBO_BOX(cbUnit), this->selectedScale);

	GtkWidget* cbTemplate = get("cbTemplate");
	store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_POINTER);
	gtk_combo_box_set_model(GTK_COMBO_BOX(cbTemplate), GTK_TREE_MODEL(store));
	g_object_unref(store);

	cell = gtk_cell_renderer_text_new();
	gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(cbTemplate), cell, TRUE);
	gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(cbTemplate), cell, "text", 0, NULL);

	int selectedFormat = -1;

	string formatlist = settings->getVisiblePageFormats();

	if (heigth < width)
	{
		double tmp = width;
		width = heigth;
		heigth = tmp;
	}

	this->list = gtk_paper_size_get_paper_sizes(false);
	int i = 0;
	GList* next = NULL;
	for (GList* l = list; l != NULL; l = next)
	{
		GtkPaperSize* s = (GtkPaperSize*) l->data;
		next = l->next;

		double w = gtk_paper_size_get_width(s, GTK_UNIT_POINTS);
		double h = gtk_paper_size_get_height(s, GTK_UNIT_POINTS);

		bool visible = false;

		if (((int) (w - width) * 10) == 0 && ((int) (h - heigth) * 10) == 0)
		{
			selectedFormat = i;
			visible = true;
		}

		if (formatlist.find(gtk_paper_size_get_name(s)) != string::npos)
		{
			visible = true;
		}

		if (visible)
		{
			GtkTreeIter iter;
			gtk_list_store_append(store, &iter);
			gtk_list_store_set(store, &iter, 0, gtk_paper_size_get_display_name(s), -1);
			gtk_list_store_set(store, &iter, 1, s, -1);
			i++;
		}
		else
		{
			gtk_paper_size_free(s);
			this->list = g_list_delete_link(this->list, l);

		}
	}

	GtkTreeIter iter;
	gtk_list_store_append(store, &iter);
	gtk_list_store_set(store, &iter, 0, _C("Custom"), -1);
	gtk_list_store_set(store, &iter, 1, NULL, -1);

	// not found, select custom format
	if (selectedFormat == -1)
	{
		selectedFormat = i;
	}

	gtk_combo_box_set_active(GTK_COMBO_BOX(cbTemplate), selectedFormat);

	spinValueChangedCb(NULL, this);

	g_signal_connect(get("btLandscape"), "toggled", G_CALLBACK(landscapeSelectedCb), this);
	g_signal_connect(get("btPortrait"), "toggled", G_CALLBACK(portraitSelectedCb), this);
	g_signal_connect(cbTemplate, "changed", G_CALLBACK(cbFormatChangedCb), this);
	g_signal_connect(cbUnit, "changed", G_CALLBACK(cbUnitChanged), this);

	g_signal_connect(get("spinWidth"), "value-changed", G_CALLBACK(spinValueChangedCb), this);
	g_signal_connect(get("spinHeight"), "value-changed", G_CALLBACK(spinValueChangedCb), this);
}
Exemplo n.º 15
0
/* static */ nsresult
GeckoPrintService::TranslateSettings (GtkPrintSettings *aGtkSettings,
				      GtkPageSetup *aPageSetup,
				      GtkPrinter *aPrinter,
				      const nsACString &aSourceFile,
				      PRInt16 aPrintFrames,
				      PRBool aIsForPrinting,
				      nsIPrintSettings *aSettings)
{
  NS_ENSURE_ARG (aGtkSettings);
  NS_ENSURE_ARG (aPageSetup);

  GtkPrintCapabilities capabilities = GtkPrintCapabilities (0);
  if (aIsForPrinting) {
    NS_ENSURE_TRUE (aPrinter, NS_ERROR_FAILURE);

    capabilities = gtk_printer_get_capabilities (aPrinter);
  }

  /* Initialisation */
  aSettings->SetIsInitializedFromPrinter (PR_FALSE); /* FIXME: PR_TRUE? */
  aSettings->SetIsInitializedFromPrefs (PR_FALSE); /* FIXME: PR_TRUE? */
  aSettings->SetPrintSilent (PR_FALSE);
  aSettings->SetShowPrintProgress (PR_TRUE);

  /* We always print PS to a file and then hand that off to gtk-print */
  aSettings->SetPrinterName (LITERAL ("PostScript/default"));

  if (aIsForPrinting) {
    aSettings->SetPrintToFile (PR_TRUE);

    nsString sourceFile;
    NS_CStringToUTF16 (aSourceFile,
		       NS_CSTRING_ENCODING_NATIVE_FILESYSTEM,
		       sourceFile);

    aSettings->SetToFileName (sourceFile.get ());
  } else {
    /* Otherwise mozilla will create the file nevertheless and 
     * fail since we haven't set a name!
     */
    aSettings->SetPrintToFile (PR_FALSE);
  }

  /* This is the time between printing each page, in ms.
   * It 'gives the user more time to press cancel' !
   * We don't want any of this nonsense, so set this to a low value,
   * just enough to update the print dialogue.
   */
  aSettings->SetPrintPageDelay (50);

  if (aIsForPrinting) {
#ifdef HAVE_NSIPRINTSETTINGS_SETOUTPUTFORMAT
    NS_ENSURE_TRUE (aPrinter, NS_ERROR_FAILURE);

    const char *format = gtk_print_settings_get (aGtkSettings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT);
    if (!format)
      format = "ps";

    if (strcmp (format, "pdf") == 0 &&
	gtk_printer_accepts_pdf (aPrinter)) {
      aSettings->SetOutputFormat (nsIPrintSettings::kOutputFormatPDF);
    } else if (strcmp (format, "ps") == 0 &&
	       gtk_printer_accepts_ps (aPrinter)) {
      aSettings->SetOutputFormat (nsIPrintSettings::kOutputFormatPS);
    } else {
      g_warning ("Output format '%s' specified, but printer '%s' does not support it!",
		 format, gtk_printer_get_name (aPrinter));
      return NS_ERROR_FAILURE;
    }
#endif
	  
    int n_copies = gtk_print_settings_get_n_copies (aGtkSettings);
    if (n_copies <= 0)
      return NS_ERROR_FAILURE;
    if (capabilities & GTK_PRINT_CAPABILITY_COPIES) {
      aSettings->SetNumCopies (1);
    } else {
      /* We have to copy them ourself */
      aSettings->SetNumCopies (n_copies);
      gtk_print_settings_set_n_copies (aGtkSettings, 1);
    }

    gboolean reverse = gtk_print_settings_get_reverse (aGtkSettings);
    if (capabilities & GTK_PRINT_CAPABILITY_REVERSE) {
      aSettings->SetPrintReversed (PR_FALSE);
    } else {
      aSettings->SetPrintReversed (reverse);
      gtk_print_settings_set_reverse (aGtkSettings, FALSE);
    }

    GtkPageSet pageSet = gtk_print_settings_get_page_set (aGtkSettings);
    aSettings->SetPrintOptions (nsIPrintSettings::kPrintEvenPages,
			        pageSet != GTK_PAGE_SET_ODD);
    aSettings->SetPrintOptions (nsIPrintSettings::kPrintEvenPages,
			        pageSet != GTK_PAGE_SET_EVEN);

    GtkPrintPages printPages = gtk_print_settings_get_print_pages (aGtkSettings);
    switch (printPages) {
      case GTK_PRINT_PAGES_RANGES: {
        int numRanges = 0;
        GtkPageRange *pageRanges = gtk_print_settings_get_page_ranges (aGtkSettings, &numRanges);
        if (numRanges > 0) {
          /* FIXME: We can only support one range, ignore more ranges or raise error? */
          aSettings->SetPrintRange (nsIPrintSettings::kRangeSpecifiedPageRange);
	  /* Gecko page numbers start at 1, while gtk page numbers start at 0 */
          aSettings->SetStartPageRange (pageRanges[0].start + 1);
	  aSettings->SetEndPageRange (pageRanges[0].end + 1);

	  g_free (pageRanges);
          break;
        }
	/* Fall-through to PAGES_ALL */
      }
      case GTK_PRINT_PAGES_CURRENT:
        /* not supported, fall through */
      case GTK_PRINT_PAGES_ALL:
        aSettings->SetPrintRange (nsIPrintSettings::kRangeAllPages);
        break;
        /* FIXME: we need some custom ranges here, "Selection" and "Focused Frame" */
    }
  } else {
    aSettings->SetPrintOptions (nsIPrintSettings::kPrintEvenPages, PR_TRUE);
    aSettings->SetPrintOptions (nsIPrintSettings::kPrintEvenPages, PR_TRUE);
    aSettings->SetPrintReversed (PR_FALSE);
    aSettings->SetPrintRange (nsIPrintSettings::kRangeAllPages);
  }

  /* And clear those in the settings, so the printer doesn't try to apply them too */
  gtk_print_settings_set_print_pages (aGtkSettings, GTK_PRINT_PAGES_ALL);
  gtk_print_settings_set_page_ranges (aGtkSettings, NULL, 0);
  gtk_print_settings_set_page_set (aGtkSettings, GTK_PAGE_SET_ALL);

  /* We must use the page setup here instead of the print settings, see gtk bug #485685 */
  switch (gtk_page_setup_get_orientation (aPageSetup)) {
    case GTK_PAGE_ORIENTATION_PORTRAIT:
    case GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT: /* not supported */
      aSettings->SetOrientation (nsIPrintSettings::kPortraitOrientation);
      break;
    case GTK_PAGE_ORIENTATION_LANDSCAPE:
    case GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE: /* not supported */
      aSettings->SetOrientation (nsIPrintSettings::kLandscapeOrientation);
      break;
  }

  aSettings->SetPrintInColor (gtk_print_settings_get_use_color (aGtkSettings));

  aSettings->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeMillimeters);

#ifdef HAVE_NSIPRINTSETTINGS_SETPAPERSIZE
  aSettings->SetPaperSize (nsIPrintSettings::kPaperSizeDefined);
#endif

  GtkPaperSize *paperSize = gtk_page_setup_get_paper_size (aPageSetup);
  if (!paperSize) {
    return NS_ERROR_FAILURE;
  }

  aSettings->SetPaperSizeType (nsIPrintSettings::kPaperSizeDefined);
  aSettings->SetPaperWidth (gtk_paper_size_get_width (paperSize, GTK_UNIT_MM));
  aSettings->SetPaperHeight (gtk_paper_size_get_height (paperSize, GTK_UNIT_MM));

#ifdef HAVE_NSIPRINTSETTINGS_SETPAPERNAME
  aSettings->SetPaperName (NS_ConvertUTF8toUTF16 (gtk_paper_size_get_name (paperSize)).get ());
#else
{
  /* Mozilla bug https://bugzilla.mozilla.org/show_bug.cgi?id=307404
   * means that we cannot actually use any paper sizes except mozilla's
   * builtin list, and we must refer to them *by name*!
  */
  static const struct {
    const char gtkPaperName[13];
    const char mozPaperName[10];
  } paperTable [] = {
    { GTK_PAPER_NAME_A5, "A5" },
    { GTK_PAPER_NAME_A4, "A4" },
    { GTK_PAPER_NAME_A3, "A3" },
    { GTK_PAPER_NAME_LETTER, "Letter" },
    { GTK_PAPER_NAME_LEGAL, "Legal" },
    { GTK_PAPER_NAME_EXECUTIVE, "Executive" },
  };

  const char *paperName = gtk_paper_size_get_name (paperSize);
	
  PRUint32 i;
  for (i = 0; i < G_N_ELEMENTS (paperTable); i++) {
    if (g_ascii_strcasecmp (paperTable[i].gtkPaperName, paperName) == 0) {
      paperName = paperTable[i].mozPaperName;
      break;
    }
  }
  if (i == G_N_ELEMENTS (paperTable)) {
    /* Not in table, fall back to A4 */
    g_warning ("Unknown paper name '%s', falling back to A4", gtk_paper_size_get_name (paperSize));
    paperName = paperTable[1].mozPaperName;
  }

  aSettings->SetPaperName (NS_ConvertUTF8toUTF16 (paperName).get ());
}
#endif /* !HAVE_NSIPRINTSETTINGS_SETPAPERNAME */

  /* Sucky mozilla wants margins in inch! */
  aSettings->SetMarginTop (gtk_page_setup_get_top_margin (aPageSetup, GTK_UNIT_INCH));
  aSettings->SetMarginBottom (gtk_page_setup_get_bottom_margin (aPageSetup, GTK_UNIT_INCH));
  aSettings->SetMarginLeft (gtk_page_setup_get_left_margin (aPageSetup, GTK_UNIT_INCH));
  aSettings->SetMarginRight (gtk_page_setup_get_right_margin (aPageSetup, GTK_UNIT_INCH));

  aSettings->SetHeaderStrLeft (eel_gconf_get_boolean (CONF_PRINT_PAGE_TITLE) ? LITERAL ("&T") : LITERAL (""));
  aSettings->SetHeaderStrCenter (LITERAL (""));
  aSettings->SetHeaderStrRight (eel_gconf_get_boolean (CONF_PRINT_PAGE_URL) ? LITERAL ("&U") : LITERAL (""));
  aSettings->SetFooterStrLeft (eel_gconf_get_boolean (CONF_PRINT_PAGE_NUMBERS) ? LITERAL ("&PT") : LITERAL (""));
  aSettings->SetFooterStrCenter (LITERAL (""));
  aSettings->SetFooterStrRight (eel_gconf_get_boolean (CONF_PRINT_DATE) ? LITERAL ("&D") : LITERAL (""));

  aSettings->SetPrintFrameType (aPrintFrames);
  aSettings->SetPrintFrameTypeUsage (nsIPrintSettings::kUseSettingWhenPossible);

  /* FIXME: only if GTK_PRINT_CAPABILITY_SCALE is not set? */
  aSettings->SetScaling (gtk_print_settings_get_scale (aGtkSettings) / 100.0);
  gtk_print_settings_set_scale (aGtkSettings, 1.0);

  aSettings->SetShrinkToFit (PR_FALSE); /* FIXME setting */
  
  aSettings->SetPrintBGColors (eel_gconf_get_boolean (CONF_PRINT_BG_COLORS) != FALSE);
  aSettings->SetPrintBGImages (eel_gconf_get_boolean (CONF_PRINT_BG_IMAGES) != FALSE);

  /* aSettings->SetPlexName (LITERAL ("default")); */
  /* aSettings->SetColorspace (LITERAL ("default")); */
  /* aSettings->SetResolutionName (LITERAL ("default")); */
  /* aSettings->SetDownloadFonts (PR_TRUE); */

  /* Unset those setting that we can handle, so they don't get applied
   * again for the print job.
   */
  /* gtk_print_settings_set_collate (aGtkSettings, FALSE); not yet */
  /* FIXME: Unset the orientation for the print job? */
  /* gtk_page_setup_set_orientation (aPageSetup, GTK_PAGE_ORIENTATION_PORTRAIT); */
  /* FIXME: unset output format -> "ps" ? */

  return NS_OK;
}
Exemplo n.º 16
0
/* Calculates a page layout.  If page is NULL, uses the first page
 * (this is convenient for single-page rendering).  The required size
 * of the page is returned in extents, and the cairo transformation
 * matrix needed to fit the drawing into the page is returned in mtx.
 * Takes into account all of the margin/orientation/paper settings,
 * and the size of the drawing itself. */
static void
export_layout_page (PAGE *page, cairo_rectangle_t *extents, cairo_matrix_t *mtx)
{
  cairo_rectangle_t drawable;
  int wx_min, wy_min, wx_max, wy_max, w_width, w_height;
  gboolean landscape = FALSE;
  gdouble m[4]; /* Calculated margins */
  gdouble s; /* Calculated scale */
  gdouble slack[2]; /* Calculated alignment slack */

  if (page == NULL) {
    const GList *pages = geda_list_get_glist (toplevel->pages);
    g_assert (pages != NULL && pages->data != NULL);
    page = (PAGE *) pages->data;
  }

  /* Set the margins. If none were provided by the user, get them
   * from the paper size (if a paper size is being used) or just use a
   * sensible default. */
  if (settings.margins[0] >= 0) {
    memcpy (m, settings.margins, 4*sizeof(gdouble));
  } else if (settings.paper != NULL) {
    m[0] = gtk_paper_size_get_default_top_margin (settings.paper, GTK_UNIT_POINTS);
    m[1] = gtk_paper_size_get_default_left_margin (settings.paper, GTK_UNIT_POINTS);
    m[2] = gtk_paper_size_get_default_bottom_margin (settings.paper, GTK_UNIT_POINTS);
    m[3] = gtk_paper_size_get_default_right_margin (settings.paper, GTK_UNIT_POINTS);
  } else {
    m[0] = DEFAULT_MARGIN;
    m[1] = DEFAULT_MARGIN;
    m[2] = DEFAULT_MARGIN;
    m[3] = DEFAULT_MARGIN;
  }

  /* Now calculate extents of objects within page */
  world_get_object_glist_bounds (toplevel, s_page_objects (page),
                                 &wx_min, &wy_min, &wx_max, &wy_max);
  w_width = wx_max - wx_min;
  w_height = wy_max - wy_min;

  /* If a size was specified, use it.  Otherwise, use paper size, if
   * provided.  Fall back to just using the size of the drawing. */
  extents->x = extents->y = 0;
  if (settings.size[0] >= 0) {
    /* get extents from size */

    extents->width = settings.size[0];
    extents->height = settings.size[1];

  } else if (settings.paper != NULL) {
    /* get extents from paper */

    gdouble p_width, p_height;

    /* Select orientation */
    switch (settings.layout) {
    case ORIENTATION_LANDSCAPE:
      landscape = TRUE;
      break;
    case ORIENTATION_PORTRAIT:
      landscape = FALSE;
      break;
    case ORIENTATION_AUTO:
    default:
      landscape = (w_width > w_height);
      break;
    }

    p_width = gtk_paper_size_get_width (settings.paper, GTK_UNIT_POINTS);
    p_height = gtk_paper_size_get_height (settings.paper, GTK_UNIT_POINTS);

    if (landscape) {
      extents->width = p_height;
      extents->height = p_width;
    } else {
      extents->width = p_width;
      extents->height = p_height;
    }
  } else {
    /* get extents from drawing */

    extents->width = w_width * settings.scale; /* in points */
    extents->height = w_height * settings.scale; /* in points */

    /* If the extents were obtained from the drawing, grow the extents
     * rather than shrinking the drawable area.  This ensures that the
     * overall aspect ratio of the image remains correct. */
    extents->width += m[1] + m[3];
    extents->height += m[0] + m[2];
  }

  drawable.x = m[1];
  drawable.y = m[0];

  drawable.width = extents->width - m[1] - m[3];
  drawable.height = extents->height - m[0] - m[2];

  /* Calculate optimum scale */
  s = fmin (drawable.width / w_width, drawable.height / w_height);

  /* Calculate alignment slack */
  slack[0] = fmin (1, fmax (0, settings.align[0])) * (drawable.width - w_width * s);
  slack[1] = fmin (1, fmax (0, settings.align[1])) * (drawable.height - w_height * s);

  /* Finally, create and set a cairo transformation matrix that
   * centres the drawing into the drawable area. */
  cairo_matrix_init (mtx, s, 0, 0, -s,
                     - wx_min * s + drawable.x + slack[0],
                     (wy_min + w_height) * s + drawable.y + slack[1]);
}
Exemplo n.º 17
0
static VALUE
rg_get_width(VALUE self, VALUE unit)
{
    return rb_float_new(gtk_paper_size_get_width(_SELF(self), RVAL2UNIT(unit)));
}