Changeset d53af3c8 in mainline for uspace/lib/gfxfont/src/glyph.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/glyph.c

    r7bef2d8 rd53af3c8  
    4444#include "../private/font.h"
    4545#include "../private/glyph.h"
     46#include "../private/tpf_file.h"
    4647
    4748/** Initialize glyph metrics structure.
     
    314315}
    315316
     317/** Save glyph metrics to RIFF TPF file.
     318 *
     319 * @param metrics Glyph metrics
     320 * @param riffw RIFF writer
     321 * @return EOK on success or an error code
     322 */
     323static errno_t gfx_glyph_metrics_save(gfx_glyph_metrics_t *metrics,
     324    riffw_t *riffw)
     325{
     326        errno_t rc;
     327        riff_wchunk_t mtrck;
     328
     329        rc = riff_wchunk_start(riffw, CKID_gmtr, &mtrck);
     330        if (rc != EOK)
     331                return rc;
     332
     333        rc = riff_wchunk_write(riffw, (void *) metrics, sizeof(*metrics));
     334        if (rc != EOK)
     335                return rc;
     336
     337        rc = riff_wchunk_end(riffw, &mtrck);
     338        if (rc != EOK)
     339                return rc;
     340
     341        return EOK;
     342}
     343
     344/** Save glyph patterns to RIFF TPF file.
     345 *
     346 * @param glyph Glyph
     347 * @param riffw RIFF writer
     348 * @return EOK on success or an error code
     349 */
     350static errno_t gfx_glyph_patterns_save(gfx_glyph_t *glyph, riffw_t *riffw)
     351{
     352        errno_t rc;
     353        riff_wchunk_t patck;
     354        gfx_glyph_pattern_t *pat;
     355        const char *str;
     356
     357        rc = riff_wchunk_start(riffw, CKID_gpat, &patck);
     358        if (rc != EOK)
     359                return rc;
     360
     361        pat = gfx_glyph_first_pattern(glyph);
     362        while (pat != NULL) {
     363                str = gfx_glyph_pattern_str(pat);
     364
     365                rc = riff_wchunk_write(riffw, (void *) str, 1 + str_size(str));
     366                if (rc != EOK)
     367                        return rc;
     368
     369                pat = gfx_glyph_next_pattern(pat);
     370        }
     371
     372        rc = riff_wchunk_end(riffw, &patck);
     373        if (rc != EOK)
     374                return rc;
     375
     376        return EOK;
     377}
     378
     379/** Save glyph rectangle/origin to RIFF TPF file.
     380 *
     381 * @param glyph Glyph
     382 * @param riffw RIFF writer
     383 * @return EOK on success or an error code
     384 */
     385static errno_t gfx_glyph_rectangle_origin_save(gfx_glyph_t *glyph,
     386    riffw_t *riffw)
     387{
     388        errno_t rc;
     389        riff_wchunk_t rorck;
     390
     391        rc = riff_wchunk_start(riffw, CKID_gror, &rorck);
     392        if (rc != EOK)
     393                return rc;
     394
     395        rc = riff_wchunk_write(riffw, (void *) &glyph->rect,
     396            sizeof(glyph->rect));
     397        if (rc != EOK)
     398                return rc;
     399
     400        rc = riff_wchunk_write(riffw, (void *) &glyph->origin,
     401            sizeof(glyph->origin));
     402        if (rc != EOK)
     403                return rc;
     404
     405        rc = riff_wchunk_end(riffw, &rorck);
     406        if (rc != EOK)
     407                return rc;
     408
     409        return EOK;
     410}
     411
     412/** Save glyph into RIFF TPF file.
     413 *
     414 * @param glyph Glyph
     415 * @param riffw RIFF writer
     416 */
     417errno_t gfx_glyph_save(gfx_glyph_t *glyph, riffw_t *riffw)
     418{
     419        errno_t rc;
     420        riff_wchunk_t glyphck;
     421
     422        rc = riff_wchunk_start(riffw, CKID_LIST, &glyphck);
     423        if (rc != EOK)
     424                return rc;
     425
     426        rc = riff_write_uint32(riffw, LTYPE_glph);
     427        if (rc != EOK)
     428                return rc;
     429
     430        rc = gfx_glyph_metrics_save(&glyph->metrics, riffw);
     431        if (rc != EOK)
     432                return rc;
     433
     434        rc = gfx_glyph_patterns_save(glyph, riffw);
     435        if (rc != EOK)
     436                return rc;
     437
     438        rc = gfx_glyph_rectangle_origin_save(glyph, riffw);
     439        if (rc != EOK)
     440                return rc;
     441
     442        rc = riff_wchunk_end(riffw, &glyphck);
     443        if (rc != EOK)
     444                return rc;
     445
     446        return EOK;
     447}
     448
    316449/** @}
    317450 */
Note: See TracChangeset for help on using the changeset viewer.