forked from parallax/jsPDF
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstandard.spec.js
More file actions
111 lines (82 loc) · 2.36 KB
/
Copy pathstandard.spec.js
File metadata and controls
111 lines (82 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
'use strict'
/* global describe, it, jsPDF, comparePdf */
/**
* Standard spec tests
*
* These tests return the datauristring so that reference files can be generated.
* We compare the exact output.
*/
describe('Drawing functions', () => {
it('should draw circles', () => {
const doc = jsPDF()
doc.ellipse(40, 20, 10, 5)
doc.setFillColor(0, 0, 255)
doc.ellipse(80, 20, 10, 5, 'F')
doc.setLineWidth(1)
doc.setDrawColor(0)
doc.setFillColor(255, 0, 0)
doc.circle(120, 20, 5, 'FD')
comparePdf(doc.output(), 'circles.pdf', 'shapes')
})
it('should draw rectangles', () => {
const doc = jsPDF()
// Empty square
doc.rect(20, 20, 10, 10)
// Filled square
doc.rect(40, 20, 10, 10, 'F')
// Empty red square
doc.setDrawColor(255, 0, 0)
doc.rect(60, 20, 10, 10)
// Filled square with red borders
doc.setDrawColor(255, 0, 0)
doc.rect(80, 20, 10, 10, 'FD')
// Filled red square
doc.setDrawColor(0)
doc.setFillColor(255, 0, 0)
doc.rect(100, 20, 10, 10, 'F')
// Filled red square with black borders
doc.setDrawColor(0)
doc.setFillColor(255, 0, 0)
doc.rect(120, 20, 10, 10, 'FD')
// Black square with rounded corners
doc.setDrawColor(0)
doc.setFillColor(255, 255, 255)
doc.roundedRect(140, 20, 10, 10, 3, 3, 'FD')
comparePdf(doc.output(), 'rectangles.pdf', 'shapes')
})
it('should draw a line', () => {
const doc = jsPDF()
// horizontal line
doc.line(20, 20, 60, 20)
comparePdf(doc.output(), 'line.pdf', 'shapes')
})
it('should draw lines', () => {
const doc = jsPDF()
// horizontal line
doc.line(20, 20, 60, 20)
doc.setLineWidth(0.5)
doc.line(20, 25, 60, 25)
doc.setLineWidth(1)
doc.line(20, 30, 60, 30)
doc.setLineWidth(1.5)
doc.line(20, 35, 60, 35)
// draw red lines
doc.setDrawColor(255, 0, 0)
doc.setLineWidth(0.1)
// vertical line
doc.line(100, 20, 100, 60)
doc.setLineWidth(0.5)
doc.line(105, 20, 105, 60)
doc.setLineWidth(1)
doc.line(110, 20, 110, 60)
doc.setLineWidth(1.5)
doc.line(115, 20, 115, 60)
comparePdf(doc.output(), 'lines.pdf', 'shapes')
})
it('should use grey color mode', () => {
const doc = jsPDF()
doc.setFillColor(22)
doc.rect(20, 20, 10, 10, 'F')
comparePdf(doc.output(), 'fill-color.pdf', 'shapes')
})
})