Changeset 453f203b in mainline for uspace/lib/gfxfont/src/font.c
- Timestamp:
- 2020-09-25T14:31:27Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 16357ec
- Parents:
- 120031a5
- git-author:
- Jiri Svoboda <jiri@…> (2020-09-24 18:30:07)
- git-committer:
- Jiri Svoboda <jiri@…> (2020-09-25 14:31:27)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfxfont/src/font.c
r120031a5 r453f203b 36 36 #include <adt/list.h> 37 37 #include <assert.h> 38 #include <byteorder.h> 38 39 #include <errno.h> 39 40 #include <gfx/bitmap.h> … … 403 404 errno_t rc; 404 405 riff_rchunk_t propsck; 406 tpf_font_props_t tprops; 405 407 size_t nread; 406 408 … … 409 411 return rc; 410 412 411 rc = riff_read(&propsck, (void *) props, sizeof(*props), &nread);412 if (rc != EOK || nread != sizeof( *props))413 rc = riff_read(&propsck, (void *) &tprops, sizeof(tprops), &nread); 414 if (rc != EOK || nread != sizeof(tprops)) 413 415 return EIO; 414 416 … … 416 418 if (rc != EOK) 417 419 return rc; 420 421 props->size = uint16_t_le2host(tprops.size); 422 props->flags = uint16_t_le2host(tprops.flags); 418 423 419 424 return EOK; … … 430 435 errno_t rc; 431 436 riff_wchunk_t propsck; 437 tpf_font_props_t tprops; 438 439 tprops.size = host2uint16_t_le(props->size); 440 tprops.flags = host2uint16_t_le(props->flags); 432 441 433 442 rc = riff_wchunk_start(riffw, CKID_fprp, &propsck); … … 435 444 return rc; 436 445 437 rc = riff_write(riffw, (void *) props, sizeof(*props));446 rc = riff_write(riffw, (void *) &tprops, sizeof(tprops)); 438 447 if (rc != EOK) 439 448 return rc; … … 457 466 errno_t rc; 458 467 riff_rchunk_t mtrck; 468 tpf_font_metrics_t tmetrics; 459 469 size_t nread; 460 470 … … 463 473 return rc; 464 474 465 rc = riff_read(&mtrck, (void *) metrics, sizeof(*metrics), &nread);466 if (rc != EOK || nread != sizeof( *metrics))475 rc = riff_read(&mtrck, (void *) &tmetrics, sizeof(tmetrics), &nread); 476 if (rc != EOK || nread != sizeof(tmetrics)) 467 477 return EIO; 468 478 … … 471 481 return rc; 472 482 483 metrics->ascent = uint16_t_le2host(tmetrics.ascent); 484 metrics->descent = uint16_t_le2host(tmetrics.descent); 485 metrics->leading = uint16_t_le2host(tmetrics.leading); 473 486 return EOK; 474 487 } … … 484 497 { 485 498 errno_t rc; 499 tpf_font_metrics_t tmetrics; 486 500 riff_wchunk_t mtrck; 487 501 502 tmetrics.ascent = host2uint16_t_le(metrics->ascent); 503 tmetrics.descent = host2uint16_t_le(metrics->descent); 504 tmetrics.leading = host2uint16_t_le(metrics->leading); 505 488 506 rc = riff_wchunk_start(riffw, CKID_fmtr, &mtrck); 489 507 if (rc != EOK) 490 508 return rc; 491 509 492 rc = riff_write(riffw, (void *) metrics, sizeof(*metrics));510 rc = riff_write(riffw, (void *) &tmetrics, sizeof(tmetrics)); 493 511 if (rc != EOK) 494 512 return rc; … … 511 529 errno_t rc; 512 530 riff_rchunk_t bmpck; 531 tpf_font_bmp_hdr_t thdr; 513 532 gfx_bitmap_params_t params; 514 533 gfx_bitmap_alloc_t alloc; … … 516 535 uint32_t width; 517 536 uint32_t height; 518 uint32_t depth; 537 uint16_t fmt; 538 uint16_t depth; 519 539 size_t nread; 520 540 … … 523 543 goto error; 524 544 525 rc = riff_read_uint32(&bmpck, &width); 526 if (rc != EOK) 527 goto error; 528 529 rc = riff_read_uint32(&bmpck, &height); 530 if (rc != EOK) 531 goto error; 532 533 rc = riff_read_uint32(&bmpck, &depth); 534 if (rc != EOK) 535 goto error; 536 537 if (depth != 8 * sizeof(uint32_t)) { 545 rc = riff_read(&bmpck, &thdr, sizeof(thdr), &nread); 546 if (rc != EOK || nread != sizeof(thdr)) 547 goto error; 548 549 width = uint32_t_le2host(thdr.width); 550 height = uint32_t_le2host(thdr.height); 551 fmt = uint16_t_le2host(thdr.fmt); 552 depth = uint16_t_le2host(thdr.depth); 553 554 if (fmt != 0 || depth != 8 * sizeof(uint32_t)) { 538 555 rc = ENOTSUP; 539 556 goto error; … … 587 604 { 588 605 errno_t rc; 606 tpf_font_bmp_hdr_t thdr; 589 607 riff_wchunk_t bmpck; 590 608 gfx_bitmap_alloc_t alloc; 591 609 610 thdr.width = host2uint32_t_le(font->rect.p1.x); 611 thdr.height = host2uint32_t_le(font->rect.p1.y); 612 thdr.fmt = 0; 613 thdr.depth = host2uint16_t_le(8 * sizeof(uint32_t)); 614 592 615 rc = gfx_bitmap_get_alloc(font->bitmap, &alloc); 593 616 if (rc != EOK) … … 598 621 return rc; 599 622 600 rc = riff_write_uint32(riffw, font->rect.p1.x); 601 if (rc != EOK) 602 return rc; 603 604 rc = riff_write_uint32(riffw, font->rect.p1.y); 605 if (rc != EOK) 606 return rc; 607 608 rc = riff_write_uint32(riffw, 8 * sizeof(uint32_t)); 623 rc = riff_write(riffw, &thdr, sizeof(thdr)); 609 624 if (rc != EOK) 610 625 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.