Changeset 8fa65af0 in mainline
- Timestamp:
- 2020-10-06T08:59:57Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 74f59b7
- Parents:
- 25f2983b
- git-author:
- Jiri Svoboda <jiri@…> (2020-10-05 18:59:36)
- git-committer:
- Jiri Svoboda <jiri@…> (2020-10-06 08:59:57)
- Location:
- uspace
- Files:
-
- 4 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/fontedit/fontedit.c
r25f2983b r8fa65af0 41 41 #include <gfx/glyph.h> 42 42 #include <gfx/render.h> 43 #include <gfx/text.h> 43 44 #include <gfx/typeface.h> 44 45 #include <stdbool.h> … … 422 423 gfx_coord_t x, gfx_coord_t y, const char *str) 423 424 { 424 gfx_glyph_metrics_t gmetrics; 425 size_t stradv; 426 const char *cp; 425 gfx_text_fmt_t fmt; 427 426 gfx_coord2_t pos; 428 gfx_glyph_t *glyph; 429 errno_t rc;427 428 gfx_text_fmt_init(&fmt); 430 429 431 430 pos.x = x; 432 431 pos.y = y; 433 cp = str; 434 435 while (*cp != '\0') { 436 rc = gfx_font_search_glyph(fedit->font, cp, &glyph, &stradv); 437 if (rc != EOK) { 438 ++cp; 439 continue; 440 } 441 442 gfx_glyph_get_metrics(glyph, &gmetrics); 443 444 rc = gfx_glyph_render(glyph, &pos); 445 if (rc != EOK) 446 return rc; 447 448 cp += stradv; 449 pos.x += gmetrics.advance; 450 } 451 452 return EOK; 432 433 return gfx_puttext(fedit->font, &pos, &fmt, str); 453 434 } 454 435 -
uspace/app/gfxdemo/gfxdemo.c
r25f2983b r8fa65af0 42 42 #include <gfx/color.h> 43 43 #include <gfx/render.h> 44 #include <gfx/font.h> 45 #include <gfx/text.h> 46 #include <gfx/typeface.h> 44 47 #include <io/console.h> 45 48 #include <io/pixelmap.h> … … 366 369 return rc; 367 370 } 371 368 372 /** Run bitmap color key demo on a graphic context. 369 373 * … … 424 428 } 425 429 426 /** Run demo loopon a graphic context.430 /** Run text demo on a graphic context. 427 431 * 428 432 * @param gc Graphic context … … 430 434 * @param h Height 431 435 */ 436 static errno_t demo_text(gfx_context_t *gc, gfx_coord_t w, gfx_coord_t h) 437 { 438 gfx_color_t *color = NULL; 439 gfx_rect_t rect; 440 gfx_typeface_t *tface = NULL; 441 gfx_font_info_t *finfo; 442 gfx_font_t *font = NULL; 443 gfx_coord2_t pos; 444 gfx_text_fmt_t fmt; 445 int i; 446 errno_t rc; 447 448 rc = gfx_typeface_open(gc, "/data/font/helena.tpf", &tface); 449 if (rc != EOK) { 450 printf("Error opening typeface\n"); 451 goto error; 452 } 453 454 finfo = gfx_typeface_first_font(tface); 455 if (finfo == NULL) { 456 printf("Typeface contains no font.\n"); 457 rc = ENOENT; 458 goto error; 459 } 460 461 rc = gfx_font_open(finfo, &font); 462 if (rc != EOK) { 463 printf("Error opening font.\n"); 464 goto error; 465 } 466 467 rc = clear_scr(gc, w, h); 468 if (rc != EOK) 469 goto error; 470 471 /* Vertical bars */ 472 473 for (i = 0; i < 20; i++) { 474 rc = gfx_color_new_rgb_i16(0, 0x8000 * i / 20, 475 0x8000 * i / 20, &color); 476 if (rc != EOK) 477 goto error; 478 479 rc = gfx_set_color(gc, color); 480 if (rc != EOK) 481 goto error; 482 483 rect.p0.x = w * i / 20; 484 rect.p0.y = 0; 485 rect.p1.x = w * (i + 1) / 20; 486 rect.p1.y = h; 487 488 rc = gfx_fill_rect(gc, &rect); 489 if (rc != EOK) 490 goto error; 491 492 gfx_color_delete(color); 493 } 494 495 rc = gfx_color_new_rgb_i16(0, 0, 0x8000, &color); 496 if (rc != EOK) 497 goto error; 498 499 rc = gfx_set_color(gc, color); 500 if (rc != EOK) 501 goto error; 502 503 rect.p0.x = w / 20; 504 rect.p0.y = 3 * h / 15; 505 rect.p1.x = w - w / 20; 506 rect.p1.y = 5 * h / 15; 507 508 rc = gfx_fill_rect(gc, &rect); 509 if (rc != EOK) 510 goto error; 511 512 gfx_color_delete(color); 513 514 rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color); 515 if (rc != EOK) 516 goto error; 517 518 rc = gfx_set_color(gc, color); 519 if (rc != EOK) 520 goto error; 521 522 gfx_text_fmt_init(&fmt); 523 524 pos.x = rect.p0.x; 525 pos.y = rect.p0.y; 526 rc = gfx_puttext(font, &pos, &fmt, "Top left"); 527 if (rc != EOK) { 528 printf("Error rendering text.\n"); 529 goto error; 530 } 531 532 pos.x = (rect.p0.x + rect.p1.x) / 2; 533 pos.y = rect.p0.y; 534 fmt.halign = gfx_halign_center; 535 rc = gfx_puttext(font, &pos, &fmt, "Top center"); 536 if (rc != EOK) 537 goto error; 538 539 pos.x = rect.p1.x; 540 pos.y = rect.p0.y; 541 fmt.halign = gfx_halign_right; 542 rc = gfx_puttext(font, &pos, &fmt, "Top right"); 543 if (rc != EOK) 544 goto error; 545 546 fmt.valign = gfx_valign_center; 547 548 pos.x = rect.p0.x; 549 pos.y = (rect.p0.y + rect.p1.y) / 2; 550 fmt.halign = gfx_halign_left; 551 rc = gfx_puttext(font, &pos, &fmt, "Center left"); 552 if (rc != EOK) 553 goto error; 554 555 pos.x = (rect.p0.x + rect.p1.x) / 2; 556 pos.y = (rect.p0.y + rect.p1.y) / 2; 557 fmt.halign = gfx_halign_center; 558 rc = gfx_puttext(font, &pos, &fmt, "Center"); 559 if (rc != EOK) 560 goto error; 561 562 pos.x = rect.p1.x; 563 pos.y = (rect.p0.y + rect.p1.y) / 2; 564 fmt.halign = gfx_halign_right; 565 rc = gfx_puttext(font, &pos, &fmt, "Center right"); 566 if (rc != EOK) 567 goto error; 568 569 fmt.valign = gfx_valign_bottom; 570 571 pos.x = rect.p0.x; 572 pos.y = rect.p1.y; 573 fmt.halign = gfx_halign_left; 574 rc = gfx_puttext(font, &pos, &fmt, "Bottom left"); 575 if (rc != EOK) 576 goto error; 577 578 pos.x = (rect.p0.x + rect.p1.x) / 2; 579 pos.y = rect.p1.y; 580 fmt.halign = gfx_halign_center; 581 rc = gfx_puttext(font, &pos, &fmt, "Bottom center"); 582 if (rc != EOK) 583 goto error; 584 585 pos.x = rect.p1.x; 586 pos.y = rect.p1.y; 587 fmt.halign = gfx_halign_right; 588 rc = gfx_puttext(font, &pos, &fmt, "Bottom right"); 589 if (rc != EOK) 590 goto error; 591 592 gfx_text_fmt_init(&fmt); 593 594 for (i = 0; i < 8; i++) { 595 pos.x = w / 20; 596 pos.y = (7 + i) * h / 15; 597 rc = gfx_puttext(font, &pos, &fmt, "The quick brown fox jumps over the lazy dog."); 598 if (rc != EOK) 599 goto error; 600 } 601 602 for (i = 0; i < 10; i++) { 603 fibril_usleep(500 * 1000); 604 if (quit) 605 break; 606 } 607 608 gfx_color_delete(color); 609 610 gfx_font_close(font); 611 gfx_typeface_destroy(tface); 612 return EOK; 613 error: 614 if (font != NULL) 615 gfx_font_close(font); 616 if (tface != NULL) 617 gfx_typeface_destroy(tface); 618 return rc; 619 } 620 621 /** Run demo loop on a graphic context. 622 * 623 * @param gc Graphic context 624 * @param w Width 625 * @param h Height 626 */ 432 627 static errno_t demo_loop(gfx_context_t *gc, gfx_coord_t w, gfx_coord_t h) 433 628 { … … 448 643 449 644 rc = demo_bitmap_kc(gc, w, h); 645 if (rc != EOK) 646 return rc; 647 648 rc = demo_text(gc, w, h); 450 649 if (rc != EOK) 451 650 return rc; -
uspace/app/gfxdemo/meson.build
r25f2983b r8fa65af0 27 27 # 28 28 29 deps = [ 'gfx', 'g uigfx', 'congfx', 'ipcgfx', 'display' ]29 deps = [ 'gfx', 'gfxfont', 'guigfx', 'congfx', 'ipcgfx', 'display' ] 30 30 src = files( 31 31 'gfxdemo.c', -
uspace/lib/gfxfont/include/gfx/font.h
r25f2983b r8fa65af0 42 42 #include <types/gfx/font.h> 43 43 #include <types/gfx/glyph.h> 44 #include <types/gfx/text.h> 44 45 #include <types/gfx/typeface.h> 45 46 -
uspace/lib/gfxfont/meson.build
r25f2983b r8fa65af0 32 32 'src/glyph.c', 33 33 'src/glyph_bmp.c', 34 'src/text.c', 34 35 'src/typeface.c', 35 36 ) … … 40 41 'test/glyph_bmp.c', 41 42 'test/main.c', 43 'test/text.c', 42 44 'test/tpf.c', 43 45 'test/typeface.c', -
uspace/lib/gfxfont/test/main.c
r25f2983b r8fa65af0 34 34 PCUT_IMPORT(glyph); 35 35 PCUT_IMPORT(glyph_bmp); 36 PCUT_IMPORT(text); 36 37 PCUT_IMPORT(tpf); 37 38 PCUT_IMPORT(typeface);
Note:
See TracChangeset
for help on using the changeset viewer.