[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gzz-commits] alph/alph/util dsc.test dscutil.py
From: |
Tuomas J. Lukka |
Subject: |
[Gzz-commits] alph/alph/util dsc.test dscutil.py |
Date: |
Tue, 22 Apr 2003 07:09:08 -0400 |
CVSROOT: /cvsroot/alph
Module name: alph
Changes by: Tuomas J. Lukka <address@hidden> 03/04/22 07:09:07
Modified files:
alph/util : dsc.test dscutil.py
Log message:
FIRST DSC TEST PASSES
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/alph/alph/alph/util/dsc.test.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/alph/alph/alph/util/dscutil.py.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
Patches:
Index: alph/alph/util/dsc.test
diff -u alph/alph/util/dsc.test:1.1 alph/alph/util/dsc.test:1.2
--- alph/alph/util/dsc.test:1.1 Tue Apr 22 05:10:18 2003
+++ alph/alph/util/dsc.test Tue Apr 22 07:09:07 2003
@@ -24,4 +24,6 @@
for f in pdffiles:
_rm(outdsc)
assert alph.util.dscutil.reliablePDF2DSC("testdata/"+f[0], outdsc)
+ pageinfo = alph.util.dscutil.dsc2pageinfo(outdsc)
+ assert pageinfo.getNPages() == f[1]
_rm(outdsc)
Index: alph/alph/util/dscutil.py
diff -u alph/alph/util/dscutil.py:1.1 alph/alph/util/dscutil.py:1.2
--- alph/alph/util/dscutil.py:1.1 Tue Apr 22 05:10:38 2003
+++ alph/alph/util/dscutil.py Tue Apr 22 07:09:07 2003
@@ -1,4 +1,7 @@
import os
+import jarray
+import alph
+from copy import deepcopy
def reliablePS2DSC(infile, outfile):
"""Convert a postscript file to a .dsc file reliably.
@@ -55,6 +58,13 @@
print "Tok: '"+string+"' ",tokens
return tokens
+class SinglePageInfo:
+ def parseLine(self, str):
+ if str.startswith("%%PageMedia:"):
+ self.media = str[12:].strip()
+ elif str.startswith("%%PageOrientation:"):
+ self.orient = str[19:].strip()
+
def dsc2pageinfo(infile):
f = open(infile)
lines = f.readlines()
@@ -64,11 +74,53 @@
if lines[i].startswith("%%+"):
lines[i-1] += lines[i][3:]
lines[i:i] = []
+ i-=1
# Look for DocumentMedia
documentmedia = [l for l in lines if l.startswith("%%DocumentMedia:")]
assert len(documentmedia) == 1
media = _dsctokens(documentmedia[0][16:])
+ assert len(media) % 6 == 0
+ mtypes = {}
+ for i in range(0, len(media)/6):
+ (name, w, h, weight, color, type) = media[i*6:(i+1)*6]
+ print "Docmedia '%(name)s' %(w)s %(h)s %(weight)s %(color)s %(type)s" \
+ % locals()
+ mtypes[name] = (float(w),float(h))
+
+ # find the dsc defaults
+ start = [i for i in range(0, len(lines)) if
lines[i].startswith("%%BeginDefaults")]
+ end = [i for i in range(0, len(lines)) if
lines[i].startswith("%%EndDefaults")]
+ if len(start):
+ assert len(end)
+ assert 1 == 0
+ # Don't want to deal with these quite yet
+
+ # Start parsing the pages
+ curpage = 0
+ pages = []
+
+ defaultSPI = SinglePageInfo()
+ spi = None
+
+ for l in lines:
+ if l.startswith("%%Page:"):
+ toks = _dsctokens(l[7:])
+ assert len(toks) == 2
+ newpage = int(toks[1])
+ assert newpage == curpage + 1
+ curpage = newpage
+ if spi:
+ pages.append(spi)
+ spi = deepcopy(defaultSPI)
+ else:
+ if spi:
+ spi.parseLine(l)
+ pages.append(spi)
+
+ pagemedias = [ mtypes[p.media] for p in pages ]
+
+ w = jarray.array([ m[0] for m in pagemedias ], 'f')
+ h = jarray.array([ m[1] for m in pagemedias ], 'f')
-
-
+ return alph.util.PageInfo(w, h)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gzz-commits] alph/alph/util dsc.test dscutil.py,
Tuomas J. Lukka <=