source: mainline/uspace/lib/draw/font.h@ cc36562b

Last change on this file since cc36562b was 7c3fb9b, checked in by Jiri Svoboda <jiri@…>, 7 years ago

Fix block comment formatting (ccheck).

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 * Copyright (c) 2012 Petr Koupy
3 * Copyright (c) 2014 Martin Sucha
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
30/** @addtogroup draw
31 * @{
32 */
33/**
34 * @file
35 */
36
37#ifndef DRAW_FONT_H_
38#define DRAW_FONT_H_
39
40#include <stdint.h>
41
42#include "surface.h"
43#include "source.h"
44
45struct drawctx;
46typedef struct drawctx drawctx_t;
47
48typedef int metric_t;
49
50typedef struct {
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 /*
58 * Horizontal distance between right side of the glyph and origin
59 * of the next glyph
60 */
61 metric_t right_side_bearing;
62
63 /*
64 * Vertical distance between baseline and top of the glyph
65 * (positive to top)
66 */
67 metric_t ascender;
68
69 /* Height of the actual glyph drawn */
70 metric_t height;
71} glyph_metrics_t;
72
73static inline metric_t glyph_metrics_get_descender(glyph_metrics_t *gm)
74{
75 return gm->height - gm->ascender;
76}
77
78static inline metric_t glyph_metrics_get_advancement(glyph_metrics_t *gm)
79{
80 return gm->left_side_bearing + gm->width + gm->right_side_bearing;
81}
82
83typedef struct {
84 /* Distance between top of the line and baseline */
85 metric_t ascender;
86
87 /* Distance between baseline and bottom of the line */
88 metric_t descender;
89
90 /* Distance between bottom of the line and top of the next line */
91 metric_t leading;
92} font_metrics_t;
93
94typedef uint32_t glyph_id_t;
95
96typedef struct {
97 errno_t (*get_font_metrics)(void *, font_metrics_t *);
98 errno_t (*resolve_glyph)(void *, wchar_t, glyph_id_t *);
99 errno_t (*get_glyph_metrics)(void *, glyph_id_t, glyph_metrics_t *);
100 errno_t (*render_glyph)(void *, drawctx_t *, source_t *, sysarg_t,
101 sysarg_t, glyph_id_t);
102 void (*release)(void *);
103} font_backend_t;
104
105typedef struct {
106 font_backend_t *backend;
107 void *backend_data;
108} font_t;
109
110extern font_t *font_create(font_backend_t *, void *);
111extern errno_t font_get_metrics(font_t *, font_metrics_t *);
112extern errno_t font_resolve_glyph(font_t *, wchar_t, glyph_id_t *);
113extern errno_t font_get_glyph_metrics(font_t *, glyph_id_t, glyph_metrics_t *);
114extern errno_t font_render_glyph(font_t *, drawctx_t *, source_t *,
115 sysarg_t, sysarg_t, glyph_id_t);
116extern void font_release(font_t *);
117
118extern errno_t font_get_box(font_t *, char *, sysarg_t *, sysarg_t *);
119extern errno_t font_draw_text(font_t *, drawctx_t *, source_t *, const char *,
120 sysarg_t, sysarg_t);
121
122#endif
123
124/** @}
125 */
Note: See TracBrowser for help on using the repository browser.