1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 """
26 Provide base interface to text based documents. Specific document
27 interfaces should be derived from the core classes.
28 """
29
30
31
32
33
34
35 import os
36 from xml.sax.saxutils import escape
37
39 """
40 Escapes XML special characters.
41 """
42 return escape(string, { '"' : '"' } )
43
44
45
46
47
48
49 import Utils
50 import FontScale
51 import const
52
53
54
55
56
57
58 import logging
59 log = logging.getLogger(".BaseDoc")
60
61
62
63
64
65
66 try:
67 from xml.sax import make_parser, handler, SAXParseException
68 except ImportError:
69 from _xmlplus.sax import make_parser, handler, SAXParseException
70
71
72
73
74
75
76 FONT_SANS_SERIF = 0
77 FONT_SERIF = 1
78 FONT_MONOSPACE = 2
79
80
81
82
83
84
85 PAPER_PORTRAIT = 0
86 PAPER_LANDSCAPE = 1
87
88
89
90
91
92
93 PARA_ALIGN_CENTER = 0
94 PARA_ALIGN_LEFT = 1
95 PARA_ALIGN_RIGHT = 2
96 PARA_ALIGN_JUSTIFY = 3
97
98
99
100
101
102
103 TEXT_MODE = 0
104 GRAPHICS_MODE = 1
105
106
107
108
109
110
111 SOLID = 0
112 DASHED = 1
113
114
115
116
117
118
119 INDEX_TYPE_ALP = 0
120 INDEX_TYPE_TOC = 1
121
122
123
124
125
126
128 """
129 converts a hex value in the form of #XXXXXX into a tuple of integers
130 representing the RGB values
131 """
132 return (int(text[1:3], 16), int(text[3:5], 16), int(text[5:7], 16))
133
134
135
136
137
138
140 """
141 Defines the dimensions of a sheet of paper. All dimensions are in
142 centimeters.
143 """
144 - def __init__(self, name, height, width):
145 """
146 Create a new paper style with.
147
148 @param name: name of the new style
149 @param height: page height in centimeters
150 @param width: page width in centimeters
151 """
152 self.name = name
153 self.height = height
154 self.width = width
155
157 "Return the name of the paper style"
158 return self.name
159
161 "Return the page height in cm"
162 return self.height
163
165 "Set the page height in cm"
166 self.height = height
167
169 "Return the page width in cm"
170 return self.width
171
173 "Set the page width in cm"
174 self.width = width
175
177 "Return the page height in inches"
178 return self.height / 2.54
179
181 "Return the page width in inches"
182 return self.width / 2.54
183
184
185
186
187
188
190 """
191 Define the various options for a sheet of paper.
192 """
193 - def __init__(self, size, orientation,
194 lmargin=2.54, rmargin=2.54, tmargin=2.54, bmargin=2.54):
195 """
196 Create a new paper style.
197
198 @param size: size of the new style
199 @type size: PaperSize
200 @param orientation: page orientation
201 @type orientation: PAPER_PORTRAIT or PAPER_LANDSCAPE
202
203 """
204 self.__orientation = orientation
205
206 if orientation == PAPER_PORTRAIT:
207 self.__size = PaperSize(size.get_name(),
208 size.get_height(),
209 size.get_width())
210 else:
211 self.__size = PaperSize(size.get_name(),
212 size.get_width(),
213 size.get_height())
214 self.__lmargin = lmargin
215 self.__rmargin = rmargin
216 self.__tmargin = tmargin
217 self.__bmargin = bmargin
218
220 """
221 Return the size of the paper.
222
223 @returns: object indicating the paper size
224 @rtype: PaperSize
225
226 """
227 return self.__size
228
230 """
231 Return the orientation of the page.
232
233 @returns: PAPER_PORTRIAT or PAPER_LANDSCAPE
234 @rtype: int
235
236 """
237 return self.__orientation
238
240 """
241 Return the width of the page area in centimeters.
242
243 The value is the page width less the margins.
244
245 """
246 return self.__size.get_width() - (self.__rmargin + self.__lmargin)
247
249 """
250 Return the height of the page area in centimeters.
251
252 The value is the page height less the margins.
253
254 """
255 return self.__size.get_height() - (self.__tmargin + self.__bmargin)
256
258 """
259 Return the right margin.
260
261 @returns: Right margin in centimeters
262 @rtype: float
263
264 """
265 return self.__rmargin
266
268 """
269 Return the left margin.
270
271 @returns: Left margin in centimeters
272 @rtype: float
273
274 """
275 return self.__lmargin
276
278 """
279 Return the top margin.
280
281 @returns: Top margin in centimeters
282 @rtype: float
283
284 """
285 return self.__tmargin
286
288 """
289 Return the bottom margin.
290
291 @returns: Bottom margin in centimeters
292 @rtype: float
293
294 """
295 return self.__bmargin
296
297
298
299
300
301
303 """
304 Defines a font style. Controls the font face, size, color, and
305 attributes. In order to remain generic, the only font faces available
306 are FONT_SERIF and FONT_SANS_SERIF. Document formatters should convert
307 these to the appropriate fonts for the target format.
308
309 The FontStyle represents the desired characteristics. There are no
310 guarentees that the document format generator will be able implement
311 all or any of the characteristics.
312 """
313
315 """
316 Create a new FontStyle object, accepting the default values.
317
318 @param style: if specified, initializes the FontStyle from the passed
319 FontStyle instead of using the defaults.
320 """
321 if style:
322 self.face = style.face
323 self.size = style.size
324 self.italic = style.italic
325 self.bold = style.bold
326 self.color = style.color
327 self.under = style.under
328 else:
329 self.face = FONT_SERIF
330 self.size = 12
331 self.italic = 0
332 self.bold = 0
333 self.color = (0, 0, 0)
334 self.under = 0
335
336 - def set(self, face=None, size=None, italic=None, bold=None,
337 underline=None, color=None):
338 """
339 Set font characteristics.
340
341 @param face: font type face, either FONT_SERIF or FONT_SANS_SERIF
342 @param size: type face size in points
343 @param italic: True enables italics, False disables italics
344 @param bold: True enables bold face, False disables bold face
345 @param underline: True enables underline, False disables underline
346 @param color: an RGB color representation in the form of three integers
347 in the range of 0-255 represeting the red, green, and blue
348 components of a color.
349 """
350 if face != None:
351 self.set_type_face(face)
352 if size != None:
353 self.set_size(size)
354 if italic != None:
355 self.set_italic(italic)
356 if bold != None:
357 self.set_bold(bold)
358 if underline != None:
359 self.set_underline(underline)
360 if color != None:
361 self.set_color(color)
362
364 "0 disables italics, 1 enables italics"
365 self.italic = val
366
368 "1 indicates use italics"
369 return self.italic
370
372 "0 disables bold face, 1 enables bold face"
373 self.bold = val
374
376 "1 indicates use bold face"
377 return self.bold
378
380 "sets the color using an RGB color tuple"
381 self.color = val
382
384 "Return an RGB color tuple"
385 return self.color
386
388 "sets font size in points"
389 self.size = val
390
392 "returns font size in points"
393 return self.size
394
396 "sets the font face type"
397 self.face = val
398
400 "returns the font face type"
401 return self.face
402
404 "1 enables underlining"
405 self.under = val
406
408 "1 indicates underlining"
409 return self.under
410
411
412
413
414
415
417 """
418 Specifies the style or format of a table. The TableStyle contains the
419 characteristics of table width (in percentage of the full width), the
420 number of columns, and the width of each column as a percentage of the
421 width of the table.
422 """
424 """
425 Create a new TableStyle object, with the values initialized to
426 empty, with allocating space for up to 100 columns.
427
428 @param obj: if not None, then the object created gets is attributes
429 from the passed object instead of being initialized to empty.
430 """
431 if obj:
432 self.width = obj.width
433 self.columns = obj.columns
434 self.colwid = obj.colwid[:]
435 else:
436 self.width = 0
437 self.columns = 0
438 self.colwid = [ 0 ] * 100
439
441 """
442 Set the width of the table in terms of percent of the available
443 width
444 """
445 self.width = width
446
448 """
449 Return the specified width as a percentage of the available space
450 """
451 return self.width
452
454 """
455 Set the number of columns.
456
457 @param columns: number of columns that should be used.
458 """
459 self.columns = columns
460
462 """
463 Return the number of columns
464 """
465 return self.columns
466
468 """
469 Set the width of all the columns at once, taking the percentages
470 from the passed list.
471 """
472 self.columns = len(clist)
473 for i in range(self.columns):
474 self.colwid[i] = clist[i]
475
477 """
478 Set the width of a specified column to the specified width.
479
480 @param index: column being set (index starts at 0)
481 @param width: percentage of the table width assigned to the column
482 """
483 self.colwid[index] = width
484
486 """
487 Return the column width of the specified column as a percentage of
488 the entire table width.
489
490 @param index: column to return (index starts at 0)
491 """
492 return self.colwid[index]
493
494
495
496
497
498
500 """
501 Defines the style of a particular table cell. Characteristics are:
502 right border, left border, top border, bottom border, and padding.
503 """
505 """
506 Create a new TableCellStyle instance.
507
508 @param obj: if not None, specifies that the values should be
509 copied from the passed object instead of being initialized to empty.
510 """
511 if obj:
512 self.rborder = obj.rborder
513 self.lborder = obj.lborder
514 self.tborder = obj.tborder
515 self.bborder = obj.bborder
516 self.padding = obj.padding
517 self.longlist = obj.longlist
518 else:
519 self.rborder = 0
520 self.lborder = 0
521 self.tborder = 0
522 self.bborder = 0
523 self.padding = 0
524 self.longlist = 0
525
527 "Return the cell padding in centimeters"
528 self.padding = val
529
531 """
532 Defines if a right border in used
533
534 @param val: if True, a right border is used, if False, it is not
535 """
536 self.rborder = val
537
539 """
540 Defines if a left border in used
541
542 @param val: if True, a left border is used, if False, it is not
543 """
544 self.lborder = val
545
547 """
548 Defines if a top border in used
549
550 @param val: if True, a top border is used, if False, it is not
551 """
552 self.tborder = val
553
555 """
556 Defines if a bottom border in used
557
558 @param val: if 1, a bottom border is used, if 0, it is not
559 """
560 self.bborder = val
561
564
566 "Return the cell padding in centimeters"
567 return self.padding
568
570 "Return 1 if a right border is requested"
571 return self.rborder
572
574 "Return 1 if a left border is requested"
575 return self.lborder
576
578 "Return 1 if a top border is requested"
579 return self.tborder
580
582 "Return 1 if a bottom border is requested"
583 return self.bborder
584
587
588
589
590
591
592
594 """
595 Defines the characteristics of a paragraph. The characteristics are:
596 font (a FontStyle instance), right margin, left margin, first indent,
597 top margin, bottom margin, alignment, level, top border, bottom border,
598 right border, left border, padding, and background color.
599
600 """
602 """
603 @param source: if not None, then the ParagraphStyle is created
604 using the values of the source instead of the default values.
605 """
606 if source:
607 self.font = FontStyle(source.font)
608 self.rmargin = source.rmargin
609 self.lmargin = source.lmargin
610 self.first_indent = source.first_indent
611 self.tmargin = source.tmargin
612 self.bmargin = source.bmargin
613 self.align = source.align
614 self.level = source.level
615 self.top_border = source.top_border
616 self.bottom_border = source.bottom_border
617 self.right_border = source.right_border
618 self.left_border = source.left_border
619 self.pad = source.pad
620 self.bgcolor = source.bgcolor
621 self.description = source.description
622 self.tabs = source.tabs
623 else:
624 self.font = FontStyle()
625 self.rmargin = 0
626 self.lmargin = 0
627 self.tmargin = 0
628 self.bmargin = 0
629 self.first_indent = 0
630 self.align = PARA_ALIGN_LEFT
631 self.level = 0
632 self.top_border = 0
633 self.bottom_border = 0
634 self.right_border = 0
635 self.left_border = 0
636 self.pad = 0
637 self.bgcolor = (255, 255, 255)
638 self.description = ""
639 self.tabs = []
640
642 """
643 Set the desciption of the paragraph
644 """
645 self.description = text
646
648 """
649 Return the desciption of the paragraph
650 """
651 return self.description
652
653 - def set(self, rmargin=None, lmargin=None, first_indent=None,
654 tmargin=None, bmargin=None, align=None,
655 tborder=None, bborder=None, rborder=None, lborder=None,
656 pad=None, bgcolor=None, font=None):
657 """
658 Allows the values of the object to be set.
659
660 @param rmargin: right indent in centimeters
661 @param lmargin: left indent in centimeters
662 @param first_indent: first line indent in centimeters
663 @param tmargin: space above paragraph in centimeters
664 @param bmargin: space below paragraph in centimeters
665 @param align: alignment type (PARA_ALIGN_LEFT, PARA_ALIGN_RIGHT, PARA_ALIGN_CENTER, or PARA_ALIGN_JUSTIFY)
666 @param tborder: non zero indicates that a top border should be used
667 @param bborder: non zero indicates that a bottom border should be used
668 @param rborder: non zero indicates that a right border should be used
669 @param lborder: non zero indicates that a left border should be used
670 @param pad: padding in centimeters
671 @param bgcolor: background color of the paragraph as an RGB tuple.
672 @param font: FontStyle instance that defines the font
673 """
674 if font != None:
675 self.font = FontStyle(font)
676 if pad != None:
677 self.set_padding(pad)
678 if tborder != None:
679 self.set_top_border(tborder)
680 if bborder != None:
681 self.set_bottom_border(bborder)
682 if rborder != None:
683 self.set_right_border(rborder)
684 if lborder != None:
685 self.set_left_border(lborder)
686 if bgcolor != None:
687 self.set_background_color(bgcolor)
688 if align != None:
689 self.set_alignment(align)
690 if rmargin != None:
691 self.set_right_margin(rmargin)
692 if lmargin != None:
693 self.set_left_margin(lmargin)
694 if first_indent != None:
695 self.set_first_indent(first_indent)
696 if tmargin != None:
697 self.set_top_margin(tmargin)
698 if bmargin != None:
699 self.set_bottom_margin(bmargin)
700
702 """
703 Set the header level for the paragraph. This is useful for
704 numbered paragraphs. A value of 1 indicates a header level
705 format of X, a value of two implies X.X, etc. A value of zero
706 means no header level.
707 """
708 self.level = level
709
711 "Return the header level of the paragraph"
712 return self.level
713
715 """
716 Set the font style of the paragraph.
717
718 @param font: FontStyle object containing the font definition to use.
719 """
720 self.font = FontStyle(font)
721
723 "Return the FontStyle of the paragraph"
724 return self.font
725
727 """
728 Set the paragraph padding in centimeters
729
730 @param val: floating point value indicating the padding in centimeters
731 """
732 self.pad = val
733
735 """Return a the padding of the paragraph"""
736 return self.pad
737
739 """
740 Set the presence or absence of top border.
741
742 @param val: True indicates a border should be used, False indicates
743 no border.
744 """
745 self.top_border = val
746
748 "Return 1 if a top border is specified"
749 return self.top_border
750
752 """
753 Set the presence or absence of bottom border.
754
755 @param val: True indicates a border should be used, False
756 indicates no border.
757 """
758 self.bottom_border = val
759
761 "Return 1 if a bottom border is specified"
762 return self.bottom_border
763
765 """
766 Set the presence or absence of left border.
767
768 @param val: True indicates a border should be used, False
769 indicates no border.
770 """
771 self.left_border = val
772
774 "Return 1 if a left border is specified"
775 return self.left_border
776
778 """
779 Set the presence or absence of rigth border.
780
781 @param val: True indicates a border should be used, False
782 indicates no border.
783 """
784 self.right_border = val
785
787 "Return 1 if a right border is specified"
788 return self.right_border
789
791 """
792 Return a tuple indicating the RGB components of the background
793 color
794 """
795 return self.bgcolor
796
798 """
799 Set the background color of the paragraph.
800
801 @param color: tuple representing the RGB components of a color
802 (0,0,0) to (255,255,255)
803 """
804 self.bgcolor = color
805
807 """
808 Set the paragraph alignment.
809
810 @param align: PARA_ALIGN_LEFT, PARA_ALIGN_RIGHT, PARA_ALIGN_CENTER,
811 or PARA_ALIGN_JUSTIFY
812 """
813 self.align = align
814
816 "Return the alignment of the paragraph"
817 return self.align
818
820 """
821 Return a text string representing the alginment, either 'left',
822 'right', 'center', or 'justify'
823 """
824 if self.align == PARA_ALIGN_LEFT:
825 return "left"
826 elif self.align == PARA_ALIGN_CENTER:
827 return "center"
828 elif self.align == PARA_ALIGN_RIGHT:
829 return "right"
830 elif self.align == PARA_ALIGN_JUSTIFY:
831 return "justify"
832 return "unknown"
833
835 "sets the left indent in centimeters"
836 self.lmargin = value
837
839 "sets the right indent in centimeters"
840 self.rmargin = value
841
843 "sets the first line indent in centimeters"
844 self.first_indent = value
845
847 "sets the space above paragraph in centimeters"
848 self.tmargin = value
849
851 "sets the space below paragraph in centimeters"
852 self.bmargin = value
853
855 "returns the left indent in centimeters"
856 return self.lmargin
857
859 "returns the right indent in centimeters"
860 return self.rmargin
861
863 "returns the first line indent in centimeters"
864 return self.first_indent
865
867 "returns the space above paragraph in centimeters"
868 return self.tmargin
869
871 "returns the space below paragraph in centimeters"
872 return self.bmargin
873
875 assert(type(tab_stops) == type([]))
876 self.tabs = tab_stops
877
880
881
882
883
884
885
887 """
888 Interface into the user's defined style sheets. Each StyleSheetList
889 has a predefined default style specified by the report. Additional
890 styles are loaded from a specified XML file if it exists.
891 """
892
893 - def __init__(self, filename, defstyle):
894 """
895 Create a new StyleSheetList from the specified default style and
896 any other styles that may be defined in the specified file.
897
898 file - XML file that contains style definitions
899 defstyle - default style
900 """
901 defstyle.set_name('default')
902 self.map = { "default" : defstyle }
903 self.file = os.path.join(const.HOME_DIR, filename)
904 self.parse()
905
907 """
908 Remove a style from the list. Since each style must have a
909 unique name, the name is used to delete the stylesheet.
910
911 name - Name of the style to delete
912 """
913 del self.map[name]
914
916 """
917 Return the map of names to styles.
918 """
919 return self.map
920
922 """
923 Return the StyleSheet associated with the name
924
925 name - name associated with the desired StyleSheet.
926 """
927 return self.map[name]
928
930 "Return a list of all the style names in the StyleSheetList"
931 return self.map.keys()
932
934 """
935 Add or replaces a StyleSheet in the StyleSheetList. The
936 default style may not be replaced.
937
938 name - name assocated with the StyleSheet to add or replace.
939 style - definition of the StyleSheet
940 """
941 style.set_name(name)
942 if name != "default":
943 self.map[name] = style
944
994
996 """
997 Loads the StyleSheets from the associated file, if it exists.
998 """
999 try:
1000 if os.path.isfile(self.file):
1001 parser = make_parser()
1002 parser.setContentHandler(SheetParser(self))
1003 the_file = open(self.file)
1004 parser.parse(the_file)
1005 the_file.close()
1006 except (IOError,OSError,SAXParseException):
1007 pass
1008
1009
1010
1011
1012
1013
1015 """
1016 A collection of named paragraph styles.
1017 """
1018
1020 """
1021 Create a new empty StyleSheet.
1022
1023 @param obj: if not None, creates the StyleSheet from the values in
1024 obj, instead of creating an empty StyleSheet
1025 """
1026 self.para_styles = {}
1027 self.draw_styles = {}
1028 self.table_styles = {}
1029 self.cell_styles = {}
1030 self.name = ""
1031 if obj != None:
1032 for style_name in obj.para_styles.keys():
1033 style = obj.para_styles[style_name]
1034 self.para_styles[style_name] = ParagraphStyle(style)
1035 for style_name in obj.draw_styles.keys():
1036 style = obj.draw_styles[style_name]
1037 self.draw_styles[style_name] = GraphicsStyle(style)
1038 for style_name in obj.table_styles.keys():
1039 style = obj.table_styles[style_name]
1040 self.table_styles[style_name] = TableStyle(style)
1041 for style_name in obj.cell_styles.keys():
1042 style = obj.cell_styles[style_name]
1043 self.cell_styles[style_name] = TableCellStyle(style)
1044
1046 """
1047 Set the name of the StyleSheet
1048
1049 @param name: The name to be given to the StyleSheet
1050 """
1051 self.name = name
1052
1054 """
1055 Return the name of the StyleSheet
1056 """
1057 return self.name
1058
1060 "Remove all styles from the StyleSheet"
1061 self.para_styles = {}
1062 self.draw_styles = {}
1063 self.table_styles = {}
1064 self.cell_styles = {}
1065
1067 "Checks if any styles are defined"
1068 style_count = len(self.para_styles) + \
1069 len(self.draw_styles) + \
1070 len(self.table_styles) + \
1071 len(self.cell_styles)
1072 if style_count > 0:
1073 return False
1074 else:
1075 return True
1076
1078 """
1079 Add a paragraph style to the style sheet.
1080
1081 @param name: The name of the ParagraphStyle
1082 @param style: ParagraphStyle instance to be added.
1083 """
1084 self.para_styles[name] = ParagraphStyle(style)
1085
1087 """
1088 Return the ParagraphStyle associated with the name
1089
1090 @param name: name of the ParagraphStyle that is wanted
1091 """
1092 return ParagraphStyle(self.para_styles[name])
1093
1095 "Return the the list of paragraph names in the StyleSheet"
1096 return self.para_styles.keys()
1097
1099 """
1100 Add a draw style to the style sheet.
1101
1102 @param name: The name of the GraphicsStyle
1103 @param style: GraphicsStyle instance to be added.
1104 """
1105 self.draw_styles[name] = GraphicsStyle(style)
1106
1108 """
1109 Return the GraphicsStyle associated with the name
1110
1111 @param name: name of the GraphicsStyle that is wanted
1112 """
1113 return GraphicsStyle(self.draw_styles[name])
1114
1116 "Return the the list of draw style names in the StyleSheet"
1117 return self.draw_styles.keys()
1118
1120 """
1121 Add a table style to the style sheet.
1122
1123 @param name: The name of the TableStyle
1124 @param style: TableStyle instance to be added.
1125 """
1126 self.table_styles[name] = TableStyle(style)
1127
1129 """
1130 Return the TableStyle associated with the name
1131
1132 @param name: name of the TableStyle that is wanted
1133 """
1134 return TableStyle(self.table_styles[name])
1135
1137 "Return the the list of table style names in the StyleSheet"
1138 return self.table_styles.keys()
1139
1141 """
1142 Add a cell style to the style sheet.
1143
1144 @param name: The name of the TableCellStyle
1145 @param style: TableCellStyle instance to be added.
1146 """
1147 self.cell_styles[name] = TableCellStyle(style)
1148
1150 """
1151 Return the TableCellStyle associated with the name
1152
1153 @param name: name of the TableCellStyle that is wanted
1154 """
1155 return TableCellStyle(self.cell_styles[name])
1156
1158 "Return the the list of cell style names in the StyleSheet"
1159 return self.cell_styles.keys()
1160
1161
1162
1163
1164
1165
1167 """
1168 SAX parsing class for the StyleSheetList XML file.
1169 """
1170
1172 """
1173 Create a SheetParser class that populates the passed StyleSheetList
1174 class.
1175
1176 sheetlist - StyleSheetList instance to be loaded from the file.
1177 """
1178 handler.ContentHandler.__init__(self)
1179 self.sheetlist = sheetlist
1180 self.f = None
1181 self.p = None
1182 self.s = None
1183 self.sname = None
1184 self.pname = None
1185
1226
1228 "Overridden class that handles the start of a XML element"
1229 if tag == "style":
1230 self.p.set_font(self.f)
1231 self.s.add_paragraph_style(self.pname, self.p)
1232 elif tag == "sheet":
1233 self.sheetlist.set_style_sheet(self.sname, self.s)
1234
1235
1236
1237
1238
1239
1241 """
1242 Defines the properties of graphics objects, such as line width,
1243 color, fill, ect.
1244 """
1246 """
1247 Initialize the object with default values, unless a source
1248 object is specified. In that case, make a copy of the source
1249 object.
1250 """
1251 if obj:
1252 self.para_name = obj.para_name
1253 self.shadow = obj.shadow
1254 self.shadow_space = obj.shadow_space
1255 self.color = obj.color
1256 self.fill_color = obj.fill_color
1257 self.lwidth = obj.lwidth
1258 self.lstyle = obj.lstyle
1259 else:
1260 self.para_name = ""
1261 self.shadow = 0
1262 self.shadow_space = 0.2
1263 self.lwidth = 0.5
1264 self.color = (0, 0, 0)
1265 self.fill_color = (255, 255, 255)
1266 self.lstyle = SOLID
1267
1269 """
1270 sets the line width
1271 """
1272 self.lwidth = val
1273
1275 """
1276 Return the name of the StyleSheet
1277 """
1278 return self.lwidth
1279
1282
1285
1287 self.para_name = val
1288
1290 self.shadow = val
1291 self.shadow_space = space
1292
1294 return self.shadow_space
1295
1298
1300 self.fill_color = val
1301
1303 return self.para_name
1304
1307
1310
1312 return self.fill_color
1313
1314
1315
1316
1317
1318
1320 """
1321 Defines a mark to be associated with text for indexing.
1322 """
1324 """
1325 Initialize the object with default values, unless values are specified.
1326 """
1327 self.key = key
1328 self.type = itype
1329 self.level = level
1330
1331
1332
1333
1334
1335
1337 """
1338 Base class for document generators. Different output formats,
1339 such as OpenOffice, AbiWord, and LaTeX are derived from this base
1340 class, providing a common interface to all document generators.
1341 """
1342 - def __init__(self, styles, paper_style, template):
1343 """
1344 Create a BaseDoc instance, which provides a document generation
1345 interface. This class should never be instantiated directly, but
1346 only through a derived class.
1347
1348 @param styles: StyleSheet containing the styles used.
1349 @param paper_style: PaperStyle instance containing information about
1350 the paper. If set to None, then the document is not a page
1351 oriented document (e.g. HTML)
1352 @param template: Format template for document generators that are
1353 not page oriented.
1354 """
1355 self.template = template
1356 self.paper = paper_style
1357 self._style_sheet = styles
1358 self._creator = ""
1359 self.print_req = 0
1360 self.init_called = False
1361 self.type = "standard"
1362
1364 self.init_called = True
1365
1368
1370 "Set the owner name"
1371 self._creator = name
1372
1374 "Return the owner name"
1375 return self._creator
1376
1378 """
1379 Return the StyleSheet of the document.
1380 """
1381 return StyleSheet(self._style_sheet)
1382
1384 """
1385 Set the StyleSheet of the document.
1386
1387 @param style_sheet: The new style sheet for the document
1388 @type style_sheet: StyleSheet
1389 """
1390 self._style_sheet = StyleSheet(style_sheet)
1391
1392 - def open(self, filename):
1393 """
1394 Opens the document.
1395
1396 @param filename: path name of the file to create
1397 """
1398 raise NotImplementedError
1399
1401 "Closes the document"
1402 raise NotImplementedError
1403
1404
1405
1406
1407
1408
1410 """
1411 Abstract Interface for text document generators. Output formats for
1412 text reports must implment this interface to be used by the report
1413 system.
1414 """
1415 - def page_break(self):
1416 "Forces a page break, creating a new page"
1417 raise NotImplementedError
1418
1419 - def start_bold(self):
1420 raise NotImplementedError
1421
1422 - def end_bold(self):
1423 raise NotImplementedError
1424
1426 raise NotImplementedError
1427
1428 - def end_superscript(self):
1429 raise NotImplementedError
1430
1431 - def start_paragraph(self, style_name, leader=None):
1432 """
1433 Starts a new paragraph, using the specified style name.
1434
1435 @param style_name: name of the ParagraphStyle to use for the
1436 paragraph.
1437 @param leader: Leading text for a paragraph. Typically used
1438 for numbering.
1439 """
1440 raise NotImplementedError
1441
1442 - def end_paragraph(self):
1443 "Ends the current parsgraph"
1444 raise NotImplementedError
1445
1446 - def start_table(self, name, style_name):
1447 """
1448 Starts a new table.
1449
1450 @param name: Unique name of the table.
1451 @param style_name: TableStyle to use for the new table
1452 """
1453 raise NotImplementedError
1454
1455 - def end_table(self):
1456 "Ends the current table"
1457 raise NotImplementedError
1458
1459 - def start_row(self):
1460 "Starts a new row on the current table"
1461 raise NotImplementedError
1462
1463 - def end_row(self):
1464 "Ends the current row on the current table"
1465 raise NotImplementedError
1466
1467 - def start_cell(self, style_name, span=1):
1468 """
1469 Starts a new table cell, using the paragraph style specified.
1470
1471 @param style_name: TableCellStyle to use for the cell
1472 @param span: number of columns to span
1473 """
1474 raise NotImplementedError
1475
1476 - def end_cell(self):
1477 "Ends the current table cell"
1478 raise NotImplementedError
1479
1480 - def write_note(self, text, format, style_name):
1481 """
1482 Writes the note's text and take care of paragraphs,
1483 depending on the format.
1484
1485 @param text: text to write.
1486 @param format: format to use for writing. True for flowed text,
1487 1 for preformatted text.
1488 """
1489 raise NotImplementedError
1490
1491 - def write_text(self, text, mark=None):
1492 """
1493 Writes the text in the current paragraph. Should only be used after a
1494 start_paragraph and before an end_paragraph.
1495
1496 @param text: text to write.
1497 @param mark: IndexMark to use for indexing (if supported)
1498 """
1499 raise NotImplementedError
1500
1502 """
1503 Add a photo of the specified width (in centimeters)
1504
1505 @param name: filename of the image to add
1506 @param align: alignment of the image. Valid values are 'left',
1507 'right', 'center', and 'single'
1508 @param w_cm: width in centimeters
1509 @param h_cm: height in centimeters
1510 """
1511 raise NotImplementedError
1512
1513
1514
1515
1516
1517
1519 """
1520 Abstract Interface for graphical document generators. Output formats
1521 for graphical reports must implment this interface to be used by the
1522 report system.
1523 """
1524
1525 - def start_page(self):
1526 raise NotImplementedError
1527
1528 - def end_page(self):
1529 raise NotImplementedError
1530
1532 """
1533 Return the width of the text area in centimeters. The value is
1534 the page width less the margins.
1535 """
1536 width = self.paper.get_size().get_width()
1537 right = self.paper.get_right_margin()
1538 left = self.paper.get_left_margin()
1539 return width - (right + left)
1540
1542 """
1543 Return the height of the text area in centimeters. The value is
1544 the page height less the margins.
1545 """
1546 height = self.paper.get_size().get_height()
1547 top = self.paper.get_top_margin()
1548 bottom = self.paper.get_bottom_margin()
1549 return height - (top + bottom)
1550
1552 "Determine the width need for text in given font"
1553 return FontScale.string_width(fontstyle, text)
1554
1556 raise NotImplementedError
1557
1558 - def draw_box(self, style, text, x, y, w, h):
1559 raise NotImplementedError
1560
1561 - def draw_text(self, style, text, x1, y1):
1562 raise NotImplementedError
1563
1564 - def center_text(self, style, text, x1, y1):
1565 raise NotImplementedError
1566
1567 - def rotate_text(self, style, text, x, y, angle):
1568 raise NotImplementedError
1569
1570 - def draw_line(self, style, x1, y1, x2, y2):
1571 raise NotImplementedError
1572
1573
1574
1575
1576
1577
1579 """
1580 Abstract Interface for Graphviz document generators. Output formats
1581 for Graphviz reports must implment this interface to be used by the
1582 report system.
1583 """
1584 - def add_node(self, id, label, shape="box", fillcolor="white", url="", htmloutput=False):
1585 """
1586 Add a node to this graph. Nodes can be different shapes like boxes and
1587 circles.
1588
1589 @param id: A unique identification value for this node.
1590 Example: "p55"
1591 @type id: string
1592 @param label: The text to be displayed in the node.
1593 Example: "John Smith"
1594 @type label: string
1595 @param shape: The shape for the node.
1596 Examples: "box", "ellipse", "circle"
1597 @type shape: string
1598 @param fillcolor: The fill color for the node.
1599 Examples: "blue", "lightyellow"
1600 @type fillcolor: string
1601 @param url: A URL for the node.
1602 @type url: string
1603 @param htmloutput: Whether the label contains HTML.
1604 @type htmloutput: boolean
1605 @return: nothing
1606 """
1607 raise NotImplementedError
1608
1609 - def add_link(self, id1, id2, style="", head="", tail="", comment=""):
1610 """
1611 Add a link between two nodes.
1612
1613 @param id1: The unique identifier of the starting node.
1614 Example: "p55"
1615 @type id1: string
1616 @param id2: The unique identifier of the ending node.
1617 Example: "p55"
1618 @type id2: string
1619 @param comment: A text string displayed at the end of the link line.
1620 Example: "person C is the son of person A and person B"
1621 @type comment: string
1622 @return: nothing
1623 """
1624 raise NotImplementedError
1625
1636
1638 """
1639 Start a subgraph in this graph.
1640
1641 @param id: The unique identifier of the subgraph.
1642 Example: "p55"
1643 @type id1: string
1644 @return: nothing
1645 """
1646 raise NotImplementedError
1647
1649 """
1650 End a subgraph that was previously started in this graph.
1651
1652 @return: nothing
1653 """
1654 raise NotImplementedError
1655