Ejemplo n.º 1
0
    def read(self, stream: Stream, version):
        self.angle = stream.read_double('angle')
        self.cap = self.read_cap(stream)
        unknown = binascii.hexlify(stream.read(3))
        if unknown != b'000000':
            raise UnreadableSymbolException(
                'Differing unknown string {}'.format(unknown))
        self.join = self.read_join(stream)
        unknown = binascii.hexlify(stream.read(3))
        if unknown != b'000000':
            raise UnreadableSymbolException(
                'Differing unknown string {}'.format(unknown))
        self.width = stream.read_double('width')
        stream.read(1)
        self.offset = stream.read_double('offset')

        self.line = stream.read_object('line')

        self.color = stream.read_object('color')
        self.template = stream.read_object('template')

        self.decoration = stream.read_object('decoration')
        stream.read_0d_terminator()

        _ = stream.read_uchar('unknown char')
        _ = stream.read_double('unknown')
        _ = stream.read_double('unknown')
Ejemplo n.º 2
0
    def read(self, stream: Stream, version):
        self.color = stream.read_object('color')

        self.unicode = stream.read_int('unicode')
        self.angle = stream.read_double('angle')
        self.size = stream.read_double('size')
        self.x_offset = stream.read_double('x offset')
        self.y_offset = stream.read_double('y offset')

        stream.read_double('unknown 1')
        stream.read_double('unknown 2')

        self.read_0d_terminator(stream)
        if binascii.hexlify(stream.read(2)) != b'ffff':
            raise UnreadableSymbolException('Expected ffff')

        self.font = stream.read_string('font name')

        # lot of unknown stuff
        stream.read_double('unknown 3')  # or object?
        stream.read_double('unknown 4')  # or object?
        if binascii.hexlify(stream.read(2)) != b'9001':
            raise UnreadableSymbolException('Expected 9001')

        stream.read(4)
        stream.read(6)

        # std OLE font .. maybe contains useful stuff like bold/etc, but these aren't exposed in ArcGIS anyway..
        self.std_font = stream.read_object('font')
Ejemplo n.º 3
0
    def read(self, stream: Stream, version):
        stream.read_int('unknown')
        stream.read_int('unknown 2')

        self.file = stream.read_embedded_file('image')

        self.color_foreground = stream.read_object('color 1')
        self.color_background = stream.read_object('color 2')
        self.color_transparent = stream.read_object('color 3')

        self.angle = stream.read_double('angle')
        self.size = stream.read_double('size')
        self.x_offset = stream.read_double('x offset')
        self.y_offset = stream.read_double('y offset')

        stream.read_double('unknown')
        stream.read_double('unknown')

        stream.read_0d_terminator()
        self.swap_fb_gb = bool(stream.read_uchar('swap fgbg'))

        check = binascii.hexlify(stream.read(2))
        if check != b'ffff':
            raise UnreadableSymbolException(
                'Expected ffff at {}, got {}'.format(check,
                                                     hex(stream.tell() - 2)))

        # unknown
        stream.read(6)
Ejemplo n.º 4
0
    def read(self, stream: Stream, version):
        if not stream.read_0d_terminator():
            raise UnreadableSymbolException('Could not find 0d terminator at {}'.format(hex(stream.tell() - 8)))

        # consume unused properties - MultiLayerMarkerSymbol implements IMarkerSymbol
        # so that the size/offsets/angle are required properties. But they aren't used
        # or exposed anywhere for MultiLayerMarkerSymbol
        _ = stream.read_double('unused marker size')
        _ = stream.read_double('unused marker x/y/offset or angle')
        _ = stream.read_double('unused marker x/y/offset or angle')
        _ = stream.read_double('unused marker x/y/offset or angle')
        _ = stream.read_object('unused color')

        self.halo = stream.read_int() == 1
        self.halo_size = stream.read_double('halo size')

        self.halo_symbol = stream.read_object('halo')

        # useful stuff
        number_layers = stream.read_int('layers')
        for i in range(number_layers):
            layer = stream.read_object('symbol layer {}/{}'.format(i + 1, number_layers))
            self.levels.extend([layer])

        for l in self.levels:
            l.read_enabled(stream)
        for l in self.levels:
            l.read_locked(stream)

        _ = stream.read_double('unknown size')
        _ = stream.read_double('unknown size')

        if version >= 3:
            for l in self.levels:
                l.read_tags(stream)
Ejemplo n.º 5
0
def read_symbol(_io_stream, debug=False):
    """
    Reads a symbol from the specified file
    """
    stream = Stream(_io_stream, debug)
    try:
        symbol_object = stream.read_object('symbol')
    except InvalidColorException:
        raise UnreadableSymbolException()
    return symbol_object
Ejemplo n.º 6
0
 def read_0d_terminator(stream):
     """
     Tries the read the standard 0d00000000000000 layer terminator,
     raising a UnreadableSymbolException if it's not found.
     """
     check = binascii.hexlify(stream.read(8))
     if check != b'0d00000000000000':
         raise UnreadableSymbolException(
             'Did not find expected layer terminator, got {} at {}'.format(
                 check, hex(stream.tell() - 8)))
Ejemplo n.º 7
0
 def read_embedded_file(self, debug_string: str = '') -> bin:
     """
     Reads an embedded file stored within the stream.
     """
     embedded_file_length = self.read_int('binary length')
     self.log('Found embedded file {} of length {}'.format(
         debug_string, embedded_file_length))
     try:
         return self.read(embedded_file_length)
     except error:  # struct.error
         raise UnreadableSymbolException('Truncated file binary')
Ejemplo n.º 8
0
    def read(self, stream: Stream, version):
        self.color = stream.read_object('color')
        self.size = stream.read_double('size')

        type_code = stream.read_int()
        type_dict = {
            0: 'circle',
            1: 'square',
            2: 'cross',
            3: 'x',
            4: 'diamond'
        }

        if type_code not in type_dict:
            raise UnreadableSymbolException(
                'Unknown marker type at {}, got {}'.format(
                    hex(stream.tell() - 4), type_code))
        stream.log('found a {}'.format(type_dict[type_code]), 4)
        self.type = type_dict[type_code]

        # look for 0d terminator
        if not binascii.hexlify(stream.read(8)) == b'0d00000000000000':
            raise UnreadableSymbolException()

        stream.read_double('unknown')

        self.x_offset = stream.read_double('x offset')
        self.y_offset = stream.read_double('y offset')

        has_outline = stream.read_uchar()
        if has_outline == 1:
            self.outline_enabled = True
        self.outline_width = stream.read_double('outline width')
        self.outline_color = stream.read_object('outline color')

        check = binascii.hexlify(stream.read(2))
        if check != b'ffff':
            raise UnreadableSymbolException(
                'Expected ffff at {}, got {}'.format(check,
                                                     hex(stream.tell() - 2)))
Ejemplo n.º 9
0
 def read_join(stream: Stream):
     """
     Reads a line join style from the stream
     """
     join_bin = stream.read_uchar()
     if join_bin == 0:
         return 'miter'
     elif join_bin == 1:
         return 'round'
     elif join_bin == 2:
         return 'bevel'
     else:
         raise UnreadableSymbolException('unknown join style {}'.format(join_bin))
Ejemplo n.º 10
0
 def read_cap(stream: Stream):
     """
     Reads a line cap style from the stream
     """
     cap_bin = stream.read_uchar()
     if cap_bin == 0:
         return 'butt'
     elif cap_bin == 1:
         return 'round'
     elif cap_bin == 2:
         return 'square'
     else:
         raise UnreadableSymbolException('unknown cap style {}'.format(cap_bin))
Ejemplo n.º 11
0
    def read_int(self, debug_string: str = '') -> int:
        """
        Reads an int from the stream.
        :return:
        """
        try:
            res = unpack("<L", self._io_stream.read(4))[0]
        except error:  # struct.error
            raise UnreadableSymbolException('Truncated integer')

        if debug_string:
            self.log('read int {} of {}'.format(debug_string, res), 4)
        return res
Ejemplo n.º 12
0
 def read_line_type(stream: Stream):
     """
     Interprets the line type bytes
     """
     line_type = stream.read_uint()
     types = {0: 'solid',
              1: 'dashed',
              2: 'dotted',
              3: 'dash dot',
              4: 'dash dot dot',
              5: 'null'}
     if line_type not in types:
         raise UnreadableSymbolException('unknown line type {} at {}'.format(line_type, hex(stream.tell() - 4)))
     return types[line_type]
Ejemplo n.º 13
0
    def read(self, stream: Stream, version):
        if not stream.read_0d_terminator():
            raise UnreadableSymbolException('Could not find 0d terminator at {}'.format(hex(stream.tell() - 8)))

        number_layers = stream.read_uint('layer count')
        for i in range(number_layers):
            layer = stream.read_object('symbol layer {}/{}'.format(i + 1, number_layers))
            self.levels.extend([layer])

        for l in self.levels:
            l.read_enabled(stream)
        for l in self.levels:
            l.read_locked(stream)

        if version >= 2:
            for l in self.levels:
                l.read_tags(stream)
Ejemplo n.º 14
0
    def read(self, stream: Stream, version):
        stream.read(8)
        self._read(stream, version)
        # do we end in 02?
        check = binascii.hexlify(stream.read(1))
        if check != b'02':
            raise UnreadableSymbolException(
                'Found unexpected value {} at {}, expected x02'.format(
                    check, hex(stream.tell() - 1)))
        stream.read(5)

        # PROBLEMATIC!!

        check = binascii.hexlify(stream.read(1))
        if check == b'02':
            stream.read(5)
        else:
            stream.rewind(1)
Ejemplo n.º 15
0
    def read(self, stream: Stream, version):
        self.color = stream.read_object('color')

        self.size = stream.read_double('size')
        self.width = stream.read_double('width')
        self.angle = stream.read_double('angle')

        # 12 bytes unknown purpose
        stream.log('skipping 12 unknown bytes')

        _ = stream.read_uint('unknown')
        stream.read_0d_terminator()

        self.x_offset = stream.read_double('x offset')
        self.y_offset = stream.read_double('y offset')

        check = binascii.hexlify(stream.read(2))
        if check != b'ffff':
            raise UnreadableSymbolException('Expected ffff at {}, got {}'.format(check, hex(stream.tell() - 2)))
Ejemplo n.º 16
0
    def _read(self, stream: Stream, version):
        # consume section of unknown purpose
        _ = stream.read_double('unknown size')

        unknown_object = stream.read_object('unknown')
        if unknown_object is not None:
            assert False, unknown_object
        _ = stream.read_double('unknown size')

        self.color = stream.read_object('color')

        self.halo = stream.read_int() == 1
        self.halo_size = stream.read_double('halo size')

        self.halo_symbol = stream.read_object('halo')

        # not sure about this - there's an extra 02 here if a full fill symbol is used for the halo
        if False and isinstance(self.halo_symbol, Symbol):
            check = binascii.hexlify(stream.read(1))
            if check != b'02':
                raise UnreadableSymbolException(
                    'Found unexpected value {} at {}, expected x02'.format(
                        check, hex(stream.tell() - 1)))
            stream.read(1)

        if isinstance(self.halo_symbol, SymbolLayer):
            stream.read(4)

        # useful stuff
        number_layers = stream.read_int('layers')
        for i in range(number_layers):
            layer = stream.read_object('symbol layer {}/{}'.format(
                i + 1, number_layers))
            self.levels.extend([layer])

        for l in self.levels:
            l.read_enabled(stream)
        for l in self.levels:
            l.read_locked(stream)

        _ = stream.read_double('unknown size')
        _ = stream.read_double('unknown size')
Ejemplo n.º 17
0
    def read(self, stream: Stream, version):
        if version in (4, 5):
            self.picture = stream.read_object('picture')
        elif version == 8:
            _ = stream.read_ushort('pic version?')
            _ = stream.read_uint('picture type?')
            self.picture = stream.read_object('picture')
        elif version == 9:
            self.picture = stream.read_picture('picture')

        if version <= 8:
            _ = stream.read_object()

        self.color_foreground = stream.read_object('color 1')
        self.color_background = stream.read_object('color 2')

        if version >= 9:
            self.color_transparent = stream.read_object('color 3')

        self.angle = stream.read_double('angle')
        self.size = stream.read_double('size')
        self.x_offset = stream.read_double('x offset')
        self.y_offset = stream.read_double('y offset')

        stream.read_double('unknown')
        stream.read_double('unknown')

        stream.read_0d_terminator()
        self.swap_fb_gb = bool(stream.read_uchar('swap fgbg'))

        check = binascii.hexlify(stream.read(2))
        if check != b'ffff':
            raise UnreadableSymbolException('Expected ffff at {}, got {}'.format(check, hex(stream.tell() - 2)))

        if version < 6:
            return

        stream.read(6)
        if version <= 8:
            stream.read(4)
Ejemplo n.º 18
0
    def read(self, stream: Stream, version):
        self.cap = self.read_cap(stream)
        stream.log('read cap of {}'.format(self.cap), 1)

        self.offset = stream.read_double('offset')
        self.pattern_marker = stream.read_object('pattern marker')
        self.template = stream.read_object('template')
        self.decoration = stream.read_object('decoration')

        stream.read_0d_terminator()

        _ = stream.read_double('unknown double')
        _ = stream.read_int('unknown int')
        _ = stream.read_uchar('unknown char')

        self.join = self.read_join(stream)
        unknown = binascii.hexlify(stream.read(3))
        if unknown != b'000000':
            raise UnreadableSymbolException(
                'Differing unknown string {}'.format(unknown))

        _ = stream.read_double('unknown double')