Changeset 9eb8d12 in mainline for uspace/lib/gfxfont
- Timestamp:
- 2021-07-19T22:35:19Z (4 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c9722c1
- Parents:
- ead72f2
- Location:
- uspace/lib/gfxfont
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfxfont/include/gfx/text.h
read72f2 r9eb8d12 50 50 extern size_t gfx_text_find_pos(gfx_font_t *, gfx_coord2_t *, gfx_text_fmt_t *, 51 51 const char *, gfx_coord2_t *); 52 extern void gfx_text_cont(gfx_font_t *, gfx_coord2_t *, gfx_text_fmt_t *, 53 const char *, gfx_coord2_t *, gfx_text_fmt_t *); 54 extern void gfx_text_rect(gfx_font_t *, gfx_coord2_t *, gfx_text_fmt_t *, 55 const char *, gfx_rect_t *); 52 56 53 57 #endif -
uspace/lib/gfxfont/src/text.c
read72f2 r9eb8d12 174 174 * @param str String 175 175 * @param spos Place to store starting position 176 * @return EOK on success or an error code177 176 */ 178 177 void gfx_text_start_pos(gfx_font_t *font, gfx_coord2_t *pos, … … 333 332 } 334 333 334 /** Get text continuation parameters. 335 * 336 * Return the anchor position and format needed to continue printing 337 * text after the specified string. It is allowed for the sources 338 * (@a pos, @a fmt) and destinations (@a cpos, @a cfmt) to point 339 * to the same objects, respectively. 340 * 341 * @param font Font 342 * @param pos Anchor position 343 * @param fmt Text formatting 344 * @param str String 345 * @param cpos Place to store anchor position for continuation 346 * @param cfmt Place to store format for continuation 347 */ 348 void gfx_text_cont(gfx_font_t *font, gfx_coord2_t *pos, 349 gfx_text_fmt_t *fmt, const char *str, gfx_coord2_t *cpos, 350 gfx_text_fmt_t *cfmt) 351 { 352 gfx_coord2_t spos; 353 gfx_text_fmt_t tfmt; 354 355 /* Continuation should start where the current string ends */ 356 gfx_text_start_pos(font, pos, fmt, str, &spos); 357 cpos->x = spos.x + gfx_text_width(font, str); 358 cpos->y = spos.y; 359 360 /* 361 * Formatting is the same, except the text should be aligned 362 * so that it starts at the anchor point. 363 */ 364 tfmt = *fmt; 365 tfmt.halign = gfx_halign_left; 366 tfmt.valign = gfx_valign_baseline; 367 368 *cfmt = tfmt; 369 } 370 371 /** Get text bounding rectangle. 372 * 373 * @param font Font 374 * @param pos Anchor position 375 * @param fmt Text formatting 376 * @param str String 377 * @param rect Place to store bounding rectangle 378 */ 379 void gfx_text_rect(gfx_font_t *font, gfx_coord2_t *pos, 380 gfx_text_fmt_t *fmt, const char *str, gfx_rect_t *rect) 381 { 382 gfx_coord2_t spos; 383 384 gfx_text_start_pos(font, pos, fmt, str, &spos); 385 386 rect->p0.x = spos.x; 387 rect->p0.y = spos.y - font->metrics.ascent; 388 rect->p1.x = spos.x + gfx_text_width(font, str); 389 rect->p1.y = spos.y + font->metrics.descent + 1; 390 } 391 335 392 /** @} 336 393 */ -
uspace/lib/gfxfont/test/text.c
read72f2 r9eb8d12 356 356 } 357 357 358 /** gfx_text_cont() produces correct continuation parameters */ 359 PCUT_TEST(text_cont) 360 { 361 gfx_typeface_t *tface; 362 gfx_font_t *font; 363 gfx_context_t *gc; 364 gfx_color_t *color; 365 test_gc_t tgc; 366 gfx_text_fmt_t fmt; 367 gfx_coord2_t anchor; 368 gfx_coord2_t cpos; 369 gfx_text_fmt_t cfmt; 370 errno_t rc; 371 372 rc = gfx_context_new(&test_ops, (void *)&tgc, &gc); 373 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 374 375 rc = gfx_typeface_create(gc, &tface); 376 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 377 378 rc = gfx_font_create_textmode(tface, &font); 379 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 380 381 rc = gfx_color_new_rgb_i16(0, 0, 0, &color); 382 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 383 384 anchor.x = 10; 385 anchor.y = 20; 386 gfx_text_fmt_init(&fmt); 387 fmt.color = color; 388 389 gfx_text_cont(font, &anchor, &fmt, "Abc", &cpos, &cfmt); 390 391 PCUT_ASSERT_INT_EQUALS(13, cpos.x); 392 PCUT_ASSERT_INT_EQUALS(20, cpos.y); 393 PCUT_ASSERT_EQUALS(fmt.color, cfmt.color); 394 PCUT_ASSERT_EQUALS(gfx_halign_left, cfmt.halign); 395 PCUT_ASSERT_EQUALS(gfx_valign_baseline, cfmt.valign); 396 397 gfx_font_close(font); 398 gfx_typeface_destroy(tface); 399 gfx_color_delete(color); 400 401 rc = gfx_context_delete(gc); 402 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 403 } 404 405 /** gfx_text_rect() computes bounding rectangle */ 406 PCUT_TEST(text_rect) 407 { 408 gfx_typeface_t *tface; 409 gfx_font_t *font; 410 gfx_context_t *gc; 411 gfx_color_t *color; 412 test_gc_t tgc; 413 gfx_text_fmt_t fmt; 414 gfx_coord2_t anchor; 415 gfx_rect_t rect; 416 errno_t rc; 417 418 rc = gfx_context_new(&test_ops, (void *)&tgc, &gc); 419 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 420 421 rc = gfx_typeface_create(gc, &tface); 422 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 423 424 rc = gfx_font_create_textmode(tface, &font); 425 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 426 427 rc = gfx_color_new_rgb_i16(0, 0, 0, &color); 428 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 429 430 anchor.x = 10; 431 anchor.y = 20; 432 gfx_text_fmt_init(&fmt); 433 fmt.color = color; 434 435 gfx_text_rect(font, &anchor, &fmt, "Abc", &rect); 436 437 PCUT_ASSERT_INT_EQUALS(10, rect.p0.x); 438 PCUT_ASSERT_INT_EQUALS(20, rect.p0.y); 439 PCUT_ASSERT_INT_EQUALS(13, rect.p1.x); 440 PCUT_ASSERT_INT_EQUALS(21, rect.p1.y); 441 442 gfx_font_close(font); 443 gfx_typeface_destroy(tface); 444 gfx_color_delete(color); 445 446 rc = gfx_context_delete(gc); 447 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 448 } 449 358 450 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect) 359 451 {
Note:
See TracChangeset
for help on using the changeset viewer.