Example #1
0
    def new(cls, position, size, rounding=None, **kwargs):
        kwargs['x'], kwargs['y'] = misc.rounded(position)
        kwargs['width'], kwargs['height'] = misc.rounded(size)

        if rounding is not None:
            kwargs['rx'] = kwargs['ry'] = misc.rounded(rounding)

        return super().new(**kwargs)
Example #2
0
    def to_svg_attributes(self, column=0, transform_ext=None):
        '''Produce a simple dictionary for use with SVGElement.

        The "position" argument is relevant only with a rotation
        transformation, and even then, only if it's configured for
        this usage.

        '''

        attrib = dict()
        style = svg.KeyValuePairs()

        if self.literate:
            style['font-family'] = str(self.mode.font)
            size_value = misc.rounded(float(self.font_size))
            style['font-size'] = size_value + self.font_size_unit

            if self.mode.weight is not None:
                style['font-weight'] = self.mode.weight

            if self.mode.style is not None:
                style['font-style'] = self.mode.style

            if self.mode.variant is not None:
                style['font-variant'] = self.mode.variant

            anchor_key = self.mode.anchor_key(column)
            if anchor_key is not keys.ALIGN_START:
                attrib[keys.TEXT_ANCHOR] = anchor_key

        if self.mode.fill_colors:
            color = self.mode.fill_colors[0]
            if color != '#000000':  # SVG default.
                style['fill'] = color

        if self.mode.thickness:
            try:
                color = self.mode.stroke_colors[0]
            except IndexError:
                # Black is the CBG default for stroke.
                color = '#000000'

            # Black is not the SVG default for stroke. It needs a color.
            style['stroke'] = color

            if self.mode.dasharray is not None:
                style['stroke-dasharray'] = self.mode.dasharray

            if self.literate:
                # Scale to font.
                style['stroke-width'] = self.font_size * self.mode.thickness
            else:
                style['stroke-width'] = self.mode.thickness

        if self.transformations:
            iterable = (t.to_string(extension=transform_ext)
                        for t in self.transformations)
            attrib['transform'] = ' '.join(iterable)

        if style:
            attrib.update({keys.STYLE: str(style)})
        return attrib
Example #3
0
 def test_numpy(self):
     self.assertEqual(misc.rounded(numpy.array((4, 7, 8))), ['4', '7', '8'])
Example #4
0
 def test_float_trimmed(self):
     self.assertEqual(misc.rounded(1.23456789), '1.2346')
Example #5
0
 def test_float_preserved(self):
     self.assertEqual(misc.rounded(1.2), '1.2')
Example #6
0
 def test_tuple(self):
     self.assertEqual(misc.rounded((1, 2)), ['1', '2'])
Example #7
0
 def test_simple(self):
     self.assertEqual(misc.rounded(1), '1')
Example #8
0
 def new(cls, centerpoint, radii, **kwargs):
     kwargs['cx'], kwargs['cy'] = misc.rounded(centerpoint)
     kwargs['rx'], kwargs['ry'] = misc.rounded(radii)
     return super().new(**kwargs)
Example #9
0
 def new(cls, points, **kwargs):
     coordinate_pairs = (','.join(misc.rounded(p) for p in points))
     kwargs['points'] = ' '.join(coordinate_pairs)
     return super().new(**kwargs)
Example #10
0
 def test_numpy(self):
     self.assertEqual(misc.rounded(numpy.array((4, 7, 8))), ['4', '7', '8'])
Example #11
0
 def new(cls, point1, point2, **kwargs):
     kwargs['x1'], kwargs['y1'] = misc.rounded(point1)
     kwargs['x2'], kwargs['y2'] = misc.rounded(point2)
     return super().new(**kwargs)
Example #12
0
 def test_float_trimmed(self):
     self.assertEqual(misc.rounded(1.23456789), '1.2346')
Example #13
0
 def test_float_preserved(self):
     self.assertEqual(misc.rounded(1.2), '1.2')
Example #14
0
 def test_tuple(self):
     self.assertEqual(misc.rounded((1, 2)), ['1', '2'])
Example #15
0
 def test_simple(self):
     self.assertEqual(misc.rounded(1), '1')
Example #16
0
    def to_svg_attributes(self, column=0, transform_ext=None):
        '''Produce a simple dictionary for use with SVGElement.

        The "position" argument is relevant only with a rotation
        transformation, and even then, only if it's configured for
        this usage.

        '''

        attrib = dict()
        style = svg.KeyValuePairs()

        if self.literate:
            style['font-family'] = str(self.mode.font)
            size_value = misc.rounded(float(self.font_size))
            style['font-size'] = size_value + self.font_size_unit

            if self.mode.weight is not None:
                style['font-weight'] = self.mode.weight

            if self.mode.style is not None:
                style['font-style'] = self.mode.style

            if self.mode.variant is not None:
                style['font-variant'] = self.mode.variant

            anchor_key = self.mode.anchor_key(column)
            if anchor_key is not keys.ALIGN_START:
                attrib[keys.TEXT_ANCHOR] = anchor_key

        if self.mode.fill_colors:
            color = self.mode.fill_colors[0]
            if color != '#000000':  # SVG default.
                style['fill'] = color

        if self.mode.thickness:
            try:
                color = self.mode.stroke_colors[0]
            except IndexError:
                # Black is the CBG default for stroke.
                color = '#000000'

            # Black is not the SVG default for stroke. It needs a color.
            style['stroke'] = color

            if self.mode.dasharray is not None:
                style['stroke-dasharray'] = self.mode.dasharray

            if self.literate:
                # Scale to font.
                style['stroke-width'] = self.font_size * self.mode.thickness
            else:
                style['stroke-width'] = self.mode.thickness

        if self.transformations:
            iterable = (t.to_string(extension=transform_ext)
                        for t in self.transformations)
            attrib['transform'] = ' '.join(iterable)

        if style:
            attrib.update({keys.STYLE: str(style)})
        return attrib