Example #1
0
    def draw(self, widget, context):
        """
        Draw the widget (the PDF, all strokes and the background). Called by Gtk.
        
        Positional arguments:
        widget -- The widget to redraw
        context -- A Cairo context to draw on
        """
        scaling = self.widget_width / self.page.width

        # Check if the page has already been rendered in the correct size
        if not self.backbuffer or self.backbuffer.get_width(
        ) != self.widget_width or self.backbuffer_valid is False:
            self.backbuffer = cairo.ImageSurface(cairo.FORMAT_ARGB32,
                                                 self.widget_width,
                                                 self.widget_height)
            self.backbuffer_valid = True
            bb_ctx = cairo.Context(self.backbuffer)

            # For correct rendering of PDF, the PDF is first rendered to a
            # transparent image (all alpha = 0).
            bb_ctx.scale(scaling, scaling)
            bb_ctx.save()
            self.page.pdf.render(bb_ctx)
            bb_ctx.restore()

            for stroke in self.page.layers[0].strokes:
                stroke.draw(bb_ctx, scaling)

            # Highlight search result
            if self.page.search_marker:
                search.draw(bb_ctx, self.page)

            # Then the image is painted on top of a white "page". Instead of
            # creating a second image, painting it white, then painting the
            # PDF image over it we can use the cairo.OPERATOR_DEST_OVER
            # operator to achieve the same effect with the one image.
            bb_ctx.set_operator(cairo.OPERATOR_DEST_OVER)
            bb_ctx.set_source_rgb(1, 1, 1)
            bb_ctx.paint()

        context.set_source_surface(self.backbuffer, 0, 0)
        context.paint()

        if self.preview_item:
            context.scale(scaling, scaling)
            self.preview_item.draw(context, scaling)
Example #2
0
    def draw(self, widget, context):
        """
        Draw the widget (the PDF, all strokes and the background). Called by Gtk.

        Positional arguments:
        widget -- The widget to redraw
        context -- A Cairo context to draw on
        """
        scaling = self.widget_width / self.page.width

        # Check if the page has already been rendered in the correct size
        if not self.backbuffer or self.backbuffer.get_width() != self.widget_width or self.backbuffer_valid is False:
            self.backbuffer = cairo.ImageSurface(
                 cairo.FORMAT_ARGB32, self.widget_width, self.widget_height)
            self.backbuffer_valid = True
            bb_ctx = cairo.Context(self.backbuffer)

            # For correct rendering of PDF, the PDF is first rendered to a
            # transparent image (all alpha = 0).
            bb_ctx.scale(scaling, scaling)
            bb_ctx.save()
            self.page.pdf.render(bb_ctx)
            bb_ctx.restore()

            for stroke in self.page.layers[0].strokes:
                stroke.draw(bb_ctx, scaling)

            # Highlight search result
            if self.page.search_marker:
                search.draw(bb_ctx, self.page)

            # Then the image is painted on top of a white "page". Instead of
            # creating a second image, painting it white, then painting the
            # PDF image over it we can use the cairo.OPERATOR_DEST_OVER
            # operator to achieve the same effect with the one image.
            bb_ctx.set_operator(cairo.OPERATOR_DEST_OVER)
            bb_ctx.set_source_rgb(1, 1, 1)
            bb_ctx.paint()

        context.set_source_surface(self.backbuffer, 0, 0)
        context.paint()

        if self.preview_item:
            context.scale(scaling, scaling)
            self.preview_item.draw(context, scaling)
Example #3
0
    def draw_search_marker(self, rect):
        """
        Draw the search marker on the widget

        Positional arguments:
        rect -- The rect marking the found search text
        """
        self.page.search_marker = rect.x1, self.page.height - rect.y1, rect.x2, self.page.height - rect.y2
        if self.backbuffer:
            scaling = self.widget_width / self.page.width
            context = cairo.Context(self.backbuffer)

            context.scale(scaling, scaling)
            search.draw(context, self.page)
            update_rect = Gdk.Rectangle()
            update_rect.x = rect.x1 * scaling
            update_rect.y = (self.page.height - rect.y2) * scaling
            update_rect.width = (rect.x2 - rect.x1) * scaling
            update_rect.height = (rect.y2 - rect.y1) * scaling

            if self.get_window():
                self.get_window().invalidate_rect(update_rect, False)
Example #4
0
    def draw_search_marker(self, rect):
        """
        Draw the search marker on the widget

        Positional arguments:
        rect -- The rect marking the found search text
        """
        self.page.search_marker = rect.x1, self.page.height-rect.y1, rect.x2, self.page.height-rect.y2
        if self.backbuffer:
            scaling = self.widget_width / self.page.width
            context = cairo.Context(self.backbuffer)

            context.scale(scaling, scaling)
            search.draw(context, self.page)
            update_rect = Gdk.Rectangle()
            update_rect.x = rect.x1*scaling
            update_rect.y = (self.page.height-rect.y2)*scaling
            update_rect.width = (rect.x2-rect.x1)*scaling
            update_rect.height = (rect.y2-rect.y1)*scaling

            if self.get_window():
                self.get_window().invalidate_rect(update_rect, False)