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.blob;
8 
9 import bindbc.hb.config;
10 
11 import bindbc.hb.bind.common;
12 
13 extern(C) @nogc nothrow:
14 
15 /*
16  * Note re various memory-modes:
17  *
18  * - In no case shall the HarfBuzz client modify memory
19  *   that is passed to HarfBuzz in a blob.  If there is
20  *   any such possibility, MODE_DUPLICATE should be used
21  *   such that HarfBuzz makes a copy immediately,
22  *
23  * - Use MODE_READONLY otherwise, unless you really really
24  *   really know what you are doing,
25  *
26  * - MODE_WRITABLE is appropriate if you really made a
27  *   copy of data solely for the purpose of passing to
28  *   HarfBuzz and doing that just once (no reuse!),
29  *
30  * - If the font is mmap()ed, it's ok to use
31  *   READONLY_MAY_MAKE_WRITABLE, however, using that mode
32  *   correctly is very tricky.  Use MODE_READONLY instead.
33  */
34 enum : int
35 {
36     HB_MEMORY_MODE_DUPLICATE = 0,
37     HB_MEMORY_MODE_READONLY = 1,
38     HB_MEMORY_MODE_WRITABLE = 2,
39     HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE = 3
40 }
41 alias hb_memory_mode_t = int;
42 
43 struct hb_blob_t;
44 
45 version(BindHB_Static)
46     hb_blob_t* hb_blob_create (
47         const(char)* data,
48         uint length,
49         hb_memory_mode_t mode,
50         void* user_data,
51         hb_destroy_func_t destroy);
52 else
53 {
54     private alias fp_hb_blob_create = hb_blob_t* function (
55         const(char)* data,
56         uint length,
57         hb_memory_mode_t mode,
58         void* user_data,
59         hb_destroy_func_t destroy);
60     __gshared fp_hb_blob_create hb_blob_create;
61 }
62 
63 static if (hbSupport >= HBSupport.v2_6_3)
64 {
65 	version(BindHB_Static)
66 		hb_blob_t* hb_blob_create_from_file (const(char)* file_name);
67 	else
68 	{
69 		private alias fp_hb_blob_create_from_file = hb_blob_t* function (const(char)* file_name);
70 		__gshared fp_hb_blob_create_from_file hb_blob_create_from_file;
71 	}
72 }
73 
74 /* Always creates with MEMORY_MODE_READONLY.
75  * Even if the parent blob is writable, we don't
76  * want the user of the sub-blob to be able to
77  * modify the parent data as that data may be
78  * shared among multiple sub-blobs.
79  */
80 version(BindHB_Static)
81     hb_blob_t* hb_blob_create_sub_blob (
82         hb_blob_t* parent,
83         uint offset,
84         uint length);
85 else
86 {
87     private alias fp_hb_blob_create_sub_blob = hb_blob_t* function (
88         hb_blob_t* parent,
89         uint offset,
90         uint length);
91     __gshared fp_hb_blob_create_sub_blob hb_blob_create_sub_blob;
92 }
93 
94 static if (hbSupport >= HBSupport.v2_6_3)
95 {
96 	version(BindHB_Static)
97 		hb_blob_t* hb_blob_copy_writable_or_fail (hb_blob_t* blob);
98 	else
99 	{
100 		private alias fp_hb_blob_copy_writable_or_fail = hb_blob_t* function (hb_blob_t* blob);
101 		__gshared fp_hb_blob_copy_writable_or_fail hb_blob_copy_writable_or_fail;
102 	}
103 }
104 
105 version(BindHB_Static)
106     hb_blob_t* hb_blob_get_empty ();
107 else
108 {
109     private alias fp_hb_blob_get_empty = hb_blob_t* function ();
110     __gshared fp_hb_blob_get_empty hb_blob_get_empty;
111 }
112 
113 version(BindHB_Static)
114     hb_blob_t* hb_blob_reference (hb_blob_t* blob);
115 else
116 {
117     private alias fp_hb_blob_reference = hb_blob_t* function (hb_blob_t* blob);
118     __gshared fp_hb_blob_reference hb_blob_reference;
119 }
120 
121 version(BindHB_Static)
122     void hb_blob_destroy (hb_blob_t* blob);
123 else
124 {
125     private alias fp_hb_blob_destroy = void function (hb_blob_t* blob);
126     __gshared fp_hb_blob_destroy hb_blob_destroy;
127 }
128 
129 version(BindHB_Static)
130     hb_bool_t hb_blob_set_user_data (
131         hb_blob_t* blob,
132         hb_user_data_key_t* key,
133         void* data,
134         hb_destroy_func_t destroy,
135         hb_bool_t replace);
136 else
137 {
138     private alias fp_hb_blob_set_user_data = hb_bool_t function (
139         hb_blob_t* blob,
140         hb_user_data_key_t* key,
141         void* data,
142         hb_destroy_func_t destroy,
143         hb_bool_t replace);
144     __gshared fp_hb_blob_set_user_data hb_blob_set_user_data;
145 }
146 
147 version(BindHB_Static)
148     void* hb_blob_get_user_data (hb_blob_t* blob, hb_user_data_key_t* key);
149 else
150 {
151     private alias fp_hb_blob_get_user_data = void* function (hb_blob_t* blob, hb_user_data_key_t* key);
152     __gshared fp_hb_blob_get_user_data hb_blob_get_user_data;
153 }
154 
155 version(BindHB_Static)
156     void hb_blob_make_immutable (hb_blob_t* blob);
157 else
158 {
159     private alias fp_hb_blob_make_immutable = void function (hb_blob_t* blob);
160     __gshared fp_hb_blob_make_immutable hb_blob_make_immutable;
161 }
162 
163 version(BindHB_Static)
164     hb_bool_t hb_blob_is_immutable (hb_blob_t* blob);
165 else
166 {
167     private alias fp_hb_blob_is_immutable = hb_bool_t function (hb_blob_t* blob);
168     __gshared fp_hb_blob_is_immutable hb_blob_is_immutable;
169 }
170 
171 version(BindHB_Static)
172     uint hb_blob_get_length (hb_blob_t* blob);
173 else
174 {
175     private alias fp_hb_blob_get_length = uint function (hb_blob_t* blob);
176     __gshared fp_hb_blob_get_length hb_blob_get_length;
177 }
178 
179 version(BindHB_Static)
180     const(char)* hb_blob_get_data (hb_blob_t* blob, uint* length);
181 else
182 {
183     private alias fp_hb_blob_get_data = const(char)* function (hb_blob_t* blob, uint* length);
184     __gshared fp_hb_blob_get_data hb_blob_get_data;
185 }
186 
187 version(BindHB_Static)
188     char* hb_blob_get_data_writable (hb_blob_t* blob, uint* length);
189 else
190 {
191     private alias fp_hb_blob_get_data_writable = char* function (hb_blob_t* blob, uint* length);
192     __gshared fp_hb_blob_get_data_writable hb_blob_get_data_writable;
193 }