Changeset d53af3c8 in mainline for uspace/lib/gfxfont/src/font.c
- Timestamp:
- 2020-09-18T23:00:44Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0ee3157
- Parents:
- 7bef2d8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfxfont/src/font.c
r7bef2d8 rd53af3c8 44 44 #include "../private/font.h" 45 45 #include "../private/glyph.h" 46 #include "../private/tpf_file.h" 46 47 #include "../private/typeface.h" 47 48 … … 359 360 } 360 361 362 /** Save font properties to RIFF TPF file. 363 * 364 * @param props Font properties 365 * @param riffw RIFF writer 366 * @return EOK on success or an error code 367 */ 368 static errno_t gfx_font_props_save(gfx_font_props_t *props, riffw_t *riffw) 369 { 370 errno_t rc; 371 riff_wchunk_t propsck; 372 373 rc = riff_wchunk_start(riffw, CKID_fprp, &propsck); 374 if (rc != EOK) 375 return rc; 376 377 rc = riff_wchunk_write(riffw, (void *) props, sizeof(*props)); 378 if (rc != EOK) 379 return rc; 380 381 rc = riff_wchunk_end(riffw, &propsck); 382 if (rc != EOK) 383 return rc; 384 385 return EOK; 386 } 387 388 /** Save font metrics to RIFF TPF file. 389 * 390 * @param metrics Font metrics 391 * @param riffw RIFF writer 392 * @return EOK on success or an error code 393 */ 394 static errno_t gfx_font_metrics_save(gfx_font_metrics_t *metrics, 395 riffw_t *riffw) 396 { 397 errno_t rc; 398 riff_wchunk_t mtrck; 399 400 rc = riff_wchunk_start(riffw, CKID_fmtr, &mtrck); 401 if (rc != EOK) 402 return rc; 403 404 rc = riff_wchunk_write(riffw, (void *) metrics, sizeof(*metrics)); 405 if (rc != EOK) 406 return rc; 407 408 rc = riff_wchunk_end(riffw, &mtrck); 409 if (rc != EOK) 410 return rc; 411 412 return EOK; 413 } 414 415 /** Save font bitmap to RIFF TPF file. 416 * 417 * @param font Font 418 * @param riffw RIFF writer 419 * @return EOK on success or an error code 420 */ 421 static errno_t gfx_font_bitmap_save(gfx_font_t *font, riffw_t *riffw) 422 { 423 errno_t rc; 424 riff_wchunk_t bmpck; 425 gfx_bitmap_alloc_t alloc; 426 427 rc = gfx_bitmap_get_alloc(font->bitmap, &alloc); 428 if (rc != EOK) 429 return rc; 430 431 rc = riff_wchunk_start(riffw, CKID_fbmp, &bmpck); 432 if (rc != EOK) 433 return rc; 434 435 rc = riff_write_uint32(riffw, font->rect.p1.x); 436 if (rc != EOK) 437 return rc; 438 439 rc = riff_write_uint32(riffw, font->rect.p1.y); 440 if (rc != EOK) 441 return rc; 442 443 rc = riff_write_uint32(riffw, 8 * sizeof(uint32_t)); 444 if (rc != EOK) 445 return rc; 446 447 rc = riff_wchunk_write(riffw, (void *) alloc.pixels, 448 font->rect.p1.x * font->rect.p1.y * sizeof(uint32_t)); 449 if (rc != EOK) 450 return rc; 451 452 rc = riff_wchunk_end(riffw, &bmpck); 453 if (rc != EOK) 454 return rc; 455 456 return EOK; 457 } 458 459 /** Save font into RIFF TPF file. 460 * 461 * @param finfo Font info 462 * @param riffw RIFF writer 463 */ 464 errno_t gfx_font_save(gfx_font_info_t *finfo, riffw_t *riffw) 465 { 466 errno_t rc; 467 riff_wchunk_t fontck; 468 gfx_glyph_t *glyph; 469 470 rc = riff_wchunk_start(riffw, CKID_LIST, &fontck); 471 if (rc != EOK) 472 return rc; 473 474 rc = riff_write_uint32(riffw, LTYPE_font); 475 if (rc != EOK) 476 return rc; 477 478 rc = gfx_font_props_save(&finfo->props, riffw); 479 if (rc != EOK) 480 return rc; 481 482 rc = gfx_font_metrics_save(&finfo->font->metrics, riffw); 483 if (rc != EOK) 484 return rc; 485 486 rc = gfx_font_bitmap_save(finfo->font, riffw); 487 if (rc != EOK) 488 return rc; 489 490 glyph = gfx_font_first_glyph(finfo->font); 491 while (glyph != NULL) { 492 rc = gfx_glyph_save(glyph, riffw); 493 if (rc != EOK) 494 return rc; 495 496 glyph = gfx_font_next_glyph(glyph); 497 } 498 499 rc = riff_wchunk_end(riffw, &fontck); 500 if (rc != EOK) 501 return rc; 502 503 return EOK; 504 } 505 361 506 /** @} 362 507 */
Note:
See TracChangeset
for help on using the changeset viewer.