Changeset 2cc1ec0 in mainline for uspace/lib/draw/font.h


Ignore:
Timestamp:
2014-08-27T21:23:01Z (10 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a9763c6
Parents:
613d644
Message:

Refactor drawing of fonts into multiple layers.

This will need further work to split glyph resolution
process to separate functions in order to support ligatures,
addition of kerning support, separate text layout functions,
etc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/draw/font.h

    r613d644 r2cc1ec0  
    11/*
    22 * Copyright (c) 2012 Petr Koupy
     3 * Copyright (c) 2014 Martin Sucha
    34 * All rights reserved.
    45 *
     
    4546typedef struct drawctx drawctx_t;
    4647
    47 typedef enum {
    48         FONT_DECODER_EMBEDDED
    49 } font_decoder_type_t;
     48typedef int metric_t;
    5049
    5150typedef struct {
    52         void (*init)(char *, uint16_t *, void **);
    53         uint16_t (*resolve)(const wchar_t, void *);
    54         surface_t *(*render)(uint16_t, uint16_t);
     51        /* Horizontal distance between origin and left side of the glyph */
     52        metric_t left_side_bearing;
     53       
     54        /* Width of the actual glyph drawn */
     55        metric_t width;
     56       
     57        /* Horizontal distance between right side of the glyph and origin
     58           of the next glyph */
     59        metric_t right_side_bearing;
     60       
     61        /* Vertical distance between baseline and top of the glyph
     62           (positive to top) */
     63        metric_t ascender;
     64       
     65        /* Height of the actual glyph drawn */
     66        metric_t height;
     67} glyph_metrics_t;
     68
     69static inline metric_t glyph_metrics_get_descender(glyph_metrics_t *gm)
     70{
     71        return gm->height - gm->ascender;
     72}
     73
     74static inline metric_t glyph_metrics_get_advancement(glyph_metrics_t *gm)
     75{
     76        return gm->left_side_bearing + gm->width + gm->right_side_bearing;
     77}
     78
     79typedef struct {
     80        /* Distance between top of the line and baseline */
     81        metric_t ascender;
     82       
     83        /* Distance between baseline and bottom of the line */
     84        metric_t descender;
     85       
     86        /* Distance between bottom of the line and top of the next line */
     87        metric_t leading;
     88} font_metrics_t;
     89
     90typedef uint32_t glyph_id_t;
     91
     92typedef struct {
     93        int (*get_font_metrics)(void *, font_metrics_t *);
     94        int (*resolve_glyph)(void *, wchar_t, glyph_id_t *);
     95        int (*get_glyph_metrics)(void *, glyph_id_t, glyph_metrics_t *);
     96        int (*render_glyph)(void *, drawctx_t *, source_t *, sysarg_t,
     97            sysarg_t, glyph_id_t);
    5598        void (*release)(void *);
    56 } font_decoder_t;
     99} font_backend_t;
    57100
    58 typedef struct font {
    59         uint16_t points;
    60         uint16_t glyph_count;
    61         surface_t **glyphs;
    62         font_decoder_t *decoder;
    63         void *decoder_data;
     101typedef struct {
     102        font_backend_t *backend;
     103        void *backend_data;
    64104} font_t;
    65105
    66 extern void font_init(font_t *, font_decoder_type_t, char *, uint16_t);
     106extern font_t *font_create(font_backend_t *, void *);
     107extern int font_get_metrics(font_t *, font_metrics_t *);
     108extern int font_resolve_glyph(font_t *, wchar_t, glyph_id_t *);
     109extern int font_get_glyph_metrics(font_t *, glyph_id_t, glyph_metrics_t *);
     110extern int font_render_glyph(font_t *, drawctx_t *, source_t *,
     111    sysarg_t, sysarg_t, glyph_id_t);
    67112extern void font_release(font_t *);
    68113
    69 extern void font_get_box(font_t *, char *, sysarg_t *, sysarg_t *);
    70 extern void font_draw_text(font_t *, drawctx_t *, source_t *, const char *,
     114extern int font_get_box(font_t *, char *, sysarg_t *, sysarg_t *);
     115extern int font_draw_text(font_t *, drawctx_t *, source_t *, const char *,
    71116    sysarg_t, sysarg_t);
    72117
Note: See TracChangeset for help on using the changeset viewer.