diff --git a/ChangeLog b/ChangeLog index b74546c39..9e37038fd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2007-04-29 Brian Matherly + * src/ReportBase/_Report.py: + * src/BaseDoc.py: + * src/docgen/HtmlDoc.py: + * src/docgen/ODFDoc.py: + * src/docgen/PdfDoc.py: + * src/docgen/AbiWord2Doc.py: + * src/docgen/GtkPrint.py: + * src/docgen/OpenOfficeDoc.py: + * src/docgen/LaTeXDoc.py: + * src/docgen/SvgDrawDoc.py: + * src/docgen/KwordDoc.py: + * src/docgen/AsciiDoc.py: + * src/docgen/RTFDoc.py: + * src/docgen/LPRDoc.py: + * src/docgen/PSDrawDoc.py: + Divide BaseDoc into BaseDoc, TextDoc and DrawDoc. TextDoc and DrawDoc are + abstract interfaces that must be implemented by the corresponding document + generators. + 2007-04-28 Benny Malengier * src/images/.../Makefile.am: * src/images/Makefile.am: diff --git a/src/BaseDoc.py b/src/BaseDoc.py index 44858d0f6..ef2b1e6c8 100644 --- a/src/BaseDoc.py +++ b/src/BaseDoc.py @@ -1265,7 +1265,7 @@ class IndexMark: #------------------------------------------------------------------------ class BaseDoc: """ - Base class for text document generators. Different output formats, + Base class for document generators. Different output formats, such as OpenOffice, AbiWord, and LaTeX are derived from this base class, providing a common interface to all document generators. """ @@ -1284,61 +1284,24 @@ class BaseDoc: """ self.template = template self.paper = paper_style - self.title = "" self._style_sheet = styles - self.name = "" + self._creator = "" self.print_req = 0 self.init_called = False def init(self): self.init_called = True - - def start_page(self): - pass - - def end_page(self): - pass def print_requested(self): self.print_req = 1 + + def set_creator(self, name): + "Sets the owner name" + self._creator = name - def add_media_object(self, name, align, w_cm, h_cm): - """ - Adds a photo of the specified width (in centimeters) - - @param name: filename of the image to add - @param align: alignment of the image. Valid values are 'left', - 'right', 'center', and 'single' - @param w_cm: width in centimeters - @param h_cm: height in centimeters - """ - pass - - def get_usable_width(self): - """ - Returns the width of the text area in centimeters. The value is - the page width less the margins. - """ - return self.paper.get_size().get_width() - (self.paper.get_right_margin() + self.paper.get_left_margin()) - - def get_usable_height(self): - """ - Returns the height of the text area in centimeters. The value is - the page height less the margins. - """ - return self.paper.get_size().get_height() - (self.paper.get_top_margin() + self.paper.get_bottom_margin()) - - def creator(self, name): + def get_creator(self): "Returns the owner name" - self.name = name - - def set_title(self, name): - """ - Sets the title of the document. - - @param name: Title of the document - """ - self.title = name + return self._creator def get_style_sheet(self): """ @@ -1361,35 +1324,38 @@ class BaseDoc: @param filename: path name of the file to create """ - pass + raise NotImplementedError def close(self): "Closes the document" - pass - - def string_width(self, fontstyle, text): - "Determine the width need for text in given font" - return FontScale.string_width(fontstyle, text) - - def line_break(self): - "Forces a line break within a paragraph" - pass + raise NotImplementedError +#------------------------------------------------------------------------ +# +# TextDoc +# +#------------------------------------------------------------------------ +class TextDoc: + """ + Abstract Interface for text document generators. Output formats for + text reports must implment this interface to be used by the report + system. + """ def page_break(self): "Forces a page break, creating a new page" - pass + raise NotImplementedError def start_bold(self): - pass + raise NotImplementedError def end_bold(self): - pass + raise NotImplementedError def start_superscript(self): - pass + raise NotImplementedError def end_superscript(self): - pass + raise NotImplementedError def start_paragraph(self, style_name, leader=None): """ @@ -1400,11 +1366,11 @@ class BaseDoc: @param leader: Leading text for a paragraph. Typically used for numbering. """ - pass + raise NotImplementedError def end_paragraph(self): "Ends the current parsgraph" - pass + raise NotImplementedError def start_table(self, name, style_name): """ @@ -1413,19 +1379,19 @@ class BaseDoc: @param name: Unique name of the table. @param style_name: TableStyle to use for the new table """ - pass + raise NotImplementedError def end_table(self): "Ends the current table" - pass + raise NotImplementedError def start_row(self): "Starts a new row on the current table" - pass + raise NotImplementedError def end_row(self): "Ends the current row on the current table" - pass + raise NotImplementedError def start_cell(self, style_name, span=1): """ @@ -1434,11 +1400,11 @@ class BaseDoc: @param style_name: TableCellStyle to use for the cell @param span: number of columns to span """ - pass + raise NotImplementedError def end_cell(self): "Ends the current table cell" - pass + raise NotImplementedError def write_note(self, text, format, style_name): """ @@ -1449,7 +1415,7 @@ class BaseDoc: @param format: format to use for writing. True for flowed text, 1 for preformatted text. """ - pass + raise NotImplementedError def write_text(self, text, mark=None): """ @@ -1459,23 +1425,71 @@ class BaseDoc: @param text: text to write. @param mark: IndexMark to use for indexing (if supported) """ - pass + raise NotImplementedError + + def add_media_object(self, name, align, w_cm, h_cm): + """ + Adds a photo of the specified width (in centimeters) + + @param name: filename of the image to add + @param align: alignment of the image. Valid values are 'left', + 'right', 'center', and 'single' + @param w_cm: width in centimeters + @param h_cm: height in centimeters + """ + raise NotImplementedError + +#------------------------------------------------------------------------ +# +# DrawDoc +# +#------------------------------------------------------------------------ +class DrawDoc: + """ + Abstract Interface for graphical document generators. Output formats + for graphical reports must implment this interface to be used by the + report system. + """ + + def start_page(self): + raise NotImplementedError + + def end_page(self): + raise NotImplementedError + + def get_usable_width(self): + """ + Returns the width of the text area in centimeters. The value is + the page width less the margins. + """ + return self.paper.get_size().get_width() - (self.paper.get_right_margin() + self.paper.get_left_margin()) + + def get_usable_height(self): + """ + Returns the height of the text area in centimeters. The value is + the page height less the margins. + """ + return self.paper.get_size().get_height() - (self.paper.get_top_margin() + self.paper.get_bottom_margin()) + + def string_width(self, fontstyle, text): + "Determine the width need for text in given font" + return FontScale.string_width(fontstyle, text) def draw_path(self, style, path): - pass + raise NotImplementedError def draw_box(self, style, text, x, y, w, h): - pass + raise NotImplementedError def draw_text(self, style, text, x1, y1): - pass + raise NotImplementedError def center_text(self, style, text, x1, y1): - pass + raise NotImplementedError def rotate_text(self, style, text, x, y, angle): - pass + raise NotImplementedError def draw_line(self, style, x1, y1, x2, y2): - pass + raise NotImplementedError diff --git a/src/ReportBase/_Report.py b/src/ReportBase/_Report.py index fea6e06a8..f6faf94e5 100644 --- a/src/ReportBase/_Report.py +++ b/src/ReportBase/_Report.py @@ -57,7 +57,7 @@ class Report: self.doc = options_class.get_document() creator = database.get_researcher().get_name() - self.doc.creator(creator) + self.doc.set_creator(creator) output = options_class.get_output() if output: diff --git a/src/docgen/AbiWord2Doc.py b/src/docgen/AbiWord2Doc.py index d35cc6558..62a0c7a26 100644 --- a/src/docgen/AbiWord2Doc.py +++ b/src/docgen/AbiWord2Doc.py @@ -51,7 +51,7 @@ mime_type = "" # Class Definitions # #------------------------------------------------------------------------- -class AbiWordDoc(BaseDoc.BaseDoc): +class AbiWordDoc(BaseDoc.BaseDoc,BaseDoc.TextDoc): """AbiWord document generator. Inherits from the BaseDoc generic document interface class.""" diff --git a/src/docgen/AsciiDoc.py b/src/docgen/AsciiDoc.py index 77db2d740..4ae208353 100644 --- a/src/docgen/AsciiDoc.py +++ b/src/docgen/AsciiDoc.py @@ -121,7 +121,7 @@ def reformat_para(para='',left=0,right=72,just=LEFT,right_pad=0,first=0): # Ascii # #------------------------------------------------------------------------ -class AsciiDoc(BaseDoc.BaseDoc): +class AsciiDoc(BaseDoc.BaseDoc,BaseDoc.TextDoc): #-------------------------------------------------------------------- # @@ -169,28 +169,17 @@ class AsciiDoc(BaseDoc.BaseDoc): def end_page(self): self.f.write('\012') - #-------------------------------------------------------------------- - # - # Force a line break - # - #-------------------------------------------------------------------- - def line_break(self): - if self.in_cell: - self.cellpars[self.cellnum] = self.cellpars[self.cellnum] + '\n' - else: - self.f.write('\n') + def start_bold(self): + pass + + def end_bold(self): + pass def start_superscript(self): - if self.in_cell: - self.cellpars[self.cellnum] = self.cellpars[self.cellnum] + '[' - else: - self.f.write('[') + self.text = self.text + '[' def end_superscript(self): - if self.in_cell: - self.cellpars[self.cellnum] = self.cellpars[self.cellnum] + ']' - else: - self.f.write(']') + self.text = self.text + ']' #-------------------------------------------------------------------- # @@ -347,7 +336,7 @@ class AsciiDoc(BaseDoc.BaseDoc): if self.cell_lines[self.cellnum] > self.maxlines: self.maxlines = self.cell_lines[self.cellnum] - def add_photo(self,name,pos,x,y): + def add_media_object(self, name, align, w_cm, h_cm): this_text = '(photo)' if self.in_cell: self.cellpars[self.cellnum] = self.cellpars[self.cellnum] + this_text diff --git a/src/docgen/GtkPrint.py b/src/docgen/GtkPrint.py index 7a538b210..45f340ddd 100644 --- a/src/docgen/GtkPrint.py +++ b/src/docgen/GtkPrint.py @@ -348,7 +348,7 @@ class CairoJob(object): # # #------------------------------------------------------------------------ -class GtkDoc(BaseDoc.BaseDoc): +class GtkDoc(BaseDoc.BaseDoc,BaseDoc.TextDoc,BaseDoc.DrawDoc): def open(self,filename): self._job = CairoJob() diff --git a/src/docgen/HtmlDoc.py b/src/docgen/HtmlDoc.py index 17037d799..ca8720706 100644 --- a/src/docgen/HtmlDoc.py +++ b/src/docgen/HtmlDoc.py @@ -95,7 +95,7 @@ _bottom = [ # HtmlDoc # #------------------------------------------------------------------------ -class HtmlDoc(BaseDoc.BaseDoc): +class HtmlDoc(BaseDoc.BaseDoc,BaseDoc.TextDoc): def __init__(self,styles,type,template): BaseDoc.BaseDoc.__init__(self,styles,None,template) diff --git a/src/docgen/KwordDoc.py b/src/docgen/KwordDoc.py index b652349c2..cae1e8da6 100644 --- a/src/docgen/KwordDoc.py +++ b/src/docgen/KwordDoc.py @@ -57,7 +57,7 @@ def points(val): # # #------------------------------------------------------------------------ -class KwordDoc(BaseDoc.BaseDoc): +class KwordDoc(BaseDoc.BaseDoc,BaseDoc.TextDoc): def open(self,filename): self.media_list = [] diff --git a/src/docgen/LPRDoc.py b/src/docgen/LPRDoc.py index 979c5e3f0..37dbb648a 100644 --- a/src/docgen/LPRDoc.py +++ b/src/docgen/LPRDoc.py @@ -492,7 +492,7 @@ class GnomePrintPhoto: # LPRDoc class # #------------------------------------------------------------------------ -class LPRDoc(BaseDoc.BaseDoc): +class LPRDoc(BaseDoc.BaseDoc,BaseDoc.TextDoc,BaseDoc.DrawDoc): """Gnome-print document interface class. Derived from BaseDoc.""" #------------------------------------------------------------------------ @@ -579,17 +579,6 @@ class LPRDoc(BaseDoc.BaseDoc): "Override generic Fontscale-based width." return get_text_width(text,fontstyle) - def line_break(self): - "Forces a line break within a paragraph." - # Add previously held text to the paragraph, - # then add line break directive, - # then start accumulating further text - append_to_paragraph(self.paragraph,self.paragraph_directive, - self.paragraph_text) - self.paragraph.add_piece(_LINE_BREAK,"") - self.paragraph_text = "" - self.brand_new_page = 0 - def start_paragraph(self,style_name,leader=None): """Paragraphs handling - A Gramps paragraph is any single body of text, from a single word, to several sentences. diff --git a/src/docgen/LaTeXDoc.py b/src/docgen/LaTeXDoc.py index 9fab04612..ccf5fbb9e 100644 --- a/src/docgen/LaTeXDoc.py +++ b/src/docgen/LaTeXDoc.py @@ -128,7 +128,7 @@ class TexFont: # LaTeXDon # #------------------------------------------------------------------------ -class LaTeXDoc(BaseDoc.BaseDoc): +class LaTeXDoc(BaseDoc.BaseDoc,BaseDoc.TextDoc): """LaTeX document interface class. Derived from BaseDoc""" def open(self,filename): diff --git a/src/docgen/ODFDoc.py b/src/docgen/ODFDoc.py index b8bda6b4e..10a24d17e 100644 --- a/src/docgen/ODFDoc.py +++ b/src/docgen/ODFDoc.py @@ -74,7 +74,7 @@ _esc_map = { # ODFDoc # #------------------------------------------------------------------------- -class ODFDoc(BaseDoc.BaseDoc): +class ODFDoc(BaseDoc.BaseDoc,BaseDoc.TextDoc,BaseDoc.DrawDoc): def __init__(self,styles,type,template): BaseDoc.BaseDoc.__init__(self,styles,type,template) @@ -945,13 +945,13 @@ class ODFDoc(BaseDoc.BaseDoc): self.meta.write('') self.meta.write('\n') self.meta.write('') - self.meta.write(self.name) + self.meta.write(self.get_creator()) self.meta.write('\n') self.meta.write('') self.meta.write(self.time) self.meta.write('\n') self.meta.write('') - self.meta.write(self.name) + self.meta.write(self.get_creator()) self.meta.write('\n') self.meta.write('') self.meta.write(self.time) diff --git a/src/docgen/OpenOfficeDoc.py b/src/docgen/OpenOfficeDoc.py index 13fc3c74f..19fc796f6 100644 --- a/src/docgen/OpenOfficeDoc.py +++ b/src/docgen/OpenOfficeDoc.py @@ -69,7 +69,7 @@ _esc_map = { # OpenOfficeDoc # #------------------------------------------------------------------------- -class OpenOfficeDoc(BaseDoc.BaseDoc): +class OpenOfficeDoc(BaseDoc.BaseDoc,BaseDoc.TextDoc,BaseDoc.DrawDoc): def __init__(self,styles,type,template): BaseDoc.BaseDoc.__init__(self,styles,type,template) @@ -800,13 +800,13 @@ class OpenOfficeDoc(BaseDoc.BaseDoc): self.meta.write(const.program_name + ' ' + const.version) self.meta.write('\n') self.meta.write('') - self.meta.write(self.name) + self.meta.write(self.get_creator()) self.meta.write('\n') self.meta.write('') self.meta.write(self.time) self.meta.write('\n') self.meta.write('') - self.meta.write(self.name) + self.meta.write(self.get_creator()) self.meta.write('\n') self.meta.write('') self.meta.write(self.time) diff --git a/src/docgen/PSDrawDoc.py b/src/docgen/PSDrawDoc.py index 87273705d..1b4d8d670 100644 --- a/src/docgen/PSDrawDoc.py +++ b/src/docgen/PSDrawDoc.py @@ -69,7 +69,7 @@ if print_label == None: # PSDrawDoc # #------------------------------------------------------------------------- -class PSDrawDoc(BaseDoc.BaseDoc): +class PSDrawDoc(BaseDoc.BaseDoc,BaseDoc.DrawDoc): def __init__(self,styles,type,template): BaseDoc.BaseDoc.__init__(self,styles,type,template) diff --git a/src/docgen/PdfDoc.py b/src/docgen/PdfDoc.py index 7b6d97917..ad8f8ff7a 100644 --- a/src/docgen/PdfDoc.py +++ b/src/docgen/PdfDoc.py @@ -119,7 +119,7 @@ class GrampsDocTemplate(BaseDocTemplate): # # #------------------------------------------------------------------------ -class PdfDoc(BaseDoc.BaseDoc): +class PdfDoc(BaseDoc.BaseDoc,BaseDoc.TextDoc,BaseDoc.DrawDoc): def open(self,filename): if filename[-4:] != ".pdf": diff --git a/src/docgen/RTFDoc.py b/src/docgen/RTFDoc.py index 1a6d37393..8dd841da7 100644 --- a/src/docgen/RTFDoc.py +++ b/src/docgen/RTFDoc.py @@ -60,7 +60,7 @@ def twips(cm): # use style sheets. Instead it writes raw formatting. # #------------------------------------------------------------------------ -class RTFDoc(BaseDoc.BaseDoc): +class RTFDoc(BaseDoc.BaseDoc,BaseDoc.TextDoc): #-------------------------------------------------------------------- # @@ -336,7 +336,7 @@ class RTFDoc(BaseDoc.BaseDoc): self.f.write('\\clbrdrl\\brdrs\\brdrw10\n') if s.get_right_border(): self.f.write('\\clbrdrr\\brdrs\\brdrw10\n') - table_width = float(self.get_usable_width()) + table_width = float(self.paper.get_usable_width()) for cell in range(self.cell,self.cell+span): self.cell_percent = self.cell_percent + float(self.tbl_style.get_column_width(cell)) cell_width = twips((table_width * self.cell_percent)/100.0) diff --git a/src/docgen/SvgDrawDoc.py b/src/docgen/SvgDrawDoc.py index c1e222823..98b2d7462 100644 --- a/src/docgen/SvgDrawDoc.py +++ b/src/docgen/SvgDrawDoc.py @@ -42,7 +42,7 @@ import Errors # SvgDrawDoc # #------------------------------------------------------------------------- -class SvgDrawDoc(BaseDoc.BaseDoc): +class SvgDrawDoc(BaseDoc.BaseDoc,BaseDoc.DrawDoc): def __init__(self,styles,type,template): BaseDoc.BaseDoc.__init__(self,styles,type,template)