Commit 92238082497018d86df661bcb02909bef989efff

sammy 2008-05-02T09:15:38

* Change a few function names in the FTFont C bindings to avoid confusion with other classes. * Document the C bindings. Since it's almost copypasta from the C++ documentation, I put the constructors back in their original files.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
diff --git a/src/FTFont/FTFontGlue.cpp b/src/FTFont/FTFontGlue.cpp
index ace0bdb..3ae8189 100644
--- a/src/FTFont/FTFontGlue.cpp
+++ b/src/FTFont/FTFontGlue.cpp
@@ -138,67 +138,63 @@ C_FUN(int, ftglAttachData, (FTGLfont *f, const unsigned char *p, size_t s),
       return 0, Attach, (p, s));
 
 // bool FTFont::CharMap(FT_Encoding encoding);
-C_FUN(int, ftglCharMap, (FTGLfont *f, FT_Encoding enc),
+C_FUN(int, ftglSetFontCharMap, (FTGLfont *f, FT_Encoding enc),
       return 0, CharMap, (enc));
 
 // unsigned int FTFont::CharMapCount();
-C_FUN(unsigned int, ftglCharMapCount, (FTGLfont *f),
+C_FUN(unsigned int, ftglGetFontCharMapCount, (FTGLfont *f),
       return 0, CharMapCount, ());
 
 // FT_Encoding* FTFont::CharMapList();
-C_FUN(FT_Encoding *, ftglCharMapList, (FTGLfont* f),
+C_FUN(FT_Encoding *, ftglGetFontCharMapList, (FTGLfont* f),
       return NULL, CharMapList, ());
 
 // virtual bool FTFont::FaceSize(const unsigned int size,
 //                               const unsigned int res = 72);
-C_FUN(int, ftglSetFaceSize, (FTGLfont *f, unsigned int s),
-      return 0, FaceSize, (s));
-C_FUN(int, ftglSetFaceSizeRes, (FTGLfont *f, unsigned int s, unsigned int r),
-      return 0, FaceSize, (s, r));
+C_FUN(int, ftglSetFontFaceSize, (FTGLfont *f, unsigned int s, unsigned int r),
+      return 0, FaceSize, (s, r > 0 ? r : 72));
 
 // unsigned int FTFont::FaceSize() const;
 // XXX: need to call FaceSize() as FTFont::FaceSize() because of FTGLTexture
-C_FUN(unsigned int, ftglGetFaceSize, (FTGLfont *f),
+C_FUN(unsigned int, ftglGetFontFaceSize, (FTGLfont *f),
       return 0, FTFont::FaceSize, ());
 
 // virtual void FTFont::Depth(float depth);
-C_FUN(void, ftglSetDepth, (FTGLfont *f, float d), return, Depth, (d));
+C_FUN(void, ftglSetFontDepth, (FTGLfont *f, float d), return, Depth, (d));
 
 // virtual void FTFont::Outset(float front, float back);
-C_FUN(void, ftglSetOutset, (FTGLfont *f, float front, float back),
+C_FUN(void, ftglSetFontOutset, (FTGLfont *f, float front, float back),
       return, FTFont::Outset, (front, back));
 
 // void FTFont::UseDisplayList(bool useList);
-C_FUN(void, ftglUseDisplayList, (FTGLfont *f, int l),
+C_FUN(void, ftglFontUseDisplayList, (FTGLfont *f, int l),
       return, UseDisplayList, (l));
 
 // float FTFont::Ascender() const;
-C_FUN(float, ftglAscender, (FTGLfont *f), return 0.f, Ascender, ());
+C_FUN(float, ftglGetFontAscender, (FTGLfont *f), return 0.f, Ascender, ());
 
 // float FTFont::Descender() const;
-C_FUN(float, ftglDescender, (FTGLfont *f), return 0.f, Descender, ());
+C_FUN(float, ftglGetFontDescender, (FTGLfont *f), return 0.f, Descender, ());
 
 // float FTFont::LineHeight() const;
-C_FUN(float, ftglLineHeight, (FTGLfont *f), return 0.f, LineHeight, ());
+C_FUN(float, ftglGetFontLineHeight, (FTGLfont *f), return 0.f, LineHeight, ());
 
 // void FTFont::BBox(const char* string, float& llx, float& lly, float& llz,
 //                   float& urx, float& ury, float& urz);
-C_FUN(void, ftglBBox, (FTGLfont *f, const char* s, float c[6]),
-      return, BBox, (s, c[0], c[1], c[2], c[3], c[4], c[5]));
+C_FUN(void, ftglGetFontBBox, (FTGLfont *f, const char* s, int start, int end,
+                              float c[6]),
+      return, BBox, (s, start, end, c[0], c[1], c[2], c[3], c[4], c[5]));
 
 // float FTFont::Advance(const char* string);
-C_FUN(float, ftglAdvance, (FTGLfont *f, const char* s),
+C_FUN(float, ftglGetFontAdvance, (FTGLfont *f, const char* s),
       return 0.f, Advance, (s));
 
-// virtual void FTFont::Render(const char* string);
-C_FUN(void, ftglRender, (FTGLfont *f, const char * s), return, Render, (s));
-
 // virtual void Render(const char* string, int renderMode);
-C_FUN(void, ftglRenderMode, (FTGLfont *f, const char *s, int r),
+C_FUN(void, ftglRenderFont, (FTGLfont *f, const char *s, int r),
       return, Render, (s, r));
 
 // FT_Error FTFont::Error() const;
-C_FUN(FT_Error, ftglError, (FTGLfont *f), return -1, Error, ());
+C_FUN(FT_Error, ftglGetFontError, (FTGLfont *f), return -1, Error, ());
 
 FTGL_END_C_DECLS
 
diff --git a/src/FTGL/FTFont.h b/src/FTGL/FTFont.h
index b610d2a..fdc8dfd 100644
--- a/src/FTGL/FTFont.h
+++ b/src/FTGL/FTFont.h
@@ -74,12 +74,12 @@ class FTGL_EXPORT FTFont
         bool Attach(const char* fontFilePath);
 
         /**
-         * Attach auxilliary data to font e.g font metrics, from memory
+         * Attach auxilliary data to font e.g font metrics, from memory.
          *
          * Note: not all font formats implement this function.
          *
-         * @param pBufferBytes  the in-memory buffer
-         * @param bufferSizeInBytes  the length of the buffer in bytes
+         * @param pBufferBytes  the in-memory buffer.
+         * @param bufferSizeInBytes  the length of the buffer in bytes.
          * @return          <code>true</code> if file has been attached
          *                  successfully.
          */
@@ -91,7 +91,7 @@ class FTGL_EXPORT FTFont
          *
          * @param encoding      Freetype enumerate for char map code.
          * @return              <code>true</code> if charmap was valid and
-         *                      set correctly
+         *                      set correctly.
          */
         bool CharMap(FT_Encoding encoding);
 
@@ -119,7 +119,7 @@ class FTGL_EXPORT FTFont
         bool FaceSize(const unsigned int size, const unsigned int res = 72);
 
         /**
-         * Get the current face size in points.
+         * Get the current face size in points (1/72 inch).
          *
          * @return face size
          */
@@ -308,40 +308,173 @@ class FTGL_EXPORT FTFont
 
 FTGL_BEGIN_C_DECLS
 
-FTGL_EXPORT FTGLfont *ftglCreateBitmapFont(const char *fontname);
-FTGL_EXPORT FTGLfont *ftglCreateExtrudeFont(const char *fontname);
-FTGL_EXPORT FTGLfont *ftglCreateOutlineFont(const char *fontname);
-FTGL_EXPORT FTGLfont *ftglCreatePixmapFont(const char *fontname);
-FTGL_EXPORT FTGLfont *ftglCreatePolygonFont(const char *fontname);
-FTGL_EXPORT FTGLfont *ftglCreateTextureFont(const char *fontname);
+/**
+ * Destroy an FTGL font object.
+ *
+ * @param font  An FTGLfont* object.
+ */
+FTGL_EXPORT void ftglDestroyFont(FTGLfont* font);
+
+/**
+ * Attach auxilliary file to font e.g. font metrics.
+ *
+ * Note: not all font formats implement this function.
+ *
+ * @param font  An FTGLfont* object.
+ * @param path  Auxilliary font file path.
+ * @return  1 if file has been attached successfully.
+ */
+FTGL_EXPORT int ftglAttachFile(FTGLfont* font, const char* path);
+
+/**
+ * Attach auxilliary data to font, e.g. font metrics, from memory.
+ *
+ * Note: not all font formats implement this function.
+ *
+ * @param font  An FTGLfont* object.
+ * @param data  The in-memory buffer.
+ * @param size  The length of the buffer in bytes.
+ * @return  1 if file has been attached successfully.
+ */
+FTGL_EXPORT int ftglAttachData(FTGLfont* font, const unsigned char * data,
+                               size_t size);
+
+/**
+ * Set the character map for the face.
+ *
+ * @param font  An FTGLfont* object.
+ * @param encoding  Freetype enumerate for char map code.
+ * @return  1 if charmap was valid and set correctly.
+ */
+FTGL_EXPORT int ftglSetFontCharMap(FTGLfont* font, FT_Encoding encoding);
+
+/**
+ * Get the number of character maps in this face.
+ *
+ * @param font  An FTGLfont* object.
+ * @return character map count.
+ */
+FTGL_EXPORT unsigned int ftglGetFontCharMapCount(FTGLfont* font);
+
+/**
+ * Get a list of character maps in this face.
+ *
+ * @param font  An FTGLfont* object.
+ * @return pointer to the first encoding.
+ */
+FTGL_EXPORT FT_Encoding* ftglGetFontCharMapList(FTGLfont* font);
+
+/**
+ * Set the char size for the current face.
+ *
+ * @param font  An FTGLfont* object.
+ * @param size  The face size in points (1/72 inch).
+ * @param res  The resolution of the target device, or 0 to use the default
+ *             value of 72.
+ * @return  1 if size was set correctly.
+ */
+FTGL_EXPORT int ftglSetFontFaceSize(FTGLfont* font, unsigned int size,
+                                    unsigned int res);
+
+/**
+ * Get the current face size in points (1/72 inch).
+ *
+ * @param font  An FTGLfont* object.
+ * @return face size
+ */
+FTGL_EXPORT unsigned int ftglGetFontFaceSize(FTGLfont* font);
 
-FTGL_EXPORT void ftglDestroyFont(FTGLfont*);
+/**
+ * Set the extrusion distance for the font. Only implemented by
+ * FTExtrudeFont.
+ *
+ * @param font  An FTGLfont* object.
+ * @param depth  The extrusion distance.
+ */
+FTGL_EXPORT void ftglSetDepth(FTGLfont* font, float depth);
 
-FTGL_EXPORT int ftglAttachFile (FTGLfont*, const char*);
-FTGL_EXPORT int ftglAttachData (FTGLfont*, const unsigned char *, size_t);
+/**
+ * Set the outset distance for the font. Only FTOutlineFont, FTPolygonFont
+ * and FTExtrudeFont implement front outset. Only FTExtrudeFont implements
+ * back outset.
+ *
+ * @param font  An FTGLfont* object.
+ * @param front  The front outset distance.
+ * @param back  The back outset distance.
+ */
+FTGL_EXPORT void ftglSetFontOutset(FTGLfont* font, float front, float back);
 
-FTGL_EXPORT int          ftglCharMap      (FTGLfont*, FT_Encoding);
-FTGL_EXPORT unsigned int ftglCharMapCount (FTGLfont*);
-FTGL_EXPORT FT_Encoding* CharMapList      (FTGLfont*);
+/**
+ * Enable or disable the use of Display Lists inside FTGL
+ *
+ * @param font  An FTGLfont* object.
+ * @param useList  1 turns ON display lists.
+ *                 0 turns OFF display lists.
+ */
+FTGL_EXPORT void ftglFontUseDisplayList(FTGLfont* font, int useList);
 
-FTGL_EXPORT int          ftglSetFaceSize    (FTGLfont*, unsigned int);
-FTGL_EXPORT int          ftglSetFaceSizeRes (FTGLfont*,
-                                             unsigned int, unsigned int);
-FTGL_EXPORT unsigned int ftglGetFaceSize    (FTGLfont*);
-FTGL_EXPORT void         ftglSetDepth       (FTGLfont*, float);
-FTGL_EXPORT void         ftglSetOutset      (FTGLfont*, float, float);
+/**
+ * Get the global ascender height for the face.
+ *
+ * @param font  An FTGLfont* object.
+ * @return  Ascender height
+ */
+FTGL_EXPORT float ftglGetFontAscender(FTGLfont* font);
 
-FTGL_EXPORT void ftglUseDisplayList (FTGLfont*, int);
+/**
+ * Gets the global descender height for the face.
+ *
+ * @param font  An FTGLfont* object.
+ * @return  Descender height
+ */
+FTGL_EXPORT float ftglGetFontDescender(FTGLfont* font);
 
-FTGL_EXPORT float ftglAscender   (FTGLfont*);
-FTGL_EXPORT float ftglDescender  (FTGLfont*);
-FTGL_EXPORT float ftglLineHeight (FTGLfont*);
-FTGL_EXPORT void  ftglBBox       (FTGLfont*, const char *, float[]);
-FTGL_EXPORT float ftglAdvance    (FTGLfont*, const char *);
-FTGL_EXPORT void  ftglRender     (FTGLfont*, const char *);
-FTGL_EXPORT void  ftglRenderMode (FTGLfont*, const char *, int);
+/**
+ * Gets the line spacing for the font.
+ *
+ * @param font  An FTGLfont* object.
+ * @return  Line height
+ */
+FTGL_EXPORT float ftglGetFontLineHeight(FTGLfont* font);
+
+/**
+ * Get the bounding box for a string.
+ *
+ * @param font  An FTGLfont* object.
+ * @param string  A char buffer
+ * @param start  The index of the first character of string to check.
+ * @param end  The index of the last character of string to check.  If < 0
+               then characters will be parsed until a '@\0' is encountered.
+ * @param bounds  An array of 6 float values where the bounding box's lower
+ *                left near and upper right far 3D coordinates will be stored.
+ */
+FTGL_EXPORT void ftglGetFontBBox(FTGLfont* font, const char *string,
+                                 int start, int end, float bounds[6]);
+
+/**
+ * Get the advance width for a string.
+ *
+ * @param font  An FTGLfont* object.
+ * @param string  A char string.
+ * @return  Advance width
+ */
+FTGL_EXPORT float ftglGetFontAdvance(FTGLfont* font, const char *string);
+
+/**
+ * Render a string of characters.
+ *
+ * @param font  An FTGLfont* object.
+ * @param string  Char string to be output.
+ * @param mode  Render mode to display.
+ */
+FTGL_EXPORT void ftglRenderFont(FTGLfont* font, const char *string, int mode);
 
-FTGL_EXPORT FT_Error ftglError (FTGLfont*);
+/**
+ * Queries the Font for errors.
+ *
+ * @return  The current error code.
+ */
+FTGL_EXPORT FT_Error ftglGetFontError(FTGLfont* font);
 
 FTGL_END_C_DECLS
 
diff --git a/src/FTGL/FTGLBitmapFont.h b/src/FTGL/FTGLBitmapFont.h
index f91d658..58ad7e4 100644
--- a/src/FTGL/FTGLBitmapFont.h
+++ b/src/FTGL/FTGLBitmapFont.h
@@ -71,5 +71,19 @@ class FTGL_EXPORT FTBitmapFont : public FTFont
 
 #endif //__cplusplus
 
+FTGL_BEGIN_C_DECLS
+
+/**
+ * Create a specialised FTGLfont object for handling bitmap fonts.
+ *
+ * @param file  The font file name.
+ * @return  An FTGLfont* object.
+ *
+ * @see  FTGLfont
+ */
+FTGL_EXPORT FTGLfont *ftglCreateBitmapFont(const char *file);
+
+FTGL_END_C_DECLS
+
 #endif  //  __FTBitmapFont__
 
diff --git a/src/FTGL/FTGLExtrdFont.h b/src/FTGL/FTGLExtrdFont.h
index 05963cd..3404c7f 100644
--- a/src/FTGL/FTGLExtrdFont.h
+++ b/src/FTGL/FTGLExtrdFont.h
@@ -72,5 +72,20 @@ class FTGL_EXPORT FTExtrudeFont : public FTFont
 
 #endif //__cplusplus
 
+FTGL_BEGIN_C_DECLS
+
+/**
+ * Create a specialised FTGLfont object for handling extruded poygon fonts.
+ *
+ * @param file  The font file name.
+ * @return  An FTGLfont* object.
+ *
+ * @see  FTGLfont
+ * @see  ftglCreatePolygonFont
+ */
+FTGL_EXPORT FTGLfont *ftglCreateExtrudeFont(const char *file);
+
+FTGL_END_C_DECLS
+
 #endif // __FTExtrudeFont__
 
diff --git a/src/FTGL/FTGLOutlineFont.h b/src/FTGL/FTGLOutlineFont.h
index 510b0f4..5f8a2f3 100644
--- a/src/FTGL/FTGLOutlineFont.h
+++ b/src/FTGL/FTGLOutlineFont.h
@@ -71,4 +71,19 @@ class FTGL_EXPORT FTOutlineFont : public FTFont
 
 #endif //__cplusplus
 
+FTGL_BEGIN_C_DECLS
+
+/**
+ * Create a specialised FTGLfont object for handling vector outline fonts.
+ *
+ * @param file  The font file name.
+ * @return  An FTGLfont* object.
+ *
+ * @see  FTGLfont
+ */
+FTGL_EXPORT FTGLfont *ftglCreateOutlineFont(const char *file);
+
+FTGL_END_C_DECLS
+
 #endif // __FTOutlineFont__
+
diff --git a/src/FTGL/FTGLPixmapFont.h b/src/FTGL/FTGLPixmapFont.h
index 0b241cf..044674f 100644
--- a/src/FTGL/FTGLPixmapFont.h
+++ b/src/FTGL/FTGLPixmapFont.h
@@ -71,5 +71,19 @@ class FTGL_EXPORT FTPixmapFont : public FTFont
 
 #endif // __cplusplus
 
+FTGL_BEGIN_C_DECLS
+
+/**
+ * Create a specialised FTGLfont object for handling pixmap (grey scale) fonts.
+ *
+ * @param file  The font file name.
+ * @return  An FTGLfont* object.
+ *
+ * @see  FTGLfont
+ */
+FTGL_EXPORT FTGLfont *ftglCreatePixmapFont(const char *file);
+
+FTGL_END_C_DECLS
+
 #endif  //  __FTPixmapFont__
 
diff --git a/src/FTGL/FTGLPolygonFont.h b/src/FTGL/FTGLPolygonFont.h
index 9acff59..c2468d4 100644
--- a/src/FTGL/FTGLPolygonFont.h
+++ b/src/FTGL/FTGLPolygonFont.h
@@ -71,5 +71,20 @@ class FTGL_EXPORT FTPolygonFont : public FTFont
 
 #endif //__cplusplus
 
+FTGL_BEGIN_C_DECLS
+
+/**
+ * Create a specialised FTGLfont object for handling tesselated polygon
+ * mesh fonts.
+ *
+ * @param file  The font file name.
+ * @return  An FTGLfont* object.
+ *
+ * @see  FTGLfont
+ */
+FTGL_EXPORT FTGLfont *ftglCreatePolygonFont(const char *file);
+
+FTGL_END_C_DECLS
+
 #endif  //  __FTPolygonFont__
 
diff --git a/src/FTGL/FTGLTextureFont.h b/src/FTGL/FTGLTextureFont.h
index 02e3f8f..3982847 100644
--- a/src/FTGL/FTGLTextureFont.h
+++ b/src/FTGL/FTGLTextureFont.h
@@ -71,5 +71,19 @@ class  FTGL_EXPORT FTTextureFont : public FTFont
 
 #endif //__cplusplus
 
+FTGL_BEGIN_C_DECLS
+
+/**
+ * Create a specialised FTGLfont object for handling texture-mapped fonts.
+ *
+ * @param file  The font file name.
+ * @return  An FTGLfont* object.
+ *
+ * @see  FTGLfont
+ */
+FTGL_EXPORT FTGLfont *ftglCreateTextureFont(const char *file);
+
+FTGL_END_C_DECLS
+
 #endif // __FTTextureFont__
 
diff --git a/test/CTest.c b/test/CTest.c
index 883126e..3cddc27 100644
--- a/test/CTest.c
+++ b/test/CTest.c
@@ -40,13 +40,13 @@ int main(int argc, char *argv[])
     ALLOC(ftglCreateTextureFont, f[5], argv[1]);
 
     for(i = 0; i < 6; i++)
-        ftglRender(f[i], "Hello world");
+        ftglRenderFont(f[i], "Hello world", FTGL_RENDER_ALL);
 
     for(i = 0; i < 6; i++)
-        ftglSetFaceSize(f[i], 37);
+        ftglSetFontFaceSize(f[i], 37, 72);
 
     for(i = 0; i < 6; i++)
-        ftglRender(f[i], "Hello world");
+        ftglRenderFont(f[i], "Hello world", FTGL_RENDER_ALL);
 
     for(i = 0; i < 6; i++)
         ftglDestroyFont(f[i]);