diff --git a/ChangeLog b/ChangeLog index 846ede67f..2b85e10f9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2007-02-24 Brian Matherly + * src/BaseDoc.py: + * src/ReportBase/_CommandLineReport.py: + * src/ReportBase/_ReportDialgo.py: + * src/docgen/PdfDoc.py: + * src/docgen/OpenOfficeDoc.py: + * src/docgen/ODFDoc.py: + * src/docgen/RDFDoc.py: + * src/docgen/KwordDoc.py: + * src/docgen/PSDrawDoc.py: + * src/docgen/SvgDrawDoc.py: + * src/docgen/HtmlDoc.py: + * src/docgen/AbiWord2Doc.py: + * src/docgen/LaTeXDoc.py: + * src/plugins/BookReport.py: + Add PaperStyle to BaseDoc + 2007-02-24 Zsolt Foldvari * src/Makefile.am: update * src/BasicUtils/Makefile.am: update diff --git a/src/BaseDoc.py b/src/BaseDoc.py index 14140cf68..1f93a3504 100644 --- a/src/BaseDoc.py +++ b/src/BaseDoc.py @@ -211,6 +211,72 @@ class PaperSize: "Returns the page width in inches" return self.width / 2.54 +#------------------------------------------------------------------------ +# +# PaperStyle +# +#------------------------------------------------------------------------ +class PaperStyle: + """ + Defines the various options for a sheet of paper. + """ + def __init__(self, size, orientation): + """ + Creates a new paper style. + + @param size: size of the new style + @type size: PaperSize + @param orientation: page orientation + @type orientation: PAPER_PORTRAIT or PAPER_LANDSCAPE + """ + + self.__orientation = orientation + if orientation == PAPER_PORTRAIT: + self.__size = PaperSize( size.get_name(), + size.get_height(), + size.get_width() ) + else: + self.__size = PaperSize( size.get_name(), + size.get_width(), + size.get_height() ) + + self.__tmargin = 2.54 + self.__bmargin = 2.54 + self.__lmargin = 2.54 + self.__rmargin = 2.54 + + def get_size(self): + return self.__size + + def get_orientation(self): + return self.__orientation + + def get_usable_width(self): + """ + Returns the width of the page area in centimeters. The value is + the page width less the margins. + """ + return self.__size.get_width() - (self.__rmargin + self.__lmargin) + + def get_usable_height(self): + """ + Returns the height of the page area in centimeters. The value is + the page height less the margins. + """ + return self.__size.get_height() - (self.__tmargin + self.__bmargin) + + def get_right_margin(self): + return self.__rmargin + + def get_left_margin(self): + return self.__lmargin + + def get_top_margin(self): + return self.__tmargin + + def get_bottom_margin(self): + return self.__bmargin + #------------------------------------------------------------------------ # # FontStyle @@ -1173,8 +1239,7 @@ class BaseDoc: such as OpenOffice, AbiWord, and LaTeX are derived from this base class, providing a common interface to all document generators. """ - def __init__(self, styles, paper_type, template, - orientation=PAPER_PORTRAIT): + def __init__(self, styles, paper_style, template): """ Creates a BaseDoc instance, which provides a document generation interface. This class should never be instantiated directly, but @@ -1189,19 +1254,8 @@ class BaseDoc: @param orientation: page orientation, either PAPER_PORTRAIT or PAPER_LANDSCAPE """ - self.orientation = orientation self.template = template - if orientation == PAPER_PORTRAIT: - self.width = paper_type.get_width() - self.height = paper_type.get_height() - else: - self.width = paper_type.get_height() - self.height = paper_type.get_width() - self.paper = paper_type - self.tmargin = 2.54 - self.bmargin = 2.54 - self.lmargin = 2.54 - self.rmargin = 2.54 + self.paper = paper_style self.title = "" self.draw_styles = {} @@ -1243,26 +1297,14 @@ class BaseDoc: Returns the width of the text area in centimeters. The value is the page width less the margins. """ - return self.width - (self.rmargin + self.lmargin) + 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.height - (self.tmargin + self.bmargin) - - def get_right_margin(self): - return self.rmargin - - def get_left_margin(self): - return self.lmargin - - def get_top_margin(self): - return self.tmargin - - def get_bottom_margin(self): - return self.bmargin + return self.paper.get_size().get_height() - (self.paper.get_top_margin() + self.paper.get_bottom_margin()) def creator(self, name): "Returns the owner name" diff --git a/src/ReportBase/_CommandLineReport.py b/src/ReportBase/_CommandLineReport.py index d7504cc62..3f1ef2cbd 100644 --- a/src/ReportBase/_CommandLineReport.py +++ b/src/ReportBase/_CommandLineReport.py @@ -258,7 +258,9 @@ def cl_report(database,name,category,report_class, # write report try: clr.option_class.handler.doc = clr.format( - clr.selected_style,clr.paper,clr.template_name,clr.orien) + clr.selected_style, + BaseDoc.PaperStyle(clr.paper,clr.orien), + clr.template_name) MyReport = report_class(database, clr.person, clr.option_class) MyReport.doc.init() MyReport.begin_report() diff --git a/src/ReportBase/_ReportDialog.py b/src/ReportBase/_ReportDialog.py index 62010092d..96f466bb7 100644 --- a/src/ReportBase/_ReportDialog.py +++ b/src/ReportBase/_ReportDialog.py @@ -57,6 +57,7 @@ from _BareReportDialog import BareReportDialog from _FileEntry import FileEntry from _PaperMenu import PaperComboBox, OrientationComboBox, paper_sizes from _TemplateParser import _template_map, _default_template, _user_template +from BaseDoc import PaperStyle #------------------------------------------------------------------------- # @@ -177,8 +178,9 @@ class ReportDialog(BareReportDialog): def make_document(self): """Create a document of the type requested by the user.""" - self.doc = self.format(self.selected_style,self.paper, - self.template_name,self.orien) + self.doc = self.format(self.selected_style, + PaperStyle(self.paper,self.orien), + self.template_name ) self.options.set_document(self.doc) if self.print_report.get_active (): self.doc.print_requested () diff --git a/src/docgen/AbiWord2Doc.py b/src/docgen/AbiWord2Doc.py index d776b0edd..73595b35b 100644 --- a/src/docgen/AbiWord2Doc.py +++ b/src/docgen/AbiWord2Doc.py @@ -54,10 +54,10 @@ class AbiWordDoc(BaseDoc.BaseDoc): """AbiWord document generator. Inherits from the BaseDoc generic document interface class.""" - def __init__(self,styles,type,template,orientation): + def __init__(self,styles,type,template): """Initializes the AbiWordDoc class, calling the __init__ routine of the parent BaseDoc class""" - BaseDoc.BaseDoc.__init__(self,styles,type,template,orientation) + BaseDoc.BaseDoc.__init__(self,styles,type,template) self.f = None self.level = 0 self.new_page = 0 @@ -104,17 +104,17 @@ class AbiWordDoc(BaseDoc.BaseDoc): # page size section self.f.write('\n') self.f.write('
\n') diff --git a/src/docgen/HtmlDoc.py b/src/docgen/HtmlDoc.py index 0a7a434a5..7167d0a3f 100644 --- a/src/docgen/HtmlDoc.py +++ b/src/docgen/HtmlDoc.py @@ -96,8 +96,8 @@ _bottom = [ #------------------------------------------------------------------------ class HtmlDoc(BaseDoc.BaseDoc): - def __init__(self,styles,type,template,orientation): - BaseDoc.BaseDoc.__init__(self,styles,BaseDoc.PaperSize("",0,0),template,None) + def __init__(self,styles,type,template): + BaseDoc.BaseDoc.__init__(self,styles,None,template) self.year = time.localtime(time.time())[0] self.ext = '.html' self.meta = "" diff --git a/src/docgen/KwordDoc.py b/src/docgen/KwordDoc.py index 107858efa..4b46312e4 100644 --- a/src/docgen/KwordDoc.py +++ b/src/docgen/KwordDoc.py @@ -98,24 +98,25 @@ class KwordDoc(BaseDoc.BaseDoc): self.f.write('editor="KWord" >\n') self.mtime = time.time() - if self.paper.name == "A3": + paper_name = self.paper.get_size().get_name() + if paper_name == "A3": self.f.write('\n') self.f.write('' % points(self.lmargin)) + self.f.write('top="%d" ' % points(self.paper.get_top_margin())) + self.f.write('right="%d" ' % points(self.paper.get_right_margin())) + self.f.write('bottom="%d" ' % points(self.paper.get_bottom_margin())) + self.f.write('left="%d"/>' % points(self.paper.get_left_margin())) self.f.write('\n') self.f.write('\n') - self.f.write('\n') self.cell_row= 0 @@ -402,8 +403,8 @@ class KwordDoc(BaseDoc.BaseDoc): def start_table(self,name,style_name): self.tbl= self.table_styles[style_name] - self.cell_left= (self.lmargin * 72)/ 2.54 - self.tbl_width= ((self.width - self.lmargin - self.rmargin) * 72 ) / 2.54 + self.cell_left= (self.paper.get_left_margin() * 72)/ 2.54 + self.tbl_width= ((self.paper.get_size().get_width() - self.paper.get_left_margin() - self.paper.get_right_margin()) * 72 ) / 2.54 if self.frameset_flg == 1: self.f.write(' \n') self.cell_row= 0 @@ -419,7 +420,7 @@ class KwordDoc(BaseDoc.BaseDoc): def end_row(self): self.cell_row= self.cell_row + 1 self.cell_col= 0 - self.cell_left= (self.lmargin * 72)/ 2.54 + self.cell_left= (self.paper.get_left_margin() * 72)/ 2.54 def start_cell(self,style_name,span=1): self.cell_span= span diff --git a/src/docgen/LaTeXDoc.py b/src/docgen/LaTeXDoc.py index c81800032..558dd9f1e 100644 --- a/src/docgen/LaTeXDoc.py +++ b/src/docgen/LaTeXDoc.py @@ -152,21 +152,22 @@ class LaTeXDoc(BaseDoc.BaseDoc): options = "12pt" - if self.orientation == BaseDoc.PAPER_LANDSCAPE: + if self.paper.get_orientation() == BaseDoc.PAPER_LANDSCAPE: options = options + ",landscape" # Paper selections are somewhat limited on a stock installation. # If the user picks something not listed here, we'll just accept # the default of the user's LaTeX installation (usually letter). - if self.paper.name == "A4": + paper_name = self.paper.get_size().get_name() + if paper_name == "A4": options = options + ",a4paper" - elif self.paper.name == "A5": + elif paper_name == "A5": options = options + ",a5paper" - elif self.paper.name == "B5": + elif paper_name == "B5": options = options + ",b4paper" - elif self.paper.name == "Legal": + elif paper_name == "Legal": options = options + ",legalpaper" - elif self.paper.name == "Letter": + elif paper_name == "Letter": options = options + ",letterpaper" # Use the article template, T1 font encodings, and specify diff --git a/src/docgen/ODFDoc.py b/src/docgen/ODFDoc.py index 048f7596b..8300ea092 100644 --- a/src/docgen/ODFDoc.py +++ b/src/docgen/ODFDoc.py @@ -73,8 +73,8 @@ _esc_map = { #------------------------------------------------------------------------- class ODFDoc(BaseDoc.BaseDoc): - def __init__(self,styles,type,template,orientation=BaseDoc.PAPER_PORTRAIT): - BaseDoc.BaseDoc.__init__(self,styles,type,template,orientation) + def __init__(self,styles,type,template): + BaseDoc.BaseDoc.__init__(self,styles,type,template) self.cntnt = None self.filename = None self.level = 0 @@ -745,17 +745,17 @@ class ODFDoc(BaseDoc.BaseDoc): self.sfile.write('style:justify-single-word="false"/>') self.sfile.write('\n') self.sfile.write('\n') - self.sfile.write('\n') self.sfile.write('\n') self.sfile.write('\n') self.sfile.write('\n') - self.sfile.write('\n') self.sfile.write('\n') self.f.write('\n') - self.f.write('\n') def rotate_text(self,style,text,x,y,angle): @@ -93,7 +93,7 @@ class SvgDrawDoc(BaseDoc.BaseDoc): width = max(width,self.string_width(font,line)) # rangle = -((pi/180.0) * angle) - centerx,centery = units((x+self.lmargin,y+self.tmargin)) + centerx,centery = units((x+self.paper.get_left_margin(),y+self.paper.get_top_margin())) yh = 0 for line in text: @@ -130,10 +130,10 @@ class SvgDrawDoc(BaseDoc.BaseDoc): self.f.close() def draw_line(self,style,x1,y1,x2,y2): - x1 = x1 + self.lmargin - x2 = x2 + self.lmargin - y1 = y1 + self.tmargin - y2 = y2 + self.tmargin + x1 = x1 + self.paper.get_left_margin() + x2 = x2 + self.paper.get_left_margin() + y1 = y1 + self.paper.get_top_margin() + y2 = y2 + self.paper.get_top_margin() s = self.draw_styles[style] @@ -149,16 +149,16 @@ class SvgDrawDoc(BaseDoc.BaseDoc): self.f.write('\n') def draw_bar(self,style,x1,y1,x2,y2): - x1 = x1 + self.lmargin - x2 = x2 + self.lmargin - y1 = y1 + self.tmargin - y2 = y2 + self.tmargin + x1 = x1 + self.paper.get_left_margin() + x2 = x2 + self.paper.get_left_margin() + y1 = y1 + self.paper.get_top_margin() + y2 = y2 + self.paper.get_top_margin() s = self.draw_styles[style] self.f.write('\n' % s.get_line_width()) def draw_box(self,style,text,x,y): - x = x + self.lmargin - y = y + self.tmargin + x = x + self.paper.get_left_margin() + y = y + self.paper.get_top_margin() box_style = self.draw_styles[style] para_name = box_style.get_paragraph_style() @@ -224,8 +224,8 @@ class SvgDrawDoc(BaseDoc.BaseDoc): self.f.write('\n') def draw_text(self,style,text,x,y): - x = x + self.lmargin - y = y + self.tmargin + x = x + self.paper.get_left_margin() + y = y + self.paper.get_top_margin() box_style = self.draw_styles[style] para_name = box_style.get_paragraph_style() diff --git a/src/plugins/BookReport.py b/src/plugins/BookReport.py index 6af0d04a3..6a3e62aea 100644 --- a/src/plugins/BookReport.py +++ b/src/plugins/BookReport.py @@ -1053,8 +1053,9 @@ class BookReportDialog(ReportDialog): def make_document(self): """Create a document of the type requested by the user.""" - self.doc = self.format(self.selected_style,self.paper, - self.template_name,self.orien) + self.doc = self.format(self.selected_style, + BaseDoc.PaperStyle(self.paper,self.orien), + self.template_name) self.rptlist = [] newpage = 0