1 
2 //          Copyright Ahmet Sait Koçak 2020.
3 // Distributed under the Boost Software License, Version 1.0.
4 //    (See accompanying file LICENSE_1_0.txt or copy at
5 //          https://www.boost.org/LICENSE_1_0.txt)
6 
7 module bindbc.hb.bind.ft;
8 
9 version(HB_with_freetype):
10 version(Have_bindbc_freetype):
11 
12 import bindbc.freetype.bind.freetype : FT_Face;
13 import bindbc.hb.bind.common;
14 import bindbc.hb.bind.face;
15 import bindbc.hb.bind.font;
16 
17 extern(C) @nogc nothrow:
18 
19 /*
20  * Note: FreeType is not thread-safe.
21  * Hence, these functions are not either.
22  */
23 
24 /*
25  * hb-face from ft-face.
26  */
27 
28 /* This one creates a new hb-face for given ft-face.
29  * When the returned hb-face is destroyed, the destroy
30  * callback is called (if not NULL), with the ft-face passed
31  * to it.
32  *
33  * The client is responsible to make sure that ft-face is
34  * destroyed after hb-face is destroyed.
35  *
36  * Most often you don't want this function.  You should use either
37  * hb_ft_face_create_cached(), or hb_ft_face_create_referenced().
38  * In particular, if you are going to pass NULL as destroy, you
39  * probably should use (the more recent) hb_ft_face_create_referenced()
40  * instead.
41  */
42 version(BindHB_Static)
43     	hb_face_t* hb_ft_face_create (FT_Face ft_face, hb_destroy_func_t destroy);
44 else
45 {
46     private alias fp_hb_ft_face_create = 	hb_face_t* function (FT_Face ft_face, hb_destroy_func_t destroy);
47     __gshared fp_hb_ft_face_create hb_ft_face_create;
48 }
49 
50 	/* This version is like hb_ft_face_create(), except that it caches
51 	 * the hb-face using the generic pointer of the ft-face.  This means
52 	 * that subsequent calls to this function with the same ft-face will
53 	 * return the same hb-face (correctly referenced).
54 	 *
55 	 * Client is still responsible for making sure that ft-face is destroyed
56 	 * after hb-face is.
57 	 */
58 version(BindHB_Static)
59     	hb_face_t* hb_ft_face_create_cached (FT_Face ft_face);
60 else
61 {
62     private alias fp_hb_ft_face_create_cached = 	hb_face_t* function (FT_Face ft_face);
63     __gshared fp_hb_ft_face_create_cached hb_ft_face_create_cached;
64 }
65 
66 	/* This version is like hb_ft_face_create(), except that it calls
67 	 * FT_Reference_Face() on ft-face, as such keeping ft-face alive
68 	 * as long as the hb-face is.
69 	 *
70 	 * This is the most convenient version to use.  Use it unless you have
71 	 * very good reasons not to.
72 	 */
73 version(BindHB_Static)
74     	hb_face_t* hb_ft_face_create_referenced (FT_Face ft_face);
75 else
76 {
77     private alias fp_hb_ft_face_create_referenced = 	hb_face_t* function (FT_Face ft_face);
78     __gshared fp_hb_ft_face_create_referenced hb_ft_face_create_referenced;
79 }
80 
81 	/*
82 	 * hb-font from ft-face.
83 	 */
84 
85 	/*
86 	 * Note:
87 	 *
88 	 * Set face size on ft-face before creating hb-font from it.
89 	 * Otherwise hb-ft would NOT pick up the font size correctly.
90 	 */
91 
92 	/* See notes on hb_ft_face_create().  Same issues re lifecycle-management
93 	 * apply here.  Use hb_ft_font_create_referenced() if you can. */
94 version(BindHB_Static)
95     	hb_font_t* hb_ft_font_create (FT_Face ft_face, hb_destroy_func_t destroy);
96 else
97 {
98     private alias fp_hb_ft_font_create = 	hb_font_t* function (FT_Face ft_face, hb_destroy_func_t destroy);
99     __gshared fp_hb_ft_font_create hb_ft_font_create;
100 }
101 
102 	/* See notes on hb_ft_face_create_referenced() re lifecycle-management
103 	 * issues. */
104 version(BindHB_Static)
105     	hb_font_t* hb_ft_font_create_referenced (FT_Face ft_face);
106 else
107 {
108     private alias fp_hb_ft_font_create_referenced = 	hb_font_t* function (FT_Face ft_face);
109     __gshared fp_hb_ft_font_create_referenced hb_ft_font_create_referenced;
110 }
111 
112 version(BindHB_Static)
113     	FT_Face hb_ft_font_get_face (hb_font_t* font);
114 else
115 {
116     private alias fp_hb_ft_font_get_face = 	FT_Face function (hb_font_t* font);
117     __gshared fp_hb_ft_font_get_face hb_ft_font_get_face;
118 }
119 
120 version(BindHB_Static)
121     	void hb_ft_font_set_load_flags (hb_font_t* font, int load_flags);
122 else
123 {
124     private alias fp_hb_ft_font_set_load_flags = 	void function (hb_font_t* font, int load_flags);
125     __gshared fp_hb_ft_font_set_load_flags hb_ft_font_set_load_flags;
126 }
127 
128 version(BindHB_Static)
129     	int hb_ft_font_get_load_flags (hb_font_t* font);
130 else
131 {
132     private alias fp_hb_ft_font_get_load_flags = 	int function (hb_font_t* font);
133     __gshared fp_hb_ft_font_get_load_flags hb_ft_font_get_load_flags;
134 }
135 
136 	/* Call when size or variations settings on underlying FT_Face change. */
137 version(BindHB_Static)
138     	void hb_ft_font_changed (hb_font_t* font);
139 else
140 {
141     private alias fp_hb_ft_font_changed = 	void function (hb_font_t* font);
142     __gshared fp_hb_ft_font_changed hb_ft_font_changed;
143 }
144 
145 	/* Makes an hb_font_t use FreeType internally to implement font functions.
146 	 * Note: this internally creates an FT_Face.  Use it when you create your
147 	 * hb_face_t using hb_face_create(). */
148 version(BindHB_Static)
149     	void hb_ft_font_set_funcs (hb_font_t* font);
150 else
151 {
152     private alias fp_hb_ft_font_set_funcs = 	void function (hb_font_t* font);
153     __gshared fp_hb_ft_font_set_funcs hb_ft_font_set_funcs;
154 }