示例#1
0
    def __init__(self, document, imageTypes=None):
        self.config = document.config
        self.ownerDocument = document

        if imageTypes is None:
            self.imageTypes = [self.fileExtension]
        else:
            self.imageTypes = imageTypes[:]

        # Dictionary that makes sure each image is only generated once.
        # The key is the LaTeX source and the value is the image instance.
        self._cache = {}
        usednames = {}
        self._filecache = os.path.abspath(
            os.path.join('.cache', self.__class__.__name__ + '.images'))
        if self.config['images']['cache'] and os.path.isfile(self._filecache):
            try:
                self._cache = pickle.load(open(self._filecache, 'r'))
                for key, value in self._cache.items():
                    if not os.path.isfile(value.filename):
                        del self._cache[key]
                        continue
                    usednames[value.filename] = None
            except ImportError:
                os.remove(self._filecache)

        # List of images in the order that they appear in the LaTeX file
        self.images = ordereddict()

        # Images that are simply copied from the source directory
        self.staticimages = ordereddict()

        # Filename generator
        self.newFilename = Filenames(
            self.config['images'].get('filenames', raw=True),
            vars={'jobname': document.userdata.get('jobname', '')},
            extension=self.fileExtension,
            invalid=usednames)

        # Start the document with a preamble
        self.source = StringIO()
        self.source.write('\\scrollmode\n')
        self.writePreamble(document)
        self.source.write('\\begin{document}\n')

        # Set up additional options
        self._configOptions = self.formatConfigOptions(self.config['images'])
示例#2
0
    def __init__(self, document, imageTypes=None):
        self.config = document.config
        self.ownerDocument = document

        if imageTypes is None:
            self.imageTypes = [self.fileExtension]
        else:
            self.imageTypes = imageTypes[:]

        # Dictionary that makes sure each image is only generated once.
        # The key is the LaTeX source and the value is the image instance.
        self._cache = {}
        usednames = {}
        self._filecache = os.path.abspath(os.path.join(".cache", self.__class__.__name__ + ".images"))
        if self.config["images"]["cache"] and os.path.isfile(self._filecache):
            try:
                self._cache = pickle.load(open(self._filecache, "r"))
                for key, value in self._cache.items():
                    if not os.path.isfile(value.filename):
                        del self._cache[key]
                        continue
                    usednames[value.filename] = None
            except ImportError:
                os.remove(self._filecache)

        # List of images in the order that they appear in the LaTeX file
        self.images = ordereddict()

        # Images that are simply copied from the source directory
        self.staticimages = ordereddict()

        # Filename generator
        self.newFilename = Filenames(
            self.config["images"].get("filenames", raw=True),
            vars={"jobname": document.userdata.get("jobname", "")},
            extension=self.fileExtension,
            invalid=usednames,
        )

        # Start the document with a preamble
        self.source = StringIO()
        self.source.write("\\scrollmode\n")
        self.writePreamble(document)
        self.source.write("\\begin{document}\n")

        # Set up additional options
        self._configOptions = self.formatConfigOptions(self.config["images"])
示例#3
0
    def __init__(self, document):
        self.config = document.config
        self.ownerDocument = document

        # Images that are simply copied from the source directory
        self.staticimages = ordereddict()

        # Filename generator
        self.newFilename = Filenames(self.config['images'].get('filenames', raw=True), 
                           vars={'jobname':document.userdata.get('jobname','')},
                           extension=self.fileExtension, invalid={})
示例#4
0
    def __init__(self, document):
        self.config = document.config
        self.ownerDocument = document

        # Images that are simply copied from the source directory
        self.staticimages = ordereddict()

        # Filename generator
        self.newFilename = Filenames(
            self.config['images'].get('filenames', raw=True),
            vars={'jobname': document.userdata.get('jobname', '')},
            extension=self.fileExtension,
            invalid={})