* src/docgen/LPRDoc.py: New paragraph formatting algorithm.
Proper alignment support (no implementation for justify yet). svn: r2969
This commit is contained in:
parent
b8075b283f
commit
9bc863344c
@ -1,3 +1,7 @@
|
||||
2004-03-04 Alex Roitman <shura@alex.neuro.umn.edu>
|
||||
* src/docgen/LPRDoc.py: New paragraph formatting algorithm.
|
||||
Proper alignment support (no implementation for justify yet).
|
||||
|
||||
2004-03-03 Alex Roitman <shura@alex.neuro.umn.edu>
|
||||
* src/docgen/LPRDoc.py: Superscript support, line breaks,
|
||||
page breaks, paragraph leader, dirty alignment hack.
|
||||
|
@ -288,14 +288,22 @@ class GnomePrintParagraph:
|
||||
return max_word_size
|
||||
|
||||
def get_height(self,width):
|
||||
"""
|
||||
Determine the height the paragraph would have
|
||||
if formatted for a given width.
|
||||
|
||||
width - required formatting width
|
||||
"""
|
||||
if not self.lines:
|
||||
self.format(width)
|
||||
return self.height
|
||||
|
||||
def format(self,width):
|
||||
"""
|
||||
Determine the height the paragraph would have
|
||||
if formatted for a given width.
|
||||
Format the paragraph for a given width.
|
||||
This is a complex procedure. It assembles lines from the paragraph's
|
||||
pieces. It also sets the height of the whole paragraph and
|
||||
the widths available after the lines are assembled.
|
||||
|
||||
width - required formatting width
|
||||
"""
|
||||
@ -694,7 +702,11 @@ class LPRDoc(BaseDoc.BaseDoc):
|
||||
left_margin,right_margin - boundaries to obey
|
||||
"""
|
||||
|
||||
if not paragraph.get_piece_list():
|
||||
return (x,y)
|
||||
|
||||
left_margin = x
|
||||
no_space = 0
|
||||
paragraph.format(width)
|
||||
|
||||
if y - _LINE_SPACING < self.bottom_margin:
|
||||
@ -703,12 +715,10 @@ class LPRDoc(BaseDoc.BaseDoc):
|
||||
x = left_margin
|
||||
y = self.__y
|
||||
|
||||
# Loop over lines which were assembled by paragraph.format()
|
||||
for (start_piece,start_word,end_piece,end_word,avail_width) \
|
||||
in paragraph.lines:
|
||||
|
||||
if not paragraph.get_piece_list():
|
||||
continue
|
||||
|
||||
if paragraph.get_alignment() == BaseDoc.PARA_ALIGN_CENTER:
|
||||
x = x + 0.5 * avail_width
|
||||
elif paragraph.get_alignment() == BaseDoc.PARA_ALIGN_RIGHT:
|
||||
@ -719,6 +729,7 @@ class LPRDoc(BaseDoc.BaseDoc):
|
||||
print "Paragraph justification not supported."
|
||||
print "Falling back to left-justified mode."
|
||||
|
||||
# Loop over pieces that constitute the line
|
||||
for piece_num in range(start_piece,end_piece+1):
|
||||
(directive,text) = paragraph.get_piece_list()[piece_num]
|
||||
fontstyle = BaseDoc.FontStyle(paragraph.get_fontstyle())
|
||||
@ -738,18 +749,16 @@ class LPRDoc(BaseDoc.BaseDoc):
|
||||
the_textlist = textlist[start_word:]
|
||||
elif piece_num == end_piece:
|
||||
the_textlist = textlist[:end_word]
|
||||
else:
|
||||
print "ERROR!!!"
|
||||
return
|
||||
|
||||
the_text = string.join(the_textlist)
|
||||
if piece_num == start_piece \
|
||||
or directive == _SUPER \
|
||||
or directive == _LINE_BREAK \
|
||||
or (the_text and the_text[0] == '.'):
|
||||
pass
|
||||
or no_space \
|
||||
or (the_text and the_text[0] in string.punctuation):
|
||||
spacer = ""
|
||||
else:
|
||||
the_text = " " + the_text
|
||||
spacer = " "
|
||||
the_text = spacer + the_text
|
||||
|
||||
self.__pc.setfont(find_font_from_fontstyle(fontstyle))
|
||||
self.__pc.moveto(x, y)
|
||||
@ -758,69 +767,17 @@ class LPRDoc(BaseDoc.BaseDoc):
|
||||
if directive == _SUPER:
|
||||
y = y - 0.25 * _LINE_SPACING
|
||||
|
||||
# If this was the linebreak, no space on the next line's start
|
||||
if end_word:
|
||||
no_space = 0
|
||||
else:
|
||||
no_space = 1
|
||||
|
||||
y = self.__advance_line(y)
|
||||
x = left_margin
|
||||
|
||||
return (x,y)
|
||||
|
||||
# #all text will fit within the width provided
|
||||
# if not text:
|
||||
# if directive == _SUPER:
|
||||
# y = y - 0.25 * _LINE_SPACING
|
||||
# continue
|
||||
# if avail_width >= get_text_width(text,fontstyle):
|
||||
# avail_width -= get_text_width(text,fontstyle)
|
||||
# if paragraph.get_alignment() == BaseDoc.PARA_ALIGN_CENTER:
|
||||
# x = x + 0.5 * avail_width
|
||||
# elif paragraph.get_alignment() == BaseDoc.PARA_ALIGN_RIGHT:
|
||||
# x = x + avail_width
|
||||
# elif paragraph.get_alignment() == BaseDoc.PARA_ALIGN_LEFT:
|
||||
# pass
|
||||
# elif paragraph.get_alignment() == BaseDoc.PARA_ALIGN_JUSTIFY:
|
||||
# pass
|
||||
#
|
||||
# self.__pc.setfont(find_font_from_fontstyle(fontstyle))
|
||||
# self.__pc.moveto(x, y)
|
||||
# self.__pc.show(text)
|
||||
# x = x + get_text_width(text,fontstyle)
|
||||
# else:
|
||||
# #divide up text and print
|
||||
# if x == left_margin or directive == _SUPER \
|
||||
# or text[0] == '.':
|
||||
# the_text = ""
|
||||
# else:
|
||||
# the_text = " "
|
||||
# for element in text.split():
|
||||
# if get_text_width(the_text + element + " ",fontstyle) < avail_width:
|
||||
# the_text = the_text + element + " "
|
||||
# else:
|
||||
# # the_text contains as much as avail_width allows
|
||||
# self.__pc.setfont(find_font_from_fontstyle(fontstyle))
|
||||
# self.__pc.moveto(x, y)
|
||||
# self.__pc.show(the_text)
|
||||
# the_text = element + " "
|
||||
# y = self.__advance_line(y)
|
||||
# x = left_margin
|
||||
# avail_width = width
|
||||
#
|
||||
# #if not in table and cursor is below bottom margin
|
||||
# if (not self.__in_table) and (y < self.bottom_margin):
|
||||
# self.end_page()
|
||||
# self.start_page()
|
||||
# x = self.__x
|
||||
# y = self.__y
|
||||
#
|
||||
# #if __text still contains data, we will want to print it out
|
||||
# if the_text:
|
||||
# self.__pc.setfont(find_font_from_fontstyle(fontstyle))
|
||||
# self.__pc.moveto(left_margin, y)
|
||||
# self.__pc.show(the_text)
|
||||
# x = x + get_text_width(the_text,fontstyle)
|
||||
# avail_width = width - get_text_width(the_text,fontstyle)
|
||||
# if directive == _SUPER:
|
||||
# y = y - 0.25 * _LINE_SPACING
|
||||
# y = self.__advance_line(y)
|
||||
|
||||
def __output_table(self):
|
||||
"""do calcs on data in table and output data in a formatted way"""
|
||||
__min_col_size = [0] * self.__ncols
|
||||
@ -833,15 +790,16 @@ class LPRDoc(BaseDoc.BaseDoc):
|
||||
if not self.__cell_widths[__row_num][__col]:
|
||||
continue
|
||||
|
||||
__max = 0
|
||||
for paragraph in __row[__col]:
|
||||
__min = paragraph.get_min_width()
|
||||
if __min > __min_col_size[__col]:
|
||||
__min_col_size[__col] = __min
|
||||
|
||||
__max = paragraph.get_height(
|
||||
__max += paragraph.get_height(
|
||||
self.__cell_widths[__row_num][__col])
|
||||
if __max > __max_vspace[__row_num]:
|
||||
__max_vspace[__row_num] = __max
|
||||
if __max > __max_vspace[__row_num]:
|
||||
__max_vspace[__row_num] = __max
|
||||
|
||||
#is table width larger than the width of the paper?
|
||||
__min_table_width = 0
|
||||
@ -872,6 +830,7 @@ class LPRDoc(BaseDoc.BaseDoc):
|
||||
self.__cell_widths[__row_num][__col])
|
||||
|
||||
__x = __x + self.__cell_widths[__row_num][__col] # set up margin for this row
|
||||
self.__y = col_y - __max_vspace[__row_num]
|
||||
|
||||
#function to print text to a printer
|
||||
def __do_print(self,dialog, job):
|
||||
|
Loading…
Reference in New Issue
Block a user