Hash :
eb45c699
Author :
Date :
2008-05-06T06:38:37
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
/*
* FTGL - OpenGL font library
*
* Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
* 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
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include "FTGL/ftgl.h"
#include "FTInternals.h"
static FTPoint static_ftpoint;
static FTBBox static_ftbbox;
FTGL_BEGIN_C_DECLS
#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);
// FTExtrudeGlyph::FTExtrudeGlyph();
C_TOR(ftglCreateExtrudeGlyph, (FT_GlyphSlot glyph, float depth,
float frontOutset, float backOutset, int useDisplayList),
FTExtrudeGlyph, (glyph, depth, frontOutset, backOutset, (useDisplayList != 0)),
GLYPH_EXTRUDE);
// FTOutlineGlyph::FTOutlineGlyph();
C_TOR(ftglCreateOutlineGlyph, (FT_GlyphSlot glyph, float outset,
int useDisplayList),
FTOutlineGlyph, (glyph, outset, (useDisplayList != 0)), GLYPH_OUTLINE);
// FTPixmapGlyph::FTPixmapGlyph();
C_TOR(ftglCreatePixmapGlyph, (FT_GlyphSlot glyph),
FTPixmapGlyph, (glyph), GLYPH_PIXMAP);
// FTPolygonGlyph::FTPolygonGlyph();
C_TOR(ftglCreatePolyGlyph, (FT_GlyphSlot glyph, float outset,
int useDisplayList),
FTPolygonGlyph, (glyph, outset, (useDisplayList != 0)), 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<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; \
}
// 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<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;
free(g);
}
// const FTPoint& FTGlyph::Render(const FTPoint& pen, int renderMode);
C_FUN(static const FTPoint&, _ftglRenderGlyph, (FTGLglyph *g,
const FTPoint& pen, int renderMode),
return static_ftpoint, Render, (pen, renderMode));
void ftglRenderGlyph(FTGLglyph *g, FTGL_DOUBLE penx, FTGL_DOUBLE peny,
int renderMode, FTGL_DOUBLE *advancex,
FTGL_DOUBLE *advancey)
{
FTPoint pen(penx, peny);
FTPoint ret = _ftglRenderGlyph(g, pen, renderMode);
*advancex = ret.X();
*advancey = ret.Y();
}
// const FTPoint& FTGlyph::Advance() const;
C_FUN(static const FTPoint&, _ftglGetGlyphAdvance, (FTGLglyph *g),
return static_ftpoint, Advance, ());
void ftglGetGlyphAdvance(FTGLglyph *g, FTGL_DOUBLE *advancex,
FTGL_DOUBLE *advancey)
{
FTPoint ret = _ftglGetGlyphAdvance(g);
*advancex = ret.X();
*advancey = ret.Y();
}
// const FTBBox& FTGlyph::BBox() const;
C_FUN(static const FTBBox&, _ftglGetGlyphBBox, (FTGLglyph *g),
return static_ftbbox, BBox, ());
void ftglGetGlyphBBox(FTGLglyph *g, float bounds[6])
{
FTBBox ret = _ftglGetGlyphBBox(g);
FTPoint lower = ret.Lower(), upper = ret.Upper();
bounds[0] = lower.Xf(); bounds[1] = lower.Yf(); bounds[2] = lower.Zf();
bounds[3] = upper.Xf(); bounds[4] = upper.Yf(); bounds[5] = upper.Zf();
}
// FT_Error FTGlyph::Error() const;
C_FUN(FT_Error, ftglGetGlyphError, (FTGLglyph *g), return -1, Error, ());
FTGL_END_C_DECLS