Changeset d53af3c8 in mainline for uspace/lib/gfxfont/src/typeface.c


Ignore:
Timestamp:
2020-09-18T23:00:44Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0ee3157
Parents:
7bef2d8
Message:

Save typeface to (RIFF) TPF file using newly introduced libriff

Originally I planned introducing libriff for better RIFF WAVE support.
It could be used for this purpose in the future (as well as for WebP
and other RIFF-based formats).

File:
1 edited

Legend:

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

    r7bef2d8 rd53af3c8  
    4141#include <gfx/typeface.h>
    4242#include <mem.h>
     43#include <riff/chunk.h>
    4344#include <stdlib.h>
    4445#include "../private/font.h"
    4546#include "../private/glyph.h"
     47#include "../private/tpf_file.h"
    4648#include "../private/typeface.h"
    4749
     
    111113}
    112114
     115/** Save typeface into a TPF file.
     116 *
     117 * @param tface Typeface
     118 * @param fname Destination file name
     119 * @return EOK on success or an error code
     120 */
     121errno_t gfx_typeface_save(gfx_typeface_t *tface, const char *fname)
     122{
     123        riffw_t *riffw = NULL;
     124        errno_t rc;
     125        gfx_font_info_t *finfo;
     126        riff_wchunk_t riffck;
     127
     128        rc = riff_wopen(fname, &riffw);
     129        if (rc != EOK)
     130                return rc;
     131
     132        rc = riff_wchunk_start(riffw, CKID_RIFF, &riffck);
     133        if (rc != EOK)
     134                goto error;
     135
     136        rc = riff_write_uint32(riffw, FORM_TPFC);
     137        if (rc != EOK)
     138                goto error;
     139
     140        finfo = gfx_typeface_first_font(tface);
     141        while (finfo != NULL) {
     142                /* Save font */
     143                rc = gfx_font_save(finfo, riffw);
     144                if (rc != EOK)
     145                        goto error;
     146
     147                finfo = gfx_typeface_next_font(finfo);
     148        }
     149
     150        rc = riff_wchunk_end(riffw, &riffck);
     151        if (rc != EOK)
     152                goto error;
     153
     154        rc = riff_wclose(riffw);
     155        if (rc != EOK)
     156                return rc;
     157
     158        return EOK;
     159error:
     160        if (riffw != NULL)
     161                riff_wclose(riffw);
     162        return rc;
     163}
     164
    113165/** @}
    114166 */
Note: See TracChangeset for help on using the changeset viewer.