Changeset 453f203b in mainline for uspace/lib/gfxfont/src/glyph.c


Ignore:
Timestamp:
2020-09-25T14:31:27Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
16357ec
Parents:
120031a5
git-author:
Jiri Svoboda <jiri@…> (2020-09-24 18:30:07)
git-committer:
Jiri Svoboda <jiri@…> (2020-09-25 14:31:27)
Message:

Cannot just write structures to TPF file

This would compromise portability of TPF files. What was I thinking?
Endianness and type widths must be fixed.

File:
1 edited

Legend:

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

    r120031a5 r453f203b  
    3535
    3636#include <assert.h>
     37#include <byteorder.h>
    3738#include <errno.h>
    3839#include <gfx/bitmap.h>
     
    326327        errno_t rc;
    327328        riff_rchunk_t mtrck;
     329        tpf_glyph_metrics_t tmetrics;
    328330        size_t nread;
    329331
     
    332334                return rc;
    333335
    334         rc = riff_read(&mtrck, (void *) metrics, sizeof(*metrics), &nread);
    335         if (rc != EOK || nread != sizeof(*metrics))
     336        rc = riff_read(&mtrck, (void *) &tmetrics, sizeof(tmetrics), &nread);
     337        if (rc != EOK || nread != sizeof(tmetrics))
    336338                return EIO;
    337339
     
    340342                return rc;
    341343
     344        metrics->advance = uint16_t_le2host(tmetrics.advance);
    342345        return EOK;
    343346}
     
    353356{
    354357        errno_t rc;
     358        tpf_glyph_metrics_t tmetrics;
    355359        riff_wchunk_t mtrck;
    356360
     361        tmetrics.advance = host2uint16_t_le(metrics->advance);
     362
    357363        rc = riff_wchunk_start(riffw, CKID_gmtr, &mtrck);
    358364        if (rc != EOK)
    359365                return rc;
    360366
    361         rc = riff_write(riffw, (void *) metrics, sizeof(*metrics));
     367        rc = riff_write(riffw, (void *) &tmetrics, sizeof(tmetrics));
    362368        if (rc != EOK)
    363369                return rc;
     
    466472{
    467473        errno_t rc;
     474        tpf_glyph_ror_t tror;
    468475        riff_rchunk_t rorck;
    469476        size_t nread;
     
    473480                return rc;
    474481
    475         rc = riff_read(&rorck, (void *) &glyph->rect, sizeof(glyph->rect),
     482        rc = riff_read(&rorck, (void *) &tror, sizeof(tror),
    476483            &nread);
    477         if (rc != EOK || nread != sizeof(glyph->rect))
     484        if (rc != EOK || nread != sizeof(tror))
    478485                return EIO;
    479486
    480         rc = riff_read(&rorck, (void *) &glyph->origin, sizeof(glyph->origin),
    481             &nread);
    482         if (rc != EOK || nread != sizeof(glyph->origin))
    483                 return EIO;
    484 
    485487        rc = riff_rchunk_end(&rorck);
    486488        if (rc != EOK)
    487489                return rc;
    488490
     491        glyph->rect.p0.x = uint32_t_le2host(tror.p0x);
     492        glyph->rect.p0.y = uint32_t_le2host(tror.p0y);
     493        glyph->rect.p1.x = uint32_t_le2host(tror.p1x);
     494        glyph->rect.p1.y = uint32_t_le2host(tror.p1y);
     495        glyph->origin.x = uint32_t_le2host(tror.orig_x);
     496        glyph->origin.y = uint32_t_le2host(tror.orig_y);
    489497        return EOK;
    490498}
     
    500508{
    501509        errno_t rc;
     510        tpf_glyph_ror_t tror;
    502511        riff_wchunk_t rorck;
    503512
     513        tror.p0x = host2uint32_t_le(glyph->rect.p0.x);
     514        tror.p0y = host2uint32_t_le(glyph->rect.p0.y);
     515        tror.p1x = host2uint32_t_le(glyph->rect.p1.x);
     516        tror.p1y = host2uint32_t_le(glyph->rect.p1.y);
     517        tror.orig_x = host2uint32_t_le(glyph->origin.x);
     518        tror.orig_y = host2uint32_t_le(glyph->origin.y);
     519
    504520        rc = riff_wchunk_start(riffw, CKID_gror, &rorck);
    505521        if (rc != EOK)
    506522                return rc;
    507523
    508         rc = riff_write(riffw, (void *) &glyph->rect, sizeof(glyph->rect));
    509         if (rc != EOK)
    510                 return rc;
    511 
    512         rc = riff_write(riffw, (void *) &glyph->origin, sizeof(glyph->origin));
     524        rc = riff_write(riffw, (void *) &tror, sizeof(tror));
    513525        if (rc != EOK)
    514526                return rc;
Note: See TracChangeset for help on using the changeset viewer.