* Improve constructor code in the FTFont and FTLayout C bindings. Shorter (40 lines) and more consistend code.
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
diff --git a/src/FTFont/FTFontGlue.cpp b/src/FTFont/FTFontGlue.cpp
index 7a7d862..13ec6fa 100644
--- a/src/FTFont/FTFontGlue.cpp
+++ b/src/FTFont/FTFontGlue.cpp
@@ -30,82 +30,44 @@
FTGL_BEGIN_C_DECLS
-static inline FTGLfont *createFTFont(FTGL::FontType type, const char *fontname)
-{
- FTGLfont *ftgl = (FTGLfont*)malloc(sizeof(FTGLfont));
- ftgl->type = type;
- switch(type)
- {
- case FTGL::FONT_BITMAP:
- ftgl->ptr = new FTGLBitmapFont(fontname);
- break;
- case FTGL::FONT_PIXMAP:
- ftgl->ptr = new FTGLPixmapFont(fontname);
- break;
- case FTGL::FONT_OUTLINE:
- ftgl->ptr = new FTGLOutlineFont(fontname);
- break;
- case FTGL::FONT_POLYGON:
- ftgl->ptr = new FTGLPolygonFont(fontname);
- break;
- case FTGL::FONT_EXTRUDE:
- ftgl->ptr = new FTGLExtrdFont(fontname);
- break;
- case FTGL::FONT_TEXTURE:
- ftgl->ptr = new FTGLTextureFont(fontname);
- break;
- }
-
- if(ftgl->ptr->Error())
- {
- ftglDestroyFont(ftgl);
- return NULL;
+#define C_TOR(cname, cargs, cxxname, cxxarg, cxxtype) \
+ FTGLfont* cname cargs \
+ { \
+ cxxname *f = new cxxname cxxarg; \
+ if(f->Error()) \
+ { \
+ delete f; \
+ return NULL; \
+ } \
+ FTGLfont *ftgl = (FTGLfont *)malloc(sizeof(FTGLfont)); \
+ ftgl->ptr = f; \
+ ftgl->type = cxxtype; \
+ return ftgl; \
}
- return ftgl;
-}
-
// FTGLBitmapFont::FTGLBitmapFont();
-FTGLfont* ftglCreateBitmapFont(const char *fontname)
-{
- FTGLfont *ftgl = createFTFont(FTGL::FONT_BITMAP, fontname);
- return ftgl;
-}
+C_TOR(ftglCreateBitmapFont, (const char *fontname),
+ FTGLBitmapFont, (fontname), FONT_BITMAP);
// FTGLExtrdFont::FTGLExtrdFont();
-FTGLfont* ftglCreateExtrdFont(const char *fontname)
-{
- FTGLfont *ftgl = createFTFont(FTGL::FONT_EXTRUDE, fontname);
- return ftgl;
-}
+C_TOR(ftglCreateExtrdFont, (const char *fontname),
+ FTGLExtrdFont, (fontname), FONT_EXTRUDE);
// FTGLOutlineFont::FTGLOutlineFont();
-FTGLfont* ftglCreateOutlineFont(const char *fontname)
-{
- FTGLfont *ftgl = createFTFont(FTGL::FONT_OUTLINE, fontname);
- return ftgl;
-}
+C_TOR(ftglCreateOutlineFont, (const char *fontname),
+ FTGLOutlineFont, (fontname), FONT_OUTLINE);
// FTGLPixmapFont::FTGLPixmapFont();
-FTGLfont* ftglCreatePixmapFont(const char *fontname)
-{
- FTGLfont *ftgl = createFTFont(FTGL::FONT_PIXMAP, fontname);
- return ftgl;
-}
+C_TOR(ftglCreatePixmapFont, (const char *fontname),
+ FTGLPixmapFont, (fontname), FONT_PIXMAP);
// FTGLPolygonFont::FTGLPolygonFont();
-FTGLfont* ftglCreatePolygonFont(const char *fontname)
-{
- FTGLfont *ftgl = createFTFont(FTGL::FONT_POLYGON, fontname);
- return ftgl;
-}
+C_TOR(ftglCreatePolygonFont, (const char *fontname),
+ FTGLPolygonFont, (fontname), FONT_POLYGON);
// FTGLTextureFont::FTGLTextureFont();
-FTGLfont* ftglCreateTextureFont(const char *fontname)
-{
- FTGLfont *ftgl = createFTFont(FTGL::FONT_TEXTURE, fontname);
- return ftgl;
-}
+C_TOR(ftglCreateTextureFont, (const char *fontname),
+ FTGLTextureFont, (fontname), FONT_TEXTURE);
#define C_FUN(cret, cname, cargs, cxxerr, cxxname, cxxarg) \
cret cname cargs \
diff --git a/src/FTLayout/FTLayoutGlue.cpp b/src/FTLayout/FTLayoutGlue.cpp
index 3ed890f..b4b877e 100644
--- a/src/FTLayout/FTLayoutGlue.cpp
+++ b/src/FTLayout/FTLayoutGlue.cpp
@@ -30,26 +30,23 @@
FTGL_BEGIN_C_DECLS
-static inline FTGLlayout *createFTLayout(FTGL::LayoutType type)
-{
- FTGLlayout *layout = (FTGLlayout*)malloc(sizeof(FTGLlayout));
- layout->font = NULL;
- layout->type = type;
- switch(type)
- {
- case FTGL::LAYOUT_SIMPLE:
- layout->ptr = new FTSimpleLayout();
- break;
+#define C_TOR(cname, cargs, cxxname, cxxarg, cxxtype) \
+ FTGLlayout* cname cargs \
+ { \
+ cxxname *l = new cxxname cxxarg; \
+ if(l->Error()) \
+ { \
+ delete l; \
+ return NULL; \
+ } \
+ FTGLlayout *ftgl = (FTGLlayout *)malloc(sizeof(FTGLlayout)); \
+ ftgl->ptr = l; \
+ ftgl->type = cxxtype; \
+ return ftgl; \
}
- return layout;
-}
// FTSimpleLayout::FTSimpleLayout();
-FTGLlayout* ftglCreateSimpleLayout()
-{
- FTGLlayout *layout = createFTLayout(FTGL::LAYOUT_SIMPLE);
- return layout;
-}
+C_TOR(ftglCreateSimpleLayout, (), FTSimpleLayout, (), LAYOUT_SIMPLE);
#define C_FUN(cret, cname, cargs, cxxerr, cxxname, cxxarg) \
cret cname cargs \