Changeset d884672 in mainline


Ignore:
Timestamp:
2020-09-30T20:26:24Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c9748a4
Parents:
38a4b6d
Message:

Need to set rectangle/origin for new glyph

Otherwise, having unsaved glyphs would lead to corruption once another
glyph is created, edited and saved.

Location:
uspace/lib/gfxfont
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/gfxfont/include/gfx/font.h

    r38a4b6d rd884672  
    5656extern gfx_glyph_t *gfx_font_first_glyph(gfx_font_t *);
    5757extern gfx_glyph_t *gfx_font_next_glyph(gfx_glyph_t *);
     58extern gfx_glyph_t *gfx_font_last_glyph(gfx_font_t *);
     59extern gfx_glyph_t *gfx_font_prev_glyph(gfx_glyph_t *);
    5860extern errno_t gfx_font_search_glyph(gfx_font_t *, const char *, gfx_glyph_t **,
    5961    size_t *);
  • uspace/lib/gfxfont/src/font.c

    r38a4b6d rd884672  
    274274}
    275275
     276/** Get last glyph in font.
     277 *
     278 * @param font Font
     279 * @return Last glyph or @c NULL if there are none
     280 */
     281gfx_glyph_t *gfx_font_last_glyph(gfx_font_t *font)
     282{
     283        link_t *link;
     284
     285        link = list_last(&font->glyphs);
     286        if (link == NULL)
     287                return NULL;
     288
     289        return list_get_instance(link, gfx_glyph_t, lglyphs);
     290}
     291
     292/** Get previous glyph in font.
     293 *
     294 * @param cur Current glyph
     295 * @return Previous glyph in font or @c NULL if @a cur was the last one
     296 */
     297gfx_glyph_t *gfx_font_prev_glyph(gfx_glyph_t *cur)
     298{
     299        link_t *link;
     300
     301        link = list_prev(&cur->lglyphs, &cur->font->glyphs);
     302        if (link == NULL)
     303                return NULL;
     304
     305        return list_get_instance(link, gfx_glyph_t, lglyphs);
     306}
     307
    276308/** Search for glyph that should be set for the beginning of a string.
    277309 *
  • uspace/lib/gfxfont/src/glyph.c

    r38a4b6d rd884672  
    3838#include <errno.h>
    3939#include <gfx/bitmap.h>
     40#include <gfx/font.h>
    4041#include <gfx/glyph.h>
    4142#include <io/pixelmap.h>
     
    7374{
    7475        gfx_glyph_t *glyph;
     76        gfx_glyph_t *last;
    7577        errno_t rc;
    7678
     
    8890        }
    8991
     92        last = gfx_font_last_glyph(font);
     93
    9094        glyph->metrics = *metrics;
    9195        list_append(&glyph->lglyphs, &glyph->font->glyphs);
    9296        list_initialize(&glyph->patterns);
     97
     98        if (last != NULL)
     99                glyph->rect.p0.x = last->rect.p1.x;
     100        else
     101                glyph->rect.p0.x = 0;
     102
     103        glyph->rect.p0.y = 0;
     104        glyph->rect.p1.x = glyph->rect.p0.x;
     105        glyph->rect.p1.y = glyph->rect.p1.y;
     106
     107        glyph->origin.x = glyph->rect.p0.x;
     108        glyph->origin.y = glyph->rect.p0.y;
     109
    93110        *rglyph = glyph;
    94111        return EOK;
  • uspace/lib/gfxfont/test/font.c

    r38a4b6d rd884672  
    287287}
    288288
     289/** Test gfx_font_last_glyph() */
     290PCUT_TEST(last_glyph)
     291{
     292        gfx_font_props_t props;
     293        gfx_font_metrics_t metrics;
     294        gfx_glyph_metrics_t gmetrics;
     295        gfx_typeface_t *tface;
     296        gfx_font_t *font;
     297        gfx_context_t *gc;
     298        gfx_glyph_t *glyph;
     299        gfx_glyph_t *glast;
     300        test_gc_t tgc;
     301        errno_t rc;
     302
     303        rc = gfx_context_new(&test_ops, (void *)&tgc, &gc);
     304        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     305
     306        gfx_font_metrics_init(&metrics);
     307
     308        rc = gfx_typeface_create(gc, &tface);
     309        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     310
     311        gfx_font_props_init(&props);
     312        gfx_font_metrics_init(&metrics);
     313        rc = gfx_font_create(tface, &props, &metrics, &font);
     314        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     315
     316        /* Should get NULL since there is no glyph in the font */
     317        glyph = gfx_font_last_glyph(font);
     318        PCUT_ASSERT_NULL(glyph);
     319
     320        /* Now add one */
     321        gfx_glyph_metrics_init(&gmetrics);
     322        rc = gfx_glyph_create(font, &gmetrics, &glyph);
     323        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     324
     325        /* gfx_font_last_glyph() should return the same */
     326        glast = gfx_font_last_glyph(font);
     327        PCUT_ASSERT_EQUALS(glyph, glast);
     328
     329        gfx_glyph_destroy(glyph);
     330        gfx_font_close(font);
     331        gfx_typeface_destroy(tface);
     332        rc = gfx_context_delete(gc);
     333        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     334}
     335
     336/** Test gfx_font_prev_glyph() */
     337PCUT_TEST(prev_glyph)
     338{
     339        gfx_font_props_t props;
     340        gfx_font_metrics_t metrics;
     341        gfx_glyph_metrics_t gmetrics;
     342        gfx_typeface_t *tface;
     343        gfx_font_t *font;
     344        gfx_context_t *gc;
     345        gfx_glyph_t *glyph1;
     346        gfx_glyph_t *glyph2;
     347        gfx_glyph_t *gfirst;
     348        gfx_glyph_t *gsecond;
     349        test_gc_t tgc;
     350        errno_t rc;
     351
     352        rc = gfx_context_new(&test_ops, (void *)&tgc, &gc);
     353        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     354
     355        gfx_font_metrics_init(&metrics);
     356
     357        rc = gfx_typeface_create(gc, &tface);
     358        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     359
     360        gfx_font_props_init(&props);
     361        gfx_font_metrics_init(&metrics);
     362        rc = gfx_font_create(tface, &props, &metrics, &font);
     363        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     364
     365        /* Add first glyph */
     366        gfx_glyph_metrics_init(&gmetrics);
     367        rc = gfx_glyph_create(font, &gmetrics, &glyph1);
     368        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     369
     370        /* Add second glyph */
     371        gfx_glyph_metrics_init(&gmetrics);
     372        rc = gfx_glyph_create(font, &gmetrics, &glyph2);
     373        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     374
     375        /* gfx_font_last_glyph() should return glyph2 */
     376        gsecond = gfx_font_last_glyph(font);
     377        PCUT_ASSERT_EQUALS(glyph2, gsecond);
     378
     379        /* gfx_font_prev_glyph() should return glyph1 */
     380        gfirst = gfx_font_prev_glyph(gsecond);
     381        PCUT_ASSERT_EQUALS(glyph1, gfirst);
     382
     383        gfx_glyph_destroy(glyph1);
     384        gfx_glyph_destroy(glyph2);
     385        gfx_font_close(font);
     386        gfx_typeface_destroy(tface);
     387        rc = gfx_context_delete(gc);
     388        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     389}
     390
    289391/** Test gfx_font_search_glyph() */
    290392PCUT_TEST(search_glyph)
Note: See TracChangeset for help on using the changeset viewer.