Abiword can now do tables, but without lines.
svn: r766
This commit is contained in:
parent
b03d157e8f
commit
d476628336
@ -43,9 +43,9 @@ class DescendLine(GraphLayout):
|
||||
|
||||
def space_for(self,person,level=1.0,pos=1.0):
|
||||
last = self.elist[-1]
|
||||
self.elist.append(level,pos)
|
||||
self.e.append(last[0],last[1],level,pos)
|
||||
self.v.append(person,level,pos)
|
||||
self.elist.append((level,pos))
|
||||
self.e.append((last[0],last[1],level,pos))
|
||||
self.v.append((person,level,pos))
|
||||
if level > self.maxx:
|
||||
self.maxx = level
|
||||
if pos > self.maxy:
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
import os
|
||||
import const
|
||||
import string
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -29,6 +30,7 @@ import const
|
||||
try:
|
||||
import PIL.Image
|
||||
import StringIO
|
||||
PIL.Image.init()
|
||||
no_pil = 0
|
||||
except:
|
||||
import popen2
|
||||
@ -91,21 +93,26 @@ class ImgManip:
|
||||
if im.mode != 'RGB':
|
||||
im.draft('RGB',im.size)
|
||||
im = im.convert("RGB")
|
||||
im.save(dest,pil)
|
||||
im.save(dest,string.upper(pil))
|
||||
|
||||
def fmt_convert(self,dest,pil):
|
||||
im = PIL.Image.open(self.src)
|
||||
if im.mode != 'RGB':
|
||||
im.draft('RGB',im.size)
|
||||
im = im.convert("RGB")
|
||||
im.save(dest,pil)
|
||||
im.save(dest,string.upper(pil))
|
||||
|
||||
def fmt_data(self,pil):
|
||||
g = StringIO.StringIO()
|
||||
im = PIL.Image.open(self.src)
|
||||
if im.mode != 'RGB':
|
||||
im.draft('RGB',im.size)
|
||||
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):
|
||||
im = PIL.Image.open(self.src)
|
||||
@ -113,7 +120,7 @@ class ImgManip:
|
||||
if im.mode != 'RGB':
|
||||
im.draft('RGB',im.size)
|
||||
im = im.convert("RGB")
|
||||
return im.tostring(pil,"RGB")
|
||||
return im.tostring(string.upper(pil),"RGB")
|
||||
|
||||
def eps_data(self):
|
||||
g = StringIO.StringIO()
|
||||
@ -168,10 +175,10 @@ class ImgManip:
|
||||
return self.fmt_data("png")
|
||||
|
||||
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):
|
||||
return self.fmt(x,y,"png")
|
||||
return self.fmt_scale_data(x,y,"png")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -223,7 +223,7 @@ class Place(SourceNote):
|
||||
self.long = ""
|
||||
self.lat = ""
|
||||
self.title = ""
|
||||
self.main_loc = Location()
|
||||
self.main_loc = None
|
||||
self.alt_loc = []
|
||||
self.id = ""
|
||||
self.urls = []
|
||||
@ -275,6 +275,8 @@ class Place(SourceNote):
|
||||
|
||||
def get_main_location(self):
|
||||
"""Returns the Location object representing the primary information"""
|
||||
if not self.main_loc:
|
||||
self.main_loc = Location()
|
||||
return self.main_loc
|
||||
|
||||
def set_main_location(self,loc):
|
||||
@ -1868,16 +1870,16 @@ class RelDataBase:
|
||||
self.pmapIndex = self.pmapIndex+1
|
||||
return id
|
||||
|
||||
def findPersonNoMap(self,idVal):
|
||||
def findPersonNoMap(self,val):
|
||||
"""finds a Person in the database from the passed gramps' ID.
|
||||
If no such Person exists, a new Person is added to the database."""
|
||||
|
||||
val = str(idVal)
|
||||
if self.personMap.has_key(val):
|
||||
person = self.personMap[val]
|
||||
else:
|
||||
person = self.personMap.get(val)
|
||||
if not person:
|
||||
person = Person()
|
||||
self.addPersonNoMap(person,val)
|
||||
person.id = val
|
||||
self.personMap[val] = person
|
||||
self.pmapIndex = self.pmapIndex+1
|
||||
return person
|
||||
|
||||
def addSource(self,source):
|
||||
@ -1902,7 +1904,6 @@ class RelDataBase:
|
||||
idVal - external ID number
|
||||
map - map build by findSource of external to gramp's IDs"""
|
||||
|
||||
idVal = str(idVal)
|
||||
if map.has_key(idVal):
|
||||
source = self.sourceMap[map[idVal]]
|
||||
else:
|
||||
@ -1912,17 +1913,15 @@ class RelDataBase:
|
||||
|
||||
def addSourceNoMap(self,source,index):
|
||||
"""adds a Source to the database if the gramps' ID is known"""
|
||||
index = str(index)
|
||||
source.setId(index)
|
||||
self.sourceMap[index] = source
|
||||
self.smapIndex = self.smapIndex + 1
|
||||
return index
|
||||
|
||||
def findSourceNoMap(self,idVal):
|
||||
def findSourceNoMap(self,val):
|
||||
"""finds a Source in the database from the passed gramps' ID.
|
||||
If no such Source exists, a new Source is added to the database."""
|
||||
|
||||
val = str(idVal)
|
||||
if self.sourceMap.has_key(val):
|
||||
source = self.sourceMap[val]
|
||||
else:
|
||||
@ -2019,16 +2018,16 @@ class RelDataBase:
|
||||
self.lmapIndex = self.lmapIndex + 1
|
||||
return index
|
||||
|
||||
def findPlaceNoMap(self,idVal):
|
||||
def findPlaceNoMap(self,val):
|
||||
"""finds a Place in the database from the passed gramps' ID.
|
||||
If no such Place exists, a new Place is added to the database."""
|
||||
|
||||
val = str(idVal)
|
||||
if self.placeMap.has_key(val):
|
||||
place = self.placeMap[val]
|
||||
else:
|
||||
place = self.placeMap.get(val)
|
||||
if not place:
|
||||
place = Place()
|
||||
self.addPlaceNoMap(place,val)
|
||||
place.id = val
|
||||
self.placeMap[val] = place
|
||||
self.lmapIndex = self.lmapIndex + 1
|
||||
return place
|
||||
|
||||
def newFamily(self):
|
||||
@ -2063,7 +2062,6 @@ class RelDataBase:
|
||||
idVal - external ID number
|
||||
map - map build by findFamily of external to gramp's IDs"""
|
||||
|
||||
idVal = str(idVal)
|
||||
if map.has_key(idVal):
|
||||
family = self.familyMap[map[idVal]]
|
||||
else:
|
||||
@ -2071,14 +2069,16 @@ class RelDataBase:
|
||||
map[idVal] = family.getId()
|
||||
return family
|
||||
|
||||
def findFamilyNoMap(self,idVal):
|
||||
def findFamilyNoMap(self,val):
|
||||
"""finds a Family in the database from the passed gramps' ID.
|
||||
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[val]
|
||||
else:
|
||||
family = self.newFamilyNoMap(val)
|
||||
|
||||
family = self.familyMap.get(val)
|
||||
if not family:
|
||||
family = Family()
|
||||
family.id = val
|
||||
self.familyMap[val] = family
|
||||
self.fmapIndex = self.fmapIndex + 1
|
||||
return family
|
||||
|
||||
def deleteFamily(self,family):
|
||||
|
@ -47,13 +47,14 @@ class AbiWordDoc(TextDoc):
|
||||
"""AbiWord document generator. Inherits from the TextDoc generic
|
||||
document interface class."""
|
||||
|
||||
def __init__(self,styles,type,orientation):
|
||||
def __init__(self,styles,type,template,orientation):
|
||||
"""Initializes the AbiWordDoc class, calling the __init__ routine
|
||||
of the parent TextDoc class"""
|
||||
TextDoc.__init__(self,styles,type,orientation)
|
||||
TextDoc.__init__(self,styles,type,template,orientation)
|
||||
self.f = None
|
||||
self.level = 0
|
||||
self.new_page = 0
|
||||
self.in_table = 0
|
||||
|
||||
def open(self,filename):
|
||||
"""Opens the document, writing the necessary header information.
|
||||
@ -66,15 +67,18 @@ class AbiWordDoc(TextDoc):
|
||||
|
||||
self.f = open(self.filename,"w")
|
||||
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('pagetype="%s" ' % self.paper.get_name())
|
||||
if self.orientation == PAPER_PORTRAIT:
|
||||
self.f.write('orientation="portrait" ')
|
||||
else:
|
||||
self.f.write('orientation="landscape" ')
|
||||
self.f.write('width="%.4f" ' % self.width/2.54)
|
||||
self.f.write('height="%.4f" ' % self.height/2.54)
|
||||
self.f.write('width="%.4f" ' % (self.width/2.54))
|
||||
self.f.write('height="%.4f" ' % (self.height/2.54))
|
||||
self.f.write('units="inch" page-scale="1.000000"/>\n')
|
||||
self.f.write('<section ')
|
||||
rmargin = float(self.rmargin)/2.54
|
||||
@ -96,27 +100,30 @@ class AbiWordDoc(TextDoc):
|
||||
tag = string.replace(base,'.','_')
|
||||
|
||||
img = ImgManip.ImgManip(file)
|
||||
buf = img.png_scale_data(width,height)
|
||||
buf = img.png_data()
|
||||
|
||||
self.f.write('<d name="')
|
||||
self.f.write(tag)
|
||||
self.f.write('" mime-type="image/png" base64="yes">\n')
|
||||
self.f.write(base64.encodestring(buf))
|
||||
os.unlink(base)
|
||||
self.f.write('</d>\n')
|
||||
self.f.write('</data>\n')
|
||||
|
||||
self.f.write('</abiword>\n')
|
||||
self.f.close()
|
||||
|
||||
def add_photo(self,pos,name,x_cm,y_cm):
|
||||
import gtk
|
||||
import GdkImlib
|
||||
def add_photo(self,name,pos,x_cm,y_cm):
|
||||
|
||||
image = GdkImlib.Image(name)
|
||||
scale = float(image.rgb_width)/float(image.rgb_height)
|
||||
act_width = int(((x_cm * scale)*2.54)*72)
|
||||
act_height = int(((y_cm * scale)*2.54)*72)
|
||||
image = ImgManip.ImgManip(name)
|
||||
(x,y) = image.size()
|
||||
aspect_ratio = float(x)/float(y)
|
||||
|
||||
if aspect_ratio > x_cm/y_cm:
|
||||
act_width = x_cm
|
||||
act_height = y_cm/aspect_ratio
|
||||
else:
|
||||
act_height = y_cm
|
||||
act_width = x_cm*aspect_ratio
|
||||
|
||||
self.photo_list.append((name,act_width,act_height))
|
||||
|
||||
@ -129,6 +136,12 @@ class AbiWordDoc(TextDoc):
|
||||
self.f.write('height:%.3fin"/>' % act_height)
|
||||
|
||||
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]
|
||||
self.current_style = style
|
||||
self.f.write('<p props="')
|
||||
@ -172,17 +185,47 @@ class AbiWordDoc(TextDoc):
|
||||
self.f.write(leader)
|
||||
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):
|
||||
self.new_page = 1
|
||||
|
||||
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):
|
||||
text = string.replace(text,'&','&'); # Must be first
|
||||
text = string.replace(text,'<','<');
|
||||
text = string.replace(text,'>','>');
|
||||
self.f.write(text)
|
||||
if self.in_table:
|
||||
self.cdata = self.cdata + text
|
||||
else:
|
||||
self.f.write(text)
|
||||
|
||||
def start_bold(self):
|
||||
font = self.current_style.get_font()
|
||||
@ -221,4 +264,62 @@ class AbiWordDoc(TextDoc):
|
||||
self.f.write('; text-decoration:underline')
|
||||
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)
|
||||
|
@ -238,21 +238,21 @@ class PdfDoc(TextDoc):
|
||||
self.tblstyle.append(('FONT', loc, loc, fn, f.get_size()))
|
||||
if self.span == 1 or inc == self.col + self.span - 1:
|
||||
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.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():
|
||||
self.tblstyle.append('LINEABOVE', loc, loc, 1, black)
|
||||
self.tblstyle.append(('LINEABOVE', loc, loc, 1, black))
|
||||
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:
|
||||
self.tblstyle.append('ALIGN', loc, loc, 'LEFT')
|
||||
self.tblstyle.append(('ALIGN', loc, loc, 'LEFT'))
|
||||
elif p.get_alignment() == PARA_ALIGN_RIGHT:
|
||||
self.tblstyle.append('ALIGN', loc, loc, 'RIGHT')
|
||||
self.tblstyle.append(('ALIGN', loc, loc, 'RIGHT'))
|
||||
else:
|
||||
self.tblstyle.append('ALIGN', loc, loc, 'CENTER')
|
||||
self.tblstyle.append('VALIGN', loc, loc, 'TOP')
|
||||
self.tblstyle.append(('ALIGN', loc, loc, 'CENTER'))
|
||||
self.tblstyle.append(('VALIGN', loc, loc, 'TOP'))
|
||||
|
||||
self.col = self.col + self.span
|
||||
|
||||
@ -273,6 +273,9 @@ class PdfDoc(TextDoc):
|
||||
self.image = 1
|
||||
|
||||
def write_text(self,text):
|
||||
text = string.replace(text,'&','&'); # Must be first
|
||||
text = string.replace(text,'<','<');
|
||||
text = string.replace(text,'>','>');
|
||||
self.text = self.text + text
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user