Changes in uspace/lib/gfxfont/test/text.c [9eb8d12:1fa6292] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfxfont/test/text.c
r9eb8d12 r1fa6292 36 36 #include "../private/font.h" 37 37 #include "../private/typeface.h" 38 #include "../private/testgc.h" 38 39 39 40 PCUT_INIT; 40 41 41 42 PCUT_TEST_SUITE(text); 42 43 static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);44 static errno_t testgc_set_color(void *, gfx_color_t *);45 static errno_t testgc_fill_rect(void *, gfx_rect_t *);46 static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,47 gfx_bitmap_alloc_t *, void **);48 static errno_t testgc_bitmap_destroy(void *);49 static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);50 static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);51 52 static gfx_context_ops_t test_ops = {53 .set_clip_rect = testgc_set_clip_rect,54 .set_color = testgc_set_color,55 .fill_rect = testgc_fill_rect,56 .bitmap_create = testgc_bitmap_create,57 .bitmap_destroy = testgc_bitmap_destroy,58 .bitmap_render = testgc_bitmap_render,59 .bitmap_get_alloc = testgc_bitmap_get_alloc60 };61 62 typedef struct {63 gfx_bitmap_params_t bm_params;64 void *bm_pixels;65 gfx_rect_t bm_srect;66 gfx_coord2_t bm_offs;67 } test_gc_t;68 69 typedef struct {70 test_gc_t *tgc;71 gfx_bitmap_alloc_t alloc;72 bool myalloc;73 } testgc_bitmap_t;74 43 75 44 /** Test text width computation with a dummy font */ … … 135 104 136 105 gfx_text_fmt_init(&fmt); 106 fmt.font = font; 137 107 fmt.color = color; 138 108 pos.x = 0; 139 109 pos.y = 0; 140 110 141 rc = gfx_puttext( font,&pos, &fmt, "Hello world!");111 rc = gfx_puttext(&pos, &fmt, "Hello world!"); 142 112 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 143 113 … … 181 151 182 152 gfx_text_fmt_init(&fmt); 153 fmt.font = font; 183 154 fmt.color = color; 184 155 pos.x = 0; 185 156 pos.y = 0; 186 157 187 rc = gfx_puttext( font,&pos, &fmt, "Hello world!");158 rc = gfx_puttext(&pos, &fmt, "Hello world!"); 188 159 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 189 160 … … 245 216 246 217 gfx_text_fmt_init(&fmt); 218 fmt.font = font; 247 219 anchor.x = 10; 248 220 anchor.y = 0; … … 250 222 fpos.x = 9; 251 223 fpos.y = 0; 252 off = gfx_text_find_pos( font,&anchor, &fmt, "Aii", &fpos);224 off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos); 253 225 PCUT_ASSERT_INT_EQUALS(0, off); 254 226 255 227 fpos.x = 10; 256 228 fpos.y = 0; 257 off = gfx_text_find_pos( font,&anchor, &fmt, "Aii", &fpos);229 off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos); 258 230 PCUT_ASSERT_INT_EQUALS(0, off); 259 231 260 232 fpos.x = 11; 261 233 fpos.y = 0; 262 off = gfx_text_find_pos( font,&anchor, &fmt, "Aii", &fpos);234 off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos); 263 235 PCUT_ASSERT_INT_EQUALS(0, off); 264 236 265 237 fpos.x = 19; 266 238 fpos.y = 0; 267 off = gfx_text_find_pos( font,&anchor, &fmt, "Aii", &fpos);239 off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos); 268 240 PCUT_ASSERT_INT_EQUALS(1, off); 269 241 270 242 fpos.x = 20; 271 243 fpos.y = 0; 272 off = gfx_text_find_pos( font,&anchor, &fmt, "Aii", &fpos);244 off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos); 273 245 PCUT_ASSERT_INT_EQUALS(2, off); 274 246 275 247 fpos.x = 21; 276 248 fpos.y = 0; 277 off = gfx_text_find_pos( font,&anchor, &fmt, "Aii", &fpos);249 off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos); 278 250 PCUT_ASSERT_INT_EQUALS(3, off); 279 251 280 252 fpos.x = 22; 281 253 fpos.y = 0; 282 off = gfx_text_find_pos( font,&anchor, &fmt, "Aii", &fpos);254 off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos); 283 255 PCUT_ASSERT_INT_EQUALS(3, off); 284 256 … … 318 290 anchor.y = 0; 319 291 gfx_text_fmt_init(&fmt); 292 fmt.font = font; 320 293 321 294 fpos.x = 9; 322 295 fpos.y = 0; 323 off = gfx_text_find_pos( font,&anchor, &fmt, "Abc", &fpos);296 off = gfx_text_find_pos(&anchor, &fmt, "Abc", &fpos); 324 297 PCUT_ASSERT_INT_EQUALS(0, off); 325 298 326 299 fpos.x = 10; 327 300 fpos.y = 0; 328 off = gfx_text_find_pos( font,&anchor, &fmt, "Abc", &fpos);301 off = gfx_text_find_pos(&anchor, &fmt, "Abc", &fpos); 329 302 PCUT_ASSERT_INT_EQUALS(0, off); 330 303 331 304 fpos.x = 11; 332 305 fpos.y = 0; 333 off = gfx_text_find_pos( font,&anchor, &fmt, "Abc", &fpos);306 off = gfx_text_find_pos(&anchor, &fmt, "Abc", &fpos); 334 307 PCUT_ASSERT_INT_EQUALS(1, off); 335 308 336 309 fpos.x = 12; 337 310 fpos.y = 0; 338 off = gfx_text_find_pos( font,&anchor, &fmt, "Abc", &fpos);311 off = gfx_text_find_pos(&anchor, &fmt, "Abc", &fpos); 339 312 PCUT_ASSERT_INT_EQUALS(2, off); 340 313 341 314 fpos.x = 13; 342 315 fpos.y = 0; 343 off = gfx_text_find_pos( font,&anchor, &fmt, "Abc", &fpos);316 off = gfx_text_find_pos(&anchor, &fmt, "Abc", &fpos); 344 317 PCUT_ASSERT_INT_EQUALS(3, off); 345 318 346 319 fpos.x = 14; 347 320 fpos.y = 0; 348 off = gfx_text_find_pos( font,&anchor, &fmt, "Abc", &fpos);321 off = gfx_text_find_pos(&anchor, &fmt, "Abc", &fpos); 349 322 PCUT_ASSERT_INT_EQUALS(3, off); 350 323 … … 385 358 anchor.y = 20; 386 359 gfx_text_fmt_init(&fmt); 360 fmt.font = font; 387 361 fmt.color = color; 388 362 389 gfx_text_cont( font,&anchor, &fmt, "Abc", &cpos, &cfmt);363 gfx_text_cont(&anchor, &fmt, "Abc", &cpos, &cfmt); 390 364 391 365 PCUT_ASSERT_INT_EQUALS(13, cpos.x); … … 431 405 anchor.y = 20; 432 406 gfx_text_fmt_init(&fmt); 407 fmt.font = font; 433 408 fmt.color = color; 434 409 435 gfx_text_rect( font,&anchor, &fmt, "Abc", &rect);410 gfx_text_rect(&anchor, &fmt, "Abc", &rect); 436 411 437 412 PCUT_ASSERT_INT_EQUALS(10, rect.p0.x); … … 448 423 } 449 424 450 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)451 {452 return EOK;453 }454 455 static errno_t testgc_set_color(void *arg, gfx_color_t *color)456 {457 return EOK;458 }459 460 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)461 {462 return EOK;463 }464 465 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,466 gfx_bitmap_alloc_t *alloc, void **rbm)467 {468 test_gc_t *tgc = (test_gc_t *) arg;469 testgc_bitmap_t *tbm;470 471 tbm = calloc(1, sizeof(testgc_bitmap_t));472 if (tbm == NULL)473 return ENOMEM;474 475 if (alloc == NULL) {476 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *477 sizeof(uint32_t);478 tbm->alloc.off0 = 0;479 tbm->alloc.pixels = calloc(sizeof(uint32_t),480 tbm->alloc.pitch * (params->rect.p1.y - params->rect.p0.y));481 tbm->myalloc = true;482 if (tbm->alloc.pixels == NULL) {483 free(tbm);484 return ENOMEM;485 }486 } else {487 tbm->alloc = *alloc;488 }489 490 tbm->tgc = tgc;491 tgc->bm_params = *params;492 tgc->bm_pixels = tbm->alloc.pixels;493 *rbm = (void *)tbm;494 return EOK;495 }496 497 static errno_t testgc_bitmap_destroy(void *bm)498 {499 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;500 if (tbm->myalloc)501 free(tbm->alloc.pixels);502 free(tbm);503 return EOK;504 }505 506 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,507 gfx_coord2_t *offs)508 {509 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;510 tbm->tgc->bm_srect = *srect;511 tbm->tgc->bm_offs = *offs;512 return EOK;513 }514 515 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)516 {517 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;518 *alloc = tbm->alloc;519 return EOK;520 }521 522 425 PCUT_EXPORT(text);
Note:
See TracChangeset
for help on using the changeset viewer.