diff --git a/widget/src/gtk2/nsDeviceContextSpecG.cpp b/widget/src/gtk2/nsDeviceContextSpecG.cpp index 8038568b4d68..f40d465cbf8a 100644 --- a/widget/src/gtk2/nsDeviceContextSpecG.cpp +++ b/widget/src/gtk2/nsDeviceContextSpecG.cpp @@ -391,6 +391,16 @@ nsDeviceContextSpecGTK::nsDeviceContextSpecGTK() nsDeviceContextSpecGTK::~nsDeviceContextSpecGTK() { DO_PR_DEBUG_LOG(("nsDeviceContextSpecGTK::~nsDeviceContextSpecGTK()\n")); + + if (mGtkPageSetup) { + g_object_unref(mGtkPageSetup); + mGtkPageSetup = NULL; + } + + if (mGtkPrintSettings) { + g_object_unref(mGtkPrintSettings); + mGtkPrintSettings = NULL; + } } NS_IMPL_ISUPPORTS1(nsDeviceContextSpecGTK, @@ -510,6 +520,25 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(nsIWidget *aWidget, mGtkPrintSettings = printSettingsGTK->GetGtkPrintSettings(); mGtkPageSetup = printSettingsGTK->GetGtkPageSetup(); + // This is a horrible workaround for some printer driver bugs that treat custom page sizes different + // to standard ones. If our paper object matches one of a standard one, use a standard paper size + // object instead. + GtkPaperSize* geckosHackishPaperSize = gtk_page_setup_get_paper_size(mGtkPageSetup); + GtkPaperSize* standardGtkPaperSize = gtk_paper_size_new(gtk_paper_size_get_name(geckosHackishPaperSize)); + + mGtkPageSetup = gtk_page_setup_copy(mGtkPageSetup); + mGtkPrintSettings = gtk_print_settings_copy(mGtkPrintSettings); + + GtkPaperSize* properPaperSize; + if (gtk_paper_size_is_equal(geckosHackishPaperSize, standardGtkPaperSize)) { + properPaperSize = standardGtkPaperSize; + } else { + properPaperSize = geckosHackishPaperSize; + gtk_paper_size_free(standardGtkPaperSize); + } + gtk_print_settings_set_paper_size(mGtkPrintSettings, properPaperSize); + gtk_page_setup_set_paper_size_and_default_margins(mGtkPageSetup, properPaperSize); + return NS_OK; }