UI Code Quality: Cleanup ui_but_update_from_old_block
[blender.git] / source / blender / blenfont / intern / blf_internal.h
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2009 Blender Foundation.
17  * All rights reserved.
18  */
19
20 /** \file
21  * \ingroup blf
22  */
23
24 #pragma once
25
26 struct FontBLF;
27 struct GlyphBLF;
28 struct GlyphCacheBLF;
29 struct ResultBLF;
30 struct rctf;
31 struct rcti;
32
33 void blf_batch_draw_begin(struct FontBLF *font);
34 void blf_batch_draw(void);
35
36 unsigned int blf_next_p2(unsigned int x);
37 unsigned int blf_hash(unsigned int val);
38
39 char *blf_dir_search(const char *file);
40 char *blf_dir_metrics_search(const char *filename);
41 /* int blf_dir_split(const char *str, char *file, int *size);  */ /* UNUSED */
42
43 int blf_font_init(void);
44 void blf_font_exit(void);
45
46 bool blf_font_id_is_valid(int fontid);
47
48 void blf_draw_buffer__start(struct FontBLF *font);
49 void blf_draw_buffer__end(void);
50
51 struct FontBLF *blf_font_new(const char *name, const char *filename);
52 struct FontBLF *blf_font_new_from_mem(const char *name, const unsigned char *mem, int mem_size);
53 void blf_font_attach_from_mem(struct FontBLF *font, const unsigned char *mem, int mem_size);
54
55 void blf_font_size(struct FontBLF *font, unsigned int size, unsigned int dpi);
56 void blf_font_draw(struct FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info);
57 void blf_font_draw__wrap(struct FontBLF *font,
58                          const char *str,
59                          size_t len,
60                          struct ResultBLF *r_info);
61 void blf_font_draw_ascii(struct FontBLF *font,
62                          const char *str,
63                          size_t len,
64                          struct ResultBLF *r_info);
65 int blf_font_draw_mono(struct FontBLF *font, const char *str, size_t len, int cwidth);
66 void blf_font_draw_buffer(struct FontBLF *font,
67                           const char *str,
68                           size_t len,
69                           struct ResultBLF *r_info);
70 void blf_font_draw_buffer__wrap(struct FontBLF *font,
71                                 const char *str,
72                                 size_t len,
73                                 struct ResultBLF *r_info);
74 size_t blf_font_width_to_strlen(
75     struct FontBLF *font, const char *str, size_t len, float width, float *r_width);
76 size_t blf_font_width_to_rstrlen(
77     struct FontBLF *font, const char *str, size_t len, float width, float *r_width);
78 void blf_font_boundbox(struct FontBLF *font,
79                        const char *str,
80                        size_t len,
81                        struct rctf *r_box,
82                        struct ResultBLF *r_info);
83 void blf_font_boundbox__wrap(struct FontBLF *font,
84                              const char *str,
85                              size_t len,
86                              struct rctf *r_box,
87                              struct ResultBLF *r_info);
88 void blf_font_width_and_height(struct FontBLF *font,
89                                const char *str,
90                                size_t len,
91                                float *r_width,
92                                float *r_height,
93                                struct ResultBLF *r_info);
94 float blf_font_width(struct FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info);
95 float blf_font_height(struct FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info);
96 float blf_font_fixed_width(struct FontBLF *font);
97 int blf_font_height_max(struct FontBLF *font);
98 int blf_font_width_max(struct FontBLF *font);
99 float blf_font_descender(struct FontBLF *font);
100 float blf_font_ascender(struct FontBLF *font);
101
102 void blf_font_boundbox_foreach_glyph(struct FontBLF *font,
103                                      const char *str,
104                                      size_t len,
105                                      bool (*user_fn)(const char *str,
106                                                      const size_t str_step_ofs,
107                                                      const struct rcti *glyph_step_bounds,
108                                                      const int glyph_advance_x,
109                                                      const struct rctf *glyph_bounds,
110                                                      const int glyph_bearing[2],
111                                                      void *user_data),
112                                      void *user_data,
113                                      struct ResultBLF *r_info);
114
115 int blf_font_count_missing_chars(struct FontBLF *font,
116                                  const char *str,
117                                  const size_t len,
118                                  int *r_tot_chars);
119
120 void blf_font_free(struct FontBLF *font);
121
122 struct KerningCacheBLF *blf_kerning_cache_find(struct FontBLF *font);
123 struct KerningCacheBLF *blf_kerning_cache_new(struct FontBLF *font, struct GlyphCacheBLF *gc);
124 void blf_kerning_cache_clear(struct FontBLF *font);
125
126 struct GlyphCacheBLF *blf_glyph_cache_find(struct FontBLF *font,
127                                            unsigned int size,
128                                            unsigned int dpi);
129 struct GlyphCacheBLF *blf_glyph_cache_new(struct FontBLF *font);
130 struct GlyphCacheBLF *blf_glyph_cache_acquire(struct FontBLF *font);
131 void blf_glyph_cache_release(struct FontBLF *font);
132 void blf_glyph_cache_clear(struct FontBLF *font);
133 void blf_glyph_cache_free(struct GlyphCacheBLF *gc);
134
135 struct GlyphBLF *blf_glyph_search(struct GlyphCacheBLF *gc, unsigned int c);
136 struct GlyphBLF *blf_glyph_add(struct FontBLF *font,
137                                struct GlyphCacheBLF *gc,
138                                unsigned int index,
139                                unsigned int c);
140
141 void blf_glyph_free(struct GlyphBLF *g);
142 void blf_glyph_render(
143     struct FontBLF *font, struct GlyphCacheBLF *gc, struct GlyphBLF *g, float x, float y);
144
145 #ifdef WIN32
146 /* blf_font_win32_compat.c */
147 #  ifdef FT_FREETYPE_H
148 extern FT_Error FT_New_Face__win32_compat(FT_Library library,
149                                           const char *pathname,
150                                           FT_Long face_index,
151                                           FT_Face *aface);
152 #  endif
153 #endif