NetSurf
layout.h
Go to the documentation of this file.
1/*
2 * Copyright 2016 Vincent Sanders <vince@netsurf-browser.org>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/**
20 * \file
21 *
22 * Interface to platform-specific layout operation table.
23 *
24 * This table is part of the layout used to measure glyphs before
25 * rendering, previously referred to as font functions.
26 *
27 * \note This is an old interface within the browser, it has been
28 * broken out purely to make the API obvious not as an indication this
29 * is the correct approach.
30 */
31
32#ifndef _NETSURF_LAYOUT_H_
33#define _NETSURF_LAYOUT_H_
34
35struct plot_font_style;
36
38{
39 /**
40 * Measure the width of a string.
41 *
42 * \param[in] fstyle plot style for this text
43 * \param[in] string UTF-8 string to measure
44 * \param[in] length length of string, in bytes
45 * \param[out] width updated to width of string[0..length)
46 * \return NSERROR_OK and width updated or appropriate error
47 * code on faliure
48 */
49 nserror (*width)(const struct plot_font_style *fstyle, const char *string, size_t length, int *width);
50
51
52 /**
53 * Find the position in a string where an x coordinate falls.
54 *
55 * \param[in] fstyle style for this text
56 * \param[in] string UTF-8 string to measure
57 * \param[in] length length of string, in bytes
58 * \param[in] x coordinate to search for
59 * \param[out] char_offset updated to offset in string of actual_x, [0..length]
60 * \param[out] actual_x updated to x coordinate of character closest to x
61 * \return NSERROR_OK and char_offset and actual_x updated or appropriate error code on faliure
62 */
63 nserror (*position)(const struct plot_font_style *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x);
64
65
66 /**
67 * Find where to split a string to make it fit a width.
68 *
69 * \param[in] fstyle style for this text
70 * \param[in] string UTF-8 string to measure
71 * \param[in] length length of string, in bytes
72 * \param[in] x width available
73 * \param[out] char_offset updated to offset in string of actual_x, [1..length]
74 * \param[out] actual_x updated to x coordinate of character closest to x
75 * \return NSERROR_OK or appropriate error code on faliure
76 *
77 * On exit, char_offset indicates first character after split point.
78 *
79 * \note char_offset of 0 must never be returned.
80 *
81 * Returns:
82 * char_offset giving split point closest to x, where actual_x <= x
83 * else
84 * char_offset giving split point closest to x, where actual_x > x
85 *
86 * Returning char_offset == length means no split possible
87 */
88 nserror (*split)(const struct plot_font_style *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x);
89};
90
91#endif
nserror
Enumeration of error codes.
Definition: errors.h:29
nserror(* position)(const struct plot_font_style *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x)
Find the position in a string where an x coordinate falls.
Definition: layout.h:63
nserror(* width)(const struct plot_font_style *fstyle, const char *string, size_t length, int *width)
Measure the width of a string.
Definition: layout.h:49
nserror(* split)(const struct plot_font_style *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x)
Find where to split a string to make it fit a width.
Definition: layout.h:88
Font style for plotting.
Definition: plot_style.h:111