src/reportlab/pdfbase/pdfdoc.py
branchpy33
changeset 3794 398ea04239b5
parent 3781 df8b57380768
child 3801 0c12fc9ce323
equal deleted inserted replaced
3793:cc3f9cc828f7 3794:398ea04239b5
    12 
    12 
    13 The classes within this generally mirror structures in the PDF file
    13 The classes within this generally mirror structures in the PDF file
    14 and are not part of any public interface.  Instead, canvas and font
    14 and are not part of any public interface.  Instead, canvas and font
    15 classes are made available elsewhere for users to manipulate.
    15 classes are made available elsewhere for users to manipulate.
    16 """
    16 """
    17 import string, types, binascii, codecs
    17 import types, binascii, codecs
    18 from reportlab.pdfbase import pdfutils
    18 from reportlab.pdfbase import pdfutils
    19 from reportlab.pdfbase.pdfutils import LINEEND # this constant needed in both
    19 from reportlab.pdfbase.pdfutils import LINEEND # this constant needed in both
    20 from reportlab import rl_config
    20 from reportlab import rl_config
    21 from reportlab.lib.utils import import_zlib, open_for_read, makeFileName, isSeq, isBytes, isUnicode, _digester
    21 from reportlab.lib.utils import import_zlib, open_for_read, makeFileName, isSeq, isBytes, isUnicode, _digester
    22 from reportlab.lib.rl_accel import escapePDF, fp_str, asciiBase85Encode, asciiBase85Decode
    22 from reportlab.lib.rl_accel import escapePDF, fp_str, asciiBase85Encode, asciiBase85Decode
   841 def teststream(content=None):
   841 def teststream(content=None):
   842     #content = "" # test
   842     #content = "" # test
   843     if content is None:
   843     if content is None:
   844         content = teststreamcontent
   844         content = teststreamcontent
   845     content = content.strip()
   845     content = content.strip()
   846     content = string.replace(content, "\n", LINEEND) + LINEEND
   846     content = content.replace("\n", LINEEND) + LINEEND
   847     S = PDFStream(content = content,
   847     S = PDFStream(content = content,
   848                     filters=rl_config.useA85 and [PDFBase85Encode,PDFZCompress] or [PDFZCompress])
   848                     filters=rl_config.useA85 and [PDFBase85Encode,PDFZCompress] or [PDFZCompress])
   849     # nothing else needed...
   849     # nothing else needed...
   850     S.__Comment__ = "test stream"
   850     S.__Comment__ = "test stream"
   851     return S
   851     return S
  2008 ## These attribute listings will be useful in future, even if we
  2008 ## These attribute listings will be useful in future, even if we
  2009 ## put them elsewhere
  2009 ## put them elsewhere
  2010 
  2010 
  2011 class PDFTrueTypeFont(PDFType1Font):
  2011 class PDFTrueTypeFont(PDFType1Font):
  2012     Subtype = "TrueType"
  2012     Subtype = "TrueType"
  2013     #local_attributes = string.split("FirstChar LastChar Widths Encoding ToUnicode FontDescriptor") #same
  2013     #local_attributes = "FirstChar LastChar Widths Encoding ToUnicode FontDescriptor".split() #same
  2014 
  2014 
  2015 ##class PDFMMType1Font(PDFType1Font):
  2015 ##class PDFMMType1Font(PDFType1Font):
  2016 ##    Subtype = "MMType1"
  2016 ##    Subtype = "MMType1"
  2017 ##
  2017 ##
  2018 ##class PDFType3Font(PDFType1Font):
  2018 ##class PDFType3Font(PDFType1Font):
  2019 ##    Subtype = "Type3"
  2019 ##    Subtype = "Type3"
  2020 ##    local_attributes = string.split(
  2020 ##    local_attributes = "FirstChar LastChar Widths CharProcs FontBBox FontMatrix Resources Encoding".split()
  2021 ##        "FirstChar LastChar Widths CharProcs FontBBox FontMatrix Resources Encoding")
       
  2022 ##
  2021 ##
  2023 ##class PDFType0Font(PDFType1Font):
  2022 ##class PDFType0Font(PDFType1Font):
  2024 ##    Subtype = "Type0"
  2023 ##    Subtype = "Type0"
  2025 ##    local_attributes = string.split(
  2024 ##    local_attributes = "DescendantFonts Encoding".split(
  2026 ##        "DescendantFonts Encoding")
       
  2027 ##
  2025 ##
  2028 ##class PDFCIDFontType0(PDFType1Font):
  2026 ##class PDFCIDFontType0(PDFType1Font):
  2029 ##    Subtype = "CIDFontType0"
  2027 ##    Subtype = "CIDFontType0"
  2030 ##    local_attributes = string.split(
  2028 ##    local_attributes = "CIDSystemInfo FontDescriptor DW W DW2 W2 Registry Ordering Supplement".split()
  2031 ##        "CIDSystemInfo FontDescriptor DW W DW2 W2 Registry Ordering Supplement")
       
  2032 ##
  2029 ##
  2033 ##class PDFCIDFontType0(PDFType1Font):
  2030 ##class PDFCIDFontType0(PDFType1Font):
  2034 ##    Subtype = "CIDFontType2"
  2031 ##    Subtype = "CIDFontType2"
  2035 ##    local_attributes = string.split(
  2032 ##    local_attributes = "BaseFont CIDToGIDMap CIDSystemInfo FontDescriptor DW W DW2 W2".split()
  2036 ##        "BaseFont CIDToGIDMap CIDSystemInfo FontDescriptor DW W DW2 W2")
       
  2037 ##
  2033 ##
  2038 ##class PDFEncoding(PDFType1Font):
  2034 ##class PDFEncoding(PDFType1Font):
  2039 ##    Type = "Encoding"
  2035 ##    Type = "Encoding"
  2040 ##    name_attributes = string.split("Type BaseEncoding")
  2036 ##    name_attributes = "Type BaseEncoding".split()
  2041 ##    # these attributes are assumed to already be of the right type
  2037 ##    # these attributes are assumed to already be of the right type
  2042 ##    local_attributes = ["Differences"]
  2038 ##    local_attributes = ["Differences"]
  2043 ##
  2039 ##
  2044 
  2040 
  2045 # UGLY ALERT - this needs turning into something O-O, it was hacked
  2041 # UGLY ALERT - this needs turning into something O-O, it was hacked
  2204         return True
  2200         return True
  2205 
  2201 
  2206     def loadImageFromRaw(self,source):
  2202     def loadImageFromRaw(self,source):
  2207         IMG=[]
  2203         IMG=[]
  2208         imagedata = pdfutils.makeRawImage(source,IMG=IMG)
  2204         imagedata = pdfutils.makeRawImage(source,IMG=IMG)
  2209         words = string.split(imagedata[1])
  2205         words = imagedata[1].split()
  2210         self.width = int(words[1])
  2206         self.width = int(words[1])
  2211         self.height = int(words[3])
  2207         self.height = int(words[3])
  2212         self.colorSpace = {'/RGB':'DeviceRGB', '/G':'DeviceGray', '/CMYK':'DeviceCMYK'}[words[7]]
  2208         self.colorSpace = {'/RGB':'DeviceRGB', '/G':'DeviceGray', '/CMYK':'DeviceCMYK'}[words[7]]
  2213         self.bitsPerComponent = 8
  2209         self.bitsPerComponent = 8
  2214         self._filters = 'FlateDecode', #'Fl'
  2210         self._filters = 'FlateDecode', #'Fl'