* Wrote C bindings for the FTGlyph class.
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
diff --git a/include/FTBBox.h b/include/FTBBox.h
index 3db2c4b..6202e41 100644
--- a/include/FTBBox.h
+++ b/include/FTBBox.h
@@ -26,8 +26,11 @@
#ifndef __FTBBox__
#define __FTBBox__
-#include "ftgl.h"
-#include "FTPoint.h"
+#include <ftgl.h>
+#include <FTPoint.h>
+
+#ifdef __cplusplus
+
/**
* FTBBox is a convenience class for handling bounding boxes.
@@ -158,5 +161,7 @@ class FTGL_EXPORT FTBBox
};
+#endif //__cplusplus
+
#endif // __FTBBox__
diff --git a/include/FTBitmapGlyph.h b/include/FTBitmapGlyph.h
index e2387f0..3c41b38 100644
--- a/include/FTBitmapGlyph.h
+++ b/include/FTBitmapGlyph.h
@@ -28,6 +28,9 @@
#include <ftgl.h>
+#ifdef __cplusplus
+
+
/**
* FTBitmapGlyph is a specialisation of FTGlyph for creating bitmaps.
*
@@ -54,5 +57,7 @@ class FTGL_EXPORT FTBitmapGlyph : public FTGlyph
virtual ~FTBitmapGlyph();
};
+#endif //__cplusplus
+
#endif // __FTBitmapGlyph__
diff --git a/include/FTExtrdGlyph.h b/include/FTExtrdGlyph.h
index 50c6c0d..142f7b3 100644
--- a/include/FTExtrdGlyph.h
+++ b/include/FTExtrdGlyph.h
@@ -28,6 +28,9 @@
#include <ftgl.h>
+#ifdef __cplusplus
+
+
/**
* FTExtrdGlyph is a specialisation of FTGlyph for creating tessellated
* extruded polygon glyphs.
@@ -61,5 +64,7 @@ class FTGL_EXPORT FTExtrdGlyph : public FTGlyph
virtual ~FTExtrdGlyph();
};
+#endif //__cplusplus
+
#endif // __FTExtrdGlyph__
diff --git a/include/FTGlyph.h b/include/FTGlyph.h
index 6a443de..a1716bf 100644
--- a/include/FTGlyph.h
+++ b/include/FTGlyph.h
@@ -28,6 +28,8 @@
#include <ftgl.h>
+#ifdef __cplusplus
+
class FTGlyphImpl;
/**
@@ -85,5 +87,34 @@ class FTGL_EXPORT FTGlyph
FTGlyphImpl *impl;
};
+#endif //__cplusplus
+
+FTGL_BEGIN_C_DECLS
+
+FTGL_EXPORT FTGLglyph *ftglCreateBitmapGlyph(FT_GlyphSlot glyph);
+FTGL_EXPORT FTGLglyph *ftglCreateExtrdGlyph(FT_GlyphSlot glyph, float depth,
+ float frontOutset, float backOutset,
+ int useDisplayList);
+FTGL_EXPORT FTGLglyph *ftglCreateOutlineGlyph(FT_GlyphSlot glyph, float outset,
+ int useDisplayList);
+FTGL_EXPORT FTGLglyph *ftglCreatePixmapGlyph(FT_GlyphSlot glyph);
+FTGL_EXPORT FTGLglyph *ftglCreatePolyGlyph(FT_GlyphSlot glyph, float outset,
+ int useDisplayList);
+FTGL_EXPORT FTGLglyph *ftglCreateTextureGlyph(FT_GlyphSlot glyph, int id,
+ int xOffset, int yOffset,
+ int width, int height);
+
+FTGL_EXPORT void ftglDestroyGlyph(FTGLglyph *g);
+
+FTGL_EXPORT void ftglGlyphRender(FTGLglyph *g, FTGL_DOUBLE penx,
+ FTGL_DOUBLE peny, int renderMode,
+ FTGL_DOUBLE *advancex, FTGL_DOUBLE *advancey);
+FTGL_EXPORT void ftglGlyphAdvance(FTGLglyph *g, FTGL_DOUBLE *advancex,
+ FTGL_DOUBLE *advancey);
+FTGL_EXPORT void ftglGlyphBBox(FTGLglyph *g, float *lx, float *ly, float *lz,
+ float *ux, float *uy, float *uz);
+
+FTGL_END_C_DECLS
+
#endif // __FTGlyph__
diff --git a/include/FTLayout.h b/include/FTLayout.h
index 11242b2..4dde6d6 100644
--- a/include/FTLayout.h
+++ b/include/FTLayout.h
@@ -91,7 +91,7 @@ FTGL_EXPORT float ftglLayoutGetLineLength (FTGLlayout *);
FTGL_EXPORT void ftglLayoutSetAlignment (FTGLlayout *, const FTGL::TextAlignment);
FTGL_EXPORT FTGL::TextAlignment ftglLayoutGetAlignement (FTGLlayout *);
#else
-FTGL_EXPORT void ftglLayoutSetAlignment (FTGLlayout *, const TextAlignment);
+FTGL_EXPORT void ftglLayoutSetAlignment (FTGLlayout *, const int);
FTGL_EXPORT int ftglLayoutGetAlignement (FTGLlayout *);
#endif
diff --git a/include/FTOutlineGlyph.h b/include/FTOutlineGlyph.h
index 1435996..1aad548 100644
--- a/include/FTOutlineGlyph.h
+++ b/include/FTOutlineGlyph.h
@@ -28,6 +28,9 @@
#include <ftgl.h>
+#ifdef __cplusplus
+
+
/**
* FTOutlineGlyph is a specialisation of FTGlyph for creating outlines.
*
@@ -57,5 +60,7 @@ class FTGL_EXPORT FTOutlineGlyph : public FTGlyph
virtual ~FTOutlineGlyph();
};
+#endif //__cplusplus
+
#endif // __FTOutlineGlyph__
diff --git a/include/FTPixmapGlyph.h b/include/FTPixmapGlyph.h
index 03f858e..86528da 100644
--- a/include/FTPixmapGlyph.h
+++ b/include/FTPixmapGlyph.h
@@ -28,6 +28,9 @@
#include <ftgl.h>
+#ifdef __cplusplus
+
+
/**
* FTPixmapGlyph is a specialisation of FTGlyph for creating pixmaps.
*
@@ -50,5 +53,7 @@ class FTGL_EXPORT FTPixmapGlyph : public FTGlyph
virtual ~FTPixmapGlyph();
};
+#endif //__cplusplus
+
#endif // __FTPixmapGlyph__
diff --git a/include/FTPoint.h b/include/FTPoint.h
index 4b86f3b..cb9d258 100644
--- a/include/FTPoint.h
+++ b/include/FTPoint.h
@@ -26,7 +26,10 @@
#ifndef __FTPoint__
#define __FTPoint__
-#include "ftgl.h"
+#include <ftgl.h>
+
+#ifdef __cplusplus
+
/**
* FTPoint class is a basic 3 dimensional point or vector.
@@ -221,5 +224,7 @@ class FTGL_EXPORT FTPoint
FTGL_DOUBLE values[3];
};
+#endif //__cplusplus
+
#endif // __FTPoint__
diff --git a/include/FTPolyGlyph.h b/include/FTPolyGlyph.h
index 8732443..2d3e96a 100644
--- a/include/FTPolyGlyph.h
+++ b/include/FTPolyGlyph.h
@@ -28,6 +28,9 @@
#include <ftgl.h>
+#ifdef __cplusplus
+
+
/**
* FTPolyGlyph is a specialisation of FTGlyph for creating tessellated
* polygon glyphs.
@@ -58,5 +61,7 @@ class FTGL_EXPORT FTPolyGlyph : public FTGlyph
virtual ~FTPolyGlyph();
};
+#endif //__cplusplus
+
#endif // __FTPolyGlyph__
diff --git a/include/FTSimpleLayout.h b/include/FTSimpleLayout.h
index 26fb6c1..6190f9b 100644
--- a/include/FTSimpleLayout.h
+++ b/include/FTSimpleLayout.h
@@ -123,7 +123,7 @@ class FTGL_EXPORT FTSimpleLayout : public FTLayout
#endif //__cplusplus
FTGL_BEGIN_C_DECLS
- FTGL_EXPORT FTGLlayout *ftglCreateSimpleLayout();
+ FTGL_EXPORT FTGLlayout *ftglCreateSimpleLayout(void);
FTGL_END_C_DECLS
#endif /* __FTSimpleLayout__ */
diff --git a/include/FTTextureGlyph.h b/include/FTTextureGlyph.h
index 6206513..c14bd96 100644
--- a/include/FTTextureGlyph.h
+++ b/include/FTTextureGlyph.h
@@ -28,6 +28,9 @@
#include <ftgl.h>
+#ifdef __cplusplus
+
+
/**
* FTTextureGlyph is a specialisation of FTGlyph for creating texture
* glyphs.
@@ -60,5 +63,7 @@ class FTGL_EXPORT FTTextureGlyph : public FTGlyph
virtual ~FTTextureGlyph();
};
+#endif //__cplusplus
+
#endif // __FTTextureGlyph__
diff --git a/include/ftgl.h b/include/ftgl.h
index eba6ea5..0d558a0 100644
--- a/include/ftgl.h
+++ b/include/ftgl.h
@@ -47,6 +47,8 @@ typedef float FTGL_FLOAT;
FTGL_BEGIN_C_DECLS
+ struct _FTGLGlyph;
+ typedef struct _FTGLglyph FTGLglyph;
struct _FTGLFont;
typedef struct _FTGLfont FTGLfont;
struct _FTGLlayout;
diff --git a/src/FTGlyph/FTGlyphGlue.cpp b/src/FTGlyph/FTGlyphGlue.cpp
index b74b528..d969c32 100644
--- a/src/FTGlyph/FTGlyphGlue.cpp
+++ b/src/FTGlyph/FTGlyphGlue.cpp
@@ -2,7 +2,7 @@
* FTGL - OpenGL font library
*
* Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
- * 2008 Éric Beets <ericbeets@free.fr>
+ * 2008 Sam Hocevar <sam@zoy.org>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@@ -31,9 +31,150 @@
FTGL_BEGIN_C_DECLS
-//
-// C wrappers for FTGlyph
-//
+#define C_TOR(cname, cargs, cxxname, cxxarg, cxxtype) \
+ FTGLglyph* cname cargs \
+ { \
+ cxxname *g = new cxxname cxxarg; \
+ if(g->Error()) \
+ { \
+ delete g; \
+ return NULL; \
+ } \
+ FTGLglyph *ftgl = (FTGLglyph *)malloc(sizeof(FTGLglyph)); \
+ ftgl->ptr = g; \
+ ftgl->type = cxxtype; \
+ return ftgl; \
+ }
+
+// FTBitmapGlyph::FTBitmapGlyph();
+C_TOR(ftglCreateBitmapGlyph, (FT_GlyphSlot glyph),
+ FTBitmapGlyph, (glyph), GLYPH_BITMAP);
+
+// FTExtrdGlyph::FTExtrdGlyph();
+C_TOR(ftglCreateExtrdGlyph, (FT_GlyphSlot glyph, float depth, float frontOutset,
+ float backOutset, int useDisplayList),
+ FTExtrdGlyph, (glyph, depth, frontOutset, backOutset, useDisplayList),
+ GLYPH_EXTRUDE);
+
+// FTOutlineGlyph::FTOutlineGlyph();
+C_TOR(ftglCreateOutlineGlyph, (FT_GlyphSlot glyph, float outset,
+ int useDisplayList),
+ FTOutlineGlyph, (glyph, outset, useDisplayList), GLYPH_OUTLINE);
+
+// FTPixmapGlyph::FTPixmapGlyph();
+C_TOR(ftglCreatePixmapGlyph, (FT_GlyphSlot glyph),
+ FTPixmapGlyph, (glyph), GLYPH_PIXMAP);
+
+// FTPolyGlyph::FTPolyGlyph();
+C_TOR(ftglCreatePolyGlyph, (FT_GlyphSlot glyph, float outset,
+ int useDisplayList),
+ FTPolyGlyph, (glyph, outset, useDisplayList), GLYPH_OUTLINE);
+
+// FTTextureGlyph::FTTextureGlyph();
+C_TOR(ftglCreateTextureGlyph, (FT_GlyphSlot glyph, int id, int xOffset,
+ int yOffset, int width, int height),
+ FTTextureGlyph, (glyph, id, xOffset, yOffset, width, height),
+ GLYPH_TEXTURE);
+
+#define C_FUN(cret, cname, cargs, cxxerr, cxxname, cxxarg) \
+ cret cname cargs \
+ { \
+ if(!g || !g->ptr) \
+ { \
+ fprintf(stderr, "FTGL warning: NULL pointer in %s\n", #cname); \
+ cxxerr; \
+ } \
+ switch(g->type) \
+ { \
+ case FTGL::GLYPH_BITMAP: \
+ return dynamic_cast<FTBitmapGlyph*>(g->ptr)->cxxname cxxarg; \
+ case FTGL::GLYPH_EXTRUDE: \
+ return dynamic_cast<FTExtrdGlyph*>(g->ptr)->cxxname cxxarg; \
+ case FTGL::GLYPH_OUTLINE: \
+ return dynamic_cast<FTOutlineGlyph*>(g->ptr)->cxxname cxxarg; \
+ case FTGL::GLYPH_PIXMAP: \
+ return dynamic_cast<FTPixmapGlyph*>(g->ptr)->cxxname cxxarg; \
+ case FTGL::GLYPH_POLYGON: \
+ return dynamic_cast<FTPolyGlyph*>(g->ptr)->cxxname cxxarg; \
+ case FTGL::GLYPH_TEXTURE: \
+ return dynamic_cast<FTTextureGlyph*>(g->ptr)->cxxname cxxarg; \
+ } \
+ fprintf(stderr, "FTGL warning: %s not implemented for %d\n", #cname, g->type); \
+ cxxerr; \
+ }
+
+// FTGlyph::~FTGlyph();
+void ftglDestroyGlyph(FTGLglyph *g)
+{
+ if(!g || !g->ptr)
+ {
+ fprintf(stderr, "FTGL warning: NULL pointer in %s\n", __FUNCTION__);
+ return;
+ }
+ switch(g->type)
+ {
+ case FTGL::GLYPH_BITMAP:
+ delete dynamic_cast<FTBitmapGlyph*>(g->ptr); break;
+ case FTGL::GLYPH_EXTRUDE:
+ delete dynamic_cast<FTExtrdGlyph*>(g->ptr); break;
+ case FTGL::GLYPH_OUTLINE:
+ delete dynamic_cast<FTOutlineGlyph*>(g->ptr); break;
+ case FTGL::GLYPH_PIXMAP:
+ delete dynamic_cast<FTPixmapGlyph*>(g->ptr); break;
+ case FTGL::GLYPH_POLYGON:
+ delete dynamic_cast<FTPolyGlyph*>(g->ptr); break;
+ case FTGL::GLYPH_TEXTURE:
+ delete dynamic_cast<FTTextureGlyph*>(g->ptr); break;
+ default:
+ fprintf(stderr, "FTGL warning: %s not implemented for %d\n",
+ __FUNCTION__, g->type);
+ break;
+ }
+
+ g->ptr = NULL;
+}
+
+// const FTPoint& FTGlyph::Render(const FTPoint& pen, int renderMode);
+C_FUN(static const FTPoint&, _ftglGlyphRender, (FTGLglyph *g,
+ const FTPoint& pen, int renderMode),
+ return *(new FTPoint()), Render, (pen, renderMode));
+
+void ftglGlyphRender(FTGLglyph *g, FTGL_DOUBLE penx, FTGL_DOUBLE peny,
+ int renderMode, FTGL_DOUBLE *advancex,
+ FTGL_DOUBLE *advancey)
+{
+ FTPoint pen(penx, peny);
+ FTPoint ret = _ftglGlyphRender(g, pen, renderMode);
+ *advancex = ret.X();
+ *advancey = ret.Y();
+}
+
+// const FTPoint& FTGlyph::Advance() const;
+C_FUN(static const FTPoint&, _ftglGlyphAdvance, (FTGLglyph *g),
+ return *(new FTPoint()), Advance, ());
+
+void ftglGlyphAdvance(FTGLglyph *g, FTGL_DOUBLE *advancex,
+ FTGL_DOUBLE *advancey)
+{
+ FTPoint ret = _ftglGlyphAdvance(g);
+ *advancex = ret.X();
+ *advancey = ret.Y();
+}
+
+// const FTBBox& FTGlyph::BBox() const;
+C_FUN(static const FTBBox&, _ftglGlyphBBox, (FTGLglyph *g),
+ return *(new FTBBox()), BBox, ());
+
+void ftglGlyphBBox(FTGLglyph *g, float *lx, float *ly, float *lz,
+ float *ux, float *uy, float *uz)
+{
+ FTBBox ret = _ftglGlyphBBox(g);
+ *lx = ret.lowerX; *ly = ret.lowerY; *lz = ret.lowerZ;
+ *ux = ret.upperX; *uy = ret.upperY; *uz = ret.upperZ;
+}
+
+// FT_Error FTGlyph::Error() const;
+C_FUN(FT_Error, ftglGlyphError, (FTGLglyph *g), return -1, Error, ());
FTGL_END_C_DECLS
diff --git a/src/FTInternals.h b/src/FTInternals.h
index dce6887..871056d 100644
--- a/src/FTInternals.h
+++ b/src/FTInternals.h
@@ -92,6 +92,22 @@ FTGL_BEGIN_C_DECLS
typedef enum
{
+ GLYPH_BITMAP,
+ GLYPH_PIXMAP,
+ GLYPH_OUTLINE,
+ GLYPH_POLYGON,
+ GLYPH_EXTRUDE,
+ GLYPH_TEXTURE,
+} GlyphType;
+
+struct _FTGLglyph
+{
+ FTGlyph *ptr;
+ FTGL::GlyphType type;
+};
+
+typedef enum
+{
FONT_BITMAP,
FONT_PIXMAP,
FONT_OUTLINE,