Changes in uspace/lib/gfxfont/test/text.c [1fa6292:9eb8d12] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfxfont/test/text.c
r1fa6292 r9eb8d12 36 36 #include "../private/font.h" 37 37 #include "../private/typeface.h" 38 #include "../private/testgc.h"39 38 40 39 PCUT_INIT; 41 40 42 41 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_alloc 60 }; 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; 43 74 44 75 /** Test text width computation with a dummy font */ … … 104 135 105 136 gfx_text_fmt_init(&fmt); 106 fmt.font = font;107 137 fmt.color = color; 108 138 pos.x = 0; 109 139 pos.y = 0; 110 140 111 rc = gfx_puttext( &pos, &fmt, "Hello world!");141 rc = gfx_puttext(font, &pos, &fmt, "Hello world!"); 112 142 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 113 143 … … 151 181 152 182 gfx_text_fmt_init(&fmt); 153 fmt.font = font;154 183 fmt.color = color; 155 184 pos.x = 0; 156 185 pos.y = 0; 157 186 158 rc = gfx_puttext( &pos, &fmt, "Hello world!");187 rc = gfx_puttext(font, &pos, &fmt, "Hello world!"); 159 188 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 160 189 … … 216 245 217 246 gfx_text_fmt_init(&fmt); 218 fmt.font = font;219 247 anchor.x = 10; 220 248 anchor.y = 0; … … 222 250 fpos.x = 9; 223 251 fpos.y = 0; 224 off = gfx_text_find_pos( &anchor, &fmt, "Aii", &fpos);252 off = gfx_text_find_pos(font, &anchor, &fmt, "Aii", &fpos); 225 253 PCUT_ASSERT_INT_EQUALS(0, off); 226 254 227 255 fpos.x = 10; 228 256 fpos.y = 0; 229 off = gfx_text_find_pos( &anchor, &fmt, "Aii", &fpos);257 off = gfx_text_find_pos(font, &anchor, &fmt, "Aii", &fpos); 230 258 PCUT_ASSERT_INT_EQUALS(0, off); 231 259 232 260 fpos.x = 11; 233 261 fpos.y = 0; 234 off = gfx_text_find_pos( &anchor, &fmt, "Aii", &fpos);262 off = gfx_text_find_pos(font, &anchor, &fmt, "Aii", &fpos); 235 263 PCUT_ASSERT_INT_EQUALS(0, off); 236 264 237 265 fpos.x = 19; 238 266 fpos.y = 0; 239 off = gfx_text_find_pos( &anchor, &fmt, "Aii", &fpos);267 off = gfx_text_find_pos(font, &anchor, &fmt, "Aii", &fpos); 240 268 PCUT_ASSERT_INT_EQUALS(1, off); 241 269 242 270 fpos.x = 20; 243 271 fpos.y = 0; 244 off = gfx_text_find_pos( &anchor, &fmt, "Aii", &fpos);272 off = gfx_text_find_pos(font, &anchor, &fmt, "Aii", &fpos); 245 273 PCUT_ASSERT_INT_EQUALS(2, off); 246 274 247 275 fpos.x = 21; 248 276 fpos.y = 0; 249 off = gfx_text_find_pos( &anchor, &fmt, "Aii", &fpos);277 off = gfx_text_find_pos(font, &anchor, &fmt, "Aii", &fpos); 250 278 PCUT_ASSERT_INT_EQUALS(3, off); 251 279 252 280 fpos.x = 22; 253 281 fpos.y = 0; 254 off = gfx_text_find_pos( &anchor, &fmt, "Aii", &fpos);282 off = gfx_text_find_pos(font, &anchor, &fmt, "Aii", &fpos); 255 283 PCUT_ASSERT_INT_EQUALS(3, off); 256 284 … … 290 318 anchor.y = 0; 291 319 gfx_text_fmt_init(&fmt); 292 fmt.font = font;293 320 294 321 fpos.x = 9; 295 322 fpos.y = 0; 296 off = gfx_text_find_pos( &anchor, &fmt, "Abc", &fpos);323 off = gfx_text_find_pos(font, &anchor, &fmt, "Abc", &fpos); 297 324 PCUT_ASSERT_INT_EQUALS(0, off); 298 325 299 326 fpos.x = 10; 300 327 fpos.y = 0; 301 off = gfx_text_find_pos( &anchor, &fmt, "Abc", &fpos);328 off = gfx_text_find_pos(font, &anchor, &fmt, "Abc", &fpos); 302 329 PCUT_ASSERT_INT_EQUALS(0, off); 303 330 304 331 fpos.x = 11; 305 332 fpos.y = 0; 306 off = gfx_text_find_pos( &anchor, &fmt, "Abc", &fpos);333 off = gfx_text_find_pos(font, &anchor, &fmt, "Abc", &fpos); 307 334 PCUT_ASSERT_INT_EQUALS(1, off); 308 335 309 336 fpos.x = 12; 310 337 fpos.y = 0; 311 off = gfx_text_find_pos( &anchor, &fmt, "Abc", &fpos);338 off = gfx_text_find_pos(font, &anchor, &fmt, "Abc", &fpos); 312 339 PCUT_ASSERT_INT_EQUALS(2, off); 313 340 314 341 fpos.x = 13; 315 342 fpos.y = 0; 316 off = gfx_text_find_pos( &anchor, &fmt, "Abc", &fpos);343 off = gfx_text_find_pos(font, &anchor, &fmt, "Abc", &fpos); 317 344 PCUT_ASSERT_INT_EQUALS(3, off); 318 345 319 346 fpos.x = 14; 320 347 fpos.y = 0; 321 off = gfx_text_find_pos( &anchor, &fmt, "Abc", &fpos);348 off = gfx_text_find_pos(font, &anchor, &fmt, "Abc", &fpos); 322 349 PCUT_ASSERT_INT_EQUALS(3, off); 323 350 … … 358 385 anchor.y = 20; 359 386 gfx_text_fmt_init(&fmt); 360 fmt.font = font;361 387 fmt.color = color; 362 388 363 gfx_text_cont( &anchor, &fmt, "Abc", &cpos, &cfmt);389 gfx_text_cont(font, &anchor, &fmt, "Abc", &cpos, &cfmt); 364 390 365 391 PCUT_ASSERT_INT_EQUALS(13, cpos.x); … … 405 431 anchor.y = 20; 406 432 gfx_text_fmt_init(&fmt); 407 fmt.font = font;408 433 fmt.color = color; 409 434 410 gfx_text_rect( &anchor, &fmt, "Abc", &rect);435 gfx_text_rect(font, &anchor, &fmt, "Abc", &rect); 411 436 412 437 PCUT_ASSERT_INT_EQUALS(10, rect.p0.x); … … 423 448 } 424 449 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 425 522 PCUT_EXPORT(text);
Note:
See TracChangeset
for help on using the changeset viewer.