source: mainline/uspace/lib/gfxfont/test/glyph.c@ 2791fbb7

Last change on this file since 2791fbb7 was 7470d97, checked in by Jiri Svoboda <jiri@…>, 4 years ago

Add GC operation to set clipping rectangle

The number of changed files is due to the proliferation of GC
implementations, mostly these are just dummies in unit tests.
Definitely need to tame those in the future.

  • Property mode set to 100644
File size: 16.1 KB
Line 
1/*
2 * Copyright (c) 2021 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <gfx/bitmap.h>
30#include <gfx/context.h>
31#include <gfx/font.h>
32#include <gfx/glyph.h>
33#include <gfx/glyph_bmp.h>
34#include <gfx/typeface.h>
35#include <io/pixelmap.h>
36#include <pcut/pcut.h>
37#include <stdbool.h>
38#include <str.h>
39#include "../private/glyph.h"
40
41PCUT_INIT;
42
43PCUT_TEST_SUITE(glyph);
44
45static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
46static errno_t testgc_set_color(void *, gfx_color_t *);
47static errno_t testgc_fill_rect(void *, gfx_rect_t *);
48static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
49 gfx_bitmap_alloc_t *, void **);
50static errno_t testgc_bitmap_destroy(void *);
51static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
52static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
53
54static gfx_context_ops_t test_ops = {
55 .set_clip_rect = testgc_set_clip_rect,
56 .set_color = testgc_set_color,
57 .fill_rect = testgc_fill_rect,
58 .bitmap_create = testgc_bitmap_create,
59 .bitmap_destroy = testgc_bitmap_destroy,
60 .bitmap_render = testgc_bitmap_render,
61 .bitmap_get_alloc = testgc_bitmap_get_alloc
62};
63
64typedef struct {
65 gfx_bitmap_params_t bm_params;
66 void *bm_pixels;
67 gfx_rect_t bm_srect;
68 gfx_coord2_t bm_offs;
69} test_gc_t;
70
71typedef struct {
72 test_gc_t *tgc;
73 gfx_bitmap_alloc_t alloc;
74 bool myalloc;
75} testgc_bitmap_t;
76
77/** Test creating and destroying glyph */
78PCUT_TEST(create_destroy)
79{
80 gfx_font_props_t fprops;
81 gfx_font_metrics_t fmetrics;
82 gfx_typeface_t *tface;
83 gfx_font_t *font;
84 gfx_glyph_metrics_t gmetrics;
85 gfx_glyph_t *glyph;
86 gfx_context_t *gc;
87 test_gc_t tgc;
88 errno_t rc;
89
90 rc = gfx_context_new(&test_ops, (void *) &tgc, &gc);
91 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
92
93 rc = gfx_typeface_create(gc, &tface);
94 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
95
96 gfx_font_props_init(&fprops);
97 gfx_font_metrics_init(&fmetrics);
98 rc = gfx_font_create(tface, &fprops, &fmetrics, &font);
99 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
100
101 gfx_glyph_metrics_init(&gmetrics);
102 rc = gfx_glyph_create(font, &gmetrics, &glyph);
103 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
104
105 gfx_glyph_destroy(glyph);
106
107 gfx_font_close(font);
108 gfx_typeface_destroy(tface);
109 rc = gfx_context_delete(gc);
110 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
111}
112
113/** Test gfx_glyph_get_metrics() */
114PCUT_TEST(get_metrics)
115{
116 gfx_font_props_t fprops;
117 gfx_font_metrics_t fmetrics;
118 gfx_typeface_t *tface;
119 gfx_font_t *font;
120 gfx_glyph_metrics_t gmetrics;
121 gfx_glyph_t *glyph;
122 gfx_glyph_metrics_t rmetrics;
123 gfx_context_t *gc;
124 test_gc_t tgc;
125 errno_t rc;
126
127 rc = gfx_context_new(&test_ops, (void *) &tgc, &gc);
128 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
129
130 rc = gfx_typeface_create(gc, &tface);
131 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
132
133 gfx_font_props_init(&fprops);
134 gfx_font_metrics_init(&fmetrics);
135 rc = gfx_font_create(tface, &fprops, &fmetrics, &font);
136 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
137
138 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
139
140 gfx_glyph_metrics_init(&gmetrics);
141 gmetrics.advance = 42;
142
143 rc = gfx_glyph_create(font, &gmetrics, &glyph);
144 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
145
146 gfx_glyph_get_metrics(glyph, &rmetrics);
147 PCUT_ASSERT_INT_EQUALS(gmetrics.advance, rmetrics.advance);
148
149 gfx_glyph_destroy(glyph);
150
151 gfx_font_close(font);
152 gfx_typeface_destroy(tface);
153 rc = gfx_context_delete(gc);
154 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
155}
156
157/** Test gfx_glyph_set_metrics() */
158PCUT_TEST(set_metrics)
159{
160 gfx_font_props_t fprops;
161 gfx_font_metrics_t fmetrics;
162 gfx_typeface_t *tface;
163 gfx_font_t *font;
164 gfx_glyph_metrics_t gmetrics1;
165 gfx_glyph_metrics_t gmetrics2;
166 gfx_glyph_t *glyph;
167 gfx_glyph_metrics_t rmetrics;
168 gfx_context_t *gc;
169 test_gc_t tgc;
170 errno_t rc;
171
172 rc = gfx_context_new(&test_ops, (void *) &tgc, &gc);
173 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
174
175 rc = gfx_typeface_create(gc, &tface);
176 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
177
178 gfx_font_props_init(&fprops);
179 gfx_font_metrics_init(&fmetrics);
180 rc = gfx_font_create(tface, &fprops, &fmetrics, &font);
181 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
182
183 gfx_glyph_metrics_init(&gmetrics1);
184 gmetrics1.advance = 1;
185
186 rc = gfx_glyph_create(font, &gmetrics1, &glyph);
187 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
188
189 gfx_glyph_metrics_init(&gmetrics2);
190 gmetrics2.advance = 2;
191
192 gfx_glyph_set_metrics(glyph, &gmetrics2);
193
194 gfx_glyph_get_metrics(glyph, &rmetrics);
195 PCUT_ASSERT_INT_EQUALS(gmetrics2.advance, rmetrics.advance);
196
197 gfx_glyph_destroy(glyph);
198
199 gfx_font_close(font);
200 gfx_typeface_destroy(tface);
201 rc = gfx_context_delete(gc);
202 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
203}
204
205/** Test gfx_glyph_set_pattern() */
206PCUT_TEST(set_pattern)
207{
208 gfx_font_props_t fprops;
209 gfx_font_metrics_t fmetrics;
210 gfx_typeface_t *tface;
211 gfx_font_t *font;
212 gfx_glyph_metrics_t gmetrics;
213 gfx_glyph_t *glyph;
214 gfx_context_t *gc;
215 test_gc_t tgc;
216 errno_t rc;
217
218 rc = gfx_context_new(&test_ops, (void *) &tgc, &gc);
219 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
220
221 rc = gfx_typeface_create(gc, &tface);
222 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
223
224 gfx_font_props_init(&fprops);
225 gfx_font_metrics_init(&fmetrics);
226 rc = gfx_font_create(tface, &fprops, &fmetrics, &font);
227 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
228
229 gfx_glyph_metrics_init(&gmetrics);
230 gmetrics.advance = 1;
231
232 rc = gfx_glyph_create(font, &gmetrics, &glyph);
233 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
234
235 PCUT_ASSERT_NULL(gfx_glyph_first_pattern(glyph));
236
237 /* Set a pattern */
238 rc = gfx_glyph_set_pattern(glyph, "A");
239 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
240 PCUT_ASSERT_NOT_NULL(gfx_glyph_first_pattern(glyph));
241
242 /* Setting the same pattern again should be OK */
243 rc = gfx_glyph_set_pattern(glyph, "A");
244 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
245 PCUT_ASSERT_NOT_NULL(gfx_glyph_first_pattern(glyph));
246
247 gfx_glyph_destroy(glyph);
248
249 gfx_font_close(font);
250 gfx_typeface_destroy(tface);
251 rc = gfx_context_delete(gc);
252 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
253}
254
255/** Test gfx_glyph_clear_pattern() */
256PCUT_TEST(clear_pattern)
257{
258 gfx_font_props_t fprops;
259 gfx_font_metrics_t fmetrics;
260 gfx_typeface_t *tface;
261 gfx_font_t *font;
262 gfx_glyph_metrics_t gmetrics;
263 gfx_glyph_t *glyph;
264 gfx_context_t *gc;
265 test_gc_t tgc;
266 errno_t rc;
267
268 rc = gfx_context_new(&test_ops, (void *) &tgc, &gc);
269 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
270
271 rc = gfx_typeface_create(gc, &tface);
272 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
273
274 gfx_font_props_init(&fprops);
275 gfx_font_metrics_init(&fmetrics);
276 rc = gfx_font_create(tface, &fprops, &fmetrics, &font);
277 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
278
279 gfx_glyph_metrics_init(&gmetrics);
280 gmetrics.advance = 1;
281
282 rc = gfx_glyph_create(font, &gmetrics, &glyph);
283 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
284
285 PCUT_ASSERT_NULL(gfx_glyph_first_pattern(glyph));
286
287 /* Set a pattern */
288 rc = gfx_glyph_set_pattern(glyph, "A");
289 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
290 PCUT_ASSERT_NOT_NULL(gfx_glyph_first_pattern(glyph));
291
292 /* Now clear a different pattern - should be OK */
293 gfx_glyph_clear_pattern(glyph, "AA");
294 PCUT_ASSERT_NOT_NULL(gfx_glyph_first_pattern(glyph));
295
296 /* Now clear the pattern which has been set */
297 gfx_glyph_clear_pattern(glyph, "A");
298 PCUT_ASSERT_NULL(gfx_glyph_first_pattern(glyph));
299
300 gfx_glyph_destroy(glyph);
301
302 gfx_font_close(font);
303 gfx_typeface_destroy(tface);
304 rc = gfx_context_delete(gc);
305 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
306}
307
308/** Test gfx_glyph_matches() */
309PCUT_TEST(matches)
310{
311 gfx_font_props_t fprops;
312 gfx_font_metrics_t fmetrics;
313 gfx_typeface_t *tface;
314 gfx_font_t *font;
315 gfx_glyph_metrics_t gmetrics;
316 gfx_glyph_t *glyph;
317 gfx_context_t *gc;
318 test_gc_t tgc;
319 bool match;
320 size_t msize;
321 errno_t rc;
322
323 rc = gfx_context_new(&test_ops, (void *) &tgc, &gc);
324 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
325
326 rc = gfx_typeface_create(gc, &tface);
327 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
328
329 gfx_font_props_init(&fprops);
330 gfx_font_metrics_init(&fmetrics);
331 rc = gfx_font_create(tface, &fprops, &fmetrics, &font);
332 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
333
334 gfx_glyph_metrics_init(&gmetrics);
335 gmetrics.advance = 1;
336
337 rc = gfx_glyph_create(font, &gmetrics, &glyph);
338 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
339
340 PCUT_ASSERT_NULL(gfx_glyph_first_pattern(glyph));
341
342 /* Set a pattern */
343 rc = gfx_glyph_set_pattern(glyph, "AB");
344 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
345 PCUT_ASSERT_NOT_NULL(gfx_glyph_first_pattern(glyph));
346
347 match = gfx_glyph_matches(glyph, "A", &msize);
348 PCUT_ASSERT_FALSE(match);
349
350 match = gfx_glyph_matches(glyph, "AB", &msize);
351 PCUT_ASSERT_TRUE(match);
352 PCUT_ASSERT_INT_EQUALS(2, msize);
353
354 match = gfx_glyph_matches(glyph, "ABC", &msize);
355 PCUT_ASSERT_TRUE(match);
356 PCUT_ASSERT_INT_EQUALS(2, msize);
357
358 match = gfx_glyph_matches(glyph, "BAB", &msize);
359 PCUT_ASSERT_FALSE(match);
360
361 gfx_glyph_destroy(glyph);
362
363 gfx_font_close(font);
364 gfx_typeface_destroy(tface);
365 rc = gfx_context_delete(gc);
366 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
367}
368
369/** Test gfx_glyph_first_pattern(), gfx_glyph_next_pattern() */
370PCUT_TEST(first_next_pattern)
371{
372 gfx_font_props_t fprops;
373 gfx_font_metrics_t fmetrics;
374 gfx_typeface_t *tface;
375 gfx_font_t *font;
376 gfx_glyph_metrics_t gmetrics;
377 gfx_glyph_t *glyph;
378 gfx_context_t *gc;
379 test_gc_t tgc;
380 gfx_glyph_pattern_t *pat;
381 errno_t rc;
382
383 rc = gfx_context_new(&test_ops, (void *) &tgc, &gc);
384 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
385
386 rc = gfx_typeface_create(gc, &tface);
387 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
388
389 gfx_font_props_init(&fprops);
390 gfx_font_metrics_init(&fmetrics);
391 rc = gfx_font_create(tface, &fprops, &fmetrics, &font);
392 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
393
394 gfx_glyph_metrics_init(&gmetrics);
395 gmetrics.advance = 1;
396
397 rc = gfx_glyph_create(font, &gmetrics, &glyph);
398 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
399
400 PCUT_ASSERT_NULL(gfx_glyph_first_pattern(glyph));
401
402 /* Set a pattern */
403 rc = gfx_glyph_set_pattern(glyph, "A");
404 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
405 PCUT_ASSERT_NOT_NULL(gfx_glyph_first_pattern(glyph));
406
407 pat = gfx_glyph_first_pattern(glyph);
408 PCUT_ASSERT_NOT_NULL(pat);
409
410 pat = gfx_glyph_next_pattern(pat);
411 PCUT_ASSERT_NULL(pat);
412
413 gfx_glyph_destroy(glyph);
414
415 gfx_font_close(font);
416 gfx_typeface_destroy(tface);
417 rc = gfx_context_delete(gc);
418 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
419}
420
421/** Test gfx_glyph_pattern_str() */
422PCUT_TEST(pattern_str)
423{
424 gfx_font_props_t fprops;
425 gfx_font_metrics_t fmetrics;
426 gfx_typeface_t *tface;
427 gfx_font_t *font;
428 gfx_glyph_metrics_t gmetrics;
429 gfx_glyph_t *glyph;
430 gfx_context_t *gc;
431 test_gc_t tgc;
432 gfx_glyph_pattern_t *pat;
433 const char *pstr;
434 errno_t rc;
435
436 rc = gfx_context_new(&test_ops, (void *) &tgc, &gc);
437 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
438
439 rc = gfx_typeface_create(gc, &tface);
440 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
441
442 gfx_font_props_init(&fprops);
443 gfx_font_metrics_init(&fmetrics);
444 rc = gfx_font_create(tface, &fprops, &fmetrics, &font);
445 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
446
447 gfx_glyph_metrics_init(&gmetrics);
448 gmetrics.advance = 1;
449
450 rc = gfx_glyph_create(font, &gmetrics, &glyph);
451 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
452
453 PCUT_ASSERT_NULL(gfx_glyph_first_pattern(glyph));
454
455 /* Set a pattern */
456 rc = gfx_glyph_set_pattern(glyph, "A");
457 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
458 PCUT_ASSERT_NOT_NULL(gfx_glyph_first_pattern(glyph));
459
460 pat = gfx_glyph_first_pattern(glyph);
461 PCUT_ASSERT_NOT_NULL(pat);
462
463 pstr = gfx_glyph_pattern_str(pat);
464 PCUT_ASSERT_INT_EQUALS(0, str_cmp("A", pstr));
465
466 gfx_glyph_destroy(glyph);
467
468 gfx_font_close(font);
469 gfx_typeface_destroy(tface);
470 rc = gfx_context_delete(gc);
471 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
472}
473
474/** Test gfx_glyph_transfer() */
475PCUT_TEST(transfer)
476{
477 gfx_font_props_t fprops;
478 gfx_font_metrics_t fmetrics;
479 gfx_typeface_t *tface;
480 gfx_font_t *font;
481 gfx_glyph_metrics_t gmetrics;
482 gfx_glyph_t *glyph;
483 gfx_context_t *gc;
484 gfx_bitmap_t *bitmap;
485 gfx_bitmap_params_t params;
486 gfx_bitmap_alloc_t alloc;
487 gfx_glyph_bmp_t *bmp;
488 pixelmap_t pmap;
489 pixel_t pixel;
490 test_gc_t tgc;
491 errno_t rc;
492
493 rc = gfx_context_new(&test_ops, (void *) &tgc, &gc);
494 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
495
496 rc = gfx_typeface_create(gc, &tface);
497 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
498
499 gfx_font_props_init(&fprops);
500 gfx_font_metrics_init(&fmetrics);
501 rc = gfx_font_create(tface, &fprops, &fmetrics, &font);
502 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
503
504 gfx_glyph_metrics_init(&gmetrics);
505 gmetrics.advance = 1;
506
507 rc = gfx_glyph_create(font, &gmetrics, &glyph);
508 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
509
510 /*
511 * We need to fill some pixels of the glyph.
512 * We'll use the glyph bitmap for that.
513 * That means this test won't pass unless glyph
514 * bitmap works.
515 */
516
517 rc = gfx_glyph_bmp_open(glyph, &bmp);
518 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
519 PCUT_ASSERT_NOT_NULL(bmp);
520
521 rc = gfx_glyph_bmp_setpix(bmp, 0, 0, 1);
522 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
523
524 rc = gfx_glyph_bmp_setpix(bmp, 1, 1, 1);
525 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
526
527 rc = gfx_glyph_bmp_save(bmp);
528 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
529 gfx_glyph_bmp_close(bmp);
530
531 /* Now create a new bitmap */
532
533 gfx_bitmap_params_init(&params);
534 params.rect.p0.x = 0;
535 params.rect.p0.y = 0;
536 params.rect.p1.x = 10;
537 params.rect.p1.y = 10;
538 rc = gfx_bitmap_create(gc, &params, NULL, &bitmap);
539 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
540
541 rc = gfx_bitmap_get_alloc(bitmap, &alloc);
542 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
543
544 /* Transfer the glyph to new bitmap */
545 rc = gfx_glyph_transfer(glyph, 0, bitmap, &params.rect);
546 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
547
548 /* Now let's read pixels from the new bitmap */
549 pmap.width = params.rect.p1.x;
550 pmap.height = params.rect.p1.y;
551 pmap.data = alloc.pixels;
552
553 pixel = pixelmap_get_pixel(&pmap, 0, 0);
554 PCUT_ASSERT_INT_EQUALS(PIXEL(255, 255, 255, 255), pixel);
555
556 pixel = pixelmap_get_pixel(&pmap, 1, 1);
557 PCUT_ASSERT_INT_EQUALS(PIXEL(255, 255, 255, 255), pixel);
558
559 pixel = pixelmap_get_pixel(&pmap, 1, 0);
560 PCUT_ASSERT_INT_EQUALS(PIXEL(0, 0, 0, 0), pixel);
561
562 pixel = pixelmap_get_pixel(&pmap, 0, 1);
563 PCUT_ASSERT_INT_EQUALS(PIXEL(0, 0, 0, 0), pixel);
564
565 gfx_glyph_destroy(glyph);
566
567 gfx_font_close(font);
568 gfx_typeface_destroy(tface);
569 rc = gfx_context_delete(gc);
570 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
571}
572
573static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
574{
575 return EOK;
576}
577
578static errno_t testgc_set_color(void *arg, gfx_color_t *color)
579{
580 return EOK;
581}
582
583static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
584{
585 return EOK;
586}
587
588static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
589 gfx_bitmap_alloc_t *alloc, void **rbm)
590{
591 test_gc_t *tgc = (test_gc_t *) arg;
592 testgc_bitmap_t *tbm;
593
594 tbm = calloc(1, sizeof(testgc_bitmap_t));
595 if (tbm == NULL)
596 return ENOMEM;
597
598 if (alloc == NULL) {
599 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
600 sizeof(uint32_t);
601 tbm->alloc.off0 = 0;
602 tbm->alloc.pixels = calloc(sizeof(uint32_t),
603 tbm->alloc.pitch * (params->rect.p1.y - params->rect.p0.y));
604 tbm->myalloc = true;
605 if (tbm->alloc.pixels == NULL) {
606 free(tbm);
607 return ENOMEM;
608 }
609 } else {
610 tbm->alloc = *alloc;
611 }
612
613 tbm->tgc = tgc;
614 tgc->bm_params = *params;
615 tgc->bm_pixels = tbm->alloc.pixels;
616 *rbm = (void *)tbm;
617 return EOK;
618}
619
620static errno_t testgc_bitmap_destroy(void *bm)
621{
622 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
623 if (tbm->myalloc)
624 free(tbm->alloc.pixels);
625 free(tbm);
626 return EOK;
627}
628
629static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
630 gfx_coord2_t *offs)
631{
632 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
633 tbm->tgc->bm_srect = *srect;
634 tbm->tgc->bm_offs = *offs;
635 return EOK;
636}
637
638static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
639{
640 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
641 *alloc = tbm->alloc;
642 return EOK;
643}
644
645PCUT_EXPORT(glyph);
Note: See TracBrowser for help on using the repository browser.