diff --git a/src/KwordDoc.py b/src/KwordDoc.py index 45b130269..ca74c10a9 100644 --- a/src/KwordDoc.py +++ b/src/KwordDoc.py @@ -106,6 +106,8 @@ def sizes(val): class KwordDoc(TextDoc): def open(self,filename): + self.photolist = [] + if filename[-4:] != ".kwd": self.filename = filename + ".kwd" else: @@ -140,14 +142,28 @@ class KwordDoc(TextDoc): self.f.write('\n') self.f.write('\n') - self.f.write('\n') - self.f.write('\n') + self.f.write('' % sizes(self.lmargin)) self.f.write('\n') self.f.write('\n' % sizes(padding)) if p.get_alignment() == PARA_ALIGN_CENTER: - self.f.write('\n') + self.f.write('\n') elif p.get_alignment() == PARA_ALIGN_JUSTIFY: - self.f.write('\n') + self.f.write('\n') elif p.get_alignment() == PARA_ALIGN_RIGHT: - self.f.write('\n') + self.f.write('\n') first = p.get_first_indent() right = p.get_right_margin() @@ -225,10 +235,21 @@ class KwordDoc(TextDoc): else: self.f.write('\n') self.f.write('\n' % font.get_size()) + self.f.write('\n' % font.get_color()) if font.get_bold(): self.f.write('\n') if font.get_italic(): self.f.write('\n') + if font.get_underline(): + self.f.write('\n') + if para.get_top_border(): + self.f.write('\n') + if para.get_bottom_border(): + self.f.write('\n') + if para.get_right_border(): + self.f.write('\n') + if para.get_left_border(): + self.f.write('\n') self.f.write('\n') if left != 0: self.f.write('\n' % sizes(left)) @@ -236,6 +257,8 @@ class KwordDoc(TextDoc): self.f.write('\n') self.f.write('\n') + for file in self.photo_list: + self.f.write('\n' % file) self.f.write('\n') self.f.write('\n') self.f.write('\n') @@ -249,6 +272,10 @@ class KwordDoc(TextDoc): tar = TarFile(self.filename) tar.add_file("documentinfo.xml",mtime,self.m) tar.add_file("maindoc.xml",mtime,self.f) + for file in self.photo_list: + f = open(file[0],"r") + tar.add_file(file[1],mtime,f) + f.close() tar.close() self.f.close() @@ -303,11 +330,11 @@ class KwordDoc(TextDoc): self.f.write('\n' % sizes(padding)) if self.p.get_alignment() == PARA_ALIGN_CENTER: - self.f.write('\n') + self.f.write('\n') elif self.p.get_alignment() == PARA_ALIGN_JUSTIFY: - self.f.write('\n') + self.f.write('\n') elif self.p.get_alignment() == PARA_ALIGN_RIGHT: - self.f.write('\n') + self.f.write('\n') first = self.p.get_first_indent() right = self.p.get_right_margin() @@ -322,10 +349,21 @@ class KwordDoc(TextDoc): self.f.write('\n') self.f.write('\n' % self.font_face) self.f.write('\n' % self.font.get_size()) + self.f.write('\n' % self.font.get_color()) if self.font.get_bold(): self.f.write('\n') if self.font.get_italic(): self.f.write('\n') + if self.font.get_underline(): + self.f.write('\n') + if self.p.get_top_border(): + self.f.write('\n') + if self.p.get_bottom_border(): + self.f.write('\n') + if self.p.get_right_border(): + self.f.write('\n') + if self.p.get_left_border(): + self.f.write('\n') self.f.write('\n') if left != 0: self.f.write('\n' % sizes(left)) @@ -367,6 +405,15 @@ class KwordDoc(TextDoc): def add_photo(self,name,x,y): pass +# index = len(self.photo_list)+1 +# self.photo_list.append((name,'pictures/picture%d.jpeg' % index)) +# txt = '\n' % len(self.text) +# txt = txt + '\n\n' % name +# +# self.bold_stop = len(self.text) +# self.format_list.append(txt) +# +# self.text = self.text + chr(1) def horizontal_line(self): pass @@ -374,3 +421,46 @@ class KwordDoc(TextDoc): def write_text(self,text): self.text = self.text + text + +if __name__ == "__main__": + + paper = PaperStyle("Letter",27.94,21.59) + + styles = StyleSheet() + foo = FontStyle() + foo.set_type_face(FONT_SANS_SERIF) + foo.set_color((255,0,0)) + foo.set_size(24) + foo.set_underline(1) + foo.set_bold(1) + foo.set_italic(1) + + para = ParagraphStyle() + para.set_alignment(PARA_ALIGN_RIGHT) + para.set_font(foo) + styles.add_style("Title",para) + + foo = FontStyle() + foo.set_type_face(FONT_SERIF) + foo.set_size(12) + + para = ParagraphStyle() + para.set_font(foo) + styles.add_style("Normal",para) + + doc = KwordDoc(styles,paper,PAPER_PORTRAIT) + doc.open("/home/dona/test") + + doc.start_paragraph("Title") + doc.write_text("My Title") + doc.end_paragraph() + + doc.start_paragraph("Normal") + doc.write_text("Hello there. This is fun") + doc.end_paragraph() + + doc.start_paragraph("Normal") + doc.add_photo("/home/dona/dad.jpg",200,200) + doc.end_paragraph() + + doc.close()