Esempio n. 1
0
 def __init__(self, uid, start_x, start_y, end_x, end_y, name='Line', x=0, y=0):
     """
     Instantiate a new Line.
     """
     super().__init__(uid, 'line', name)
     self.position = Point(x, y)
     self.start = Point(start_x, start_y)
     self.end = Point(end_x, end_y)
Esempio n. 2
0
 def __init__(self, uid, name='Rectangle', x=0, y=0, width=50, height=50):
     """
     Instantiate a new Rectangle.
     """
     super(Rectangle, self).__init__(uid, 'rectangle', name)
     self.position = Point(x, y)
     self.width = width
     self.height = height
Esempio n. 3
0
 def __init__(self,
              uid: int,
              path: str,
              operation: str,
              children=None,
              name='Compound',
              x=0,
              y=0) -> None:
     """Instantiate a new Compound."""
     super().__init__(uid, 'compound', name)
     self.path = path
     self.operation = operation
     self.children = [] if children is None else children
     self.position = Point(x, y)
Esempio n. 4
0
def parse_artboard(node, source):
    """Return the Artboard represented by node."""
    uid = node['id']
    name = node['name']
    width = None
    height = None
    x = None
    y = None
    if 'uxdesign#bounds' in node:
        width = node['uxdesign#bounds']['width']
        height = node['uxdesign#bounds']['height']
        x = node['uxdesign#bounds']['x']
        y = node['uxdesign#bounds']['y']

    viewport_height = None
    if 'uxdesign#viewport' in node:
        viewport_height = node['uxdesign#viewport']['height']

    artboard_file_path = "artwork/{}/graphics/graphicContent.agc".format(
        node['path'])
    artboard_file = source.read(artboard_file_path)
    artboard_data = json.loads(artboard_file.decode('utf-8'))
    artwork = []
    for item in artboard_data['children']:
        artboard_nodes = ([item] if 'artboard' not in item else
                          item['artboard']['children'])
        for child in artboard_nodes:
            try:
                art = parse_artwork(child, source)
            except UnknownShapeException as shape_exception:
                print(shape_exception)
            except UnknownArtworkException as artwork_exception:
                print(artwork_exception)
            else:
                artwork.append(art)

    if name == 'pasteboard':
        return Artboard(uid, name, artwork=artwork)
    else:
        return Artboard(uid, name, width, height, Point(x, y), viewport_height,
                        artwork)
Esempio n. 5
0
 def __init__(self, uid, name='Group', x=0, y=0, children=None):
     """Instantiate a new Group."""
     super(Group, self).__init__(uid, 'group', name)
     self.position = Point(x, y)
     self.children = [] if children is None else children
Esempio n. 6
0
 def __init__(self, uid, name='Ellipse', x=0, y=0, width=50, height=50):
     """Instantiate a new Ellipse."""
     super().__init__(uid, 'ellipse', name)
     self.position = Point(x, y)
     self.width = width
     self.height = height
Esempio n. 7
0
 def __init__(self, uid, path_data, name='Path', x=0, y=0):
     """Instantiate a new Path."""
     super(Path, self).__init__(uid, 'path', name)
     self.path_data = path_data
     self.position = Point(x, y)
Esempio n. 8
0
 def __init__(self, uid, raw_text, name='Text', x=0, y=0):
     """Instantiate a new Text object."""
     """super(Artwork, self).__init__(uid, 'text', name)"""
     super(Text, self).__init__(uid, 'text', name)
     self.raw_text = raw_text
     self.position = Point(x, y)
Esempio n. 9
0
def parse_styles(node, source):
    """Return the Styles represented by node."""
    styles = []
    for style_type, value in node.items():
        if style_type == 'opacity':
            amount = value
            opacity = Opacity(amount)
            styles.append(opacity)
        elif style_type == 'fill':
            fill_type = value['type']
            if fill_type == 'none':
                pass
            elif fill_type == 'solid':
                color_node = value['color']['value']
                color_fill = ColorFill(color_node['r'], color_node['g'],
                                       color_node['b'])
                styles.append(color_fill)
            elif fill_type == 'gradient':
                x1 = value['gradient']['x1']
                y1 = value['gradient']['y1']
                start = Point(x1, y1)
                x2 = value['gradient']['x2']
                y2 = value['gradient']['y2']
                end = Point(x2, y2)
                target_gradient_uid = value['gradient']['ref']
                gradients = parse_gradients(source)
                gradient_fill = None
                for gradient in gradients:
                    if gradient.uid == target_gradient_uid:
                        gradient_fill = GradientFill(start, end, gradient)
                        break
                if gradient_fill is not None:
                    styles.append(gradient_fill)
            elif fill_type == 'pattern':
                width = value['pattern']['width']
                height = value['pattern']['height']
                scale_behavior = value['pattern']['meta']['ux'][
                    'scaleBehavior']
                image_href = value['pattern']['href']
                pattern_fill = PatternFill(width, height, scale_behavior,
                                           image_href)
                styles.append(pattern_fill)
            else:
                raise UnknownFillTypeException('Unable to parse fill: ' +
                                               fill_type)
        elif style_type == 'stroke':
            stroke_type = value['type']
            if stroke_type == 'none':
                pass
            elif stroke_type == 'solid':
                width = value['width']
                align = 'inside'
                if 'align' in value:
                    align = value['align']
                color_node = value['color']['value']
                color_stroke = ColorStroke(width, align, color_node['r'],
                                           color_node['g'], color_node['b'])
                styles.append(color_stroke)
            else:
                raise UnknownStrokeTypeException('Unable to parse stroke: ' +
                                                 stroke_type)
        elif style_type == 'filters':
            for filter_ in value:
                filter_type = filter_['type']
                visible = filter_['visible'] if 'visible' in filter_ else True
                if filter_type == 'none' or not visible:
                    pass
                elif filter_type == 'dropShadow':
                    for drop_shadow_json in filter_['params']['dropShadows']:
                        offset_x = drop_shadow_json['dx']
                        offset_y = drop_shadow_json['dy']
                        blur_radius = drop_shadow_json['r']
                        color_node = drop_shadow_json['color']['value']
                        color = Color(color_node['r'], color_node['g'],
                                      color_node['b'])
                        drop_shadow = DropShadow(offset_x, offset_y,
                                                 blur_radius, color)
                        styles.append(drop_shadow)
                elif filter_type == 'uxdesign#blur':
                    blur_json = filter_['params']
                    amount = blur_json['blurAmount']
                    brightness = blur_json['brightnessAmount']
                    fill_opacity = blur_json['fillOpacity']
                    background_effect = blur_json['backgroundEffect']
                    blur = Blur(amount, brightness, fill_opacity,
                                background_effect)
                    styles.append(blur)
                else:
                    raise UnknownFilterTypeException(
                        'Unable to parse filter: ' + filter_type)
        elif style_type == 'font':
            family = value['family']
            style = value['style']
            size = value['size']
            postscript_name = value['postscriptName']
            font = Font(family, style, size, postscript_name)
            styles.append(font)
        elif style_type == 'textAttributes':
            letter_spacing = value[
                'letterSpacing'] if 'letterSpacing' in value else None
            paragraph_align = value[
                'paragraphAlign'] if 'paragraphAlign' in value else None
            text_attributes = TextAttributes(letter_spacing, paragraph_align)
            styles.append(text_attributes)
        elif style_type == 'clipPath':
            target_clip_path_uid = value['ref']
            clip_paths = parse_clip_paths(source)
            clip_path = None
            for cp in clip_paths:
                if cp.uid == target_clip_path_uid:
                    clip_path = cp
                    break

            if clip_path is not None:
                styles.append(clip_path)
        else:
            raise UnknownStyleException('Unable to parse the style: ' +
                                        style_type)

    return styles