Changeset 1058


Ignore:
Timestamp:
Sep 18, 2006, 7:40:35 PM (14 years ago)
Author:
Sam Hocevar
Message:
  • Implemented cucul_get_font_blocks() to export the list of available glyphs.
Location:
libcaca/trunk/cucul
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/cucul/cucul.h

    r1039 r1058  
    207207unsigned int cucul_get_font_width(cucul_font_t *);
    208208unsigned int cucul_get_font_height(cucul_font_t *);
     209unsigned long int const *cucul_get_font_blocks(cucul_font_t *);
    209210int cucul_render_canvas(cucul_canvas_t *, cucul_font_t *, void *,
    210211                         unsigned int, unsigned int, unsigned int);
  • libcaca/trunk/cucul/font.c

    r1046 r1058  
    6969
    7070    struct block_info *block_list;
     71    unsigned int *user_block_list;
    7172    struct glyph_info *glyph_list;
    7273    uint8_t *font_data;
     
    189190    }
    190191
     192    f->user_block_list = malloc((f->header.blocks + 1)
     193                                  * 2 * sizeof(unsigned long int));
     194    if(!f->user_block_list)
     195    {
     196        free(f->block_list);
     197        free(f);
     198#if defined(HAVE_ERRNO_H)
     199        errno = ENOMEM;
     200#endif
     201        return NULL;
     202    }
     203
    191204    memcpy(f->block_list,
    192205           f->private + 8 + sizeof(struct font_header),
     
    202215            || f->block_list[i].index >= f->header.glyphs)
    203216        {
     217            free(f->user_block_list);
    204218            free(f->block_list);
    205219            free(f);
     
    209223            return NULL;
    210224        }
    211     }
     225
     226        f->user_block_list[i * 2] = f->block_list[i].start;
     227        f->user_block_list[i * 2 + 1] = f->block_list[i].stop;
     228    }
     229
     230    f->user_block_list[i * 2] = 0;
     231    f->user_block_list[i * 2] = 0;
    212232
    213233    f->glyph_list = malloc(f->header.glyphs * sizeof(struct glyph_info));
    214234    if(!f->glyph_list)
    215235    {
     236        free(f->user_block_list);
    216237        free(f->block_list);
    217238        free(f);
     
    238259        {
    239260            free(f->glyph_list);
     261            free(f->user_block_list);
    240262            free(f->block_list);
    241263            free(f);
     
    301323}
    302324
     325/** \brief Get a font's list of supported glyphs.
     326 *
     327 *  This function returns the list of Unicode blocks supported by the
     328 *  given font. The list is a zero-terminated list of indices. Here is
     329 *  an example:
     330 *
     331 *  \code
     332 *  {
     333 *       0x0,  0x80,   // Basic latin: A, B, C, a, b, c
     334 *      0x80, 0x100,   // Latin-1 supplement: "A, 'e, ^u
     335 *     0x530, 0x590,   // Armenian
     336 *       0x0,   0x0,   // END
     337 *  };
     338 *  \endcode
     339 *
     340 *  This function never fails.
     341 *
     342 *  \param f The font, as returned by cucul_load_font()
     343 *  \return The list of Unicode blocks supported by the font.
     344 */
     345unsigned long int const *cucul_get_font_blocks(cucul_font_t *f)
     346{
     347    return (unsigned long int const *)f->user_block_list;
     348}
     349
    303350/** \brief Free a font structure.
    304351 *
     
    316363{
    317364    free(f->glyph_list);
     365    free(f->user_block_list);
    318366    free(f->block_list);
    319367    free(f);
Note: See TracChangeset for help on using the changeset viewer.