2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2009 Blender Foundation.
19 * All rights reserved.
22 * Contributor(s): Blender Foundation
24 * ***** END GPL LICENSE BLOCK *****
27 /** \file blender/blenfont/BLF_api.h
35 #include "BLI_compiler_attrs.h"
38 struct ColorManagedDisplay;
40 int BLF_init(int points, int dpi);
42 void BLF_default_dpi(int dpi);
44 void BLF_cache_clear(void);
46 int BLF_load(const char *name) ATTR_NONNULL();
47 int BLF_load_mem(const char *name, const unsigned char *mem, int mem_size) ATTR_NONNULL();
49 int BLF_load_unique(const char *name) ATTR_NONNULL();
50 int BLF_load_mem_unique(const char *name, const unsigned char *mem, int mem_size) ATTR_NONNULL();
52 void BLF_unload(const char *name) ATTR_NONNULL();
54 /* Attach a file with metrics information from memory. */
55 void BLF_metrics_attach(int fontid, unsigned char *mem, int mem_size);
57 void BLF_aspect(int fontid, float x, float y, float z);
58 void BLF_position(int fontid, float x, float y, float z);
59 void BLF_size(int fontid, int size, int dpi);
61 /* Set a 4x4 matrix to be multiplied before draw the text.
62 * Remember that you need call BLF_enable(BLF_MATRIX)
65 * The order of the matrix is like GL:
67 * | m[0] m[4] m[8] m[12] |
68 * | m[1] m[5] m[9] m[13] |
69 * | m[2] m[6] m[10] m[14] |
70 * | m[3] m[7] m[11] m[15] |
73 void BLF_matrix(int fontid, const double m[16]);
75 /* Draw the string using the default font, size and dpi. */
76 void BLF_draw_default(float x, float y, float z, const char *str, size_t len) ATTR_NONNULL();
77 void BLF_draw_default_ascii(float x, float y, float z, const char *str, size_t len) ATTR_NONNULL();
79 /* Draw the string using the current font. */
80 void BLF_draw(int fontid, const char *str, size_t len);
81 void BLF_draw_ascii(int fontid, const char *str, size_t len);
82 int BLF_draw_mono(int fontid, const char *str, size_t len, int cwidth);
84 /* Get the string byte offset that fits within a given width */
85 size_t BLF_width_to_strlen(int fontid, const char *str, size_t len, float width, float *r_width) ATTR_NONNULL(2);
86 /* Same as BLF_width_to_strlen but search from the string end */
87 size_t BLF_width_to_rstrlen(int fontid, const char *str, size_t len, float width, float *r_width) ATTR_NONNULL(2);
89 /* This function return the bounding box of the string
90 * and are not multiplied by the aspect.
92 void BLF_boundbox(int fontid, const char *str, size_t len, struct rctf *box) ATTR_NONNULL();
94 /* The next both function return the width and height
95 * of the string, using the current font and both value
96 * are multiplied by the aspect of the font.
98 float BLF_width(int fontid, const char *str, size_t len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
99 float BLF_height(int fontid, const char *str, size_t len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
101 /* Return dimensions of the font without any sample text. */
102 float BLF_height_max(int fontid) ATTR_WARN_UNUSED_RESULT;
103 float BLF_width_max(int fontid) ATTR_WARN_UNUSED_RESULT;
104 float BLF_descender(int fontid) ATTR_WARN_UNUSED_RESULT;
105 float BLF_ascender(int fontid) ATTR_WARN_UNUSED_RESULT;
107 /* The following function return the width and height of the string, but
108 * just in one call, so avoid extra freetype2 stuff.
110 void BLF_width_and_height(int fontid, const char *str, size_t len, float *r_width, float *r_height) ATTR_NONNULL();
112 /* For fixed width fonts only, returns the width of a
115 float BLF_fixed_width(int fontid) ATTR_WARN_UNUSED_RESULT;
117 /* and this two function return the width and height
118 * of the string, using the default font and both value
119 * are multiplied by the aspect of the font.
121 void BLF_width_and_height_default(const char *str, size_t len, float *r_width, float *r_height) ATTR_NONNULL();
122 float BLF_width_default(const char *str, size_t len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
123 float BLF_height_default(const char *str, size_t len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
125 /* Set rotation for default font. */
126 void BLF_rotation_default(float angle);
128 /* Enable/disable options to the default font. */
129 void BLF_enable_default(int option);
130 void BLF_disable_default(int option);
132 /* By default, rotation and clipping are disable and
133 * have to be enable/disable using BLF_enable/disable.
135 void BLF_rotation(int fontid, float angle);
136 void BLF_clipping(int fontid, float xmin, float ymin, float xmax, float ymax);
137 void BLF_clipping_default(float xmin, float ymin, float xmax, float ymax);
138 void BLF_blur(int fontid, int size);
140 void BLF_enable(int fontid, int option);
141 void BLF_disable(int fontid, int option);
143 /* Shadow options, level is the blur level, can be 3, 5 or 0 and
144 * the other argument are the rgba color.
145 * Take care that shadow need to be enable using BLF_enable!!!
147 void BLF_shadow(int fontid, int level, float r, float g, float b, float a);
149 /* Set the offset for shadow text, this is the current cursor
150 * position plus this offset, don't need call BLF_position before
151 * this function, the current position is calculate only on
152 * BLF_draw, so it's safe call this whenever you like.
154 void BLF_shadow_offset(int fontid, int x, int y);
156 /* Set the buffer, size and number of channels to draw, one thing to take care is call
157 * this function with NULL pointer when we finish, for example:
159 * BLF_buffer(my_fbuf, my_cbuf, 100, 100, 4, true, NULL);
161 * ... set color, position and draw ...
163 * BLF_buffer(NULL, NULL, NULL, 0, 0, false, NULL);
165 void BLF_buffer(int fontid, float *fbuf, unsigned char *cbuf, int w, int h, int nch, struct ColorManagedDisplay *display);
167 /* Set the color to be used for text. */
168 void BLF_buffer_col(int fontid, float r, float g, float b, float a);
170 /* Draw the string into the buffer, this function draw in both buffer, float and unsigned char _BUT_
171 * it's not necessary set both buffer, NULL is valid here.
173 void BLF_draw_buffer(int fontid, const char *str) ATTR_NONNULL();
175 /* Add a path to the font dir paths. */
176 void BLF_dir_add(const char *path) ATTR_NONNULL();
178 /* Remove a path from the font dir paths. */
179 void BLF_dir_rem(const char *path) ATTR_NONNULL();
181 /* Return an array with all the font dir (this can be used for filesel) */
182 char **BLF_dir_get(int *ndir) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
184 /* Free the data return by BLF_dir_get. */
185 void BLF_dir_free(char **dirs, int count) ATTR_NONNULL();
188 void BLF_state_print(int fontid);
192 #define BLF_ROTATION (1 << 0)
193 #define BLF_CLIPPING (1 << 1)
194 #define BLF_SHADOW (1 << 2)
195 #define BLF_KERNING_DEFAULT (1 << 3)
196 #define BLF_MATRIX (1 << 4)
197 #define BLF_ASPECT (1 << 5)
198 #define BLF_HINTING (1 << 6)
200 #define BLF_DRAW_STR_DUMMY_MAX 1024
202 /* XXX, bad design */
203 extern int blf_mono_font;
204 extern int blf_mono_font_render; /* don't mess drawing with render threads. */
206 #endif /* __BLF_API_H__ */