• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1describe('Core canvas behavior', function() {
2    let container = document.createElement('div');
3    document.body.appendChild(container);
4    const CANVAS_WIDTH = 600;
5    const CANVAS_HEIGHT = 600;
6
7    beforeEach(function() {
8        container.innerHTML = `
9            <canvas width=600 height=600 id=test></canvas>
10            <canvas width=600 height=600 id=report></canvas>`;
11    });
12
13    afterEach(function() {
14        container.innerHTML = '';
15    });
16
17    it('can draw an SkPicture', function(done) {
18        LoadCanvasKit.then(catchException(done, () => {
19            // This is taken from example.html
20            const surface = CanvasKit.MakeCanvasSurface('test');
21            expect(surface).toBeTruthy('Could not make surface')
22            if (!surface) {
23                done();
24                return;
25            }
26            const spr = new CanvasKit.SkPictureRecorder();
27            const rcanvas = spr.beginRecording(
28                            CanvasKit.LTRBRect(0, 0, surface.width(), surface.height()));
29            const paint = new CanvasKit.SkPaint();
30            paint.setStrokeWidth(2.0);
31            paint.setAntiAlias(true);
32            paint.setColor(CanvasKit.Color(0, 0, 0, 1.0));
33            paint.setStyle(CanvasKit.PaintStyle.Stroke);
34
35            rcanvas.drawRoundRect(CanvasKit.LTRBRect(5, 35, 45, 80), 15, 10, paint);
36
37            const font = new CanvasKit.SkFont(null, 20);
38            rcanvas.drawText('this picture has a round rect', 5, 100, paint, font);
39            const pic = spr.finishRecordingAsPicture();
40            spr.delete();
41
42
43            const canvas = surface.getCanvas();
44            canvas.drawPicture(pic);
45
46            reportSurface(surface, 'picture_test', done);
47        }));
48    });
49
50});
51