Changeset a57c70c in mainline


Ignore:
Timestamp:
2020-09-11T13:38:00Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
414020d9
Parents:
e2776ff
git-author:
Jiri Svoboda <jiri@…> (2020-09-10 17:37:41)
git-committer:
Jiri Svoboda <jiri@…> (2020-09-11 13:38:00)
Message:

Save glyph with S key and get a preview

Location:
uspace
Files:
6 edited

Legend:

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

    re2776ff ra57c70c  
    120120}
    121121
     122/** Handle font editor keyboard event.
     123 *
     124 * @param widget Canvas widget
     125 * @param data Position event
     126 */
     127static void font_edit_kbd_event(widget_t *widget, void *data)
     128{
     129        kbd_event_t *event = (kbd_event_t *) data;
     130        font_edit_t *fedit;
     131
     132        fedit = (font_edit_t *) widget_get_data(widget);
     133
     134        if (event->type == KEY_PRESS) {
     135                if (event->key == KC_S) {
     136                        printf("Save!\n");
     137                        (void) gfx_glyph_bmp_save(fedit->gbmp);
     138                        font_edit_paint(fedit);
     139                }
     140        }
     141}
     142
    122143/** Convert glyph pixel coordinates to displayed rectangle.
    123144 *
     
    139160        drect->p1.x = glyph_orig_x + (x + 1) * glyph_scale;
    140161        drect->p1.y = glyph_orig_y + (y + 1) * glyph_scale;
     162}
     163
     164/** Paint font preview.
     165 *
     166 * @param fedit Font editor
     167 */
     168static errno_t font_edit_paint_preview(font_edit_t *fedit)
     169{
     170        gfx_glyph_metrics_t gmetrics;
     171        size_t stradv;
     172        const char *cp;
     173        gfx_glyph_t *glyph;
     174        gfx_coord2_t pos;
     175        errno_t rc;
     176
     177        cp = "ABCD";
     178        pos.x = 20;
     179        pos.y = 20;
     180
     181        while (*cp != '\0') {
     182                rc = gfx_font_search_glyph(fedit->font, cp, &glyph, &stradv);
     183                if (rc != EOK) {
     184                        ++cp;
     185                        continue;
     186                }
     187
     188                gfx_glyph_get_metrics(glyph, &gmetrics);
     189
     190                rc = gfx_glyph_render(glyph, &pos);
     191                if (rc != EOK)
     192                        return rc;
     193
     194                cp += stradv;
     195                pos.x += gmetrics.advance;
     196        }
     197
     198        return EOK;
    141199}
    142200
     
    224282
    225283        rc = font_edit_paint_gbmp(fedit);
     284        if (rc != EOK)
     285                return rc;
     286
     287        rc = font_edit_paint_preview(fedit);
    226288        if (rc != EOK)
    227289                return rc;
     
    334396        }
    335397
     398        rc = gfx_glyph_set_pattern(glyph, "A");
     399        if (rc != EOK) {
     400                printf("Error setting glyph pattern.\n");
     401                goto error;
     402        }
     403
    336404        rc = gfx_glyph_bmp_open(glyph, &bmp);
    337405        if (rc != EOK) {
     
    342410        sig_connect(&canvas->position_event, &canvas->widget,
    343411            font_edit_pos_event);
     412        sig_connect(&canvas->keyboard_event, &canvas->widget,
     413            font_edit_kbd_event);
    344414
    345415        fedit->cgc = cgc;
     
    348418        fedit->height = vh;
    349419        fedit->typeface = tface;
     420        fedit->font = font;
    350421        fedit->glyph = glyph;
    351422        fedit->gbmp = bmp;
  • uspace/app/fontedit/fontedit.h

    re2776ff ra57c70c  
    5454        /** Typeface */
    5555        gfx_typeface_t *typeface;
     56        /** Font */
     57        gfx_font_t *font;
    5658        /** Glyph */
    5759        gfx_glyph_t *glyph;
  • uspace/lib/gfxfont/include/gfx/font.h

    re2776ff ra57c70c  
    5656extern gfx_glyph_t *gfx_font_first_glyph(gfx_font_t *);
    5757extern gfx_glyph_t *gfx_font_next_glyph(gfx_glyph_t *);
    58 extern int gfx_font_search_glyph(gfx_font_t *, const char *, gfx_glyph_t **,
     58extern errno_t gfx_font_search_glyph(gfx_font_t *, const char *, gfx_glyph_t **,
    5959    size_t *);
    6060
  • uspace/lib/gfxfont/include/gfx/glyph.h

    re2776ff ra57c70c  
    5555extern gfx_glyph_pattern_t *gfx_glyph_next_pattern(gfx_glyph_pattern_t *);
    5656extern const char *gfx_glyph_pattern_str(gfx_glyph_pattern_t *);
     57extern errno_t gfx_glyph_render(gfx_glyph_t *, gfx_coord2_t *);
    5758
    5859#endif
  • uspace/lib/gfxfont/src/font.c

    re2776ff ra57c70c  
    248248 * @return EOK on success, ENOENT if no matching glyph was found
    249249 */
    250 int gfx_font_search_glyph(gfx_font_t *font, const char *str,
     250errno_t gfx_font_search_glyph(gfx_font_t *font, const char *str,
    251251    gfx_glyph_t **rglyph, size_t *rsize)
    252252{
  • uspace/lib/gfxfont/src/glyph.c

    re2776ff ra57c70c  
    254254}
    255255
     256/** Render glyph to GC.
     257 *
     258 * @param glyph Glyph
     259 * @param pos Position to render to (where glyph origin is placed)
     260 */
     261errno_t gfx_glyph_render(gfx_glyph_t *glyph, gfx_coord2_t *pos)
     262{
     263        gfx_coord2_t offs;
     264
     265        gfx_coord2_subtract(pos, &glyph->origin, &offs);
     266
     267        return gfx_bitmap_render(glyph->font->bitmap, &glyph->rect, &offs);
     268}
     269
    256270/** Transfer glyph to new font bitmap.
    257271 *
Note: See TracChangeset for help on using the changeset viewer.