Ejemplo n.º 1
0
    def write(self, fp, **kwargs):
        written = write_pascal_string(fp,
                                      self.uuid,
                                      encoding='ascii',
                                      padding=1)
        written += write_fmt(fp, 'I', self.version)

        def writer(f):
            return self._write_body(f)

        written += write_length_block(fp, writer, fmt='Q')

        if self.extra is not None:
            written += self.extra.write(fp)
        return written
Ejemplo n.º 2
0
 def write(self, fp, **kwargs):
     written = write_fmt(fp, '4s2BH', self.kind, self.is_open, self.flags,
                         self.optional_blocks)
     written += write_fmt(fp, '4i', *self.icon_location)
     written += write_fmt(fp, '4i', *self.popup_location)
     written += self.color.write(fp)
     written += write_pascal_string(fp, self.author, 'macroman', padding=2)
     written += write_pascal_string(fp, self.name, 'macroman', padding=2)
     written += write_pascal_string(fp,
                                    self.mod_date,
                                    'macroman',
                                    padding=2)
     written += write_fmt(fp, 'I4s', len(self.data) + 12, self.marker)
     written += write_length_block(fp, lambda f: write_bytes(f, self.data))
     return written
Ejemplo n.º 3
0
    def write(self, fp, encoding='macroman', version=1, padding=4):
        """Write the element to a file-like object.

        :param fp: file-like object
        :param encoding: encoding of the string
        :param version: psd file version
        """

        def writer(f):
            written = self._write_body(f, encoding, version, padding)
            logger.debug('writing layer and mask info, len=%d' % (written))
            return written

        fmt = ('I', 'Q')[version - 1]
        return write_length_block(fp, writer, fmt=fmt)
Ejemplo n.º 4
0
    def write(self, fp, version=1, padding=1):
        key = self.key if isinstance(self.key, bytes) else self.key.value
        written = write_fmt(fp, '4s4s', self.signature, key)

        def writer(f):
            if hasattr(self.data, 'write'):
                # It seems padding size applies at the block level here.
                inner_padding = 1 if padding == 4 else 4
                return self.data.write(f,
                                       padding=inner_padding,
                                       version=version)
            return write_bytes(f, self.data)

        fmt = self._length_format(self.key, version)
        written += write_length_block(fp, writer, fmt=fmt, padding=padding)
        return written
Ejemplo n.º 5
0
    def write(self, fp, encoding='macroman', version=1, padding=4):
        """Write the element to a file-like object.

        :param fp: file-like object
        :rtype: int
        """

        def writer(f):
            written = self._write_body(f, encoding, version, padding)
            logger.debug('writing layer info, len=%d' % (written))
            return written

        fmt = ('I', 'Q')[version - 1]
        if self.layer_count == 0:
            return write_fmt(fp, fmt, 0)
        return write_length_block(fp, writer, fmt=fmt)
Ejemplo n.º 6
0
    def write(self, fp, encoding='macroman'):
        """Write the element to a file-like object.

        :param fp: file-like object
        :rtype: int
        """
        written = write_fmt(fp, '4sH', self.signature,
                            getattr(self.key, 'value', self.key))
        written += write_pascal_string(fp, self.name, encoding, 2)

        def writer(f):
            if hasattr(self.data, 'write'):
                return self.data.write(f, padding=1)
            return write_bytes(f, self.data)

        written += write_length_block(fp, writer, padding=2)
        return written
Ejemplo n.º 7
0
    def write(self, fp, encoding='macroman', version=1):
        start_pos = fp.tell()
        written = write_fmt(fp, '4iH', self.top, self.left, self.bottom,
                            self.right, len(self.channel_info))
        written += sum(c.write(fp, version) for c in self.channel_info)
        written += write_fmt(fp, '4s4sBB', self.signature,
                             self.blend_mode.value, self.opacity,
                             self.clipping.value)
        written += self.flags.write(fp)

        def writer(f):
            written = self._write_extra(f, encoding, version)
            logger.debug('  wrote layer record, len=%d' %
                         (fp.tell() - start_pos))
            return written

        written += write_length_block(fp, writer, fmt='xI')
        return written
Ejemplo n.º 8
0
    def write(self, fp):
        """Write the element to a file-like object.

        :param fp: file-like object
        """
        return write_length_block(fp, lambda f: self._write_body(f))
Ejemplo n.º 9
0
 def write(self, fp, **kwargs):
     written = write_fmt(fp, 'I', self.version)
     return written + write_length_block(fp, lambda f: self._write_body(f))
Ejemplo n.º 10
0
 def write(self, fp):
     return write_length_block(fp, lambda f: self._write_body(f))
Ejemplo n.º 11
0
 def write(self, fp, **kwargs):
     written = 0
     for item in self:
         written += write_length_block(fp, lambda f: item.write(f),
                                       padding=4)
     return written
Ejemplo n.º 12
0
 def write(self, fp, **kwargs):
     written = write_fmt(fp, 'I', self.version)
     for item in self:
         written += write_length_block(fp, lambda f: item.write(f), fmt='Q', padding=4)
     return written
Ejemplo n.º 13
0
    def write(self, fp):
        def writer(f):
            return write_bytes(f, self.value)

        logger.debug('writing color mode data, len=%d' % (len(self.value)))
        return write_length_block(fp, writer)
Ejemplo n.º 14
0
 def write(self, fp):
     def writer(f):
         if hasattr(self.value, 'write'):
             return self.value.write(f)
         return write_bytes(f, self.value)
     return write_length_block(fp, writer)