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


Ignore:
Timestamp:
2020-07-21T22:48:59Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5592c56
Parents:
703c743
Message:

Flesh out most of font, glyph and glyph bitmap implementation and tests

File:
1 edited

Legend:

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

    r703c743 rc78a03d  
    3939#include <mem.h>
    4040#include <stdlib.h>
     41#include <str.h>
     42#include "../private/font.h"
    4143#include "../private/glyph.h"
    4244
     
    8385
    8486        glyph->metrics = *metrics;
     87        list_append(&glyph->lglyphs, &glyph->font->glyphs);
     88        list_initialize(&glyph->patterns);
    8589        *rglyph = glyph;
    8690        return EOK;
     
    9397void gfx_glyph_destroy(gfx_glyph_t *glyph)
    9498{
     99        list_remove(&glyph->lglyphs);
    95100        free(glyph);
    96101}
     
    130135errno_t gfx_glyph_set_pattern(gfx_glyph_t *glyph, const char *pattern)
    131136{
     137        gfx_glyph_pattern_t *pat;
     138
     139        pat = gfx_glyph_first_pattern(glyph);
     140        while (pat != NULL) {
     141                if (str_cmp(pat->text, pattern) == 0) {
     142                        /* Already set */
     143                        return EOK;
     144                }
     145
     146                pat = gfx_glyph_next_pattern(pat);
     147        }
     148
     149        pat = calloc(1, sizeof(gfx_glyph_pattern_t));
     150        if (pat == NULL)
     151                return ENOMEM;
     152
     153        pat->glyph = glyph;
     154        pat->text = str_dup(pattern);
     155        if (pat->text == NULL) {
     156                free(pat);
     157                return ENOMEM;
     158        }
     159
     160        list_append(&pat->lpatterns, &glyph->patterns);
    132161        return EOK;
    133162}
     
    142171void gfx_glyph_clear_pattern(gfx_glyph_t *glyph, const char *pattern)
    143172{
    144 }
    145 
    146 /** Open glyph bitmap for editing.
    147  *
    148  * @param glyph Glyph
    149  * @param rbmp Place to store glyph bitmap
    150  * @return EOK on success, ENOMEM if out of memory
    151  */
    152 errno_t gfx_glyph_open_bmp(gfx_glyph_t *glyph, gfx_glyph_bmp_t **rbmp)
    153 {
    154         return EOK;
     173        gfx_glyph_pattern_t *pat;
     174
     175        pat = gfx_glyph_first_pattern(glyph);
     176        while (pat != NULL) {
     177                if (str_cmp(pat->text, pattern) == 0) {
     178                        list_remove(&pat->lpatterns);
     179                        free(pat->text);
     180                        free(pat);
     181                        return;
     182                }
     183
     184                pat = gfx_glyph_next_pattern(pat);
     185        }
     186}
     187
     188/** Determine if glyph maches the beginning of a string.
     189 *
     190 * @param glyph Glyph
     191 * @param str String
     192 * @param rsize Place to store number of bytes in the matching pattern
     193 * @return @c true iff glyph matches the beginning of the string
     194 */
     195bool gfx_glyph_matches(gfx_glyph_t *glyph, const char *str, size_t *rsize)
     196{
     197        gfx_glyph_pattern_t *pat;
     198
     199        pat = gfx_glyph_first_pattern(glyph);
     200        while (pat != NULL) {
     201                if (str_test_prefix(str, pat->text)) {
     202                        *rsize = str_size(pat->text);
     203                        return true;
     204                }
     205
     206                pat = gfx_glyph_next_pattern(pat);
     207        }
     208
     209        return false;
     210}
     211
     212/** Get first glyph pattern.
     213 *
     214 * @param glyph Glyph
     215 * @return First pattern or @c NULL if there are none
     216 */
     217gfx_glyph_pattern_t *gfx_glyph_first_pattern(gfx_glyph_t *glyph)
     218{
     219        link_t *link;
     220
     221        link = list_first(&glyph->patterns);
     222        if (link == NULL)
     223                return NULL;
     224
     225        return list_get_instance(link, gfx_glyph_pattern_t, lpatterns);
     226}
     227
     228/** Get next glyph pattern.
     229 *
     230 * @param cur Current pattern
     231 * @return Next pattern or @c NULL if there are none
     232 */
     233gfx_glyph_pattern_t *gfx_glyph_next_pattern(gfx_glyph_pattern_t *cur)
     234{
     235        link_t *link;
     236
     237        link = list_next(&cur->lpatterns, &cur->glyph->patterns);
     238        if (link == NULL)
     239                return NULL;
     240
     241        return list_get_instance(link, gfx_glyph_pattern_t, lpatterns);
     242}
     243
     244/** Return pattern string.
     245 *
     246 * @param pattern Pattern
     247 * @return Pattern string (owned by @a pattern)
     248 */
     249const char *gfx_glyph_pattern_str(gfx_glyph_pattern_t *pattern)
     250{
     251        return pattern->text;
    155252}
    156253
Note: See TracChangeset for help on using the changeset viewer.