Changeset 16357ec in mainline


Ignore:
Timestamp:
2020-09-25T15:21:09Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
efca2e4
Parents:
453f203b
git-author:
Jiri Svoboda <jiri@…> (2020-09-24 19:20:54)
git-committer:
Jiri Svoboda <jiri@…> (2020-09-25 15:21:09)
Message:

Let font editor save and load typeface files

Location:
uspace/app/fontedit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/fontedit/fontedit.c

    r453f203b r16357ec  
    148148                printf("Save!\n");
    149149                (void) gfx_glyph_bmp_save(fedit->gbmp);
    150                 rc = gfx_typeface_save(fedit->typeface, "/test.tpf");
     150                rc = gfx_typeface_save(fedit->typeface, fedit->fname);
    151151                if (rc != EOK)
    152152                        printf("Error saving typeface.\n");
     
    426426 *
    427427 * @param display_svc Display service
     428 * @param fname Font file to open or @c NULL to create new font
    428429 * @param rfedit Place to store pointer to new font editor
    429430 * @return EOK on success or an error code
    430431 */
    431 static errno_t font_edit_create(const char *display_svc, font_edit_t **rfedit)
     432static errno_t font_edit_create(const char *display_svc, const char *fname,
     433    font_edit_t **rfedit)
    432434{
    433435        canvas_gc_t *cgc = NULL;
     
    439441        gfx_typeface_t *tface = NULL;
    440442        gfx_font_t *font = NULL;
     443        gfx_font_info_t *finfo;
    441444        gfx_font_props_t props;
    442445        gfx_font_metrics_t metrics;
     
    504507        gc = canvas_gc_get_ctx(cgc);
    505508
    506         rc = gfx_typeface_create(gc, &tface);
    507         if (rc != EOK) {
    508                 printf("Error creating typeface.\n");
    509                 goto error;
    510         }
    511 
    512         gfx_font_props_init(&props);
    513         gfx_font_metrics_init(&metrics);
    514 
    515         rc = gfx_font_create(tface, &props, &metrics, &font);
    516         if (rc != EOK) {
    517                 printf("Error creating font.\n");
    518                 goto error;
    519         }
    520 
    521         gfx_glyph_metrics_init(&gmetrics);
    522 
    523         rc = gfx_glyph_create(font, &gmetrics, &glyph);
    524         if (rc != EOK) {
    525                 printf("Error creating glyph.\n");
    526                 goto error;
    527         }
    528 
    529         rc = gfx_glyph_set_pattern(glyph, "A");
    530         if (rc != EOK) {
    531                 printf("Error setting glyph pattern.\n");
    532                 goto error;
     509        if (fname == NULL) {
     510                rc = gfx_typeface_create(gc, &tface);
     511                if (rc != EOK) {
     512                        printf("Error creating typeface.\n");
     513                        goto error;
     514                }
     515
     516                gfx_font_props_init(&props);
     517                gfx_font_metrics_init(&metrics);
     518
     519                rc = gfx_font_create(tface, &props, &metrics, &font);
     520                if (rc != EOK) {
     521                        printf("Error creating font.\n");
     522                        goto error;
     523                }
     524
     525                gfx_glyph_metrics_init(&gmetrics);
     526
     527                rc = gfx_glyph_create(font, &gmetrics, &glyph);
     528                if (rc != EOK) {
     529                        printf("Error creating glyph.\n");
     530                        goto error;
     531                }
     532
     533                rc = gfx_glyph_set_pattern(glyph, "A");
     534                if (rc != EOK) {
     535                        printf("Error setting glyph pattern.\n");
     536                        goto error;
     537                }
     538        } else {
     539                rc = gfx_typeface_open(gc, fname, &tface);
     540                if (rc != EOK) {
     541                        printf("Error opening typeface '%s.\n",
     542                            fname);
     543                        goto error;
     544                }
     545
     546                finfo = gfx_typeface_first_font(tface);
     547                rc = gfx_font_open(finfo, &font);
     548                if (rc != EOK) {
     549                        printf("Error opening font.\n");
     550                        goto error;
     551                }
     552
     553                glyph = gfx_font_first_glyph(font);
    533554        }
    534555
     
    543564        sig_connect(&canvas->keyboard_event, &canvas->widget,
    544565            font_edit_kbd_event);
     566
     567        if (fname == NULL)
     568                fname = "new.tpf";
    545569
    546570        fedit->cgc = cgc;
     
    549573        fedit->height = vh;
    550574        fedit->pen_color = 1;
     575        fedit->fname = fname;
    551576        fedit->typeface = tface;
    552577        fedit->font = font;
     
    583608static void print_syntax(void)
    584609{
    585         printf("Syntax: fontedit [-d <display>]\n");
     610        printf("Syntax: fontedit [-d <display>] [<file.tpf>]\n");
    586611}
    587612
     
    590615        errno_t rc;
    591616        const char *display_svc = DISPLAY_DEFAULT;
     617        const char *fname = NULL;
    592618        font_edit_t *fedit;
    593619        int i;
     
    611637        }
    612638
    613         rc = font_edit_create(display_svc, &fedit);
     639        /* File name argument? */
     640        if (i < argc) {
     641                fname = argv[i];
     642                ++i;
     643        }
     644
     645        /* Extra arguments? */
     646        if (i < argc) {
     647                printf("Unexpected argument '%s'.\n", argv[i]);
     648                print_syntax();
     649                return 1;
     650        }
     651
     652        rc = font_edit_create(display_svc, fname, &fedit);
    614653        if (rc != EOK)
    615654                return 1;
  • uspace/app/fontedit/fontedit.h

    r453f203b r16357ec  
    5454        /** Pen color (1 = set, 0 = reset) */
    5555        int pen_color;
     56        /** File name */
     57        const char *fname;
    5658        /** Typeface */
    5759        gfx_typeface_t *typeface;
Note: See TracChangeset for help on using the changeset viewer.