reportlab/demos/odyssey/fodyssey.py
author rgbecker
Fri, 14 Apr 2000 12:17:05 +0000
changeset 129 623baa767856
parent 119 b4dc589c8364
child 195 9ec081129a84
permissions -rw-r--r--
Splitting layout.py
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
     1
###############################################################################
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
     2
#
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
     3
#	ReportLab Public License Version 1.0
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
     4
#
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
     5
#	Except for the change of names the spirit and intention of this
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
     6
#	license is the same as that of Python
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
     7
#
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
     8
#	(C) Copyright ReportLab Inc. 1998-2000.
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
     9
#
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    10
#
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    11
# All Rights Reserved
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    12
#
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    13
# Permission to use, copy, modify, and distribute this software and its
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    14
# documentation for any purpose and without fee is hereby granted, provided
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    15
# that the above copyright notice appear in all copies and that both that
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    16
# copyright notice and this permission notice appear in supporting
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    17
# documentation, and that the name of ReportLab not be used
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    18
# in advertising or publicity pertaining to distribution of the software
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    19
# without specific, written prior permission. 
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    20
# 
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    21
#
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    22
# Disclaimer
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    23
#
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    24
# ReportLab Inc. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    25
# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    26
# IN NO EVENT SHALL ReportLab BE LIABLE FOR ANY SPECIAL, INDIRECT
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    27
# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    28
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    29
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    30
# PERFORMANCE OF THIS SOFTWARE. 
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    31
#
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    32
###############################################################################
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    33
#	$Log: fodyssey.py,v $
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
    34
#	Revision 1.4  2000/04/14 12:17:05  rgbecker
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
    35
#	Splitting layout.py
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
    36
#
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 117
diff changeset
    37
#	Revision 1.3  2000/04/13 14:48:41  rgbecker
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 117
diff changeset
    38
#	<para> tag added in layout.py paraparser.py
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
    39
#	
117
fd3682228853 XML Tagged Paragraph parser changes
rgbecker
parents: 73
diff changeset
    40
#	Revision 1.2  2000/04/12 16:24:34  rgbecker
fd3682228853 XML Tagged Paragraph parser changes
rgbecker
parents: 73
diff changeset
    41
#	XML Tagged Paragraph parser changes
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 117
diff changeset
    42
#	
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    43
#	Revision 1.1  2000/04/06 08:58:09  rgbecker
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    44
#	Paragraph formatting version of odyssey.py
117
fd3682228853 XML Tagged Paragraph parser changes
rgbecker
parents: 73
diff changeset
    45
#	
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
    46
__version__=''' $Id: fodyssey.py,v 1.4 2000/04/14 12:17:05 rgbecker Exp $ '''
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    47
__doc__=''
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    48
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    49
#REPORTLAB_TEST_SCRIPT
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    50
import sys, copy, string, os
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    51
from reportlab.platypus import layout
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
    52
from reportlab.platypus.paragraph import Paragraph
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    53
from reportlab.lib.units import inch
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
    54
from reportlab.lib.styles import getSampleStyleSheet
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
    55
from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    56
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
    57
styles = getSampleStyleSheet()
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    58
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    59
Title = "Odyssey"
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    60
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    61
Author = "Homer"
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    62
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    63
def myFirstPage(canvas, doc):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    64
	canvas.saveState()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    65
	canvas.setFont('Times-Bold',16)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    66
	canvas.drawString(108, layout.PAGE_HEIGHT-108, Title)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    67
	canvas.setFont('Times-Roman',9)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    68
	canvas.restoreState()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    69
	
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    70
def myLaterPages(canvas, doc):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    71
	canvas.saveState()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    72
	canvas.setFont('Times-Roman',9)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    73
	canvas.drawString(inch, 0.75 * inch, "Page %d" % doc.page)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    74
	canvas.restoreState()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    75
	
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    76
def go():
117
fd3682228853 XML Tagged Paragraph parser changes
rgbecker
parents: 73
diff changeset
    77
	doc = layout.SimpleFlowDocument('fodyssey.pdf',layout.DEFAULT_PAGE_SIZE,showBoundary=0)
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    78
	doc.onFirstPage = myFirstPage
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    79
	doc.onNewPage = myLaterPages
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    80
	doc.build(Elements)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    81
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    82
Elements = []
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    83
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    84
ChapterStyle = copy.copy(styles["Heading1"])
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
    85
ChapterStyle.alignment = TA_CENTER
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    86
ChapterStyle.fontsize = 14
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    87
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    88
def newPage():
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    89
	Elements.append(layout.PageBreak())
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    90
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    91
def chapter(txt, style=ChapterStyle):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    92
	newPage()
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
    93
	Elements.append(Paragraph(txt, style))
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    94
	Elements.append(layout.Spacer(0.2*inch, 0.3*inch))
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    95
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 117
diff changeset
    96
ParaStyle = copy.deepcopy(styles["Normal"])
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 117
diff changeset
    97
if 'right' in sys.argv:
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
    98
	ParaStyle.alignment = TA_RIGHT
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 117
diff changeset
    99
elif 'left' in sys.argv:
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
   100
	ParaStyle.alignment = TA_LEFT
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 117
diff changeset
   101
elif 'justify' in sys.argv:
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
   102
	ParaStyle.alignment = TA_JUSTIFY
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 117
diff changeset
   103
elif 'center' in sys.argv or 'centre' in sys.argv:
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
   104
	ParaStyle.alignment = TA_CENTER
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 117
diff changeset
   105
else:
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
   106
	ParaStyle.alignment = TA_JUSTIFY
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   107
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   108
def p(txt, style=ParaStyle):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   109
	Elements.append(layout.Spacer(0.2*inch, 0.1*inch))
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
   110
	Elements.append(Paragraph(txt, style))
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   111
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   112
PreStyle = styles["Code"] 
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   113
InitialStyle = copy.copy(PreStyle)
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
   114
InitialStyle.alignment = TA_CENTER
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   115
InitialStyle.fontsize = 14
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   116
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   117
def pre(txt, style=PreStyle):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   118
	s = layout.Spacer(0.1*inch, 0.1*inch)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   119
	Elements.append(s)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   120
	p = layout.Preformatted(txt, PreStyle)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   121
	Elements.append(p)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   122
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   123
def parseOdyssey(fn):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   124
	from time import time
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   125
	E = []
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   126
	t0=time()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   127
	L = open(fn,'r').readlines()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   128
	t1 = time()
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 117
diff changeset
   129
	print "open(%s,'r').readlines() took %.4f seconds" %(fn,t1-t0)
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   130
	for i in xrange(len(L)):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   131
		if L[i][-1]=='\012':
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   132
			L[i] = L[i][:-1]
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   133
	t2 = time()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   134
	print "Removing all linefeeds took %.4f seconds" %(t2-t1)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   135
	L.append('')
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   136
	L.append('-----')
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   137
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   138
	def findNext(L, i):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   139
		while 1:
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   140
			if string.strip(L[i])=='':
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   141
				del L[i]
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   142
				kind = 1
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   143
				if i<len(L):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   144
					while string.strip(L[i])=='':
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   145
						del L[i]
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   146
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   147
					if i<len(L):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   148
						kind = L[i][-1]=='-' and L[i][0]=='-'
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   149
						if kind:
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   150
							del L[i]
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   151
							if i<len(L):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   152
								while string.strip(L[i])=='':
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   153
									del L[i]
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   154
				break
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   155
			else:
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   156
				i = i + 1
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   157
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   158
		return i, kind
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   159
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   160
	f = s = 0
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   161
	while 1:
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   162
		f, k = findNext(L,0)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   163
		if k: break
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   164
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   165
	E.append([layout.Preformatted,'The Odyssey\n\nHomer\n', InitialStyle])
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   166
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   167
	while 1:
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   168
		if f>=len(L): break
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   169
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   170
		if string.upper(L[f][0:5])=='BOOK ':
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   171
			E.append([chapter,L[f]])
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   172
			f=f+1
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   173
			while string.strip(L[f])=='': del L[f]
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   174
			style = ParaStyle
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   175
			func = p
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   176
		else:
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   177
			style = PreStyle
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   178
			func = pre
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   179
	
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   180
		while 1:
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   181
			s=f
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   182
			f, k=findNext(L,s)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   183
			sep= (func is pre) and '\012' or ' '
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   184
			E.append([func,string.join(L[s:f],sep),style])
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   185
			if k: break
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   186
	t3 = time()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   187
	print "Parsing into memory took %.4f seconds" %(t3-t2)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   188
	del L
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   189
	t4 = time()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   190
	print "Deleting list of lines took %.4f seconds" %(t4-t3)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   191
	for i in xrange(len(E)):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   192
		apply(E[i][0],E[i][1:])
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   193
	t5 = time()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   194
	print "Moving into platypus took %.4f seconds" %(t5-t4)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   195
	del E
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   196
	t6 = time()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   197
	print "Deleting list of actions took %.4f seconds" %(t6-t5)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   198
	go()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   199
	t7 = time()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   200
	print "saving to PDF took %.4f seconds" %(t7-t6)
117
fd3682228853 XML Tagged Paragraph parser changes
rgbecker
parents: 73
diff changeset
   201
	print "Total run took %.4f seconds"%(t7-t0)
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   202
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   203
for fn in ('Odyssey.full.txt','Odyssey.txt'):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   204
	if os.path.isfile(fn):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   205
		break
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   206
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   207
parseOdyssey(fn)