def _init(self): """Initialize layer structure.""" group_stack = [self] clip_stack = [] last_layer = None for record, channels in self._record._iter_layers(): current_group = group_stack[-1] blocks = record.tagged_blocks end_of_group = False divider = blocks.get_data('SECTION_DIVIDER_SETTING', None) divider = blocks.get_data('NESTED_SECTION_DIVIDER_SETTING', divider) if divider is not None: if divider.kind == SectionDivider.BOUNDING_SECTION_DIVIDER: layer = Group(self, None, None, current_group) group_stack.append(layer) elif divider.kind in (SectionDivider.OPEN_FOLDER, SectionDivider.CLOSED_FOLDER): layer = group_stack.pop() assert layer is not self layer._record = record layer._channels = channels end_of_group = True elif ('TYPE_TOOL_OBJECT_SETTING' in blocks or 'TYPE_TOOL_INFO' in blocks): layer = TypeLayer(self, record, channels, current_group) elif (record.flags.pixel_data_irrelevant and ('VECTOR_ORIGINATION_DATA' in blocks or 'VECTOR_MASK_SETTING1' in blocks or 'VECTOR_MASK_SETTING2' in blocks or 'VECTOR_STROKE_DATA' in blocks or 'VECTOR_STROKE_CONTENT_DATA' in blocks)): layer = ShapeLayer(self, record, channels, current_group) elif ('SMART_OBJECT_LAYER_DATA1' in blocks or 'SMART_OBJECT_LAYER_DATA2' in blocks or 'PLACED_LAYER1' in blocks or 'PLACED_LAYER2' in blocks): layer = SmartObjectLayer(self, record, channels, current_group) else: layer = None for key in adjustments.TYPES.keys(): if key in blocks: layer = adjustments.TYPES[key](self, record, channels, current_group) break # If nothing applies, this is a pixel layer. if layer is None: layer = PixelLayer(self, record, channels, current_group) if record.clipping == Clipping.NON_BASE: clip_stack.append(layer) else: if clip_stack: last_layer._clip_layers = clip_stack clip_stack = [] if not end_of_group: current_group._layers.append(layer) last_layer = layer if clip_stack and last_layer: last_layer._clip_layers = clip_stack
def _init(self): """Initialize layer structure.""" group_stack = [self] clip_stack = [] last_layer = None for record, channels in self._record._iter_layers(): current_group = group_stack[-1] blocks = record.tagged_blocks end_of_group = False layer = None divider = blocks.get_data(Tag.SECTION_DIVIDER_SETTING, None) divider = blocks.get_data(Tag.NESTED_SECTION_DIVIDER_SETTING, divider) if divider is not None: if divider.kind == SectionDivider.BOUNDING_SECTION_DIVIDER: layer = Group(self, None, None, current_group) group_stack.append(layer) elif divider.kind in (SectionDivider.OPEN_FOLDER, SectionDivider.CLOSED_FOLDER): layer = group_stack.pop() assert layer is not self layer._record = record layer._channels = channels for key in (Tag.ARTBOARD_DATA1, Tag.ARTBOARD_DATA2, Tag.ARTBOARD_DATA3): if key in blocks: layer = Artboard._move(layer) end_of_group = True else: logger.warning('Divider %s found.' % divider.kind) elif (Tag.TYPE_TOOL_OBJECT_SETTING in blocks or Tag.TYPE_TOOL_INFO in blocks): layer = TypeLayer(self, record, channels, current_group) elif (Tag.SMART_OBJECT_LAYER_DATA1 in blocks or Tag.SMART_OBJECT_LAYER_DATA2 in blocks or Tag.PLACED_LAYER1 in blocks or Tag.PLACED_LAYER2 in blocks): layer = SmartObjectLayer(self, record, channels, current_group) else: for key in adjustments.TYPES.keys(): if key in blocks: layer = adjustments.TYPES[key](self, record, channels, current_group) break # If nothing applies, this is either a shape or pixel layer. if layer is None: if (record.flags.pixel_data_irrelevant and (Tag.VECTOR_ORIGINATION_DATA in blocks or Tag.VECTOR_MASK_SETTING1 in blocks or Tag.VECTOR_MASK_SETTING2 in blocks or Tag.VECTOR_STROKE_DATA in blocks or Tag.VECTOR_STROKE_CONTENT_DATA in blocks)): layer = ShapeLayer(self, record, channels, current_group) else: layer = PixelLayer(self, record, channels, current_group) assert layer is not None if record.clipping == Clipping.NON_BASE: clip_stack.append(layer) else: if clip_stack: last_layer._clip_layers = clip_stack clip_stack = [] if not end_of_group: current_group._layers.append(layer) last_layer = layer if clip_stack and last_layer: last_layer._clip_layers = clip_stack