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
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
[8d2dd7f2]40#include <stdint.h>
[7c014d1]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 {
[1b20da0]51 /* Horizontal distance between origin and left side of the glyph */
[2cc1ec0]52 metric_t left_side_bearing;
[a35b458]53
[2cc1ec0]54 /* Width of the actual glyph drawn */
55 metric_t width;
[a35b458]56
[7c3fb9b]57 /*
58 * Horizontal distance between right side of the glyph and origin
59 * of the next glyph
60 */
[2cc1ec0]61 metric_t right_side_bearing;
[a35b458]62
[7c3fb9b]63 /*
64 * Vertical distance between baseline and top of the glyph
65 * (positive to top)
66 */
[2cc1ec0]67 metric_t ascender;
[a35b458]68
[2cc1ec0]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;
[a35b458]86
[2cc1ec0]87 /* Distance between baseline and bottom of the line */
88 metric_t descender;
[a35b458]89
[2cc1ec0]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 {
[b7fd2a0]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,
[2cc1ec0]101 sysarg_t, glyph_id_t);
[6d5e378]102 void (*release)(void *);
[2cc1ec0]103} font_backend_t;
104
105typedef struct {
106 font_backend_t *backend;
107 void *backend_data;
[6d5e378]108} font_t;
109
[2cc1ec0]110extern font_t *font_create(font_backend_t *, void *);
[b7fd2a0]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 *,
[2cc1ec0]115 sysarg_t, sysarg_t, glyph_id_t);
[6d5e378]116extern void font_release(font_t *);
117
[b7fd2a0]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 *,
[6d5e378]120 sysarg_t, sysarg_t);
[afa6e74]121
122#endif
[67ebf21]123
124/** @}
125 */
Note: See TracBrowser for help on using the repository browser.