source: mainline/uspace/lib/draw/font.h@ 4f205248

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 4f205248 was a35b458, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 8 years ago

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

  • 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 /* 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 errno_t (*get_font_metrics)(void *, font_metrics_t *);
94 errno_t (*resolve_glyph)(void *, wchar_t, glyph_id_t *);
95 errno_t (*get_glyph_metrics)(void *, glyph_id_t, glyph_metrics_t *);
96 errno_t (*render_glyph)(void *, drawctx_t *, source_t *, sysarg_t,
97 sysarg_t, glyph_id_t);
98 void (*release)(void *);
99} font_backend_t;
100
101typedef struct {
102 font_backend_t *backend;
103 void *backend_data;
104} font_t;
105
106extern font_t *font_create(font_backend_t *, void *);
107extern errno_t font_get_metrics(font_t *, font_metrics_t *);
108extern errno_t font_resolve_glyph(font_t *, wchar_t, glyph_id_t *);
109extern errno_t font_get_glyph_metrics(font_t *, glyph_id_t, glyph_metrics_t *);
110extern errno_t font_render_glyph(font_t *, drawctx_t *, source_t *,
111 sysarg_t, sysarg_t, glyph_id_t);
112extern void font_release(font_t *);
113
114extern errno_t font_get_box(font_t *, char *, sysarg_t *, sysarg_t *);
115extern errno_t font_draw_text(font_t *, drawctx_t *, source_t *, const char *,
116 sysarg_t, sysarg_t);
117
118#endif
119
120/** @}
121 */
Note: See TracBrowser for help on using the repository browser.