Ejemplo n.º 1
0
def parse_color_swatches(source):
    """Return a list of Color swatches in the provided source file."""
    resources_file_json = get_resources_file_json(source)
    color_swatches_node = resources_file_json['resources']['meta']['ux'][
        'colorSwatches']
    color_swatches = []
    for node in color_swatches_node:
        value = node['value']
        color = Color(value['r'], value['g'], value['b'])
        color_swatches.append(color)
    return color_swatches
Ejemplo n.º 2
0
 def __init__(self, offset, r=0, g=0, b=0):
     """Initialize this GradientStop."""
     self.offset = offset
     self.color = Color(r, g, b)
Ejemplo n.º 3
0
 def __init__(self, width, align, r, g, b):
     """Instantiates this ColorStroke."""
     super(ColorStroke, self).__init__(width, align)
     self.color = Color(r, g, b)
Ejemplo n.º 4
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
Ejemplo n.º 5
0
 def __init__(self, r, g, b):
     """Instantiates this ColorFill."""
     super(ColorFill, self).__init__()
     self.color = Color(r, g, b)