Changeset d53af3c8 in mainline
- 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
- Location:
- uspace
- Files:
-
- 8 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/fontedit/fontedit.c
r7bef2d8 rd53af3c8 142 142 static void font_edit_ctrl_key(font_edit_t *fedit, kbd_event_t *event) 143 143 { 144 errno_t rc; 145 144 146 switch (event->key) { 145 147 case KC_S: 146 148 printf("Save!\n"); 147 149 (void) gfx_glyph_bmp_save(fedit->gbmp); 150 rc = gfx_typeface_save(fedit->typeface, "/test.tpf"); 151 if (rc != EOK) 152 printf("Error saving typeface.\n"); 148 153 font_edit_paint(fedit); 149 154 break; -
uspace/lib/gfxfont/include/gfx/typeface.h
r7bef2d8 rd53af3c8 48 48 extern gfx_font_info_t *gfx_typeface_first_font(gfx_typeface_t *); 49 49 extern gfx_font_info_t *gfx_typeface_next_font(gfx_font_info_t *); 50 extern errno_t gfx_typeface_save(gfx_typeface_t *, const char *); 50 51 51 52 #endif -
uspace/lib/gfxfont/meson.build
r7bef2d8 rd53af3c8 27 27 # 28 28 29 deps = [ 'gfx' ]29 deps = [ 'gfx', 'riff' ] 30 30 src = files( 31 31 'src/font.c', -
uspace/lib/gfxfont/private/font.h
r7bef2d8 rd53af3c8 44 44 #include <types/gfx/font.h> 45 45 #include <types/gfx/typeface.h> 46 #include <riff/chunk.h> 46 47 47 48 /** Font … … 85 86 extern errno_t gfx_font_splice_at_glyph(gfx_font_t *, gfx_glyph_t *, 86 87 gfx_rect_t *); 88 extern errno_t gfx_font_save(gfx_font_info_t *, riffw_t *); 87 89 88 90 #endif -
uspace/lib/gfxfont/private/glyph.h
r7bef2d8 rd53af3c8 41 41 #include <gfx/coord.h> 42 42 #include <types/gfx/glyph.h> 43 #include <riff/chunk.h> 43 44 44 45 /** Glyph … … 76 77 extern errno_t gfx_glyph_transfer(gfx_glyph_t *, gfx_coord_t, gfx_bitmap_t *, 77 78 gfx_rect_t *); 79 extern errno_t gfx_glyph_save(gfx_glyph_t *, riffw_t *); 78 80 79 81 #endif -
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 */ -
uspace/lib/gfxfont/src/glyph.c
r7bef2d8 rd53af3c8 44 44 #include "../private/font.h" 45 45 #include "../private/glyph.h" 46 #include "../private/tpf_file.h" 46 47 47 48 /** Initialize glyph metrics structure. … … 314 315 } 315 316 317 /** Save glyph metrics to RIFF TPF file. 318 * 319 * @param metrics Glyph metrics 320 * @param riffw RIFF writer 321 * @return EOK on success or an error code 322 */ 323 static errno_t gfx_glyph_metrics_save(gfx_glyph_metrics_t *metrics, 324 riffw_t *riffw) 325 { 326 errno_t rc; 327 riff_wchunk_t mtrck; 328 329 rc = riff_wchunk_start(riffw, CKID_gmtr, &mtrck); 330 if (rc != EOK) 331 return rc; 332 333 rc = riff_wchunk_write(riffw, (void *) metrics, sizeof(*metrics)); 334 if (rc != EOK) 335 return rc; 336 337 rc = riff_wchunk_end(riffw, &mtrck); 338 if (rc != EOK) 339 return rc; 340 341 return EOK; 342 } 343 344 /** Save glyph patterns to RIFF TPF file. 345 * 346 * @param glyph Glyph 347 * @param riffw RIFF writer 348 * @return EOK on success or an error code 349 */ 350 static errno_t gfx_glyph_patterns_save(gfx_glyph_t *glyph, riffw_t *riffw) 351 { 352 errno_t rc; 353 riff_wchunk_t patck; 354 gfx_glyph_pattern_t *pat; 355 const char *str; 356 357 rc = riff_wchunk_start(riffw, CKID_gpat, &patck); 358 if (rc != EOK) 359 return rc; 360 361 pat = gfx_glyph_first_pattern(glyph); 362 while (pat != NULL) { 363 str = gfx_glyph_pattern_str(pat); 364 365 rc = riff_wchunk_write(riffw, (void *) str, 1 + str_size(str)); 366 if (rc != EOK) 367 return rc; 368 369 pat = gfx_glyph_next_pattern(pat); 370 } 371 372 rc = riff_wchunk_end(riffw, &patck); 373 if (rc != EOK) 374 return rc; 375 376 return EOK; 377 } 378 379 /** Save glyph rectangle/origin to RIFF TPF file. 380 * 381 * @param glyph Glyph 382 * @param riffw RIFF writer 383 * @return EOK on success or an error code 384 */ 385 static errno_t gfx_glyph_rectangle_origin_save(gfx_glyph_t *glyph, 386 riffw_t *riffw) 387 { 388 errno_t rc; 389 riff_wchunk_t rorck; 390 391 rc = riff_wchunk_start(riffw, CKID_gror, &rorck); 392 if (rc != EOK) 393 return rc; 394 395 rc = riff_wchunk_write(riffw, (void *) &glyph->rect, 396 sizeof(glyph->rect)); 397 if (rc != EOK) 398 return rc; 399 400 rc = riff_wchunk_write(riffw, (void *) &glyph->origin, 401 sizeof(glyph->origin)); 402 if (rc != EOK) 403 return rc; 404 405 rc = riff_wchunk_end(riffw, &rorck); 406 if (rc != EOK) 407 return rc; 408 409 return EOK; 410 } 411 412 /** Save glyph into RIFF TPF file. 413 * 414 * @param glyph Glyph 415 * @param riffw RIFF writer 416 */ 417 errno_t gfx_glyph_save(gfx_glyph_t *glyph, riffw_t *riffw) 418 { 419 errno_t rc; 420 riff_wchunk_t glyphck; 421 422 rc = riff_wchunk_start(riffw, CKID_LIST, &glyphck); 423 if (rc != EOK) 424 return rc; 425 426 rc = riff_write_uint32(riffw, LTYPE_glph); 427 if (rc != EOK) 428 return rc; 429 430 rc = gfx_glyph_metrics_save(&glyph->metrics, riffw); 431 if (rc != EOK) 432 return rc; 433 434 rc = gfx_glyph_patterns_save(glyph, riffw); 435 if (rc != EOK) 436 return rc; 437 438 rc = gfx_glyph_rectangle_origin_save(glyph, riffw); 439 if (rc != EOK) 440 return rc; 441 442 rc = riff_wchunk_end(riffw, &glyphck); 443 if (rc != EOK) 444 return rc; 445 446 return EOK; 447 } 448 316 449 /** @} 317 450 */ -
uspace/lib/gfxfont/src/typeface.c
r7bef2d8 rd53af3c8 41 41 #include <gfx/typeface.h> 42 42 #include <mem.h> 43 #include <riff/chunk.h> 43 44 #include <stdlib.h> 44 45 #include "../private/font.h" 45 46 #include "../private/glyph.h" 47 #include "../private/tpf_file.h" 46 48 #include "../private/typeface.h" 47 49 … … 111 113 } 112 114 115 /** Save typeface into a TPF file. 116 * 117 * @param tface Typeface 118 * @param fname Destination file name 119 * @return EOK on success or an error code 120 */ 121 errno_t gfx_typeface_save(gfx_typeface_t *tface, const char *fname) 122 { 123 riffw_t *riffw = NULL; 124 errno_t rc; 125 gfx_font_info_t *finfo; 126 riff_wchunk_t riffck; 127 128 rc = riff_wopen(fname, &riffw); 129 if (rc != EOK) 130 return rc; 131 132 rc = riff_wchunk_start(riffw, CKID_RIFF, &riffck); 133 if (rc != EOK) 134 goto error; 135 136 rc = riff_write_uint32(riffw, FORM_TPFC); 137 if (rc != EOK) 138 goto error; 139 140 finfo = gfx_typeface_first_font(tface); 141 while (finfo != NULL) { 142 /* Save font */ 143 rc = gfx_font_save(finfo, riffw); 144 if (rc != EOK) 145 goto error; 146 147 finfo = gfx_typeface_next_font(finfo); 148 } 149 150 rc = riff_wchunk_end(riffw, &riffck); 151 if (rc != EOK) 152 goto error; 153 154 rc = riff_wclose(riffw); 155 if (rc != EOK) 156 return rc; 157 158 return EOK; 159 error: 160 if (riffw != NULL) 161 riff_wclose(riffw); 162 return rc; 163 } 164 113 165 /** @} 114 166 */ -
uspace/lib/meson.build
r7bef2d8 rd53af3c8 68 68 'pcut', 69 69 'posix', 70 'riff', 70 71 'scsi', 71 72 'sif',
Note:
See TracChangeset
for help on using the changeset viewer.