Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/gfxfont/test/text.c

    r1fa6292 r9eb8d12  
    3636#include "../private/font.h"
    3737#include "../private/typeface.h"
    38 #include "../private/testgc.h"
    3938
    4039PCUT_INIT;
    4140
    4241PCUT_TEST_SUITE(text);
     42
     43static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
     44static errno_t testgc_set_color(void *, gfx_color_t *);
     45static errno_t testgc_fill_rect(void *, gfx_rect_t *);
     46static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
     47    gfx_bitmap_alloc_t *, void **);
     48static errno_t testgc_bitmap_destroy(void *);
     49static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
     50static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
     51
     52static gfx_context_ops_t test_ops = {
     53        .set_clip_rect = testgc_set_clip_rect,
     54        .set_color = testgc_set_color,
     55        .fill_rect = testgc_fill_rect,
     56        .bitmap_create = testgc_bitmap_create,
     57        .bitmap_destroy = testgc_bitmap_destroy,
     58        .bitmap_render = testgc_bitmap_render,
     59        .bitmap_get_alloc = testgc_bitmap_get_alloc
     60};
     61
     62typedef struct {
     63        gfx_bitmap_params_t bm_params;
     64        void *bm_pixels;
     65        gfx_rect_t bm_srect;
     66        gfx_coord2_t bm_offs;
     67} test_gc_t;
     68
     69typedef struct {
     70        test_gc_t *tgc;
     71        gfx_bitmap_alloc_t alloc;
     72        bool myalloc;
     73} testgc_bitmap_t;
    4374
    4475/** Test text width computation with a dummy font */
     
    104135
    105136        gfx_text_fmt_init(&fmt);
    106         fmt.font = font;
    107137        fmt.color = color;
    108138        pos.x = 0;
    109139        pos.y = 0;
    110140
    111         rc = gfx_puttext(&pos, &fmt, "Hello world!");
     141        rc = gfx_puttext(font, &pos, &fmt, "Hello world!");
    112142        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    113143
     
    151181
    152182        gfx_text_fmt_init(&fmt);
    153         fmt.font = font;
    154183        fmt.color = color;
    155184        pos.x = 0;
    156185        pos.y = 0;
    157186
    158         rc = gfx_puttext(&pos, &fmt, "Hello world!");
     187        rc = gfx_puttext(font, &pos, &fmt, "Hello world!");
    159188        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    160189
     
    216245
    217246        gfx_text_fmt_init(&fmt);
    218         fmt.font = font;
    219247        anchor.x = 10;
    220248        anchor.y = 0;
     
    222250        fpos.x = 9;
    223251        fpos.y = 0;
    224         off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos);
     252        off = gfx_text_find_pos(font, &anchor, &fmt, "Aii", &fpos);
    225253        PCUT_ASSERT_INT_EQUALS(0, off);
    226254
    227255        fpos.x = 10;
    228256        fpos.y = 0;
    229         off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos);
     257        off = gfx_text_find_pos(font, &anchor, &fmt, "Aii", &fpos);
    230258        PCUT_ASSERT_INT_EQUALS(0, off);
    231259
    232260        fpos.x = 11;
    233261        fpos.y = 0;
    234         off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos);
     262        off = gfx_text_find_pos(font, &anchor, &fmt, "Aii", &fpos);
    235263        PCUT_ASSERT_INT_EQUALS(0, off);
    236264
    237265        fpos.x = 19;
    238266        fpos.y = 0;
    239         off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos);
     267        off = gfx_text_find_pos(font, &anchor, &fmt, "Aii", &fpos);
    240268        PCUT_ASSERT_INT_EQUALS(1, off);
    241269
    242270        fpos.x = 20;
    243271        fpos.y = 0;
    244         off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos);
     272        off = gfx_text_find_pos(font, &anchor, &fmt, "Aii", &fpos);
    245273        PCUT_ASSERT_INT_EQUALS(2, off);
    246274
    247275        fpos.x = 21;
    248276        fpos.y = 0;
    249         off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos);
     277        off = gfx_text_find_pos(font, &anchor, &fmt, "Aii", &fpos);
    250278        PCUT_ASSERT_INT_EQUALS(3, off);
    251279
    252280        fpos.x = 22;
    253281        fpos.y = 0;
    254         off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos);
     282        off = gfx_text_find_pos(font, &anchor, &fmt, "Aii", &fpos);
    255283        PCUT_ASSERT_INT_EQUALS(3, off);
    256284
     
    290318        anchor.y = 0;
    291319        gfx_text_fmt_init(&fmt);
    292         fmt.font = font;
    293320
    294321        fpos.x = 9;
    295322        fpos.y = 0;
    296         off = gfx_text_find_pos(&anchor, &fmt, "Abc", &fpos);
     323        off = gfx_text_find_pos(font, &anchor, &fmt, "Abc", &fpos);
    297324        PCUT_ASSERT_INT_EQUALS(0, off);
    298325
    299326        fpos.x = 10;
    300327        fpos.y = 0;
    301         off = gfx_text_find_pos(&anchor, &fmt, "Abc", &fpos);
     328        off = gfx_text_find_pos(font, &anchor, &fmt, "Abc", &fpos);
    302329        PCUT_ASSERT_INT_EQUALS(0, off);
    303330
    304331        fpos.x = 11;
    305332        fpos.y = 0;
    306         off = gfx_text_find_pos(&anchor, &fmt, "Abc", &fpos);
     333        off = gfx_text_find_pos(font, &anchor, &fmt, "Abc", &fpos);
    307334        PCUT_ASSERT_INT_EQUALS(1, off);
    308335
    309336        fpos.x = 12;
    310337        fpos.y = 0;
    311         off = gfx_text_find_pos(&anchor, &fmt, "Abc", &fpos);
     338        off = gfx_text_find_pos(font, &anchor, &fmt, "Abc", &fpos);
    312339        PCUT_ASSERT_INT_EQUALS(2, off);
    313340
    314341        fpos.x = 13;
    315342        fpos.y = 0;
    316         off = gfx_text_find_pos(&anchor, &fmt, "Abc", &fpos);
     343        off = gfx_text_find_pos(font, &anchor, &fmt, "Abc", &fpos);
    317344        PCUT_ASSERT_INT_EQUALS(3, off);
    318345
    319346        fpos.x = 14;
    320347        fpos.y = 0;
    321         off = gfx_text_find_pos(&anchor, &fmt, "Abc", &fpos);
     348        off = gfx_text_find_pos(font, &anchor, &fmt, "Abc", &fpos);
    322349        PCUT_ASSERT_INT_EQUALS(3, off);
    323350
     
    358385        anchor.y = 20;
    359386        gfx_text_fmt_init(&fmt);
    360         fmt.font = font;
    361387        fmt.color = color;
    362388
    363         gfx_text_cont(&anchor, &fmt, "Abc", &cpos, &cfmt);
     389        gfx_text_cont(font, &anchor, &fmt, "Abc", &cpos, &cfmt);
    364390
    365391        PCUT_ASSERT_INT_EQUALS(13, cpos.x);
     
    405431        anchor.y = 20;
    406432        gfx_text_fmt_init(&fmt);
    407         fmt.font = font;
    408433        fmt.color = color;
    409434
    410         gfx_text_rect(&anchor, &fmt, "Abc", &rect);
     435        gfx_text_rect(font, &anchor, &fmt, "Abc", &rect);
    411436
    412437        PCUT_ASSERT_INT_EQUALS(10, rect.p0.x);
     
    423448}
    424449
     450static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
     451{
     452        return EOK;
     453}
     454
     455static errno_t testgc_set_color(void *arg, gfx_color_t *color)
     456{
     457        return EOK;
     458}
     459
     460static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
     461{
     462        return EOK;
     463}
     464
     465static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
     466    gfx_bitmap_alloc_t *alloc, void **rbm)
     467{
     468        test_gc_t *tgc = (test_gc_t *) arg;
     469        testgc_bitmap_t *tbm;
     470
     471        tbm = calloc(1, sizeof(testgc_bitmap_t));
     472        if (tbm == NULL)
     473                return ENOMEM;
     474
     475        if (alloc == NULL) {
     476                tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
     477                    sizeof(uint32_t);
     478                tbm->alloc.off0 = 0;
     479                tbm->alloc.pixels = calloc(sizeof(uint32_t),
     480                    tbm->alloc.pitch * (params->rect.p1.y - params->rect.p0.y));
     481                tbm->myalloc = true;
     482                if (tbm->alloc.pixels == NULL) {
     483                        free(tbm);
     484                        return ENOMEM;
     485                }
     486        } else {
     487                tbm->alloc = *alloc;
     488        }
     489
     490        tbm->tgc = tgc;
     491        tgc->bm_params = *params;
     492        tgc->bm_pixels = tbm->alloc.pixels;
     493        *rbm = (void *)tbm;
     494        return EOK;
     495}
     496
     497static errno_t testgc_bitmap_destroy(void *bm)
     498{
     499        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     500        if (tbm->myalloc)
     501                free(tbm->alloc.pixels);
     502        free(tbm);
     503        return EOK;
     504}
     505
     506static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
     507    gfx_coord2_t *offs)
     508{
     509        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     510        tbm->tgc->bm_srect = *srect;
     511        tbm->tgc->bm_offs = *offs;
     512        return EOK;
     513}
     514
     515static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
     516{
     517        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     518        *alloc = tbm->alloc;
     519        return EOK;
     520}
     521
    425522PCUT_EXPORT(text);
Note: See TracChangeset for help on using the changeset viewer.