Exemplo n.º 1
0
 def _set_key(self):
     self._key = None
     for key in self.tagged_blocks:
         if (TaggedBlock.is_adjustment_key(key)
                 or TaggedBlock.is_fill_key(key)):
             self._key = key
             return
     logger.error("Unknown adjustment layer: {}".format(self))
Exemplo n.º 2
0
    def build(self, decoded_data):
        """Build the tree structure."""
        self.decoded_data = decoded_data
        layer_records = decoded_data.layer_and_mask_data.layers.layer_records

        group_stack = [self]
        clip_stack = []

        for index, record in reversed(list(enumerate(layer_records))):
            current_group = group_stack[-1]
            blocks = dict(record.tagged_blocks)

            divider = blocks.get(
                TaggedBlock.SECTION_DIVIDER_SETTING,
                blocks.get(TaggedBlock.NESTED_SECTION_DIVIDER_SETTING),
            )
            if divider:
                if divider.type in (SectionDivider.CLOSED_FOLDER,
                                    SectionDivider.OPEN_FOLDER):
                    layer = Group(current_group, index)
                    group_stack.append(layer)

                elif divider.type == SectionDivider.BOUNDING_SECTION_DIVIDER:
                    if len(group_stack) == 1:
                        # This means that there is a BOUNDING_SECTION_DIVIDER
                        # without an OPEN_FOLDER before it. Create a new group
                        # and move layers to this new group in this case.

                        # Assume the first layer is a group
                        # and convert it to a group:
                        layers = group_stack[0].layers[0]
                        group = Group(current_group, layers[0]._index)
                        group._layers = layers[1:]

                        # replace moved layers with newly created group:
                        group_stack[0].layers = [group]
                    else:
                        assert group_stack.pop() is not self
                    continue
                else:
                    logger.warning("Invalid state")

            elif TaggedBlock.TYPE_TOOL_OBJECT_SETTING in blocks:
                layer = TypeLayer(current_group, index)

            elif ((TaggedBlock.VECTOR_ORIGINATION_DATA in blocks
                   or TaggedBlock.VECTOR_MASK_SETTING1 in blocks
                   or TaggedBlock.VECTOR_MASK_SETTING2 in blocks
                   or TaggedBlock.VECTOR_STROKE_DATA in blocks
                   or TaggedBlock.VECTOR_STROKE_CONTENT_DATA in blocks)
                  and record.flags.pixel_data_irrelevant):
                layer = ShapeLayer(current_group, index)

            elif (TaggedBlock.SMART_OBJECT_PLACED_LAYER_DATA in blocks
                  or TaggedBlock.PLACED_LAYER_OBSOLETE2 in blocks
                  or TaggedBlock.PLACED_LAYER_DATA in blocks):
                layer = SmartObjectLayer(current_group, index)

            elif any([
                    TaggedBlock.is_adjustment_key(key)
                    or TaggedBlock.is_fill_key(key) for key in blocks.keys()
            ]):
                layer = AdjustmentLayer(current_group, index)

            else:
                layer = PixelLayer(current_group, index)

            if record.clipping:
                clip_stack.append(layer)
            else:
                layer._clip_layers = clip_stack
                clip_stack = []
                current_group._layers.append(layer)