Abiword can now do tables, but without lines.

svn: r766
This commit is contained in:
Don Allingham 2002-02-11 01:25:19 +00:00
parent b03d157e8f
commit d476628336
5 changed files with 169 additions and 58 deletions

View File

@ -43,9 +43,9 @@ class DescendLine(GraphLayout):
def space_for(self,person,level=1.0,pos=1.0): def space_for(self,person,level=1.0,pos=1.0):
last = self.elist[-1] last = self.elist[-1]
self.elist.append(level,pos) self.elist.append((level,pos))
self.e.append(last[0],last[1],level,pos) self.e.append((last[0],last[1],level,pos))
self.v.append(person,level,pos) self.v.append((person,level,pos))
if level > self.maxx: if level > self.maxx:
self.maxx = level self.maxx = level
if pos > self.maxy: if pos > self.maxy:

View File

@ -20,6 +20,7 @@
import os import os
import const import const
import string
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -29,6 +30,7 @@ import const
try: try:
import PIL.Image import PIL.Image
import StringIO import StringIO
PIL.Image.init()
no_pil = 0 no_pil = 0
except: except:
import popen2 import popen2
@ -91,21 +93,26 @@ class ImgManip:
if im.mode != 'RGB': if im.mode != 'RGB':
im.draft('RGB',im.size) im.draft('RGB',im.size)
im = im.convert("RGB") im = im.convert("RGB")
im.save(dest,pil) im.save(dest,string.upper(pil))
def fmt_convert(self,dest,pil): def fmt_convert(self,dest,pil):
im = PIL.Image.open(self.src) im = PIL.Image.open(self.src)
if im.mode != 'RGB': if im.mode != 'RGB':
im.draft('RGB',im.size) im.draft('RGB',im.size)
im = im.convert("RGB") im = im.convert("RGB")
im.save(dest,pil) im.save(dest,string.upper(pil))
def fmt_data(self,pil): def fmt_data(self,pil):
g = StringIO.StringIO()
im = PIL.Image.open(self.src) im = PIL.Image.open(self.src)
if im.mode != 'RGB': if im.mode != 'RGB':
im.draft('RGB',im.size) im.draft('RGB',im.size)
im = im.convert("RGB") im = im.convert("RGB")
return im.tostring(pil,"RGB") im.save(g,string.upper(pil))
g.seek(0)
buf = g.read()
g.close()
return buf
def fmt_scale_data(self,x,y,pil): def fmt_scale_data(self,x,y,pil):
im = PIL.Image.open(self.src) im = PIL.Image.open(self.src)
@ -113,7 +120,7 @@ class ImgManip:
if im.mode != 'RGB': if im.mode != 'RGB':
im.draft('RGB',im.size) im.draft('RGB',im.size)
im = im.convert("RGB") im = im.convert("RGB")
return im.tostring(pil,"RGB") return im.tostring(string.upper(pil),"RGB")
def eps_data(self): def eps_data(self):
g = StringIO.StringIO() g = StringIO.StringIO()
@ -168,10 +175,10 @@ class ImgManip:
return self.fmt_data("png") return self.fmt_data("png")
def jpg_scale_data(self,x,y): def jpg_scale_data(self,x,y):
return self.fmt(x,y,"jpeg") return self.fmt_scale_data(x,y,"jpeg")
def png_scale_data(self,x,y): def png_scale_data(self,x,y):
return self.fmt(x,y,"png") return self.fmt_scale_data(x,y,"png")
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -223,7 +223,7 @@ class Place(SourceNote):
self.long = "" self.long = ""
self.lat = "" self.lat = ""
self.title = "" self.title = ""
self.main_loc = Location() self.main_loc = None
self.alt_loc = [] self.alt_loc = []
self.id = "" self.id = ""
self.urls = [] self.urls = []
@ -275,6 +275,8 @@ class Place(SourceNote):
def get_main_location(self): def get_main_location(self):
"""Returns the Location object representing the primary information""" """Returns the Location object representing the primary information"""
if not self.main_loc:
self.main_loc = Location()
return self.main_loc return self.main_loc
def set_main_location(self,loc): def set_main_location(self,loc):
@ -1868,16 +1870,16 @@ class RelDataBase:
self.pmapIndex = self.pmapIndex+1 self.pmapIndex = self.pmapIndex+1
return id return id
def findPersonNoMap(self,idVal): def findPersonNoMap(self,val):
"""finds a Person in the database from the passed gramps' ID. """finds a Person in the database from the passed gramps' ID.
If no such Person exists, a new Person is added to the database.""" If no such Person exists, a new Person is added to the database."""
val = str(idVal) person = self.personMap.get(val)
if self.personMap.has_key(val): if not person:
person = self.personMap[val]
else:
person = Person() person = Person()
self.addPersonNoMap(person,val) person.id = val
self.personMap[val] = person
self.pmapIndex = self.pmapIndex+1
return person return person
def addSource(self,source): def addSource(self,source):
@ -1902,7 +1904,6 @@ class RelDataBase:
idVal - external ID number idVal - external ID number
map - map build by findSource of external to gramp's IDs""" map - map build by findSource of external to gramp's IDs"""
idVal = str(idVal)
if map.has_key(idVal): if map.has_key(idVal):
source = self.sourceMap[map[idVal]] source = self.sourceMap[map[idVal]]
else: else:
@ -1912,17 +1913,15 @@ class RelDataBase:
def addSourceNoMap(self,source,index): def addSourceNoMap(self,source,index):
"""adds a Source to the database if the gramps' ID is known""" """adds a Source to the database if the gramps' ID is known"""
index = str(index)
source.setId(index) source.setId(index)
self.sourceMap[index] = source self.sourceMap[index] = source
self.smapIndex = self.smapIndex + 1 self.smapIndex = self.smapIndex + 1
return index return index
def findSourceNoMap(self,idVal): def findSourceNoMap(self,val):
"""finds a Source in the database from the passed gramps' ID. """finds a Source in the database from the passed gramps' ID.
If no such Source exists, a new Source is added to the database.""" If no such Source exists, a new Source is added to the database."""
val = str(idVal)
if self.sourceMap.has_key(val): if self.sourceMap.has_key(val):
source = self.sourceMap[val] source = self.sourceMap[val]
else: else:
@ -2019,16 +2018,16 @@ class RelDataBase:
self.lmapIndex = self.lmapIndex + 1 self.lmapIndex = self.lmapIndex + 1
return index return index
def findPlaceNoMap(self,idVal): def findPlaceNoMap(self,val):
"""finds a Place in the database from the passed gramps' ID. """finds a Place in the database from the passed gramps' ID.
If no such Place exists, a new Place is added to the database.""" If no such Place exists, a new Place is added to the database."""
val = str(idVal) place = self.placeMap.get(val)
if self.placeMap.has_key(val): if not place:
place = self.placeMap[val]
else:
place = Place() place = Place()
self.addPlaceNoMap(place,val) place.id = val
self.placeMap[val] = place
self.lmapIndex = self.lmapIndex + 1
return place return place
def newFamily(self): def newFamily(self):
@ -2063,7 +2062,6 @@ class RelDataBase:
idVal - external ID number idVal - external ID number
map - map build by findFamily of external to gramp's IDs""" map - map build by findFamily of external to gramp's IDs"""
idVal = str(idVal)
if map.has_key(idVal): if map.has_key(idVal):
family = self.familyMap[map[idVal]] family = self.familyMap[map[idVal]]
else: else:
@ -2071,14 +2069,16 @@ class RelDataBase:
map[idVal] = family.getId() map[idVal] = family.getId()
return family return family
def findFamilyNoMap(self,idVal): def findFamilyNoMap(self,val):
"""finds a Family in the database from the passed gramps' ID. """finds a Family in the database from the passed gramps' ID.
If no such Family exists, a new Family is added to the database.""" If no such Family exists, a new Family is added to the database."""
val = str(idVal)
if self.familyMap.has_key(val): family = self.familyMap.get(val)
family = self.familyMap[val] if not family:
else: family = Family()
family = self.newFamilyNoMap(val) family.id = val
self.familyMap[val] = family
self.fmapIndex = self.fmapIndex + 1
return family return family
def deleteFamily(self,family): def deleteFamily(self,family):

View File

@ -47,13 +47,14 @@ class AbiWordDoc(TextDoc):
"""AbiWord document generator. Inherits from the TextDoc generic """AbiWord document generator. Inherits from the TextDoc generic
document interface class.""" document interface class."""
def __init__(self,styles,type,orientation): def __init__(self,styles,type,template,orientation):
"""Initializes the AbiWordDoc class, calling the __init__ routine """Initializes the AbiWordDoc class, calling the __init__ routine
of the parent TextDoc class""" of the parent TextDoc class"""
TextDoc.__init__(self,styles,type,orientation) TextDoc.__init__(self,styles,type,template,orientation)
self.f = None self.f = None
self.level = 0 self.level = 0
self.new_page = 0 self.new_page = 0
self.in_table = 0
def open(self,filename): def open(self,filename):
"""Opens the document, writing the necessary header information. """Opens the document, writing the necessary header information.
@ -66,15 +67,18 @@ class AbiWordDoc(TextDoc):
self.f = open(self.filename,"w") self.f = open(self.filename,"w")
self.f.write('<?xml version="1.0" encoding="ISO-8859-1"?>\n') self.f.write('<?xml version="1.0" encoding="ISO-8859-1"?>\n')
self.f.write('<abiword version="0.7.14" fileformat="1.0">\n') self.f.write('<!DOCTYPE abiword PUBLIC "-//ABISOURCE//DTD AWML')
self.f.write('1.0 Strict//EN" "http://www.abisource.com/awml.dtd">\n')
self.f.write('<abiword xmlns:awml="http://www.abisource.com/awml.dtd" ')
self.f.write('version="0.9.6.1" fileformat="1.0">\n')
self.f.write('<pagesize ') self.f.write('<pagesize ')
self.f.write('pagetype="%s" ' % self.paper.get_name()) self.f.write('pagetype="%s" ' % self.paper.get_name())
if self.orientation == PAPER_PORTRAIT: if self.orientation == PAPER_PORTRAIT:
self.f.write('orientation="portrait" ') self.f.write('orientation="portrait" ')
else: else:
self.f.write('orientation="landscape" ') self.f.write('orientation="landscape" ')
self.f.write('width="%.4f" ' % self.width/2.54) self.f.write('width="%.4f" ' % (self.width/2.54))
self.f.write('height="%.4f" ' % self.height/2.54) self.f.write('height="%.4f" ' % (self.height/2.54))
self.f.write('units="inch" page-scale="1.000000"/>\n') self.f.write('units="inch" page-scale="1.000000"/>\n')
self.f.write('<section ') self.f.write('<section ')
rmargin = float(self.rmargin)/2.54 rmargin = float(self.rmargin)/2.54
@ -96,27 +100,30 @@ class AbiWordDoc(TextDoc):
tag = string.replace(base,'.','_') tag = string.replace(base,'.','_')
img = ImgManip.ImgManip(file) img = ImgManip.ImgManip(file)
buf = img.png_scale_data(width,height) buf = img.png_data()
self.f.write('<d name="') self.f.write('<d name="')
self.f.write(tag) self.f.write(tag)
self.f.write('" mime-type="image/png" base64="yes">\n') self.f.write('" mime-type="image/png" base64="yes">\n')
self.f.write(base64.encodestring(buf)) self.f.write(base64.encodestring(buf))
os.unlink(base)
self.f.write('</d>\n') self.f.write('</d>\n')
self.f.write('</data>\n') self.f.write('</data>\n')
self.f.write('</abiword>\n') self.f.write('</abiword>\n')
self.f.close() self.f.close()
def add_photo(self,pos,name,x_cm,y_cm): def add_photo(self,name,pos,x_cm,y_cm):
import gtk
import GdkImlib image = ImgManip.ImgManip(name)
(x,y) = image.size()
aspect_ratio = float(x)/float(y)
image = GdkImlib.Image(name) if aspect_ratio > x_cm/y_cm:
scale = float(image.rgb_width)/float(image.rgb_height) act_width = x_cm
act_width = int(((x_cm * scale)*2.54)*72) act_height = y_cm/aspect_ratio
act_height = int(((y_cm * scale)*2.54)*72) else:
act_height = y_cm
act_width = x_cm*aspect_ratio
self.photo_list.append((name,act_width,act_height)) self.photo_list.append((name,act_width,act_height))
@ -129,6 +136,12 @@ class AbiWordDoc(TextDoc):
self.f.write('height:%.3fin"/>' % act_height) self.f.write('height:%.3fin"/>' % act_height)
def start_paragraph(self,style_name,leader=None): def start_paragraph(self,style_name,leader=None):
if self.in_table:
self.start_paragraph_intable(style_name,leader)
else:
self.start_paragraph_notable(style_name,leader)
def start_paragraph_notable(self,style_name,leader=None):
style = self.style_list[style_name] style = self.style_list[style_name]
self.current_style = style self.current_style = style
self.f.write('<p props="') self.f.write('<p props="')
@ -171,18 +184,48 @@ class AbiWordDoc(TextDoc):
if leader != None: if leader != None:
self.f.write(leader) self.f.write(leader)
self.f.write('\t') self.f.write('\t')
def start_paragraph_intable(self,style_name,leader=None):
style = self.style_list[style_name]
self.current_style = style
font = style.get_font()
self.cdata = '<c props="font-family:'
if font.get_type_face() == FONT_SANS_SERIF:
self.cdata = self.cdata + 'Arial;'
else:
self.cdata = self.cdata + 'Times New Roman;'
self.cdata = self.cdata + 'font-size:%dpt' % font.get_size()
if font.get_bold():
self.cdata = self.cdata + '; font-weight:bold'
if font.get_italic():
self.cdata = self.cdata + '; font-style:italic'
color = font.get_color()
if color != (0,0,0):
self.cdata = self.cdata + '; color:%2x%2x%2x' % color
if font.get_underline():
self.cdata = self.cdata + '; text-decoration:underline'
self.cdata = self.cdata + '; lang:en-US">'
if self.new_page == 1:
self.new_page = 0
self.f.write('<pbr/>')
def page_break(self): def page_break(self):
self.new_page = 1 self.new_page = 1
def end_paragraph(self): def end_paragraph(self):
self.f.write('</c></p>\n') if self.in_table:
self.cdata = self.cdata + '\t'
else:
self.f.write('</c></p>\n')
def write_text(self,text): def write_text(self,text):
text = string.replace(text,'&','&amp;'); # Must be first text = string.replace(text,'&','&amp;'); # Must be first
text = string.replace(text,'<','&lt;'); text = string.replace(text,'<','&lt;');
text = string.replace(text,'>','&gt;'); text = string.replace(text,'>','&gt;');
self.f.write(text) if self.in_table:
self.cdata = self.cdata + text
else:
self.f.write(text)
def start_bold(self): def start_bold(self):
font = self.current_style.get_font() font = self.current_style.get_font()
@ -221,4 +264,62 @@ class AbiWordDoc(TextDoc):
self.f.write('; text-decoration:underline') self.f.write('; text-decoration:underline')
self.f.write('">') self.f.write('">')
Plugins.register_text_doc(_("AbiWord"),AbiWordDoc,0,1,1) def start_table(self,name,style_name):
self.in_table = 1
self.tblstyle = self.table_styles[style_name]
def end_table(self):
self.in_table = 0
def start_row(self):
self.tabs = []
self.ledge = 0.0
self.col = 0
self.cdatalist = []
def end_row(self):
first = 0
self.f.write('<p')
self.tabs.sort()
oldv = -1.0
useb = 0
if len(self.tabs) > 0:
self.f.write(' props="tabstops:')
for val,t in self.tabs:
if val == oldv:
if t == 'B0':
useb = 1
continue
oldv = val
if not first:
first = 1
else:
self.f.write(',')
edge = (val * self.get_usable_width())
if val == 1.0:
edge = edge-0.1
elif val == 0.0:
edge = edge+0.1
if useb:
t = 'B0'
self.f.write("%6.4fin/%s" % (edge/2.54,t))
self.f.write('"')
self.f.write('>')
last = len(self.cdatalist)
for data in self.cdatalist:
self.f.write(data)
self.f.write('</p>\n')
def start_cell(self,style_name,span=1):
self.cstyle = self.cell_styles[style_name]
for i in range(self.col,self.col+span):
self.col = self.col + 1
self.ledge = self.ledge + self.tblstyle.get_column_width(i)
self.tabs.append((self.ledge/100.0,"L"))
def end_cell(self):
self.cdata = self.cdata + "</c>"
self.cdatalist.append(self.cdata)
Plugins.register_text_doc(_("AbiWord"),AbiWordDoc,1,1,1)

View File

@ -238,21 +238,21 @@ class PdfDoc(TextDoc):
self.tblstyle.append(('FONT', loc, loc, fn, f.get_size())) self.tblstyle.append(('FONT', loc, loc, fn, f.get_size()))
if self.span == 1 or inc == self.col + self.span - 1: if self.span == 1 or inc == self.col + self.span - 1:
if self.my_table_style.get_right_border(): if self.my_table_style.get_right_border():
self.tblstyle.append('LINEAFTER', loc, loc, 1, black) self.tblstyle.append(('LINEAFTER', loc, loc, 1, black))
if self.span == 1 or inc == self.col: if self.span == 1 or inc == self.col:
if self.my_table_style.get_left_border(): if self.my_table_style.get_left_border():
self.tblstyle.append('LINEBEFORE', loc, loc, 1, black) self.tblstyle.append(('LINEBEFORE', loc, loc, 1, black))
if self.my_table_style.get_top_border(): if self.my_table_style.get_top_border():
self.tblstyle.append('LINEABOVE', loc, loc, 1, black) self.tblstyle.append(('LINEABOVE', loc, loc, 1, black))
if self.my_table_style.get_bottom_border(): if self.my_table_style.get_bottom_border():
self.tblstyle.append('LINEBELOW', loc, loc, 1, black) self.tblstyle.append(('LINEBELOW', loc, loc, 1, black))
if p.get_alignment() == PARA_ALIGN_LEFT: if p.get_alignment() == PARA_ALIGN_LEFT:
self.tblstyle.append('ALIGN', loc, loc, 'LEFT') self.tblstyle.append(('ALIGN', loc, loc, 'LEFT'))
elif p.get_alignment() == PARA_ALIGN_RIGHT: elif p.get_alignment() == PARA_ALIGN_RIGHT:
self.tblstyle.append('ALIGN', loc, loc, 'RIGHT') self.tblstyle.append(('ALIGN', loc, loc, 'RIGHT'))
else: else:
self.tblstyle.append('ALIGN', loc, loc, 'CENTER') self.tblstyle.append(('ALIGN', loc, loc, 'CENTER'))
self.tblstyle.append('VALIGN', loc, loc, 'TOP') self.tblstyle.append(('VALIGN', loc, loc, 'TOP'))
self.col = self.col + self.span self.col = self.col + self.span
@ -273,6 +273,9 @@ class PdfDoc(TextDoc):
self.image = 1 self.image = 1
def write_text(self,text): def write_text(self,text):
text = string.replace(text,'&','&amp;'); # Must be first
text = string.replace(text,'<','&lt;');
text = string.replace(text,'>','&gt;');
self.text = self.text + text self.text = self.text + text
#------------------------------------------------------------------------ #------------------------------------------------------------------------