CairoDoc.py, GtkPrint.py and PdfDoc.py cleanup.

svn: r9028
This commit is contained in:
Zsolt Foldvari 2007-09-28 21:57:08 +00:00
parent d502801584
commit 6736044628
4 changed files with 52 additions and 37 deletions

View File

@ -1,3 +1,9 @@
2007-09-28 Zsolt Foldvari <zfoldvar@users.sourceforge.net>
* src/docgen/CairoDoc.py:
* src/docgen/GtkPrint.py:
* src/docgen/PdfDoc.py:
Cleanup.
2007-09-28 Tobias Gehrig <tobias@gehrignet.de> 2007-09-28 Tobias Gehrig <tobias@gehrignet.de>
* src/DataViews/_PedigreeView.py: use subsection thumbnails * src/DataViews/_PedigreeView.py: use subsection thumbnails
* src/DataViews/_RelationView.py: use subsection thumbnails * src/DataViews/_RelationView.py: use subsection thumbnails

View File

@ -1078,6 +1078,7 @@ class CairoDoc(BaseDoc.BaseDoc, BaseDoc.TextDoc, BaseDoc.DrawDoc):
self._doc = GtkDocDocument() self._doc = GtkDocDocument()
self._active_element = self._doc self._active_element = self._doc
self._pages = [] self._pages = []
self._elements_to_paginate = []
def close(self): def close(self):
self.run() self.run()
@ -1268,25 +1269,23 @@ class CairoDoc(BaseDoc.BaseDoc, BaseDoc.TextDoc, BaseDoc.DrawDoc):
""" """
raise NotImplementedError raise NotImplementedError
def setup_paginate(self): def paginate(self, layout, page_width, page_height, dpi_x, dpi_y):
"""Setup initial variables for pagination.
"""
# get all document level elements and beging a new page
self.elements_to_paginate = self._doc.get_children()[:]
self._pages = [GtkDocDocument(),]
self.available_height = self.page_height
def paginate(self, layout, dpi_x, dpi_y):
"""Paginate the meta document in chunks. """Paginate the meta document in chunks.
Only one document level element is handled at one run. Only one document level element is handled at one run.
""" """
# if first time run than initialize the variables
if not self._elements_to_paginate:
self._elements_to_paginate = self._doc.get_children()[:]
self._pages.append(GtkDocDocument())
self._available_height = page_height
# try to fit the next element to current page, divide it if needed # try to fit the next element to current page, divide it if needed
elem = self.elements_to_paginate.pop(0) elem = self._elements_to_paginate.pop(0)
(e1, e2), e1_h = elem.divide(layout, (e1, e2), e1_h = elem.divide(layout,
self.page_width, page_width,
self.available_height, self._available_height,
dpi_x, dpi_x,
dpi_y) dpi_y)
@ -1296,17 +1295,17 @@ class CairoDoc(BaseDoc.BaseDoc, BaseDoc.TextDoc, BaseDoc.DrawDoc):
# if elem was divided remember the second half to be processed # if elem was divided remember the second half to be processed
if e2 is not None: if e2 is not None:
self.elements_to_paginate.insert(0, e2) self._elements_to_paginate.insert(0, e2)
# calculate how much space left on current page # calculate how much space left on current page
self.available_height -= e1_h self._available_height -= e1_h
# start new page if needed # start new page if needed
if (e1 is None) or (e2 is not None): if (e1 is None) or (e2 is not None):
self._pages.append(GtkDocDocument()) self._pages.append(GtkDocDocument())
self.available_height = self.page_height self._available_height = page_height
return len(self.elements_to_paginate) == 0 return len(self._elements_to_paginate) == 0
def draw_page(self, page_nr, cr, layout, width, height, dpi_x, dpi_y): def draw_page(self, page_nr, cr, layout, width, height, dpi_x, dpi_y):
"""Draw a page on a Cairo context. """Draw a page on a Cairo context.

View File

@ -1,7 +1,7 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2000-2007 Donald N. Allingham # Copyright (C) 2007 Zsolt Foldvari
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -549,21 +549,22 @@ class GtkPrint(CairoDoc):
def on_begin_print(self, operation, context): def on_begin_print(self, operation, context):
"""Setup environment for printing. """Setup environment for printing.
""" """
# get page size # get data from print context
self.page_width = round(context.get_width()) self.page_width = round(context.get_width())
self.page_height = round(context.get_height()) self.page_height = round(context.get_height())
# initialize pagination
self.setup_paginate()
def on_paginate(self, operation, context): def on_paginate(self, operation, context):
"""Paginate the whole document in chunks. """Paginate the whole document in chunks.
""" """
layout = context.create_pango_layout() layout = context.create_pango_layout()
dpi_x = context.get_dpi_x() dpi_x = context.get_dpi_x()
dpi_y = context.get_dpi_y() dpi_y = context.get_dpi_y()
finished = self.paginate(layout, dpi_x, dpi_y) finished = self.paginate(layout,
self.page_width,
self.page_height,
dpi_x,
dpi_y)
# update page number # update page number
operation.set_n_pages(len(self._pages)) operation.set_n_pages(len(self._pages))
@ -578,12 +579,16 @@ class GtkPrint(CairoDoc):
""" """
cr = context.get_cairo_context() cr = context.get_cairo_context()
layout = context.create_pango_layout() layout = context.create_pango_layout()
width = round(context.get_width())
height = round(context.get_height())
dpi_x = context.get_dpi_x() dpi_x = context.get_dpi_x()
dpi_y = context.get_dpi_y() dpi_y = context.get_dpi_y()
self.draw_page(page_nr, cr, layout, width, height, dpi_x, dpi_y) self.draw_page(page_nr,
cr,
layout,
self.page_width,
self.page_height,
dpi_x,
dpi_y)
def on_preview(self, operation, preview, context, parent): def on_preview(self, operation, preview, context, parent):
"""Implement custom print preview functionality. """Implement custom print preview functionality.
@ -608,6 +613,6 @@ class GtkPrint(CairoDoc):
# Register the document generator with the GRAMPS plugin system # Register the document generator with the GRAMPS plugin system
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
register_text_doc(_('Print... (Gtk+)'), GtkPrint, 1, 1, 1, "", None) register_text_doc(_('Print...'), GtkPrint, 1, 1, 1, "", None)
register_draw_doc(_('Print... (Gtk+)'), GtkPrint, 1, 1, "", None) register_draw_doc(_('Print...'), GtkPrint, 1, 1, "", None)
register_book_doc(_('Print... (Gtk+)'), GtkPrint, 1, 1, 1, "", None) register_book_doc(_('Print...'), GtkPrint, 1, 1, 1, "", None)

View File

@ -1,7 +1,7 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2000-2007 Donald N. Allingham # Copyright (C) 2007 Zsolt Foldvari
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -98,9 +98,6 @@ class PdfDoc(CairoDoc):
self.page_width = round(context.get_width()) self.page_width = round(context.get_width())
self.page_height = round(context.get_height()) self.page_height = round(context.get_height())
# initialize pagination
self.setup_paginate()
def on_paginate(self, operation, context): def on_paginate(self, operation, context):
"""Paginate the whole document in chunks. """Paginate the whole document in chunks.
""" """
@ -108,7 +105,11 @@ class PdfDoc(CairoDoc):
dpi_x = context.get_dpi_x() dpi_x = context.get_dpi_x()
dpi_y = context.get_dpi_y() dpi_y = context.get_dpi_y()
finished = self.paginate(layout, dpi_x, dpi_y) finished = self.paginate(layout,
self.page_width,
self.page_height,
dpi_x,
dpi_y)
# update page number # update page number
operation.set_n_pages(len(self._pages)) operation.set_n_pages(len(self._pages))
@ -126,12 +127,16 @@ class PdfDoc(CairoDoc):
""" """
cr = context.get_cairo_context() cr = context.get_cairo_context()
layout = context.create_pango_layout() layout = context.create_pango_layout()
width = context.get_width()
height = context.get_height()
dpi_x = context.get_dpi_x() dpi_x = context.get_dpi_x()
dpi_y = context.get_dpi_y() dpi_y = context.get_dpi_y()
self.draw_page(page_nr, cr, layout, width, height, dpi_x, dpi_y) self.draw_page(page_nr,
cr,
layout,
self.page_width,
self.page_height,
dpi_x,
dpi_y)
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #