--- pdfshuffler-old 2010-10-10 13:26:37.000000000 +0200 +++ pdfshuffler-test 2011-11-17 03:23:00.000000000 +0100 @@ -32,6 +32,7 @@ import sys #needed for proccessing of command line args import urllib #needed to parse filename information passed by DnD import threading +import traceback import tempfile from copy import copy @@ -64,6 +65,7 @@ import gobject #to use custom signals import pango #to adjust the text alignment in CellRendererText import gio #to inquire mime types information +import cairo, array import poppler #for the rendering of pdf pages from pyPdf import PdfFileWriter, PdfFileReader @@ -202,35 +204,35 @@ # Create buttons self.button_exit = gtk.Button(stock=gtk.STOCK_QUIT) self.button_exit.connect('clicked', self.close_application) - hbox.pack_start(self.button_exit, expand=True, fill=True, padding=20) + hbox.pack_start(self.button_exit, expand=True, fill=False, padding=20) self.button_del = gtk.Button(_('Delete Page(s)')) image = gtk.Image() image.set_from_stock(gtk.STOCK_DELETE, gtk.ICON_SIZE_BUTTON) self.button_del.set_image(image) self.button_del.connect('clicked', self.clear_selected) - hbox.pack_start(self.button_del, expand=True, fill=True, padding=20) + hbox.pack_start(self.button_del, expand=True, fill=False, padding=20) self.button_import = gtk.Button(_('Import pdf')) image = gtk.Image() image.set_from_stock(gtk.STOCK_OPEN, gtk.ICON_SIZE_BUTTON) self.button_import.set_image(image) self.button_import.connect('clicked', self.on_action_add_doc_activate) - hbox.pack_start(self.button_import, expand=True, fill=True, padding=20) + hbox.pack_start(self.button_import, expand=True, fill=False, padding=20) self.button_export = gtk.Button(_('Export pdf')) image = gtk.Image() image.set_from_stock(gtk.STOCK_SAVE_AS, gtk.ICON_SIZE_BUTTON) self.button_export.set_image(image) self.button_export.connect('clicked', self.choose_export_pdf_name) - hbox.pack_start(self.button_export, expand=True, fill=True, padding=20) + hbox.pack_start(self.button_export, expand=True, fill=False, padding=20) self.button_export = gtk.Button(_('About')) image = gtk.Image() image.set_from_stock(gtk.STOCK_ABOUT, gtk.ICON_SIZE_BUTTON) self.button_export.set_image(image) self.button_export.connect('clicked', self.about_dialog) - hbox.pack_start(self.button_export, expand=True, fill=True, padding=20) + hbox.pack_start(self.button_export, expand=True, fill=False, padding=20) # Define window callback function and show window self.window.connect('size_allocate', self.on_window_size_request) # resize @@ -982,9 +984,22 @@ pix_w, pix_h = page.get_size() pix_w = int(pix_w * self.scale) pix_h = int(pix_h * self.scale) - thumbnail = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, - 8, pix_w , pix_h) - page.render_to_pixbuf(0,0,pix_w,pix_h,self.scale,0,thumbnail) + stride = cairo.ImageSurface.format_stride_for_width (cairo.FORMAT_ARGB32, pix_w) + data = array.array('c', '\x00' * stride * pix_h) + pix_surface = cairo.ImageSurface.create_for_data(data, cairo.FORMAT_ARGB32, + pix_w, pix_h, stride) + ctx = cairo.Context(pix_surface) + ctx.scale(self.scale, self.scale) + page.render(ctx) + if sys.byteorder == 'big': + data[0::4], data[1::4], data[2::4], data[3::4] = \ + data[1::4], data[2::4], data[3::4], data[0::4] + else: + data[0::4], data[2::4] = data[2::4], data[0::4] + thumbnail = gtk.gdk.pixbuf_new_from_data(data, + gtk.gdk.COLORSPACE_RGB, + True, 8, pix_w , pix_h, + stride) rotation = (-rotation) % 360 rotation = ((rotation + 45) / 90) * 90 thumbnail = thumbnail.rotate_simple(rotation) @@ -995,7 +1010,7 @@ src_y = int( crop[2] * pix_h ) width = int( (1. - crop[0] - crop[1]) * pix_w ) height = int( (1. - crop[2] - crop[3]) * pix_h ) - new_thumbnail = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, + new_thumbnail = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, width, height) thumbnail.copy_area(src_x, src_y, width, height, new_thumbnail, 0, 0) @@ -1003,11 +1018,13 @@ pix_w = thumbnail.get_width() pix_h = thumbnail.get_height() except: + print("Test failed: ") + traceback.print_exc() pix_w = self.default_width pix_h = pix_w thumbnail = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, pix_w, pix_h) - pixbuf.fill(0xffffffff) + thumbnail.fill(0xffffffff) #add border thickness = 3