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