source: mainline/uspace/lib/draw/font.h@ 2cc1ec0

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 2cc1ec0 was 2cc1ec0, checked in by Martin Sucha <sucha14@…>, 11 years ago

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.

  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[afa6e74]1/*
[6d5e378]2 * Copyright (c) 2012 Petr Koupy
[2cc1ec0]3 * Copyright (c) 2014 Martin Sucha
[afa6e74]4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
[6d5e378]30/** @addtogroup draw
[67ebf21]31 * @{
32 */
[6d5e378]33/**
34 * @file
[67ebf21]35 */
36
[6d5e378]37#ifndef DRAW_FONT_H_
38#define DRAW_FONT_H_
[afa6e74]39
[7c014d1]40#include <sys/types.h>
41
[6d5e378]42#include "surface.h"
43#include "source.h"
[afa6e74]44
[6d5e378]45struct drawctx;
46typedef struct drawctx drawctx_t;
47
[2cc1ec0]48typedef int metric_t;
[6d5e378]49
50typedef struct {
[2cc1ec0]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);
[6d5e378]98 void (*release)(void *);
[2cc1ec0]99} font_backend_t;
100
101typedef struct {
102 font_backend_t *backend;
103 void *backend_data;
[6d5e378]104} font_t;
105
[2cc1ec0]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);
[6d5e378]112extern void font_release(font_t *);
113
[2cc1ec0]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 *,
[6d5e378]116 sysarg_t, sysarg_t);
[afa6e74]117
118#endif
[67ebf21]119
120/** @}
121 */
Note: See TracBrowser for help on using the repository browser.