def test_PathEffect_asPoints(patheffect):
    results = skia.PathEffect.PointData()
    path = skia.Path()
    path.addCircle(10, 10, 5)
    rec = skia.StrokeRec(skia.StrokeRec.kHairline_InitStyle)
    matrix = skia.Matrix()
    assert isinstance(patheffect.asPoints(results, path, rec, matrix, None),
                      bool)
Exemple #2
0
 def transform(self, transform, center=(0, 0)):
     cx, cy = center
     t = Transform()
     t = t.translate(cx, cy)
     t = t.transform(transform)
     t = t.translate(-cx, -cy)
     matrix = skia.Matrix()
     matrix.setAffine(t)
     self.path.transform(matrix)
Exemple #3
0
 def transform(self, matrix, center=(0, 0)):
     m = skia.Matrix()
     m.setAffine(matrix)
     cx, cy = center
     if cx != 0 or cy != 0:
         self._canvas.translate(cx, cy)
         self._canvas.concat(m)
         self._canvas.translate(-cx, -cy)
     else:
         self._canvas.concat(m)
Exemple #4
0
 def __gradient_matrix(gradient, path):
 #=====================================
     if gradient.attrib.get('gradientUnits') == 'userSpaceOnUse':
         path_transform = Transform.Identity()
     else:                                    #  objectBoundingBox'
         bounds = path.getBounds()
         path_transform = Transform([[bounds.width(),               0, bounds.left()],
                                     [             0, bounds.height(), bounds.top()],
                                     [             0,               0,            1]])
     svg_transform = SVGTransform(gradient.attrib.get('gradientTransform'))
     return skia.Matrix(list((path_transform@svg_transform).flatten()))
Exemple #5
0
 def __init__(self, paint, bounds, parent_transform,
                 transform_attribute, clip_path, bbox=None, root_object=False):
     if root_object:
         T = parent_transform@SVGTransform(transform_attribute)
         self.__matrix = skia.Matrix(list(T.flatten()))
     else:
         T = parent_transform
         if transform_attribute is None:
             self.__matrix = None
         else:
             local_transform = SVGTransform(transform_attribute)
             self.__matrix = skia.Matrix(list(local_transform.flatten()))
             T = T@local_transform
     if bounds is not None and bbox is None:
         bbox = T.transform_geometry(shapely.geometry.box(*tuple(bounds)))
     self.__bbox = bbox
     self.__prep_bbox = shapely.prepared.prep(bbox) if bbox is not None else None
     self.__clip_path = clip_path
     self.__paint = paint
     self.__save_state = (self.__matrix is not None
                       or self.__clip_path is not None)
Exemple #6
0
    def image(self, src=None, opacity=1, rect=None, pattern=True):
        if isinstance(src, skia.Image):
            image = src
        else:
            image = skia.Image.MakeFromEncoded(
                skia.Data.MakeFromFileName(str(src)))

        if not image:
            print("image <", src, "> not found, cannot be used")
            return

        _, _, iw, ih = image.bounds()

        if pattern:
            matrix = skia.Matrix()
            matrix.setScale(rect.w / iw, rect.h / ih)
            self.paint.setShader(
                image.makeShader(skia.TileMode.kRepeat, skia.TileMode.kRepeat,
                                 matrix))

        if opacity != 1:
            tf = skia.ColorFilters.Matrix([
                1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, opacity,
                0
            ])
            cf = self.paint.getColorFilter()
            if cf:
                self.paint.setColorFilter(skia.ColorFilters.Compose(tf, cf))
            else:
                self.paint.setColorFilter(tf)

        if not pattern:
            bx, by, bw, bh = self.path.getBounds()
            if rect:
                bx, by = rect.flip(self.rect.h).xy()
                #bx += rx
                #by += ry
            sx = rect.w / iw
            sy = rect.h / ih
            self.canvas.save()
            #self.canvas.setMatrix(matrix)
            self.canvas.clipPath(self.path, doAntiAlias=True)
            self.canvas.scale(sx, sy)
            self.canvas.drawImage(image, bx / sx, by / sy, self.paint)
            self.canvas.restore()
            return True
Exemple #7
0
    __and__ = intersection

    def __iand__(self, other):
        result = self.intersection(other)
        self.path = result.path
        return self

    __xor__ = xor

    def __ixor__(self, other):
        result = self.xor(other)
        self.path = result.path
        return self


FLIP_MATRIX = skia.Matrix()
FLIP_MATRIX.setAffine((1, 0, 0, -1, 0, 0))


def _convertConicToCubicDirty(pt1, pt2, pt3):
    #
    # NOTE: we do a crude conversion from a conic segment to a cubic bezier,
    # for two common cases, based on the following assumptions:
    # - drawbot itself does not allow conics to be drawn
    # - skia draws conics implicitly for oval(), arc() and arcTo()
    # - for oval the conic segments span 90 degrees
    # - for arc and arcTo the conic segments do not span more than 90 degrees
    # - for arc and arcTo the conic segments are circular, never elliptical
    # For all these cases, the conic weight will be (close to) zero.
    #
    # This no longer holds once a path has been transformed with skew or x/y
Exemple #8
0
def test_Matrix_init(args):
    assert isinstance(skia.Matrix(*args), skia.Matrix)
def test_ImageFilter_CropRect_applyTo(croprect):
    assert isinstance(
        croprect.applyTo(skia.IRect(100, 100), skia.Matrix(), False),
        skia.IRect)
    canvas.scale(1, 1)


@pytest.mark.parametrize('args', [
    (0, ),
    (0, 0, 0),
])
def test_Canvas_rotate(canvas, args):
    canvas.rotate(*args)


def test_Canvas_skew(canvas):
    canvas.skew(0, 0)


@pytest.mark.parametrize('arg', [skia.Matrix(), skia.M44()])
def test_Canvas_concat(canvas, arg):
    canvas.concat(arg)


def test_Canvas_setMatrix(canvas):
    canvas.setMatrix(skia.Matrix())


def test_Canvas_resetMatrix(canvas):
    canvas.resetMatrix()


@pytest.mark.parametrize('args', [
    (skia.Rect(320, 240), skia.ClipOp.kIntersect, True),
    (skia.Rect(320, 240), True),
Exemple #11
0
def matrix():
    return skia.Matrix()
 def transform(self, matrix):
     m = skia.Matrix()
     m.setAffine(matrix)
     self._canvas.concat(m)
def test_ImageFilters_MatrixTransform():
    assert isinstance(skia.ImageFilters.MatrixTransform(
        skia.Matrix(), skia.FilterQuality.kLow_FilterQuality), skia.ImageFilter)
Exemple #14
0
def test_Matrix_decomposeScale(matrix):
    scale = skia.Size(0, 0)
    remaining = skia.Matrix()
    assert isinstance(matrix.decomposeScale(scale, remaining), bool)
Exemple #15
0
def test_Canvas_setMatrix(canvas):
    canvas.setMatrix(skia.Matrix())
Exemple #16
0
def test_Shader_makeWithLocalMatrix(shader):
    assert isinstance(shader.makeWithLocalMatrix(skia.Matrix()), skia.Shader)
Exemple #17
0
    (
        skia.TextBlob('foo', skia.Font()),
        0,
        0,
        skia.Paint(),
    ),
])
def test_Canvas_drawTextBlob(canvas, args):
    canvas.drawTextBlob(*args)


@pytest.mark.parametrize('args', [
    (skia.Picture(skia.Rect(100, 100)), ),
    (
        skia.Picture(skia.Rect(100, 100)),
        skia.Matrix(),
    ),
    (
        skia.Picture(skia.Rect(100, 100)),
        skia.Matrix(),
        skia.Paint(),
    ),
    (
        skia.Picture(skia.Rect(100, 100)),
        None,
        skia.Paint(),
    ),
])
def test_Canvas_drawPicture(canvas, args):
    canvas.drawPicture(*args)
def test_MatrixPathEffect_Make():
    assert isinstance(skia.MatrixPathEffect.Make(skia.Matrix()),
                      skia.PathEffect)
def test_Path2DPathEffect_Make():
    path = skia.Path()
    path.addCircle(10, 10, 5)
    assert isinstance(skia.Path2DPathEffect.Make(skia.Matrix(), path),
                      skia.PathEffect)
def test_ImageFilter_makeWithLocalMatrix(imagefilter):
    assert isinstance(
        imagefilter.makeWithLocalMatrix(skia.Matrix()), skia.ImageFilter)
def test_ImageFilter_MakeMatrixFilter(imagefilter):
    assert isinstance(
        skia.ImageFilter.MakeMatrixFilter(
            skia.Matrix(), skia.FilterQuality.kHigh_FilterQuality,
            imagefilter), skia.ImageFilter)
Exemple #22
0
def test_Canvas_concat(canvas):
    canvas.concat(skia.Matrix())
Exemple #23
0
def test_Matrix_postConcat(matrix):
    assert isinstance(matrix.postConcat(skia.Matrix()), skia.Matrix)
Exemple #24
0
import pytest


@pytest.fixture
def shader():
    return skia.GradientShader.MakeLinear(
        [skia.Point(0, 0), skia.Point(1, 1)], [0xFFFF00FF, 0xFFFFFF00],
        [])


def test_Shader_isOpaque(shader):
    assert isinstance(shader.isOpaque(), bool)


@pytest.mark.parametrize('args', [
    (skia.Matrix(), [skia.TileMode.kClamp, skia.TileMode.kClamp]),
    tuple(),
])
def test_Shader_isAImage(shader, args):
    assert isinstance(shader.isAImage(*args), (bool, type(None), skia.Image))


def test_Shader_asAGradient(shader):
    info = skia.Shader.GradientInfo()
    assert isinstance(shader.asAGradient(info), skia.Shader.GradientType)


def test_Shader_makeWithLocalMatrix(shader):
    assert isinstance(shader.makeWithLocalMatrix(skia.Matrix()), skia.Shader)

Exemple #25
0
def test_Matrix_invert(matrix):
    assert isinstance(matrix.invert(skia.Matrix()), bool)
Exemple #26
0
    (skia.RRect.MakeRect(skia.Rect(100, 100)), skia.PathDirection.kCCW, 0),
])
def test_Path_addRRect(path, args):
    assert isinstance(path.addRRect(*args), skia.Path)


def test_Path_addPoly(path):
    assert isinstance(path.addPoly([skia.Point(10, 10)], True), skia.Path)


@pytest.mark.parametrize('args', [
    (skia.Path(), 0, 0),
    (skia.Path(), ),
    (
        skia.Path(),
        skia.Matrix(),
    ),
])
def test_Path_addPath(path, args):
    assert isinstance(path.addPath(*args), skia.Path)


def test_Path_reverseAddPath(path):
    assert isinstance(path.reverseAddPath(skia.Path()), skia.Path)


@pytest.mark.parametrize('args', [
    (
        0,
        0,
        skia.Path(),
def test_ImageFilter_CropRect_flags(croprect):
    assert isinstance(croprect.flags(), int)


def test_ImageFilter_CropRect_rect(croprect):
    assert isinstance(croprect.rect(), skia.Rect)


def test_ImageFilter_CropRect_applyTo(croprect):
    assert isinstance(
        croprect.applyTo(skia.IRect(100, 100), skia.Matrix(), False),
        skia.IRect)


@pytest.mark.parametrize('args', [
    (skia.IRect(100, 100), skia.Matrix(),
        skia.ImageFilter.kForward_MapDirection),
    (skia.IRect(100, 100), skia.Matrix(),
        skia.ImageFilter.kReverse_MapDirection, skia.IRect(100, 100))
])
def test_ImageFilter_filterBounds(imagefilter, args):
    assert isinstance(imagefilter.filterBounds(*args), skia.IRect)


def test_ImageFilter_isColorFilterNode(imagefilter):
    assert isinstance(
        imagefilter.isColorFilterNode(), (skia.ColorFilter, type(None)))


def test_ImageFilter_countInputs(imagefilter):
    assert isinstance(imagefilter.countInputs(), int)