reportlab/demos/odyssey/fodyssey.py
author rgbecker
Wed, 17 May 2000 15:39:10 +0000
changeset 225 1f58b00cf30e
parent 207 52e4ab91cc16
child 226 a9acb67cdef7
permissions -rw-r--r--
Changes related to removal of SimpleFlowDocument
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 $
225
1f58b00cf30e Changes related to removal of SimpleFlowDocument
rgbecker
parents: 207
diff changeset
    34
#	Revision 1.9  2000/05/17 15:37:33  rgbecker
1f58b00cf30e Changes related to removal of SimpleFlowDocument
rgbecker
parents: 207
diff changeset
    35
#	Changes related to removal of SimpleFlowDocument
1f58b00cf30e Changes related to removal of SimpleFlowDocument
rgbecker
parents: 207
diff changeset
    36
#
207
52e4ab91cc16 Fix spacing bugs
rgbecker
parents: 203
diff changeset
    37
#	Revision 1.8  2000/05/13 09:23:45  rgbecker
52e4ab91cc16 Fix spacing bugs
rgbecker
parents: 203
diff changeset
    38
#	Fix spacing bugs
225
1f58b00cf30e Changes related to removal of SimpleFlowDocument
rgbecker
parents: 207
diff changeset
    39
#	
203
0e2031146bf5 Title leading changes
rgbecker
parents: 198
diff changeset
    40
#	Revision 1.7  2000/05/12 16:19:07  rgbecker
0e2031146bf5 Title leading changes
rgbecker
parents: 198
diff changeset
    41
#	Title leading changes
207
52e4ab91cc16 Fix spacing bugs
rgbecker
parents: 203
diff changeset
    42
#	
198
5604fb99b2e7 Added 'if __name__=='__main__'' handlers to demos
andy_robinson
parents: 195
diff changeset
    43
#	Revision 1.6  2000/05/12 14:19:03  andy_robinson
5604fb99b2e7 Added 'if __name__=='__main__'' handlers to demos
andy_robinson
parents: 195
diff changeset
    44
#	Added 'if __name__=='__main__'' handlers to demos
203
0e2031146bf5 Title leading changes
rgbecker
parents: 198
diff changeset
    45
#	
195
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
    46
#	Revision 1.5  2000/05/12 12:49:38  rgbecker
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
    47
#	Minor fixes and changes for comparison with dodyssey.py
198
5604fb99b2e7 Added 'if __name__=='__main__'' handlers to demos
andy_robinson
parents: 195
diff changeset
    48
#	
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
    49
#	Revision 1.4  2000/04/14 12:17:05  rgbecker
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
    50
#	Splitting layout.py
195
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
    51
#	
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 117
diff changeset
    52
#	Revision 1.3  2000/04/13 14:48:41  rgbecker
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 117
diff changeset
    53
#	<para> tag added in layout.py paraparser.py
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
    54
#	
117
fd3682228853 XML Tagged Paragraph parser changes
rgbecker
parents: 73
diff changeset
    55
#	Revision 1.2  2000/04/12 16:24:34  rgbecker
fd3682228853 XML Tagged Paragraph parser changes
rgbecker
parents: 73
diff changeset
    56
#	XML Tagged Paragraph parser changes
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 117
diff changeset
    57
#	
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    58
#	Revision 1.1  2000/04/06 08:58:09  rgbecker
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    59
#	Paragraph formatting version of odyssey.py
117
fd3682228853 XML Tagged Paragraph parser changes
rgbecker
parents: 73
diff changeset
    60
#	
225
1f58b00cf30e Changes related to removal of SimpleFlowDocument
rgbecker
parents: 207
diff changeset
    61
__version__=''' $Id: fodyssey.py,v 1.9 2000/05/17 15:37:33 rgbecker Exp $ '''
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    62
__doc__=''
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    63
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    64
#REPORTLAB_TEST_SCRIPT
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    65
import sys, copy, string, os
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
    66
from reportlab.platypus.paragraph import Paragraph
225
1f58b00cf30e Changes related to removal of SimpleFlowDocument
rgbecker
parents: 207
diff changeset
    67
from reportlab.platypus.doctemplate import *
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    68
from reportlab.lib.units import inch
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
    69
from reportlab.lib.styles import getSampleStyleSheet
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
    70
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
    71
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
    72
styles = getSampleStyleSheet()
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    73
195
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
    74
Title = "The Odyssey"
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    75
Author = "Homer"
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    76
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    77
def myFirstPage(canvas, doc):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    78
	canvas.saveState()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    79
	canvas.restoreState()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    80
	
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    81
def myLaterPages(canvas, doc):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    82
	canvas.saveState()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    83
	canvas.setFont('Times-Roman',9)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    84
	canvas.drawString(inch, 0.75 * inch, "Page %d" % doc.page)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    85
	canvas.restoreState()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    86
	
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    87
def go():
225
1f58b00cf30e Changes related to removal of SimpleFlowDocument
rgbecker
parents: 207
diff changeset
    88
	doc = SimpleDocTemplate('fodyssey.pdf',DEFAULT_PAGE_SIZE,showBoundary=0)
1f58b00cf30e Changes related to removal of SimpleFlowDocument
rgbecker
parents: 207
diff changeset
    89
	doc.allowSplitting = not 'nosplitting' in sys.argv
1f58b00cf30e Changes related to removal of SimpleFlowDocument
rgbecker
parents: 207
diff changeset
    90
	doc.build(Elements,myFirstPage,myLaterPages)
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    91
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    92
Elements = []
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    93
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
    94
ChapterStyle = copy.copy(styles["Heading1"])
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
    95
ChapterStyle.alignment = TA_CENTER
195
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
    96
ChapterStyle.fontsize = 16
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
    97
InitialStyle = copy.deepcopy(ChapterStyle)
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
    98
InitialStyle.fontsize = 16
203
0e2031146bf5 Title leading changes
rgbecker
parents: 198
diff changeset
    99
InitialStyle.leading = 20
195
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
   100
PreStyle = styles["Code"] 
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   101
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   102
def newPage():
225
1f58b00cf30e Changes related to removal of SimpleFlowDocument
rgbecker
parents: 207
diff changeset
   103
	Elements.append(PageBreak())
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   104
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   105
def chapter(txt, style=ChapterStyle):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   106
	newPage()
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
   107
	Elements.append(Paragraph(txt, style))
225
1f58b00cf30e Changes related to removal of SimpleFlowDocument
rgbecker
parents: 207
diff changeset
   108
	Elements.append(Spacer(0.2*inch, 0.3*inch))
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   109
195
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
   110
def fTitle(txt,style=InitialStyle):
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
   111
	Elements.append(Paragraph(txt, style))
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
   112
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 117
diff changeset
   113
ParaStyle = copy.deepcopy(styles["Normal"])
207
52e4ab91cc16 Fix spacing bugs
rgbecker
parents: 203
diff changeset
   114
ParaStyle.spaceBefore = 0.1*inch
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 117
diff changeset
   115
if 'right' in sys.argv:
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
   116
	ParaStyle.alignment = TA_RIGHT
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 117
diff changeset
   117
elif 'left' in sys.argv:
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
   118
	ParaStyle.alignment = TA_LEFT
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 117
diff changeset
   119
elif 'justify' in sys.argv:
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
   120
	ParaStyle.alignment = TA_JUSTIFY
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 117
diff changeset
   121
elif 'center' in sys.argv or 'centre' in sys.argv:
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
   122
	ParaStyle.alignment = TA_CENTER
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 117
diff changeset
   123
else:
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
   124
	ParaStyle.alignment = TA_JUSTIFY
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   125
195
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
   126
def spacer(inches):
225
1f58b00cf30e Changes related to removal of SimpleFlowDocument
rgbecker
parents: 207
diff changeset
   127
	Elements.append(Spacer(0.1*inch, inches*inch))
195
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
   128
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   129
def p(txt, style=ParaStyle):
129
623baa767856 Splitting layout.py
rgbecker
parents: 119
diff changeset
   130
	Elements.append(Paragraph(txt, style))
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   131
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   132
def pre(txt, style=PreStyle):
195
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
   133
	spacer(0.1)
225
1f58b00cf30e Changes related to removal of SimpleFlowDocument
rgbecker
parents: 207
diff changeset
   134
	p = Preformatted(txt, style)
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   135
	Elements.append(p)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   136
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   137
def parseOdyssey(fn):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   138
	from time import time
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   139
	E = []
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   140
	t0=time()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   141
	L = open(fn,'r').readlines()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   142
	t1 = time()
119
b4dc589c8364 <para> tag added in layout.py paraparser.py
rgbecker
parents: 117
diff changeset
   143
	print "open(%s,'r').readlines() took %.4f seconds" %(fn,t1-t0)
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   144
	for i in xrange(len(L)):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   145
		if L[i][-1]=='\012':
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   146
			L[i] = L[i][:-1]
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   147
	t2 = time()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   148
	print "Removing all linefeeds took %.4f seconds" %(t2-t1)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   149
	L.append('')
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   150
	L.append('-----')
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   151
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   152
	def findNext(L, i):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   153
		while 1:
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   154
			if string.strip(L[i])=='':
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   155
				del L[i]
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   156
				kind = 1
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   157
				if i<len(L):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   158
					while string.strip(L[i])=='':
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   159
						del L[i]
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   160
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   161
					if i<len(L):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   162
						kind = L[i][-1]=='-' and L[i][0]=='-'
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   163
						if kind:
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   164
							del L[i]
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   165
							if i<len(L):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   166
								while string.strip(L[i])=='':
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   167
									del L[i]
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   168
				break
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   169
			else:
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   170
				i = i + 1
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   171
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   172
		return i, kind
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   173
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   174
	f = s = 0
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   175
	while 1:
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   176
		f, k = findNext(L,0)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   177
		if k: break
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   178
195
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
   179
	E.append([spacer,2])
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
   180
	E.append([fTitle,'<font color=red>%s</font>' % Title, InitialStyle])
9ec081129a84 Minor fixes and changes for comparison with dodyssey.py
rgbecker
parents: 129
diff changeset
   181
	E.append([fTitle,'<font size=-4>by</font> <font color=green>%s</font>' % Author, InitialStyle])
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   182
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   183
	while 1:
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   184
		if f>=len(L): break
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   185
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   186
		if string.upper(L[f][0:5])=='BOOK ':
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   187
			E.append([chapter,L[f]])
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   188
			f=f+1
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   189
			while string.strip(L[f])=='': del L[f]
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   190
			style = ParaStyle
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   191
			func = p
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   192
		else:
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   193
			style = PreStyle
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   194
			func = pre
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   195
	
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   196
		while 1:
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   197
			s=f
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   198
			f, k=findNext(L,s)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   199
			sep= (func is pre) and '\012' or ' '
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   200
			E.append([func,string.join(L[s:f],sep),style])
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   201
			if k: break
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   202
	t3 = time()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   203
	print "Parsing into memory took %.4f seconds" %(t3-t2)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   204
	del L
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   205
	t4 = time()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   206
	print "Deleting list of lines took %.4f seconds" %(t4-t3)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   207
	for i in xrange(len(E)):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   208
		apply(E[i][0],E[i][1:])
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   209
	t5 = time()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   210
	print "Moving into platypus took %.4f seconds" %(t5-t4)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   211
	del E
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   212
	t6 = time()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   213
	print "Deleting list of actions took %.4f seconds" %(t6-t5)
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   214
	go()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   215
	t7 = time()
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   216
	print "saving to PDF took %.4f seconds" %(t7-t6)
117
fd3682228853 XML Tagged Paragraph parser changes
rgbecker
parents: 73
diff changeset
   217
	print "Total run took %.4f seconds"%(t7-t0)
73
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   218
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   219
for fn in ('Odyssey.full.txt','Odyssey.txt'):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   220
	if os.path.isfile(fn):
52c1eea5b912 Paragraph formatting version of odyssey.py
rgbecker
parents:
diff changeset
   221
		break
198
5604fb99b2e7 Added 'if __name__=='__main__'' handlers to demos
andy_robinson
parents: 195
diff changeset
   222
if __name__=='__main__':
5604fb99b2e7 Added 'if __name__=='__main__'' handlers to demos
andy_robinson
parents: 195
diff changeset
   223
	parseOdyssey(fn)