4 (defun test (output-file)
5 (with-canvas (:width
100 :height
100)
13 (set-rgb-stroke 0 1 0)
17 ;; blue+alpha transform stroke
18 (set-rgba-stroke 0 0 1 0.5)
19 (flet ((elbow (radians)
31 (step (/ (* pi
2) rotations
)))
32 (dotimes (i rotations
)
34 (save-png output-file
)))
37 (defun test-rotate (output-file)
38 (with-canvas (:width
100 :height
100)
45 (save-png output-file
)))
47 (defun test-skew (output-file)
48 (with-canvas (:width
100 :height
100)
51 (skew (- (/ pi
4)) (- (/ pi
4)))
54 (save-png output-file
)))
56 (defun hole-test (file)
57 (with-canvas (:width
100 :height
100)
74 (defun rectangle-test (file)
75 (with-canvas (:width
100 :height
100)
76 (rectangle 10 10 50 50)
80 (defun rectangle-fill-test (file)
81 (with-canvas (:width
5 :height
5)
82 (set-rgba-fill 1 0 0 0.5)
87 (defun circle-test (string file
)
88 (with-canvas (:width
250 :height
180)
92 (centered-circle-path 0 0 5)
95 (centered-circle-path 0 0 8)
98 (centered-circle-path 0 0 11)
100 (centered-ellipse-path 75 60 100 40)
102 (let ((font (get-font "/home/xach/.fonts/vagron.ttf")))
105 (let ((bbox (string-bounding-box string font
)))
107 (set-rgba-fill 1 0 0 0.5)
108 (rectangle (xmin bbox
) (ymin bbox
)
109 (- (xmax bbox
) (xmin bbox
))
110 (- (ymax bbox
) (ymin bbox
)))
113 (draw-string string
))
116 (defun center-test (string file
)
117 (with-canvas (:width
200 :height
100)
118 (let ((font (get-font #p
"times.ttf")))
120 (draw-centered-string 100 25 string
)
121 (set-rgba-fill 1 0 0 0.5)
122 (set-rgb-stroke 0 0 0)
123 (centered-circle-path 100 25 5)
127 (defun twittertext (string size font file
)
128 (zpb-ttf:with-font-loader
(loader font
)
129 (let ((bbox (string-bounding-box string size loader
)))
130 (with-canvas (:width
(- (ceiling (xmax bbox
)) (floor (xmin bbox
)))
131 :height
(- (ceiling (ymax bbox
)) (floor (ymin bbox
))))
132 (set-font loader size
)
133 (set-rgba-fill 1 1 1 0.1)
136 (translate (- (xmin bbox
)) (- (ymin bbox
)))
137 (draw-string 0 0 string
)
140 (defun arc-to (center-x center-y radius start extent
)
141 ;; An arc of extent zero will generate an error at bezarc (divide by zero).
142 ;; This case may be given by two aligned points in a polyline.
143 ;; Better do nothing.
144 (unless (zerop extent
)
145 (if (<= (abs extent
) (/ pi
2.0))
146 (multiple-value-bind (x1 y1 x2 y2 x3 y3
)
147 (bezarc center-x center-y radius start extent
)
148 (curve-to x1 y1 x2 y2 x3 y3
))
149 (let ((half-extent (/ extent
2.0)))
150 (arc-to center-x center-y radius start half-extent
)
151 (arc-to center-x center-y radius
(+ start half-extent
) half-extent
)))))
153 (defun bezarc (center-x center-y radius start extent
)
154 ;; start and extent should be in radians.
155 ;; Returns first-control-point-x first-control-point-y
156 ;; second-control-point-x second-control-point-y
157 ;; end-point-x end-point-y
158 (let* ((end (+ start extent
))
159 (s-start (sin start
)) (c-start (cos start
))
160 (s-end (sin end
)) (c-end (cos end
))
161 (ang/2 (/ extent
2.0))
162 (kappa (* (/ 4.0 3.0)
165 (x1 (- c-start
(* kappa s-start
)))
166 (y1 (+ s-start
(* kappa c-start
)))
167 (x2 (+ c-end
(* kappa s-end
)))
168 (y2 (- s-end
(* kappa c-end
))))
169 (values (+ (* x1 radius
) center-x
)(+ (* y1 radius
) center-y
)
170 (+ (* x2 radius
) center-x
)(+ (* y2 radius
) center-y
)
171 (+ (* c-end radius
) center-x
)(+ (* s-end radius
) center-y
))))
173 (defun degrees (degrees)
174 (* (/ pi
180) degrees
))
176 (defun arc-test (file)
177 (with-canvas (:width
100 :height
100)
182 (arc-to 0 0 75 0 (degrees 15))
187 (defun rect-test (file)
188 (with-canvas (:width
5 :height
5)
189 (set-rgba-fill 1 0 0 0.5)
194 (defun text-test (&key string size font file
)
195 (with-canvas (:width
200 :height
200)
196 (let ((loader (get-font font
)))
197 (set-rgb-fill 0.8 0.8 0.9)
199 (set-font loader size
)
200 (set-rgb-fill 0.0 0.0 0.3)
202 (rotate (* 15 (/ pi
180)))
203 (draw-string 10 10 string
)
207 (defun dash-test (file)
208 (with-canvas (:width
200 :height
200)
209 (rectangle 10 10 125 125)
210 (set-rgba-fill 0.3 0.5 0.9 0.5)
212 (set-dash-pattern #(10 10) 5)
216 (defun sign-test (string font file
&key
222 (zpb-ttf:with-font-loader
(loader font
)
223 (let* ((bbox (string-bounding-box string font-size loader
))
224 (text-height (ceiling (- (ymax bbox
) (ymin bbox
))))
225 (text-width (ceiling (- (xmax bbox
) (xmin bbox
))))
226 (stripe/2 (/ stripe-width
2.0))
227 (b1 (+ outer-border stripe
/2))
228 (b2 (+ inner-border stripe
/2))
235 (width (truncate (+ text-width
(* 2 (+ b1 b2
)))))
236 (width1 (- width
(* b1
2)))
237 (height (truncate (+ text-height
(* 2 (+ b1 b2
)))))
238 (height1 (- height
(* b1
2))))
239 (with-canvas (:width width
:height height
)
240 (set-rgb-fill 0.0 0.43 0.33)
241 (set-rgb-stroke 0.95 0.95 0.95)
242 ;; Stripe shadow + stripe
243 (set-line-width stripe-width
)
246 (set-rgba-stroke 0.0 0.0 0.0 0.3)
247 (rounded-rectangle x1 y1
249 corner-radius corner-radius
)
251 (rounded-rectangle x1 y1
253 corner-radius corner-radius
)
254 (set-dash-pattern #(10 20) 0)
256 ;; Text shadow & text
257 (set-font loader font-size
)
258 (translate (- (xmin bbox
)) (- (ymin bbox
)))
261 (set-rgba-fill 0.0 0.0 0.0 1.0)
262 (draw-string x2 y2 string
))
263 (set-rgb-fill 0.95 0.95 0.95)
264 (draw-string x2 y2 string
)
276 (defun fill-test (file)
277 (with-canvas (:width
100 :height
100)
278 (set-rgb-stroke 1 0 0)
286 (defun circle-test (file)
287 (with-canvas (:width
1000 :height
1000)
290 (centered-circle-path 50 50 45)
296 (defun pdf-circle (file)
297 (pdf:with-document
()
301 (pdf:set-line-width
3)
302 (pdf:circle
50 50 45)
304 (pdf:write-document file
)))