* Simplify the C bindings. 70 lines gained.
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
diff --git a/src/FTFont/FTFontGlue.cpp b/src/FTFont/FTFontGlue.cpp
index d3f8376..774ada7 100644
--- a/src/FTFont/FTFontGlue.cpp
+++ b/src/FTFont/FTFontGlue.cpp
@@ -114,25 +114,7 @@ C_TOR(ftglCreateCustomFont, (char const *fontFilePath, void *data,
fprintf(stderr, "FTGL warning: NULL pointer in %s\n", #cname); \
cxxerr; \
} \
- switch(f->type) \
- { \
- case FTGL::FONT_CUSTOM: \
- return dynamic_cast<FTCustomFont*>(f->ptr)->cxxname cxxarg; \
- case FTGL::FONT_BITMAP: \
- return dynamic_cast<FTBitmapFont*>(f->ptr)->cxxname cxxarg; \
- case FTGL::FONT_EXTRUDE: \
- return dynamic_cast<FTExtrudeFont*>(f->ptr)->cxxname cxxarg; \
- case FTGL::FONT_OUTLINE: \
- return dynamic_cast<FTOutlineFont*>(f->ptr)->cxxname cxxarg; \
- case FTGL::FONT_PIXMAP: \
- return dynamic_cast<FTPixmapFont*>(f->ptr)->cxxname cxxarg; \
- case FTGL::FONT_POLYGON: \
- return dynamic_cast<FTPolygonFont*>(f->ptr)->cxxname cxxarg; \
- case FTGL::FONT_TEXTURE: \
- return dynamic_cast<FTTextureFont*>(f->ptr)->cxxname cxxarg; \
- } \
- fprintf(stderr, "FTGL warning: %s not implemented for %d\n", #cname, f->type); \
- cxxerr; \
+ return f->ptr->cxxname cxxarg; \
}
// FTFont::~FTFont();
@@ -143,29 +125,7 @@ void ftglDestroyFont(FTGLfont *f)
fprintf(stderr, "FTGL warning: NULL pointer in %s\n", __FUNCTION__);
return;
}
- switch(f->type)
- {
- case FTGL::FONT_CUSTOM:
- delete dynamic_cast<FTCustomFont*>(f->ptr); break;
- case FTGL::FONT_BITMAP:
- delete dynamic_cast<FTBitmapFont*>(f->ptr); break;
- case FTGL::FONT_EXTRUDE:
- delete dynamic_cast<FTExtrudeFont*>(f->ptr); break;
- case FTGL::FONT_OUTLINE:
- delete dynamic_cast<FTOutlineFont*>(f->ptr); break;
- case FTGL::FONT_PIXMAP:
- delete dynamic_cast<FTPixmapFont*>(f->ptr); break;
- case FTGL::FONT_POLYGON:
- delete dynamic_cast<FTPolygonFont*>(f->ptr); break;
- case FTGL::FONT_TEXTURE:
- delete dynamic_cast<FTTextureFont*>(f->ptr); break;
- default:
- fprintf(stderr, "FTGL warning: %s not implemented for %d\n",
- __FUNCTION__, f->type);
- break;
- }
-
- f->ptr = NULL;
+ delete f->ptr;
free(f);
}
diff --git a/src/FTGlyph/FTGlyphGlue.cpp b/src/FTGlyph/FTGlyphGlue.cpp
index be9241e..f140ed0 100644
--- a/src/FTGlyph/FTGlyphGlue.cpp
+++ b/src/FTGlyph/FTGlyphGlue.cpp
@@ -139,25 +139,7 @@ C_TOR(ftglCreateCustomGlyph, (FTGLglyph *base, void *data,
fprintf(stderr, "FTGL warning: NULL pointer in %s\n", #cname); \
cxxerr; \
} \
- switch(g->type) \
- { \
- case FTGL::GLYPH_CUSTOM: \
- return dynamic_cast<FTCustomGlyph*>(g->ptr)->cxxname cxxarg; \
- case FTGL::GLYPH_BITMAP: \
- return dynamic_cast<FTBitmapGlyph*>(g->ptr)->cxxname cxxarg; \
- case FTGL::GLYPH_EXTRUDE: \
- return dynamic_cast<FTExtrudeGlyph*>(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<FTPolygonGlyph*>(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; \
+ return g->ptr->cxxname cxxarg; \
}
// FTGlyph::~FTGlyph();
@@ -168,27 +150,7 @@ void ftglDestroyGlyph(FTGLglyph *g)
fprintf(stderr, "FTGL warning: NULL pointer in %s\n", __FUNCTION__);
return;
}
- switch(g->type)
- {
- case FTGL::GLYPH_CUSTOM:
- delete dynamic_cast<FTCustomGlyph*>(g->ptr); break;
- case FTGL::GLYPH_EXTRUDE:
- delete dynamic_cast<FTExtrudeGlyph*>(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<FTPolygonGlyph*>(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;
+ delete g->ptr;
free(g);
}
diff --git a/src/FTLayout/FTLayoutGlue.cpp b/src/FTLayout/FTLayoutGlue.cpp
index 7cbdde4..d1566f4 100644
--- a/src/FTLayout/FTLayoutGlue.cpp
+++ b/src/FTLayout/FTLayoutGlue.cpp
@@ -58,13 +58,7 @@ C_TOR(ftglCreateSimpleLayout, (), FTSimpleLayout, (), LAYOUT_SIMPLE);
fprintf(stderr, "FTGL warning: NULL pointer in %s\n", #cname); \
cxxerr; \
} \
- switch(l->type) \
- { \
- case FTGL::LAYOUT_SIMPLE: \
- return dynamic_cast<FTSimpleLayout*>(l->ptr)->cxxname cxxarg; \
- } \
- fprintf(stderr, "FTGL warning: %s not implemented for %d\n", #cname, l->type); \
- cxxerr; \
+ return l->ptr->cxxname cxxarg; \
}
// FTLayout::~FTLayout();
@@ -75,16 +69,7 @@ void ftglDestroyLayout(FTGLlayout *l)
fprintf(stderr, "FTGL warning: NULL pointer in %s\n", __FUNCTION__);
return;
}
- switch(l->type)
- {
- case FTGL::LAYOUT_SIMPLE:
- delete dynamic_cast<FTSimpleLayout*>(l->ptr); break;
- default:
- fprintf(stderr, "FTGL warning: %s not implemented for %d\n",
- __FUNCTION__, l->type);
- }
-
- l->ptr = NULL;
+ delete l->ptr;
free(l);
}
@@ -106,22 +91,24 @@ void ftgGetlLayoutBBox(FTGLlayout *l, const char * s, float c[6])
C_FUN(void, ftglRenderLayout, (FTGLlayout *l, const char *s, int r),
return, Render, (s, r));
-// void SetFont(FTFont *fontInit)
+// FT_Error FTLayout::Error() const;
+C_FUN(FT_Error, ftglGetLayoutError, (FTGLlayout *l), return -1, Error, ());
+
+// void FTSimpleLayout::SetFont(FTFont *fontInit)
void ftglSetLayoutFont(FTGLlayout *l, FTGLfont *font)
{
if(!l || !l->ptr)
{
- //XXX fprintf(stderr, "FTGL warning: NULL pointer in %s\n", __func__);
+ fprintf(stderr, "FTGL warning: NULL pointer in %s\n", __FUNCTION__);
return;
}
- switch(l->type)
+ if(l->type != FTGL::LAYOUT_SIMPLE)
{
- case FTGL::LAYOUT_SIMPLE:
- l->font = font;
- return dynamic_cast<FTSimpleLayout*>(l->ptr)->SetFont(font->ptr);
+ fprintf(stderr, "FTGL warning: %s not implemented for %d\n",
+ __FUNCTION__, l->type);
}
- fprintf(stderr, "FTGL warning: %s not implemented for %d\n",
- __FUNCTION__, l->type);
+ l->font = font;
+ return dynamic_cast<FTSimpleLayout*>(l->ptr)->SetFont(font->ptr);
}
// FTFont *FTSimpleLayout::GetFont()
@@ -132,9 +119,33 @@ FTGLfont *ftglGetLayoutFont(FTGLlayout *l)
fprintf(stderr, "FTGL warning: NULL pointer in %s\n", __FUNCTION__);
return NULL;
}
+ if(l->type != FTGL::LAYOUT_SIMPLE)
+ {
+ fprintf(stderr, "FTGL warning: %s not implemented for %d\n",
+ __FUNCTION__, l->type);
+ }
return l->font;
}
+#undef C_FUN
+
+#define C_FUN(cret, cname, cargs, cxxerr, cxxname, cxxarg) \
+ cret cname cargs \
+ { \
+ if(!l || !l->ptr) \
+ { \
+ fprintf(stderr, "FTGL warning: NULL pointer in %s\n", #cname); \
+ cxxerr; \
+ } \
+ if(l->type != FTGL::LAYOUT_SIMPLE) \
+ { \
+ fprintf(stderr, "FTGL warning: %s not implemented for %d\n", \
+ __FUNCTION__, l->type); \
+ cxxerr; \
+ } \
+ return dynamic_cast<FTSimpleLayout*>(l->ptr)->cxxname cxxarg; \
+ }
+
// void FTSimpleLayout::SetLineLength(const float LineLength);
C_FUN(void, ftglSetLayoutLineLength, (FTGLlayout *l, const float length),
return, SetLineLength, (length));
@@ -155,12 +166,5 @@ C_FUN(int, ftglGetLayoutAlignement, (FTGLlayout *l),
C_FUN(void, ftglSetLayoutLineSpacing, (FTGLlayout *l, const float f),
return, SetLineSpacing, (f));
-// float FTSimpleLayout::GetLineSpacing() const
-C_FUN(float, ftglGetLayoutLineSpacing, (FTGLlayout *l),
- return 0.0f, GetLineSpacing, ());
-
-// FT_Error FTLayout::Error() const;
-C_FUN(FT_Error, ftglGetLayoutError, (FTGLlayout *l), return -1, Error, ());
-
FTGL_END_C_DECLS