commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue/reports/src/adapters/filters/Standard/Base...


From: Jason Cater
Subject: gnue/reports/src/adapters/filters/Standard/Base...
Date: Mon, 07 Apr 2003 03:18:57 -0400

CVSROOT:        /cvsroot/gnue
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    03/04/07 03:18:57

Modified files:
        reports/src/adapters/filters/Standard/Base/psutils: 
                                                            
PrinterDefinition.py 

Log message:
        more work on PPD support

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/reports/src/adapters/filters/Standard/Base/psutils/PrinterDefinition.py.diff?tr1=1.4&tr2=1.5&r1=text&r2=text

Patches:
Index: 
gnue/reports/src/adapters/filters/Standard/Base/psutils/PrinterDefinition.py
diff -c 
gnue/reports/src/adapters/filters/Standard/Base/psutils/PrinterDefinition.py:1.4
 
gnue/reports/src/adapters/filters/Standard/Base/psutils/PrinterDefinition.py:1.5
*** 
gnue/reports/src/adapters/filters/Standard/Base/psutils/PrinterDefinition.py:1.4
    Fri Apr  4 18:26:07 2003
--- 
gnue/reports/src/adapters/filters/Standard/Base/psutils/PrinterDefinition.py    
    Mon Apr  7 03:18:57 2003
***************
*** 19,35 ****
  # Copyright 2003 Free Software Foundation
  #
  # FILE:
! # FontMetrics.py
  #
  # DESCRIPTION:
  # Class that loads a Postscript Printer Description (PPD) file
  #
  # NOTES:
! #
! 
  
  from gnue.common.utils.FileUtils import openResource
  
  class PrinterDefinition:
  
    def __init__(self, location):
--- 19,40 ----
  # Copyright 2003 Free Software Foundation
  #
  # FILE:
! # PrinterDefinition.py
  #
  # DESCRIPTION:
  # Class that loads a Postscript Printer Description (PPD) file
+ # Supports version 4.3 of the PPD spec (at least, we hope)
  #
  # NOTES:
! # Spec: http://partners.adobe.com/asn/developer/pdfs/tn/5003.PPD_Spec_v4.3.pdf
  
+ import string, re
  from gnue.common.utils.FileUtils import openResource
  
+ 
+ class InvalidPPDFormat(StandardError):
+   pass
+ 
  class PrinterDefinition:
  
    def __init__(self, location):
***************
*** 41,54 ****
        close = 1
  
      currentUiOption = None
-     current
  
!     for line in handle.readlines():
        line = line.strip()
  
!       # Skip blank lines and comments
!       if line[:2] in ('','*%'):
          continue
  
      if close:
        handle.close()
--- 46,153 ----
        close = 1
  
      currentUiOption = None
  
!     line = handle.readline()
! 
!     while line is not None:
! 
        line = line.strip()
  
!       # Skip blank lines, comments (*%), and "query" (*?) keywords.
!       # We skip the query keywords as we have no intention of
!       # getting intimate with a printer and asking it questions.
!       if line[:2] in ('','*%','*?'):
!         line = handle.readline()
          continue
  
+       # Get stuff to the left of the colon
+       # (Can either be a Keyword, or a Keyword + Option)
+       keyword, data = line.split(':',2)
+ 
+       # Dump the leading asterick and trailing colon
+       # (not sure if the .strip() is necessary :)
+       keyword = keyword[1:-1].strip()
+ 
+       # Clean up the data line
+       data.strip()
+ 
+       # Do we have an Option, or just a Keyword?
+       try:
+         keyword, option = keyword.split()
+       except:
+         option = None
+ 
+       isSymbol = 0
+ 
+       # ^Data means Data is a Symbol
+       if data[:1] == '^':
+         isSymbol = 1
+         data = date[1:]
+ 
+       # Double Quotes means data is Quoted... treat specially
+       elif data[:1] == '"':
+ 
+         # If last character is a quote, then this is a single-line string
+         if data[:-1] == '"':
+           data = data[1:-1]
+ 
+         # otherwise, we need to grab the rest of the data
+         else:
+ 
+           # Get rid of leading quote, and restore
+           # the newline dropped earlier
+           data = data[1:] + '\n'
+ 
+           # Find the next '*End' marker
+           line = handle.readline()
+           while line != None and line.strip() != '*End'"
+             data += line
+             line = handle.readline()
+ 
+           # If we never hit an *End, then this isn't a valid file.
+           if line is None:
+             raise InvalidPPDFormat, 'Not a valid PPD file... missing *End'
+ 
+           # Get rid of the closing quote
+           data = data.strip()[:-1]
+ 
+           # If this was a Keyword/Option pair, then the PPD spec
+           # allows for the string to contain hex characters
+           # encoded as <ff> (i.e., inside brackets)
+           if Option and data.find('<') >= 0:
+             # expand hex references using the "re" module.
+             # (we've precompiled these functions at the end)
+             data = _hexre.sub(_hexToBinary, data)
+ 
+         # Treat as a string
+         datatype = 'S'
+ 
+       # Empty string is, of course, NoValue
+       elif not len(data):
+         datatype = None
+ 
+       # Anything else is a plain string
+       else:
+         # Good ol' string type
+         datatype = 'S'
+ 
+ 
+       line = handle.readline()
+ 
      if close:
        handle.close()
+ 
+ 
+ 
+ # Used by the class above to convert a
+ # hex-encoded string to a binary string.
+ def _hexToBinary( match ):
+   s = str(match.group())[1:-1]
+   rs = ""
+   for i in range(len(s)/2):
+     rs += chr(float('0x' + s[i*2:i*2+2]))
+   return rs
+ 
+ # Precompile our regular expression
+ _hexre = re.compile(r'<.*?>')
+ 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]