Changeset d2100e2 in mainline for uspace/lib/gfxfont/src/font.c


Ignore:
Timestamp:
2020-08-09T18:40:28Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
06b8383
Parents:
5592c56
Message:

Finish glyph bitmap operations and tests

Setting/getting pixel, opening/saving glyph bitmap.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/gfxfont/src/font.c

    r5592c56 rd2100e2  
    3737#include <assert.h>
    3838#include <errno.h>
     39#include <gfx/bitmap.h>
    3940#include <gfx/font.h>
    4041#include <gfx/glyph.h>
     
    7071{
    7172        gfx_font_t *font;
     73        gfx_bitmap_params_t params;
    7274        errno_t rc;
    7375
     
    8183        if (rc != EOK) {
    8284                assert(rc == EINVAL);
     85                free(font);
     86                return rc;
     87        }
     88
     89        /* Create font bitmap */
     90        gfx_bitmap_params_init(&params);
     91        params.rect = font->rect;
     92
     93        rc = gfx_bitmap_create(font->gc, &params, NULL, &font->bitmap);
     94        if (rc != EOK) {
    8395                free(font);
    8496                return rc;
     
    190202}
    191203
     204/** Replace glyph graphic with empty space of specified width.
     205 *
     206 * This is used to resize a glyph in the font bitmap. This changes
     207 * the bitmap widht and might also make the bitmap taller.
     208 * Width and height of the glyph is also adjusted accordingly.
     209 *
     210 * @param font Font
     211 * @param glyph Glyph to replace
     212 * @param width Width of replacement space
     213 * @param height Height of replacement space
     214 */
     215errno_t gfx_font_splice_at_glyph(gfx_font_t *font, gfx_glyph_t *glyph,
     216    gfx_coord_t width, gfx_coord_t height)
     217{
     218        gfx_glyph_t *g;
     219        gfx_bitmap_t *nbitmap;
     220        gfx_bitmap_params_t params;
     221        gfx_coord_t dwidth;
     222        errno_t rc;
     223
     224        /* Change of width of glyph */
     225        dwidth = width - (glyph->rect.p1.x - glyph->rect.p0.x);
     226
     227        /* Create new font bitmap, wider by dwidth pixels */
     228        gfx_bitmap_params_init(&params);
     229        params.rect = font->rect;
     230        params.rect.p1.x += dwidth;
     231        if (height > params.rect.p1.y)
     232                params.rect.p1.y = height;
     233
     234        rc = gfx_bitmap_create(font->gc, &params, NULL, &nbitmap);
     235        if (rc != EOK)
     236                goto error;
     237
     238        /* Transfer glyphs before @a glyph */
     239        g = gfx_font_first_glyph(font);
     240        while (g != glyph) {
     241                assert(g != NULL);
     242
     243                rc = gfx_glyph_transfer(g, 0, nbitmap, &params.rect);
     244                if (rc != EOK)
     245                        goto error;
     246
     247                g = gfx_font_next_glyph(g);
     248        }
     249
     250        /* Skip @a glyph */
     251        g = gfx_font_next_glyph(g);
     252
     253        /* Transfer glyphs after glyph */
     254        while (g != NULL) {
     255                rc = gfx_glyph_transfer(g, dwidth, nbitmap, &params.rect);
     256                if (rc != EOK)
     257                        goto error;
     258
     259                /* Update glyph coordinates */
     260                g->rect.p0.x += dwidth;
     261                g->rect.p1.x += dwidth;
     262                g->origin.x += dwidth;
     263
     264                g = gfx_font_next_glyph(g);
     265        }
     266
     267        /* Update glyph width and height */
     268        glyph->rect.p1.x = glyph->rect.p0.x + width;
     269        glyph->rect.p1.y = glyph->rect.p0.y + height;
     270
     271        /* Update font bitmap */
     272        gfx_bitmap_destroy(font->bitmap);
     273        font->bitmap = nbitmap;
     274        font->rect = params.rect;
     275
     276        return EOK;
     277error:
     278        if (nbitmap != NULL)
     279                gfx_bitmap_destroy(nbitmap);
     280        return rc;
     281}
     282
    192283/** @}
    193284 */
Note: See TracChangeset for help on using the changeset viewer.