From 97a7b690ac263a092e4c04b6c5035a60682674cf Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Wed, 29 Aug 2012 12:58:22 +0000 Subject: [PATCH] GTK3: pdf out conversion, avoid segfault in pdf report write, svn: r20283 --- src/plugins/docgen/pdfdoc.py | 16 ++++------------ src/plugins/drawreport/fanchart.py | 6 ------ src/plugins/lib/libcairodoc.py | 4 ++-- 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/plugins/docgen/pdfdoc.py b/src/plugins/docgen/pdfdoc.py index 217897485..619ddca2c 100644 --- a/src/plugins/docgen/pdfdoc.py +++ b/src/plugins/docgen/pdfdoc.py @@ -95,19 +95,15 @@ class PdfDoc(libcairodoc.CairoDoc): except: raise ReportError(_("Could not create %s") % filename) surface.set_fallback_resolution(300, 300) - cr = PangoCairo.create_context(cairo.Context(surface)) - - fontmap = PangoCairo.font_map_get_default() - saved_resolution = fontmap.get_resolution() + cr = cairo.Context(surface) + fontmap = PangoCairo.font_map_new() fontmap.set_resolution(DPI) - pango_context = fontmap.create_context() options = cairo.FontOptions() options.set_hint_metrics(cairo.HINT_METRICS_OFF) PangoCairo.context_set_font_options(pango_context, options) layout = Pango.Layout(pango_context) - cr.update_context(pango_context) - + PangoCairo.update_context(cr, pango_context) # paginate the document self.paginate_document(layout, page_width, page_height, DPI, DPI) body_pages = self._pages @@ -180,13 +176,9 @@ class PdfDoc(libcairodoc.CairoDoc): DPI, DPI) cr.show_page() cr.restore() - + # close the surface (file) surface.finish() - - # Restore the resolution. On windows, Gramps UI fonts will be smaller - # if we don't restore the resolution. - fontmap.set_resolution(saved_resolution) def __increment_pages(self, toc, index, start_page, offset): """ diff --git a/src/plugins/drawreport/fanchart.py b/src/plugins/drawreport/fanchart.py index 050b31e3e..375af28a6 100644 --- a/src/plugins/drawreport/fanchart.py +++ b/src/plugins/drawreport/fanchart.py @@ -202,9 +202,7 @@ class FanChart(Report): self.apply_filter(family.get_father_handle(),index*2) self.apply_filter(family.get_mother_handle(),(index*2)+1) - def write_report(self): - self.doc.start_page() self.apply_filter(self.center_person.get_handle(),1) @@ -259,10 +257,8 @@ class FanChart(Report): self.draw_circular (x, y, start_angle, max_angle, block_size, generation) for generation in range (max_circular, self.max_generations): self.draw_radial (x, y, start_angle, max_angle, block_size, generation) - self.doc.end_page() - def get_info(self,person_handle,generation): person = self.database.get_person_from_handle(person_handle) pn = person.get_primary_name() @@ -324,7 +320,6 @@ class FanChart(Report): else: return [ pn.get_first_name(), pn.get_surname(), val ] - def draw_circular(self, x, y, start_angle, max_angle, size, generation): segments = 2**generation delta = max_angle / segments @@ -349,7 +344,6 @@ class FanChart(Report): xc, yc, text_angle, mark) text_angle += delta - def draw_radial(self, x, y, start_angle, max_angle, size, generation): segments = 2**generation delta = max_angle / segments diff --git a/src/plugins/lib/libcairodoc.py b/src/plugins/lib/libcairodoc.py index 4686132e4..dabbd77b7 100644 --- a/src/plugins/lib/libcairodoc.py +++ b/src/plugins/lib/libcairodoc.py @@ -714,7 +714,7 @@ class GtkDocParagraph(GtkDocBaseElement): # 3/4 of the spacing is added above the text, 1/4 is added below cr.move_to(x, t_margin + v_padding + spacing * 0.75) cr.set_source_rgb(*ReportUtils.rgb_color(font_style.get_color())) - cr.show_layout(layout) + PangoCairo.show_layout(cr, layout) # calculate the full paragraph height height = layout_height + spacing + t_margin + 2*v_padding + b_margin @@ -1295,7 +1295,7 @@ class GtkDocText(GtkDocBaseElement): cr.rotate(radians(self._angle)) cr.move_to(align_x, align_y) cr.set_source_rgb(*ReportUtils.rgb_color(font_style.get_color())) - cr.show_layout(layout) + PangoCairo.show_layout(cr, layout) cr.restore() return layout_height