<commit_before>
#copyright ReportLab Inc. 2000
#see license.txt for license details
#history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/pdfbase/pdfdoc.py?cvsroot=reportlab
#$Header: /tmp/reportlab/reportlab/pdfbase/pdfdoc.py,v 1.57 2002/03/25 00:51:49 andy_robinson Exp $
__version__=''' $Id: pdfdoc.py,v 1.57 2002/03/25 00:51:49 andy_robinson Exp $ '''
__doc__=""" 
The module pdfdoc.py handles the 'outer structure' of PDF documents, ensuring that
all objects are properly cross-referenced and indexed to the nearest byte.  The 
'inner structure' - the page descriptions - are presumed to be generated before 
each page is saved.
pdfgen.py calls this and provides a 'canvas' object to handle page marking operators.
piddlePDF calls pdfgen and offers a high-level interface.

The classes within this generally mirror structures in the PDF file
and are not part of any public interface.  Instead, canvas and font
classes are made available elsewhere for users to manipulate.
"""

import string, types
from reportlab.pdfbase import pdfutils
from reportlab.pdfbase.pdfutils import LINEEND   # this constant needed in both
from reportlab import rl_config
from reportlab.lib.utils import import_zlib, PIL_Image

class PDFError(Exception):
    pass


# set this flag to get more vertical whitespace (and larger files)
LongFormat = 1
##if LongFormat: (doesn't work)
##    pass
##else:
##    LINEEND = "\n" # no wasteful carriage returns!

# __InternalName__ is a special attribute that can only be set by the Document arbitrator
__InternalName__ = "__InternalName__"

# __RefOnly__ marks reference only elements that must be formatted on top level
__RefOnly__ = "__RefOnly__"

# __Comment__ provides a (one line) comment to inline with an object ref, if present
#   if it is more than one line then percentize it...
__Comment__ = "__Comment__"

# If DoComments is set then add helpful (space wasting) comment lines to PDF files
DoComments = 1
if not LongFormat:
    DoComments = 0

# name for standard font dictionary
BasicFonts = "BasicFonts"

# name for the pages object
Pages = "Pages"

### generic utilities


# for % substitutions
LINEENDDICT = {"LINEEND": LINEEND, "PERCENT": "%"}

def markfilename(filename):
    # with the Mac, we need to tag the file in a special
    #way so the system knows it is a PDF file.
    #This supplied by <NAME>
    import os
    if os.name == 'mac':
        import macfs
        try: 
            macfs.FSSpec(filename).SetCreatorType('CARO','PDF ')
        except:
            pass

def format(element, document, toplevel=0):
    """Indirection step for formatting.
       Ensures that document parameters alter behaviour
       of formatting for all elements.
    """
    from types import InstanceType
    if type(element) is InstanceType:
        if not toplevel and hasattr(element, __RefOnly__):
            # the object cannot be a component at non top level.
            # make a reference to it and return it's format
            R = document.Reference(element)
            return R.format(document)
        else:
            try:
                fmt = element.format
            except:
                raise AttributeError, "%s has no format operation" % element
            f = fmt(document)
            if DoComments and hasattr(element, __Comment__):
                f = "%s%s%s%s" % ("% ", element.__Comment__, LINEEND, f)
            return f
    else:
        return str(element)

def indent(s, IND=LINEEND+" "):
    return string.replace(s, LINEEND, IND)

def xObjectName(externalname):
    return "Xobject.%s" % externalname


# no encryption
class NoEncryption:
    def encode(self, t):
        "encode a string, stream, text"
        return t
    def prepare(self, document):
        # get ready to do encryption
        pass
    def register(self, objnum, version):
        # enter a new direct object
        pass
    def info(self):
        # the representation of self in file if any (should be None or PDFDict)
        return None

class DummyDoc:
    "used to bypass encryption when required"
    encrypt = NoEncryption()
    
### the global document structure manager
<commit_msg>revert to older internal name for backward compatibility<commit_after>
#copyright ReportLab Inc. 2000
#see license.txt for license details
#history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/pdfbase/pdfdoc.py?cvsroot=reportlab
#$Header: /tmp/reportlab/reportlab/pdfbase/pdfdoc.py,v 1.58 2002/03/27 12:53:12 rgbecker Exp $
__version__=''' $Id: pdfdoc.py,v 1.58 2002/03/27 12:53:12 rgbecker Exp $ '''
__doc__=""" 
The module pdfdoc.py handles the 'outer structure' of PDF documents, ensuring that
all objects are properly cross-referenced and indexed to the nearest byte.  The 
'inner structure' - the page descriptions - are presumed to be generated before 
each page is saved.
pdfgen.py calls this and provides a 'canvas' object to handle page marking operators.
piddlePDF calls pdfgen and offers a high-level interface.

The classes within this generally mirror structures in the PDF file
and are not part of any public interface.  Instead, canvas and font
classes are made available elsewhere for users to manipulate.
"""

import string, types
from reportlab.pdfbase import pdfutils
from reportlab.pdfbase.pdfutils import LINEEND   # this constant needed in both
from reportlab import rl_config
from reportlab.lib.utils import import_zlib, PIL_Image

class PDFError(Exception):
    pass


# set this flag to get more vertical whitespace (and larger files)
LongFormat = 1
##if LongFormat: (doesn't work)
##    pass
##else:
##    LINEEND = "\n" # no wasteful carriage returns!

# __InternalName__ is a special attribute that can only be set by the Document arbitrator
__InternalName__ = "__InternalName__"

# __RefOnly__ marks reference only elements that must be formatted on top level
__RefOnly__ = "__RefOnly__"

# __Comment__ provides a (one line) comment to inline with an object ref, if present
#   if it is more than one line then percentize it...
__Comment__ = "__Comment__"

# If DoComments is set then add helpful (space wasting) comment lines to PDF files
DoComments = 1
if not LongFormat:
    DoComments = 0

# name for standard font dictionary
BasicFonts = "BasicFonts"

# name for the pages object
Pages = "Pages"

### generic utilities


# for % substitutions
LINEENDDICT = {"LINEEND": LINEEND, "PERCENT": "%"}

def markfilename(filename):
    # with the Mac, we need to tag the file in a special
    #way so the system knows it is a PDF file.
    #This supplied by <NAME>
    import os
    if os.name == 'mac':
        import macfs
        try: 
            macfs.FSSpec(filename).SetCreatorType('CARO','PDF ')
        except:
            pass

def format(element, document, toplevel=0):
    """Indirection step for formatting.
       Ensures that document parameters alter behaviour
       of formatting for all elements.
    """
    from types import InstanceType
    if type(element) is InstanceType:
        if not toplevel and hasattr(element, __RefOnly__):
            # the object cannot be a component at non top level.
            # make a reference to it and return it's format
            R = document.Reference(element)
            return R.format(document)
        else:
            try:
                fmt = element.format
            except:
                raise AttributeError, "%s has no format operation" % element
            f = fmt(document)
            if DoComments and hasattr(element, __Comment__):
                f = "%s%s%s%s" % ("% ", element.__Comment__, LINEEND, f)
            return f
    else:
        return str(element)

def indent(s, IND=LINEEND+" "):
    return string.replace(s, LINEEND, IND)

def xObjectName(externalname):
    return "FormXob.%s" % externalname


# no encryption
class NoEncryption:
    def encode(self, t):
        "encode a string, stream, text"
        return t
    def prepare(self, document):
        # get ready to do encryption
        pass
    def register(self, objnum, version):
        # enter a new direct object
        pass
    def info(self):
        # the representation of self in file if any (should be None or PDFDict)
        return None

class DummyDoc:
    "used to bypass encryption when required"
    encrypt = NoEncryption()
    
### the global document structure manager

{'fraction_non_alphanumeric': 0.0774673222208898, 'fraction_numerical': 0.01007315025782468, 'mean_word_length': 3.0842311459353575, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3683346', 'n_tokens_mistral': 2436, 'n_tokens_neox': 2303, 'n_words': 957}