Exemplo n.º 1
0
def fill(attributes):
    '''Returns True for any visible filling.'''
    if 'fill' not in attributes:  # default is to fill with black
        return True

    color = paint(attributes['fill'])
    if not color:
        return False

    if 'fill-opacity' in attributes:
        opacity = cssutils.css.DimensionValue(attributes['fill-opacity'])
        if opacity.dimension == '%':
            opacity = opacity.value / 100
        else:
            opacity = opacity.value
        if opacity == 0:
            return False
        elif opacity != 1:
            throw_transparency_warning()

    if 'fill-rule' in attributes and attributes['fill-rule'] != 'evenodd':
        warnings.warn(
            'Filling rule "evenodd" are not implemented: {}'.format(
                attributes), warnings.UndefinedWarning)

    return True
Exemplo n.º 2
0
    def distance_to(self, other):
        if not isinstance(other, Primitive):
            return NotImplemented

        def dist(params):
            t_self, t_other = params
            return abs(self.segment.poly()(t_self) - other.segment.poly()(t_other))

        res = minimize(dist, [.5, .5], bounds=[[0, 1], [0, 1]])
        if not res.success:
            warnings.warn('Minimization of distance failed', warnings.UndefinedWarning)
        return res.fun
Exemplo n.º 3
0
def paint(s):
    '''Returns False for 'none' or fully transparent and True otherwise.'''
    if s.lower() == 'none':
        return False

    value = cssutils.css.ColorValue(s)
    if value.alpha == 0:
        return False
    elif value.alpha != 1:
        throw_transparency_warning()
    if value.red == 255 and value.green == 255 and value.blue == 255:
        warnings.warn('White color is converted to black.',
                      warnings.UndefinedWarning)

    return True
Exemplo n.º 4
0
def stroke(attributes):
    '''Returns width of the stroke for visible strokes and None otherwise.'''
    if 'stroke' not in attributes:
        return None

    color = paint(attributes['stroke'])
    if not color:
        return None

    if 'stroke-opacity' in attributes:
        opacity = cssutils.css.DimensionValue(attributes['stroke-opacity'])
        if opacity.dimension == '%':
            opacity = opacity.value / 100
        else:
            opacity = opacity.value
        if opacity == 0:
            return None
        elif opacity != 1:
            throw_transparency_warning()

    if 'stroke-width' in attributes:
        width = units.fromrepr(attributes['stroke-width'], units.Pixels)
        if width.value == 0:
            return None
    else:
        width = units.fromrepr('1', units.Pixels)

    if 'stroke-linecap' in attributes and attributes[
            'stroke-linecap'] != 'square':
        warnings.warn('Different linecaps are not supported.',
                      warnings.UndefinedWarning)
    if 'stroke-linejoin' in attributes and attributes[
            'stroke-linejoin'] != 'miter':
        warnings.warn('Different linejoins are not supported.',
                      warnings.UndefinedWarning)
    if 'stroke-dasharray' in attributes:
        warnings.warn('Dashed strokes are not supported.',
                      warnings.UndefinedWarning)
    if 'stroke-miterlimit' in attributes:
        warnings.warn('Miterlimit is ignored.', warnings.UndefinedWarning)

    return width
Exemplo n.º 5
0
import css_parser as cssutils

from util_files.data.graphics import units
from util_files import warnings

throw_transparency_warning = lambda attributes='': warnings.warn(
    'Transparency is ignored. {}'.format(attributes), warnings.UndefinedWarning
)


def fill(attributes):
    '''Returns True for any visible filling.'''
    if 'fill' not in attributes:  # default is to fill with black
        return True

    color = paint(attributes['fill'])
    if not color:
        return False

    if 'fill-opacity' in attributes:
        opacity = cssutils.css.DimensionValue(attributes['fill-opacity'])
        if opacity.dimension == '%':
            opacity = opacity.value / 100
        else:
            opacity = opacity.value
        if opacity == 0:
            return False
        elif opacity != 1:
            throw_transparency_warning()

    if 'fill-rule' in attributes and attributes['fill-rule'] != 'evenodd':
 def __rtruediv__(self, other):
     warnings.warn('Division of number by unit', warnings.UndefinedWarning)
     return other / self.value