1 
2 //          Copyright Michael D. Parker 2018.
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.ftimage;
8 
9 import core.stdc.config;
10 import bindbc.freetype.bind.fttypes;
11 
12 alias FT_Pos = c_long;
13 
14 struct FT_Vector {
15     FT_Pos x;
16     FT_Pos y;
17 }
18 
19 struct FT_BBox {
20     FT_Pos xMin, yMin;
21     FT_Pos xMax, yMax;
22 }
23 
24 alias FT_Pixel_Mode = int;
25 enum {
26     FT_PIXEL_MODE_NONE = 0,
27     FT_PIXEL_MODE_MONO,
28     FT_PIXEL_MODE_GRAY,
29     FT_PIXEL_MODE_GRAY2,
30     FT_PIXEL_MODE_GRAY4,
31     FT_PIXEL_MODE_LCD,
32     FT_PIXEL_MODE_LCD_V,
33     FT_PIXEL_MODE_MAX
34 }
35 
36 struct FT_Bitmap {
37     uint rows;
38     uint width;
39     int pitch;
40     ubyte* buffer;
41     ushort num_grays;
42     ubyte pixel_mode;
43     ubyte palette_mode;
44     void* palette;
45 }
46 
47 struct FT_Outline {
48     short n_contours;
49     short n_points;
50     FT_Vector* points;
51     byte* tags;
52     short* contours;
53     int flags;
54 }
55 
56 enum FT_OUTLINE_CONTOURS_MAX = short.max;
57 enum FT_OUTLINE_POINTS_MAX = short.max;
58 
59 enum : uint {
60     FT_OUTLINE_NONE            = 0x0,
61     FT_OUTLINE_OWNER           = 0x1,
62     FT_OUTLINE_EVEN_ODD_FILL   = 0x2,
63     FT_OUTLINE_REVERSE_FILL    = 0x4,
64     FT_OUTLINE_IGNORE_DROPOUTS = 0x8,
65     FT_OUTLINE_HIGH_PRECISION  = 0x100,
66     FT_OUTLINE_SINGLE_PASS     = 0x200,
67 }
68 
69 enum {
70     FT_CURVE_TAG_ON          = 1,
71     FT_CURVE_TAG_CONIC       = 0,
72     FT_CURVE_TAG_CUBIC       = 2,
73     FT_CURVE_TAG_TOUCH_X     = 8,
74     FT_CURVE_TAG_TOUCH_Y     = 16,
75     FT_CURVE_TAG_TOUCH_BOTH  = FT_CURVE_TAG_TOUCH_X | FT_CURVE_TAG_TOUCH_Y,
76 }
77 
78 extern(C) nothrow {
79     alias FT_Outline_MoveToFunc = int function(const(FT_Vector)*, void*);
80     alias FT_Outline_LineToFunc = int function(const(FT_Vector)*, void*);
81     alias FT_Outline_ConicToFunc = int function(const(FT_Vector)*, const(FT_Vector)*, void*);
82     alias FT_Outline_CubicToFunc = int function(const(FT_Vector)*, const(FT_Vector)*, const(FT_Vector)*, void*);
83 }
84 
85 struct FT_Outline_Funcs {
86     FT_Outline_MoveToFunc move_to;
87     FT_Outline_LineToFunc line_to;
88     FT_Outline_ConicToFunc conic_to;
89     FT_Outline_CubicToFunc cubic_to;
90     int shift;
91     FT_Pos delta;
92 }
93 
94 alias FT_Glyph_Format = FT_Tag;
95 enum : FT_Tag {
96     FT_GLYPH_FORMAT_NONE = 0,
97     FT_GLYPH_FORMAT_COMPOSITE = FT_MAKE_TAG('c','o','m','p'),
98     FT_GLYPH_FORMAT_BITMAP = FT_MAKE_TAG('b','i','t','s'),
99     FT_GLYPH_FORMAT_OUTLINE = FT_MAKE_TAG('o','u','t','l'),
100     FT_GLYPH_FORMAT_PLOTTER = FT_MAKE_TAG('p','l','o','t'),
101 }
102 
103 struct FT_RasterRec;
104 alias FT_Raster = FT_RasterRec*;
105 
106 struct FT_Span {
107     short x;
108     ushort len;
109     ubyte coverage;
110 }
111 
112 extern(C) nothrow alias FT_SpanFunc = void function(int, int, FT_Span*, void*);
113 
114 enum {
115     FT_RASTER_FLAG_DEFAULT  = 0x0,
116     FT_RASTER_FLAG_AA       = 0x1,
117     FT_RASTER_FLAG_DIRECT   = 0x2,
118     FT_RASTER_FLAG_CLIP     = 0x4
119 }
120 
121 struct FT_Raster_Params {
122     const(FT_Bitmap)* target;
123     const(void)* source;
124     int flags;
125     FT_SpanFunc gray_spans;
126     void* black_spans;
127     void* bit_test;
128     void* bit_set;
129     void* user;
130     FT_BBox clip_box;
131 }
132 
133 extern(C) nothrow {
134     alias FT_Raster_NewFunc = int function(void*, FT_Raster*);
135     alias FT_Raster_DoneFunc = void function(FT_Raster);
136     alias FT_Raster_ResetFunc = void function(FT_Raster, ubyte*, uint);
137     alias FT_Raster_SetModeFunc = int function(FT_Raster, uint, void*);
138     alias FT_Raster_RenderFunc = int function(FT_Raster, FT_Raster_Params*);
139 }
140 
141 
142 struct FT_Raster_Funcs {
143     FT_Glyph_Format glyph_format;
144     FT_Raster_NewFunc raster_new;
145     FT_Raster_ResetFunc raster_reset;
146     FT_Raster_SetModeFunc raster_set_mode;
147     FT_Raster_RenderFunc raster_render;
148     FT_Raster_DoneFunc raster_done;
149 }