1 #ifndef COIN_GLUE_FREETYPE_H
2 #define COIN_GLUE_FREETYPE_H
3 
4 /**************************************************************************\
5  * Copyright (c) Kongsberg Oil & Gas Technologies AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from
21  * this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 \**************************************************************************/
35 
36 #ifndef COIN_INTERNAL
37 #error this is a private header file
38 #endif
39 
40 #ifdef HAVE_CONFIG_H
41 #include <config.h>
42 #endif /* HAVE_CONFIG_H */
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif /* __cplusplus */
47 
48 #if 0 /* to get proper auto-indentation in emacs */
49 }
50 #endif /* emacs indentation */
51 
52 /* FIXME: Usage of fontconfig is tightly coupled and only makes sense
53  * with freetype. therefore decided to define structures together with
54  * freetype. Still, should it better be in its own file or rather
55  * inside the HAVE_FREETYPE section? 20040411 tamer.
56  */
57 
58 #ifdef HAVE_FONTCONFIG
59 #include <fontconfig/fontconfig.h>
60 #else /* HAVE_FONTCONFIG */
61 
62 /* avoid including <fontconfig/fontconfig.h>. define absolutely
63  * necessary structs and types.
64  */
65 
66 #define FC_PIXEL_SIZE "pixelsize" /* Double */
67 
68 typedef enum _FcMatchKind {
69   FcMatchPattern, FcMatchFont
70 } FcMatchKind;
71 
72 typedef enum _FcResult {
73   FcResultMatch, FcResultNoMatch, FcResultTypeMismatch, FcResultNoId
74 } FcResult;
75 
76 typedef struct _FcPattern {
77   int num;
78   int size;
79   void * elts; /* void * instead of FcPatternElt * to minimize declarations! */
80   int ref;
81 } FcPattern;
82 
83 #endif /* !HAVE_FONTCONFIG */
84 
85 int cc_fcglue_available(void);
86 
87 int cc_fcglue_FcGetVersion(void);
88 FcPattern * cc_fcglue_FcNameParse(const unsigned char * name);
89 int cc_fcglue_FcConfigSubstitute(void * config, FcPattern * pattern, FcMatchKind kind);
90 void cc_fcglue_FcDefaultSubstitute(FcPattern *pattern);
91 FcPattern * cc_fcglue_FcFontMatch(void * config, FcPattern * pattern, FcResult * result);
92 FcResult cc_fcglue_FcPatternGetString(const FcPattern * pattern, const char * object, int n, unsigned char ** s);
93 void cc_fcglue_FcPatternDestroy(FcPattern * pattern);
94 void cc_fcglue_FcPatternPrint(const FcPattern * pattern);
95 int cc_fcglue_FcPatternAddDouble(FcPattern *pattern, const char *object, double d);
96 
97 #ifdef HAVE_FREETYPE
98 #include <ft2build.h>
99 #include <freetype/freetype.h>
100 #include <freetype/ftglyph.h>
101 #else /* HAVE_FREETYPE */
102 
103 #include <Inventor/C/basic.h>
104 
105 /*
106    We need some freetype structs, so define them here for runtime
107    linking support (we want to avoid including <freetype.h>).
108 */
109 
110 /* we also need some defines */
111 #define FT_LOAD_DEFAULT 0x0
112 #define FT_LOAD_RENDER 0x4
113 #define FT_LOAD_MONOCHROME 0x1000
114 #define FT_FACE_FLAG_KERNING (1L <<  6)
115 #define FT_KERNING_DEFAULT  0
116 #define FT_RENDER_MODE_NORMAL 0
117 #define FT_RENDER_MODE_MONO 2
118 #define ft_kerning_default FT_KERNING_DEFAULT
119 #define ft_render_mode_mono FT_RENDER_MODE_MONO
120 #define ft_render_mode_normal FT_RENDER_MODE_NORMAL
121 
122 #define FT_HAS_KERNING(face) (face->face_flags & FT_FACE_FLAG_KERNING)
123 
124 /* ...and lots of typedefs */
125 typedef void * FT_Library;
126 typedef int FT_Error;
127 typedef int FT_Int;
128 typedef long FT_Long;
129 typedef unsigned long FT_ULong;
130 typedef char FT_String;
131 typedef short FT_Short;
132 typedef unsigned short FT_UShort;
133 typedef struct FT_FaceRec_* FT_Face;
134 typedef struct FT_SizeRec_ * FT_Size;
135 typedef signed long FT_Fixed;
136 typedef signed long FT_Pos;
137 typedef int32_t FT_UInt32;
138 typedef unsigned int FT_UInt;
139 typedef struct FT_GlyphRec_ * FT_Glyph;
140 typedef struct FT_CharMapRec_ * FT_CharMap;
141 typedef struct FT_GlyphSlotRec_ * FT_GlyphSlot;
142 typedef struct FT_BitmapGlyphRec_ * FT_BitmapGlyph;
143 
144 typedef struct FT_Matrix_ {
145   long xx, xy;
146   long yx, yy;
147 } FT_Matrix;
148 
149 typedef struct FT_Vector_ {
150   long x;
151   long y;
152 } FT_Vector;
153 
154 typedef struct {
155   FT_Short height;
156   FT_Short width;
157 } FT_Bitmap_Size;
158 
159 typedef void (*FT_Generic_Finalizer)(void*  object);
160 
161 typedef struct {
162   void * data;
163   FT_Generic_Finalizer finalizer;
164 } FT_Generic;
165 
166 typedef struct {
167   FT_Pos  xMin, yMin;
168   FT_Pos  xMax, yMax;
169 } FT_BBox;
170 
171 struct FT_CharMapRec_ {
172   FT_Face face;
173   int encoding;
174   FT_UShort platform_id;
175   FT_UShort encoding_id;
176 };
177 
178 typedef struct {
179   int rows;
180   int width;
181   int pitch;
182   unsigned char * buffer;
183   short num_grays;
184   char pixel_mode;
185   char palette_mode;
186   void * palette;
187 } FT_Bitmap;
188 
189 struct FT_FaceRec_ {
190   FT_Long num_faces;
191   FT_Long face_index;
192 
193   FT_Long face_flags;
194   FT_Long style_flags;
195 
196   FT_Long num_glyphs;
197 
198   FT_String * family_name;
199   FT_String * style_name;
200 
201   FT_Int num_fixed_sizes;
202   FT_Bitmap_Size * available_sizes;
203 
204   FT_Int num_charmaps;
205   FT_CharMap * charmaps;
206 
207   FT_Generic generic;
208 
209   FT_BBox bbox;
210 
211   FT_UShort units_per_EM;
212   FT_Short ascender;
213   FT_Short descender;
214   FT_Short height;
215 
216   FT_Short max_advance_width;
217   FT_Short max_advance_height;
218 
219   FT_Short underline_position;
220   FT_Short underline_thickness;
221 
222   FT_GlyphSlot glyph;
223 
224   FT_Size size;
225   FT_CharMap charmap;
226 
227   /* private begin.
228    *
229    * FT_Driver         driver;
230    * FT_Memory         memory;
231    * FT_Stream         stream;
232    *
233    * FT_ListRec        sizes_list;
234    *
235    * FT_Generic        autohint;
236    * void*             extensions;
237    *
238    * FT_Face_Internal  internal;
239    *
240    * private end */
241 };
242 
243 typedef struct FT_GlyphRec_ {
244   FT_Library library;
245   void * clazz; /* const FT_Glyph_Class * */
246   int format;
247   FT_Vector advance;
248 } FT_GlyphRec;
249 
250 typedef struct {
251   short n_contours;
252   short n_points;
253   FT_Vector * points;
254   char * tags;
255   short * contours;
256   int flags;
257 } FT_Outline;
258 
259 typedef struct {
260   FT_Pos width;
261   FT_Pos height;
262   FT_Pos horiBearingX;
263   FT_Pos horiBearingY;
264   FT_Pos horiAdvance;
265   FT_Pos vertBearingX;
266   FT_Pos vertBearingY;
267   FT_Pos vertAdvance;
268 } FT_Glyph_Metrics;
269 
270 struct FT_GlyphSlotRec_ {
271   FT_Library library;
272   FT_Face face;
273   FT_GlyphSlot next;
274   FT_UInt flags;
275   FT_Generic generic;
276 
277   FT_Glyph_Metrics metrics;
278   FT_Fixed linearHoriAdvance;
279   FT_Fixed linearVertAdvance;
280   FT_Vector advance;
281 
282   int format; /* FT_Glyph_Format (enum) */
283 
284   FT_Bitmap bitmap;
285   FT_Int bitmap_left;
286   FT_Int bitmap_top;
287 
288   FT_Outline outline;
289 
290   FT_UInt num_subglyphs;
291   void * subglyphs; /* FT_SubGlyph (struct ptr) */
292 
293   void * control_data;
294   long control_len;
295 
296   void * other;
297   void * internal;
298 };
299 
300 typedef struct {
301   FT_UShort x_ppem;
302   FT_UShort y_ppem;
303 
304   FT_Fixed x_scale;
305   FT_Fixed y_scale;
306 
307   FT_Pos ascender;
308   FT_Pos descender;
309   FT_Pos height;
310   FT_Pos max_advance;
311 } FT_Size_Metrics;
312 
313 struct FT_Size_ {
314   FT_Face face;
315   FT_Generic generic;
316   FT_Size_Metrics metrics;
317   void * internal;
318 };
319 
320 struct FT_BitmapGlyphRec_ {
321   FT_GlyphRec  root;
322   FT_Int left;
323   FT_Int top;
324   FT_Bitmap bitmap;
325 };
326 
327 typedef int (*FT_Outline_MoveToFunc) (FT_Vector * to, void * user);
328 typedef int (*FT_Outline_LineToFunc) (FT_Vector * to, void * user);
329 typedef int (*FT_Outline_ConicToFunc) (FT_Vector * control, FT_Vector * to, void * user);
330 typedef int (*FT_Outline_CubicToFunc) (FT_Vector * control1, FT_Vector * control2, FT_Vector * to, void * user);
331 #define FT_Outline_MoveTo_Func FT_Outline_MoveToFunc
332 #define FT_Outline_LineTo_Func FT_Outline_LineToFunc
333 #define FT_Outline_ConicTo_Func FT_Outline_ConicToFunc
334 #define FT_Outline_CubicTo_Func FT_Outline_CubicToFunc
335 
336 typedef struct  FT_Outline_Funcs_ {
337   FT_Outline_MoveToFunc move_to;
338   FT_Outline_LineToFunc line_to;
339   FT_Outline_ConicToFunc conic_to;
340   FT_Outline_CubicToFunc cubic_to;
341   int shift;
342   FT_Pos delta;
343 } FT_Outline_Funcs;
344 
345 typedef struct  FT_OutlineGlyphRec_
346 {
347   FT_GlyphRec root;
348   FT_Outline outline;
349 
350 } FT_OutlineGlyphRec;
351 
352 
353 typedef struct FT_OutlineGlyphRec_* FT_OutlineGlyph;
354 
355 #endif /* !HAVE_FREETYPE */
356 
357 int cc_ftglue_available(void);
358 
359 /* FIXME: some of the typedef'ed function signatures below does not
360    match the correct function def, as given in
361    /usr/include/freetype2/freetype/freetype.h. 20050711 mortene. */
362 
363 FT_Error cc_ftglue_FT_Init_FreeType(FT_Library * library);
364 void cc_ftglue_FT_Library_Version(void * library, int * major, int * minor, int * patch);
365 void cc_ftglue_FT_Done_FreeType(void * library);
366 
367 FT_Error cc_ftglue_FT_New_Face(void * library, const char * filepathname, long faceindex, FT_Face * face);
368 FT_Error cc_ftglue_FT_Done_Face(void * face);
369 FT_Error cc_ftglue_FT_Select_Charmap(FT_Face face, int encoding);
370 FT_Error cc_ftglue_FT_Set_Char_Size(FT_Face face, long width, long height, unsigned int hres, unsigned int vres);
371 void cc_ftglue_FT_Set_Transform(FT_Face face, FT_Matrix * matrix, FT_Vector * delta);
372 FT_UInt cc_ftglue_FT_Get_Char_Index(FT_Face face, unsigned long charidx);
373 FT_Error cc_ftglue_FT_Load_Glyph(FT_Face face, unsigned int glyph, int32_t loadflags);
374 FT_Error cc_ftglue_FT_Get_Kerning(FT_Face face, unsigned int left, unsigned int right, unsigned int kernmode, FT_Vector * akerning);
375 FT_Error cc_ftglue_FT_Get_Glyph(void * glyphslot, FT_Glyph * glyph);
376 FT_Error cc_ftglue_FT_Glyph_To_Bitmap(FT_Glyph * glyph, int rendermode, FT_Vector * origin, int destroy);
377 void cc_ftglue_FT_Done_Glyph(FT_Glyph glyph);
378 FT_Error cc_ftglue_FT_Outline_Decompose(FT_Outline * outline, const FT_Outline_Funcs * func_interface, void * user);
379 
380 
381 #ifdef __cplusplus
382 }
383 #endif /* __cplusplus */
384 
385 #endif /* !COIN_GLUE_FREETYPE_H */
386