* src/BaseDoc.py: add init function to BaseDoc to be called after

all graphics formats are defined
* src/docgen/OpenOfficeDoc.py: fix rotate_print and center_print
* src/plugins/AncestorChart.py: support BaseDoc.init
* src/plugins/AncestorReport.py: support BaseDoc.init
* src/plugins/BookReport.py: support BaseDoc.init
* src/plugins/CustomBookText.py: support BaseDoc.init
* src/plugins/DesGraph.py: support BaseDoc.init
* src/plugins/DescendReport.py: support BaseDoc.init
* src/plugins/DetAncestralReport.py: support BaseDoc.init
* src/plugins/DetDescendantReport.py: support BaseDoc.init
* src/plugins/FamilyGroup.py: support BaseDoc.init
* src/plugins/FanChart.py: support BaseDoc.init
* src/plugins/FtmStyleAncestors.py: support BaseDoc.init
* src/plugins/FtmStyleDescendants.py: support BaseDoc.init
* src/plugins/SimpleBookTitle.py: support BaseDoc.init


svn: r2119
This commit is contained in:
Don Allingham 2003-09-13 04:56:04 +00:00
parent 00ee47e2e2
commit 9719ea83ee
15 changed files with 111 additions and 10 deletions

View File

@ -1091,6 +1091,9 @@ class BaseDoc:
self.print_req = 0
self.mode = TEXT_MODE
def init(self):
pass
def set_mode(self, mode):
self.mode = mode

View File

@ -91,6 +91,8 @@ class OpenOfficeDoc(BaseDoc.BaseDoc):
except:
raise Errors.ReportError("Could not create %s" % self.content_xml)
def init(self):
self.f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
self.f.write('<office:document-content ')
self.f.write('xmlns:office="http://openoffice.org/2000/office" ')
@ -166,9 +168,62 @@ class OpenOfficeDoc(BaseDoc.BaseDoc):
self.f.write('style:parent-style-name="%s">\n' % style_name)
self.f.write('<style:properties fo:break-before="page"/>\n')
self.f.write('</style:style>\n')
self.f.write('<style:style style:name="X%s" ' % style_name)
self.f.write('style:family="paragraph" ')
self.f.write('style:parent-style-name="Standard" ')
self.f.write('style:class="text">\n')
self.f.write('<style:properties ')
if style.get_padding() != 0.0:
self.f.write('fo:padding="%.3fcm" ' % style.get_padding())
if style.get_header_level() > 0:
self.f.write('fo:keep-with-next="true" ')
align = style.get_alignment()
if align == BaseDoc.PARA_ALIGN_LEFT:
self.f.write('fo:text-align="start" ')
elif align == BaseDoc.PARA_ALIGN_RIGHT:
self.f.write('fo:text-align="end" ')
elif align == BaseDoc.PARA_ALIGN_CENTER:
self.f.write('fo:text-align="center" ')
self.f.write('style:justify-single-word="false" ')
else:
self.f.write('fo:text-align="justify" ')
self.f.write('style:justify-single-word="false" ')
font = style.get_font()
if font.get_type_face() == BaseDoc.FONT_SANS_SERIF:
self.f.write('style:font-name="Arial" ')
else:
self.f.write('style:font-name="Times New Roman" ')
self.f.write('fo:font-size="' + str(font.get_size()) + 'pt" ')
color = font.get_color()
self.f.write('fo:color="#%02x%02x%02x" ' % color)
if font.get_bold():
self.f.write('fo:font-weight="bold" ')
if font.get_italic():
self.f.write('fo:font-style="italic" ')
if font.get_underline():
self.f.write('style:text-underline="single" ')
self.f.write('style:text-underline-color="font-color" ')
self.f.write('fo:text-indent="%.2fcm" ' % style.get_first_indent())
self.f.write('fo:margin-right="%.2fcm" ' % style.get_right_margin())
self.f.write('fo:margin-left="%.2fcm" ' % style.get_left_margin())
self.f.write('fo:margin-top="0cm" ')
self.f.write('fo:margin-bottom="0.212cm"')
self.f.write('/>\n')
self.f.write('</style:style>\n')
self.f.write('<style:style style:name="F%s" ' % style_name)
self.f.write('style:family="text">\n')
self.f.write('<style:properties ')
align = style.get_alignment()
if align == BaseDoc.PARA_ALIGN_LEFT:
self.f.write('fo:text-align="start" ')
elif align == BaseDoc.PARA_ALIGN_RIGHT:
self.f.write('fo:text-align="end" ')
elif align == BaseDoc.PARA_ALIGN_CENTER:
self.f.write('fo:text-align="center" ')
font = style.get_font()
if font.get_type_face() == BaseDoc.FONT_SANS_SERIF:
self.f.write('style:font-name="Arial" ')
@ -324,7 +379,7 @@ class OpenOfficeDoc(BaseDoc.BaseDoc):
tag = string.replace(base,'.','_')
if self.new_cell:
self.f.write('<text:p>\n')
self.f.write('<text:p>')
if pos == "left":
self.f.write('<draw:image draw:style-name="Left" ')
elif pos == "right":
@ -575,10 +630,10 @@ class OpenOfficeDoc(BaseDoc.BaseDoc):
self.new_page = 1
def start_page(self):
self.f.write('<text:p text:style-name="docgen_page_break">')
self.f.write('<text:p text:style-name="docgen_page_break">\n')
def end_page(self):
self.f.write('</text:p>')
self.f.write('</text:p>\n')
def start_paragraph(self,style_name,leader=None):
style = self.style_list[style_name]
@ -593,10 +648,10 @@ class OpenOfficeDoc(BaseDoc.BaseDoc):
else:
self.f.write('<text:h text:style-name="')
self.f.write(name)
self.f.write('" text:level="' + str(self.level) + '">')
self.f.write('" text:level="' + str(self.level) + '">\n')
if leader != None:
self.f.write(leader)
self.f.write('<text:tab-stop/>')
self.f.write('<text:tab-stop/>\n')
self.new_cell = 0
def end_paragraph(self):
@ -709,6 +764,7 @@ class OpenOfficeDoc(BaseDoc.BaseDoc):
size = font.get_size()
height = size*(len(text))
oneline = (size/72.0)*2.54
width = 0
for line in text:
width = max(width,FontScale.string_width(font,line))
@ -722,12 +778,14 @@ class OpenOfficeDoc(BaseDoc.BaseDoc):
self.f.write('svg:height="%.3fpt" ' % hcm)
self.f.write('draw:transform="rotate (%.8f) ' % rangle)
xloc = x-((wcm/2.0)*cos(-rangle))
yloc = y-((hcm)*sin(-rangle))
yloc = y-((hcm)*sin(-rangle))-(hcm/2.0)
self.f.write('translate (%.3fcm %.3fcm)"' % (xloc,yloc))
self.f.write('>')
self.f.write('<text:p><text:span text:style-name="%s">' % pname)
self.f.write('<text:p text:style-name="X%s">' % pname)
self.f.write('<text:span text:style-name="F%s">\n' % pname)
self.write_text(string.join(text,'\n'))
self.f.write('</text:span></text:p></draw:text-box>\n')
self.f.write('</text:span>\n</text:p>\n</draw:text-box>\n')
def draw_path(self,style,path):
stype = self.draw_styles[style]
@ -842,6 +900,29 @@ class OpenOfficeDoc(BaseDoc.BaseDoc):
self.f.write('</text:p>\n')
self.f.write('</draw:rect>\n')
def center_text(self,style,text,x,y):
box_style = self.draw_styles[style]
para_name = box_style.get_paragraph_style()
pstyle = self.style_list[para_name]
font = pstyle.get_font()
size = (FontScale.string_width(font,text)/72.0) * 2.54
self.f.write('<draw:text-box text:anchor-type="paragraph" ')
self.f.write('draw:style-name="%s" ' % style)
self.f.write('draw:z-index="0" ')
self.f.write('svg:width="%.3fcm" ' % self.get_usable_width())
self.f.write('svg:height="%dpt" ' % (font.get_size()*1.1))
self.f.write('svg:x="0cm" ')
self.f.write('svg:y="%.3fcm">\n' % float(y))
if text != "":
self.f.write('<text:p text:style-name="X%s">' % para_name)
self.f.write(text)
self.f.write('</text:p>\n')
self.f.write('</draw:text-box>\n')
#--------------------------------------------------------------------------
#
# Register plugins

View File

@ -172,6 +172,8 @@ class AncestorChart:
g = BaseDoc.GraphicsStyle()
self.doc.add_draw_style("line",g)
if self.standalone:
self.doc.init()
def get_numbers(self,start,index,vals):
if index > 4:

View File

@ -58,6 +58,7 @@ class AncestorReport(Report.Report):
if output:
self.standalone = 1
self.doc.open(output)
self.doc.init()
else:
self.standalone = 0

View File

@ -970,6 +970,7 @@ class BookReportDialog(Report.ReportDialog):
"""The actual book report. Start it out, then go through the item list
and call each item's write_book_item method."""
self.doc.init()
for item in self.rptlist:
item.write_report()
self.doc.close()

View File

@ -66,6 +66,7 @@ class CustomText(Report.Report):
if output:
self.standalone = 1
self.doc.open(output)
self.doc.init()
else:
self.standalone = 0
self.sref_map = {}

View File

@ -241,6 +241,8 @@ class DescendantReport:
g = BaseDoc.GraphicsStyle()
self.doc.add_draw_style("line",g)
if self.standalone:
self.doc.init()
def print_page(self, plist,elist,r,c):
self.doc.start_page()

View File

@ -69,6 +69,7 @@ class DescendantReport:
if output:
self.standalone = 1
self.doc.open(output)
self.doc.init()
else:
self.standalone = 0

View File

@ -63,6 +63,7 @@ class DetAncestorReport(Report.Report):
self.standalone = 1
try:
self.doc.open(output)
self.doc.init()
except IOError,msg:
ErrorDialog(_("Could not open %s") % output + "\n" + msg)
else:

View File

@ -64,6 +64,7 @@ class DetDescendantReport(Report.Report):
self.standalone = 1
try:
self.doc.open(output)
self.doc.init()
except IOError,msg:
ErrorDialog(_("Could not open %s") % output + "\n" + msg)
else:

View File

@ -57,6 +57,7 @@ class FamilyGroup:
if output:
self.standalone = 1
self.doc.open(output)
self.doc.init()
else:
self.standalone = 0

View File

@ -76,6 +76,7 @@ class FanChart:
g = BaseDoc.GraphicsStyle()
g.set_paragraph_style('FC-Title')
g.set_line_width(0)
self.doc.add_draw_style("t",g)
g = BaseDoc.GraphicsStyle()
@ -136,6 +137,8 @@ class FanChart:
self.map = [None] * 32
self.text= {}
self.box_width = 0
if self.standalone:
self.doc.init()
def filter(self,person,index):
"""traverse the ancestors recursively until either the end

View File

@ -57,6 +57,7 @@ class FtmAncestorReport(Report.Report):
if output:
self.standalone = 1
self.doc.open(output)
self.doc.init()
else:
self.standalone = 0
self.sref_map = {}

View File

@ -65,6 +65,7 @@ class FtmDescendantReport(Report.Report):
if output:
self.standalone = 1
self.doc.open(output)
self.doc.init()
else:
self.standalone = 0
self.sref_map = {}

View File

@ -67,6 +67,7 @@ class SimpleBookTitle(Report.Report):
if output:
self.standalone = 1
self.doc.open(output)
self.doc.init()
else:
self.standalone = 0
self.sref_map = {}