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


Ignore:
Timestamp:
2020-09-17T15:28:03Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7bef2d8
Parents:
414020d9
Message:

Make negative quadrants actually work

File:
1 edited

Legend:

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

    r414020d9 r313ac8e  
    271271 *
    272272 * This is used to resize a glyph in the font bitmap. This changes
    273  * the bitmap widht and might also make the bitmap taller.
    274  * Width and height of the glyph is also adjusted accordingly.
     273 * the bitmap widht might also make the bitmap taller.
     274 * Dimensions of the glyph are also adjusted according to @a nrect.
    275275 *
    276276 * @param font Font
    277277 * @param glyph Glyph to replace
    278  * @param width Width of replacement space
    279  * @param height Height of replacement space
     278 * @param nrect Replacement rectangle
    280279 */
    281280errno_t gfx_font_splice_at_glyph(gfx_font_t *font, gfx_glyph_t *glyph,
    282     gfx_coord_t width, gfx_coord_t height)
     281    gfx_rect_t *nrect)
    283282{
    284283        gfx_glyph_t *g;
     
    286285        gfx_bitmap_params_t params;
    287286        gfx_coord_t dwidth;
     287        gfx_coord_t x0;
    288288        errno_t rc;
    289289
    290290        /* Change of width of glyph */
    291         dwidth = width - (glyph->rect.p1.x - glyph->rect.p0.x);
     291        dwidth = (nrect->p1.x - nrect->p0.x) -
     292            (glyph->rect.p1.x - glyph->rect.p0.x);
    292293
    293294        /* Create new font bitmap, wider by dwidth pixels */
     
    295296        params.rect = font->rect;
    296297        params.rect.p1.x += dwidth;
    297         if (height > params.rect.p1.y)
    298                 params.rect.p1.y = height;
     298        if (nrect->p1.y - nrect->p0.y > params.rect.p1.y)
     299                params.rect.p1.y = nrect->p1.y - nrect->p0.y;
    299300
    300301        rc = gfx_bitmap_create(font->typeface->gc, &params, NULL, &nbitmap);
    301302        if (rc != EOK)
    302303                goto error;
     304
     305        /*
     306         * In x0 we compute the left margin of @a glyph. We start with
     307         * zero and then, if there are any preceding glyphs, we set it
     308         * to the right margin of the last one.
     309         */
     310        x0 = 0;
    303311
    304312        /* Transfer glyphs before @a glyph */
     
    310318                if (rc != EOK)
    311319                        goto error;
     320
     321                /* Left margin of the next glyph */
     322                x0 = g->rect.p1.x;
    312323
    313324                g = gfx_font_next_glyph(g);
     
    331342        }
    332343
    333         /* Update glyph width and height */
    334         glyph->rect.p1.x = glyph->rect.p0.x + width;
    335         glyph->rect.p1.y = glyph->rect.p0.y + height;
     344        /* Place glyph rectangle inside the newly created space */
     345        glyph->origin.x = x0 - nrect->p0.x;
     346        glyph->origin.y = 0 - nrect->p0.y;
     347        gfx_rect_translate(&glyph->origin, nrect, &glyph->rect);
    336348
    337349        /* Update font bitmap */
Note: See TracChangeset for help on using the changeset viewer.