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 void blf_draw_buffer__start(struct FontBLF *font);
47 void blf_draw_buffer__end(void);
48 
49 struct FontBLF *blf_font_new(const char *name, const char *filename);
50 struct FontBLF *blf_font_new_from_mem(const char *name, const unsigned char *mem, int mem_size);
51 void blf_font_attach_from_mem(struct FontBLF *font, const unsigned char *mem, int mem_size);
52 
53 void blf_font_size(struct FontBLF *font, unsigned int size, unsigned int dpi);
54 void blf_font_draw(struct FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info);
55 void blf_font_draw__wrap(struct FontBLF *font,
56                          const char *str,
57                          size_t len,
58                          struct ResultBLF *r_info);
59 void blf_font_draw_ascii(struct FontBLF *font,
60                          const char *str,
61                          size_t len,
62                          struct ResultBLF *r_info);
63 int blf_font_draw_mono(struct FontBLF *font, const char *str, size_t len, int cwidth);
64 void blf_font_draw_buffer(struct FontBLF *font,
65                           const char *str,
66                           size_t len,
67                           struct ResultBLF *r_info);
68 void blf_font_draw_buffer__wrap(struct FontBLF *font,
69                                 const char *str,
70                                 size_t len,
71                                 struct ResultBLF *r_info);
72 size_t blf_font_width_to_strlen(
73     struct FontBLF *font, const char *str, size_t len, float width, float *r_width);
74 size_t blf_font_width_to_rstrlen(
75     struct FontBLF *font, const char *str, size_t len, float width, float *r_width);
76 void blf_font_boundbox(struct FontBLF *font,
77                        const char *str,
78                        size_t len,
79                        struct rctf *r_box,
80                        struct ResultBLF *r_info);
81 void blf_font_boundbox__wrap(struct FontBLF *font,
82                              const char *str,
83                              size_t len,
84                              struct rctf *r_box,
85                              struct ResultBLF *r_info);
86 void blf_font_width_and_height(struct FontBLF *font,
87                                const char *str,
88                                size_t len,
89                                float *r_width,
90                                float *r_height,
91                                struct ResultBLF *r_info);
92 float blf_font_width(struct FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info);
93 float blf_font_height(struct FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info);
94 float blf_font_fixed_width(struct FontBLF *font);
95 int blf_font_height_max(struct FontBLF *font);
96 int blf_font_width_max(struct FontBLF *font);
97 float blf_font_descender(struct FontBLF *font);
98 float blf_font_ascender(struct FontBLF *font);
99 
100 void blf_font_boundbox_foreach_glyph(struct FontBLF *font,
101                                      const char *str,
102                                      size_t len,
103                                      bool (*user_fn)(const char *str,
104                                                      const size_t str_step_ofs,
105                                                      const struct rcti *glyph_step_bounds,
106                                                      const int glyph_advance_x,
107                                                      const struct rctf *glyph_bounds,
108                                                      const int glyph_bearing[2],
109                                                      void *user_data),
110                                      void *user_data,
111                                      struct ResultBLF *r_info);
112 
113 int blf_font_count_missing_chars(struct FontBLF *font,
114                                  const char *str,
115                                  const size_t len,
116                                  int *r_tot_chars);
117 
118 void blf_font_free(struct FontBLF *font);
119 
120 struct KerningCacheBLF *blf_kerning_cache_find(struct FontBLF *font);
121 struct KerningCacheBLF *blf_kerning_cache_new(struct FontBLF *font, struct GlyphCacheBLF *gc);
122 void blf_kerning_cache_clear(struct FontBLF *font);
123 
124 struct GlyphCacheBLF *blf_glyph_cache_find(struct FontBLF *font,
125                                            unsigned int size,
126                                            unsigned int dpi);
127 struct GlyphCacheBLF *blf_glyph_cache_new(struct FontBLF *font);
128 struct GlyphCacheBLF *blf_glyph_cache_acquire(struct FontBLF *font);
129 void blf_glyph_cache_release(struct FontBLF *font);
130 void blf_glyph_cache_clear(struct FontBLF *font);
131 void blf_glyph_cache_free(struct GlyphCacheBLF *gc);
132 
133 struct GlyphBLF *blf_glyph_search(struct GlyphCacheBLF *gc, unsigned int c);
134 struct GlyphBLF *blf_glyph_add(struct FontBLF *font,
135                                struct GlyphCacheBLF *gc,
136                                unsigned int index,
137                                unsigned int c);
138 
139 void blf_glyph_free(struct GlyphBLF *g);
140 void blf_glyph_render(
141     struct FontBLF *font, struct GlyphCacheBLF *gc, struct GlyphBLF *g, float x, float y);
142 
143 #ifdef WIN32
144 /* blf_font_win32_compat.c */
145 #  ifdef FT_FREETYPE_H
146 extern FT_Error FT_New_Face__win32_compat(FT_Library library,
147                                           const char *pathname,
148                                           FT_Long face_index,
149                                           FT_Face *aface);
150 #  endif
151 #endif
152