1 
2 //          Copyright 2019 - 2021 Michael D. Parker
3 // Distributed under the Boost Software License, Version 1.0.
4 //    (See accompanying file LICENSE_1_0.txt or copy at
5 //          http://www.boost.org/LICENSE_1_0.txt)
6 
7 module bindbc.freetype.bind.ftcolor;
8 
9 import bindbc.freetype.config;
10 
11 static if(ftSupport >= FTSupport.ft210) {
12     import bindbc.freetype.bind.freetype,
13            bindbc.freetype.bind.ftimage,
14            bindbc.freetype.bind.fttypes;
15 
16     struct FT_Color {
17         FT_Byte blue;
18         FT_Byte green;
19         FT_Byte red;
20         FT_Byte alpha;
21     }
22 
23     enum FT_PALETTE_FOR_LIGHT_BACKGROUND = 0x01;
24     enum FT_PALETTE_FOR_DARK_BACKGROUND = 0x02;
25 
26     struct FT_Palette_Data {
27         FT_UShort num_palettes;
28         const(FT_UShort)* palette_name_ids;
29         const(FT_UShort)* palette_flags;
30         FT_UShort num_palette_entries;
31         const(FT_UShort)* palette_entry_name_ids;
32     }
33 
34     static if(staticBinding) {
35         extern(C) @nogc nothrow {
36             FT_Error FT_Palette_Data_Get(FT_Face face, FT_Palette_Data* apalette);
37             FT_Error FT_Palette_Select(FT_Face face, FT_UShort palette_index, FT_Color* apalette);
38             FT_Error FT_Palette_Set_Foreground_Color(FT_Face face, FT_Color foreground_color);
39         }
40     }
41     else {
42         extern(C) @nogc nothrow {
43             alias pFT_Palette_Data_Get = FT_Error function(FT_Face face,FT_Palette_Data* apalette);
44             alias pFT_Palette_Select = FT_Error function(FT_Face face, FT_UShort palette_index, FT_Color* apalette);
45             alias pFT_Palette_Set_Foreground_Color = FT_Error function(FT_Face face, FT_Color foreground_color);
46         }
47         __gshared {
48             pFT_Palette_Data_Get FT_Palette_Data_Get;
49             pFT_Palette_Select FT_Palette_Select;
50             pFT_Palette_Set_Foreground_Color FT_Palette_Set_Foreground_Color;
51         }
52     }
53 }
54 
55 static if(ftSupport >= FTSupport.ft211) {
56     struct FT_LayerIterator {
57         FT_UInt num_layers;
58         FT_UInt layer;
59         FT_Byte* p;
60     }
61 
62     alias FT_PaintFormat = int;
63     enum {
64         FT_COLR_PAINTFORMAT_COLR_LAYERS     = 1,
65         FT_COLR_PAINTFORMAT_SOLID           = 2,
66         FT_COLR_PAINTFORMAT_LINEAR_GRADIENT = 4,
67         FT_COLR_PAINTFORMAT_RADIAL_GRADIENT = 6,
68         FT_COLR_PAINTFORMAT_SWEEP_GRADIENT  = 8,
69         FT_COLR_PAINTFORMAT_GLYPH           = 10,
70         FT_COLR_PAINTFORMAT_COLR_GLYPH      = 11,
71         FT_COLR_PAINTFORMAT_TRANSFORM       = 12,
72         FT_COLR_PAINTFORMAT_TRANSLATE       = 14,
73         FT_COLR_PAINTFORMAT_SCALE           = 16,
74         FT_COLR_PAINTFORMAT_ROTATE          = 24,
75         FT_COLR_PAINTFORMAT_SKEW            = 28,
76         FT_COLR_PAINTFORMAT_COMPOSITE       = 32,
77         FT_COLR_PAINT_FORMAT_MAX            = 33,
78         FT_COLR_PAINTFORMAT_UNSUPPORTED     = 255,
79     }
80 
81     struct FT_ColorStopIterator {
82         FT_UInt num_color_stops;
83         FT_UInt current_color_stop;
84         FT_Byte* p;
85     }
86 
87     struct FT_ColorIndex {
88         FT_UInt16 palette_index;
89         FT_F2Dot14 alpha;
90     }
91 
92     struct FT_ColorStop {
93         FT_F2Dot14 stop_offset;
94         FT_ColorIndex color;
95     }
96 
97     alias FT_PaintExtend = int;
98     enum {
99         FT_COLR_PAINT_EXTEND_PAD     = 0,
100         FT_COLR_PAINT_EXTEND_REPEAT  = 1,
101         FT_COLR_PAINT_EXTEND_REFLECT = 2,
102     }
103 
104     struct FT_ColorLine {
105         FT_PaintExtend extend;
106         FT_ColorStopIterator color_stop_iterator;
107     }
108 
109     struct FT_Affine23 {
110         FT_Fixed xx, xy, dx;
111         FT_Fixed yx, yy, dy;
112     }
113 
114     alias FT_Composite_Mode = int;
115     enum {
116         FT_COLR_COMPOSITE_CLEAR          = 0,
117         FT_COLR_COMPOSITE_SRC            = 1,
118         FT_COLR_COMPOSITE_DEST           = 2,
119         FT_COLR_COMPOSITE_SRC_OVER       = 3,
120         FT_COLR_COMPOSITE_DEST_OVER      = 4,
121         FT_COLR_COMPOSITE_SRC_IN         = 5,
122         FT_COLR_COMPOSITE_DEST_IN        = 6,
123         FT_COLR_COMPOSITE_SRC_OUT        = 7,
124         FT_COLR_COMPOSITE_DEST_OUT       = 8,
125         FT_COLR_COMPOSITE_SRC_ATOP       = 9,
126         FT_COLR_COMPOSITE_DEST_ATOP      = 10,
127         FT_COLR_COMPOSITE_XOR            = 11,
128         FT_COLR_COMPOSITE_SCREEN         = 12,
129         FT_COLR_COMPOSITE_OVERLAY        = 13,
130         FT_COLR_COMPOSITE_DARKEN         = 14,
131         FT_COLR_COMPOSITE_LIGHTEN        = 15,
132         FT_COLR_COMPOSITE_COLOR_DODGE    = 16,
133         FT_COLR_COMPOSITE_COLOR_BURN     = 17,
134         FT_COLR_COMPOSITE_HARD_LIGHT     = 18,
135         FT_COLR_COMPOSITE_SOFT_LIGHT     = 19,
136         FT_COLR_COMPOSITE_DIFFERENCE     = 20,
137         FT_COLR_COMPOSITE_EXCLUSION      = 21,
138         FT_COLR_COMPOSITE_MULTIPLY       = 22,
139         FT_COLR_COMPOSITE_HSL_HUE        = 23,
140         FT_COLR_COMPOSITE_HSL_SATURATION = 24,
141         FT_COLR_COMPOSITE_HSL_COLOR      = 25,
142         FT_COLR_COMPOSITE_HSL_LUMINOSITY = 26,
143         FT_COLR_COMPOSITE_MAX            = 27,
144     }
145 
146     struct FT_OpaquePaint {
147         FT_Byte* p;
148         FT_Bool insert_root_transform;
149     }
150 
151     struct FT_PaintColrLayers {
152         FT_LayerIterator layer_iterator;
153     }
154 
155     struct FT_PaintSolid {
156         FT_ColorIndex color;
157     }
158 
159     struct FT_PaintLinearGradient {
160         FT_ColorLine colorline;
161         FT_Vector p0;
162         FT_Vector p1;
163         FT_Vector p2;
164     }
165 
166     struct FT_PaintRadialGradient {
167         FT_ColorLine colorline;
168         FT_Vector c0;
169         FT_UShort r0;
170         FT_Vector c1;
171         FT_UShort r1;
172     }
173 
174     struct FT_PaintSweepGradient {
175         FT_ColorLine colorline;
176         FT_Vector center;
177         FT_Fixed start_angle;
178         FT_Fixed end_angle;
179     }
180 
181     struct FT_PaintGlyph {
182         FT_OpaquePaint paint;
183         FT_UInt glyphID;
184     }
185 
186     struct FT_PaintColrGlyph {
187         FT_UInt glyphID;
188     }
189 
190     struct FT_PaintTransform {
191         FT_OpaquePaint paint;
192         FT_Affine23 affine;
193     }
194 
195     struct FT_PaintTranslate {
196         FT_OpaquePaint paint;
197         FT_Fixed dx;
198         FT_Fixed dy;
199     }
200 
201     struct FT_PaintScale {
202         FT_OpaquePaint paint;
203         FT_Fixed scale_x;
204         FT_Fixed scale_y;
205         FT_Fixed center_x;
206         FT_Fixed center_y;
207     }
208 
209     struct FT_PaintRotate {
210         FT_OpaquePaint paint;
211         FT_Fixed angle;
212         FT_Fixed center_x;
213         FT_Fixed center_y;
214     }
215 
216     struct FT_PaintSkew {
217         FT_OpaquePaint paint;
218         FT_Fixed x_skew_angle;
219         FT_Fixed y_skew_angle;
220         FT_Fixed center_x;
221         FT_Fixed center_y;
222     }
223 
224     struct FT_PaintComposite {
225         FT_OpaquePaint source_paint;
226         FT_Composite_Mode composite_mode;
227         FT_OpaquePaint backdrop_paint;
228     }
229 
230     struct FT_COLR_Paint {
231         FT_PaintFormat format;
232         union u {
233             FT_PaintColrLayers colr_layers;
234             FT_PaintGlyph           glyph;
235             FT_PaintSolid           solid;
236             FT_PaintLinearGradient  linear_gradient;
237             FT_PaintRadialGradient  radial_gradient;
238             FT_PaintSweepGradient   sweep_gradient;
239             FT_PaintTransform       transform;
240             FT_PaintTranslate       translate;
241             FT_PaintScale           scale;
242             FT_PaintRotate          rotate;
243             FT_PaintSkew            skew;
244             FT_PaintComposite       composite;
245             FT_PaintColrGlyph       colr_glyph;
246         }
247     }
248 
249     alias FT_Color_Root_Transform = int;
250     enum {
251         FT_COLOR_INCLUDE_ROOT_TRANSFORM,
252         FT_COLOR_NO_ROOT_TRANSFORM,
253         FT_COLOR_ROOT_TRANSFORM_MAX,
254     }
255 
256     static if(staticBinding) {
257         extern(C) @nogc nothrow {
258             FT_Bool FT_Get_Color_Glyph_Layer(FT_Face face, FT_UInt base_glyph, FT_UInt* aglyph_index, FT_UInt* acolor_index, FT_LayerIterator* iterator);
259             FT_Bool FT_Get_Color_Glyph_Paint(FT_Face face, FT_UInt base_glyph, FT_Color_Root_Transform root_transform, FT_OpaquePaint* paint);
260             FT_Bool FT_Get_Paint_Layers(FT_Face face, FT_LayerIterator* iterator, FT_OpaquePaint* paint);
261             FT_Bool FT_Get_Colorline_Stops(FT_Face face, FT_ColorStop* color_stop, FT_ColorStopIterator iterator);
262             FT_Bool FT_Get_Paint(FT_Face face, FT_OpaquePaint opaque_paint, FT_COLR_Paint* paint);
263         }
264     }
265     else {
266         extern(C) @nogc nothrow {
267             alias pFT_Get_Color_Glyph_Layer = FT_Bool function(FT_Face face, FT_UInt base_glyph, FT_UInt* aglyph_index, FT_UInt* acolor_index, FT_LayerIterator* iterator);
268             alias pFT_Get_Color_Glyph_Paint = FT_Bool function(FT_Face face, FT_UInt base_glyph, FT_Color_Root_Transform root_transform, FT_OpaquePaint* paint);
269             alias pFT_Get_Paint_Layers = FT_Bool function(FT_Face face, FT_LayerIterator* iterator, FT_OpaquePaint* paint);
270             alias pFT_Get_Colorline_Stops = FT_Bool function(FT_Face face, FT_ColorStop* color_stop, FT_ColorStopIterator iterator);
271             alias pFT_Get_Paint = FT_Bool function(FT_Face face, FT_OpaquePaint opaque_paint, FT_COLR_Paint* paint);
272         }
273         __gshared {
274             pFT_Get_Color_Glyph_Layer FT_Get_Color_Glyph_Layer;
275             pFT_Get_Color_Glyph_Paint FT_Get_Color_Glyph_Paint;
276             pFT_Get_Paint_Layers FT_Get_Paint_Layers;
277             pFT_Get_Colorline_Stops FT_Get_Colorline_Stops;
278             pFT_Get_Paint FT_Get_Paint;
279         }
280     }
281 }