57 #define PI (3.1415926535897932384626433)
58 #define RtoD (180.0/PI)
59 #define DtoR (PI/180.0)
61 #define max(a,b) (((a) > (b)) ? (a) : (b))
62 #define min(a,b) (((a) < (b)) ? (a) : (b))
63 #define abs(a) (((a)<0) ? -(a) : (a))
64 #define sign(a) (((a)<0) ? -1 : (a)>0 ? 1 : 0)
86 #pragma warning(disable: 4244) // !!! should be replaced by a stronger type binding
125 #define numWeights (sizeof(weightOffset) / sizeof(vertex))
132 #define unfix(value) ((SUMOReal)(value)) / ((SUMOReal)pfFixScale)
170 {
"GL_POINTS", GL_POINTS},
171 {
"GL_LINES", GL_LINES},
172 {
"GL_LINE_LOOP", GL_LINE_LOOP},
173 {
"GL_LINE_STRIP", GL_LINE_STRIP},
174 {
"GL_TRIANGLES", GL_TRIANGLES},
175 {
"GL_TRIANGLE_STRIP", GL_TRIANGLE_STRIP},
176 {
"GL_TRIANGLE_FAN", GL_TRIANGLE_FAN},
177 {
"GL_QUADS", GL_QUADS},
178 {
"GL_QUAD_STRIP", GL_QUAD_STRIP},
179 {
"GL_POLYGON", GL_POLYGON},
190 if (0 == strcmp(glPrims[i].name, op))
209 printf(
"font is NULL\n");
212 if (NULL == font->
name)
214 printf(
"fontname is NULL\n");
217 printf(
"fontinfo = %s %f, %f, %f, %f, %d %p\n",
227 printf(
"glyph point is NULL\n");
230 printf(
"NumGlyphs = %d\n", font->
numglyphs);
234 if (NULL == glyph[i].segments)
236 printf(
"glyph[%d].segments = NULL\n", i);
239 printf(
"glyph[%d] = %f, %f, %f, %f, %f, %hu, %hu %p\n",
241 glyph[i].minx, glyph[i].miny,
242 glyph[i].maxx, glyph[i].maxy,
245 glyph[i].numsegments,
263 if (pfDefaultFont == font)
273 if (NULL == font->
name)
287 if (NULL != glyphs[i].segments)
289 free(glyphs[i].segments);
300 #ifdef POLYFONTS_WANTS_IO
301 pffont *pfLoadFont(
char *fileName)
308 char *fontname = NULL;
312 f = fopen(fileName,
"r");
318 while (NULL != fgets(buf,
sizeof(buf), f))
320 if (0 == strcmp(
"/*PolyFontVersion\n", buf))
322 fscanf(f,
"%f\n", &version);
324 else if (0 == strcmp(
"/*fontinfo\n", buf))
327 if (NULL == fontinfo)
332 fgets(buf,
sizeof(buf), f);
334 "%f, %f, %f, %f, %d\n",
344 fontinfo->
name = fontname;
345 fontinfo->
glyphs = glyphs;
348 else if (0 == strcmp(
"/*fontname\n", buf))
350 if (NULL != fgets(buf,
sizeof(buf), f))
352 int len = strlen(buf);
354 if (len >=
sizeof(buf))
362 fontname = calloc(len,
sizeof(
char));
363 if (NULL == fontname)
369 strncpy(fontname, buf, len);
372 else if (0 == strcmp(
"/*glyphcount\n", buf))
374 fscanf(f,
"%d\n", &glyphcount);
383 else if (0 == strcmp(
"/*glyphinfo\n", buf))
386 fscanf(f,
"%d\n", &n);
388 fgets(buf,
sizeof(buf), f);
390 "%f, %f, %f, %f, %f, %hu, %hu\n",
391 &glyphs[n].minx, &glyphs[n].miny,
392 &glyphs[n].maxx, &glyphs[n].maxy,
395 &glyphs[n].numsegments);
405 else if (0 == strcmp(
"/*glyphdata\n", buf))
415 fscanf(f,
"%d,%d\n", &n, &size);
425 for (i = 0; i < size; )
427 while ((NULL != fgets(buf,
sizeof(buf), f)) &&
428 (0 != strcmp(
"/*segment\n", buf)))
431 fscanf(f,
"%d\n", &segs);
433 fgets(buf,
sizeof(buf), f);
434 fscanf(f,
"%s\n", &op[0]);
435 fgets(buf,
sizeof(buf), f);
436 fscanf(f,
"%d\n", &points);
443 for (j = 0; j < points; j++)
445 fgets(buf,
sizeof(buf), f);
446 fscanf(f,
"%hd,%hd\n", &data[i], &data[i + 1]);
530 if (NULL != pfCurrentFont)
582 *miny =
min(*miny, y1);
584 *maxy =
max(*maxy, y2);
622 *miny =
min(*miny, y1);
624 *maxy =
max(*maxy, y2);
678 if (NULL != pfCurrentFont)
680 name = pfCurrentFont->
name;
697 if (NULL != pfCurrentFont)
707 *minx =
pfSkew(*minx, *miny);
708 *maxx =
pfSkew(*maxx, *maxy);
712 *minx =
pfSkew(*minx, *maxy);
713 *maxx =
pfSkew(*maxx, *miny);
787 if (NULL != pfCurrentFont)
802 if (NULL != pfCurrentFont)
805 if ((g >= 0) && (g < ng))
816 static int comp(
const void *key,
const void *target)
828 return (
pfglyph *) bsearch((
void *)find, (
void *)glyphs, numglyphs,
sizeof(
pfglyph),
comp);
838 if (NULL == pfCurrentFont)
891 *minx =
pfSkew(*minx, *miny);
892 *maxx =
pfSkew(*maxx, *maxy);
896 *minx =
pfSkew(*minx, *maxy);
897 *maxx =
pfSkew(*maxx, *miny);
1002 for (i = 0; i < segs; i++)
1008 for (j = 0; j < points; j++)
1016 gx += weightOffset[k].
x;
1017 gy += weightOffset[k].
y;
static pfglyph * pfFindGlyph(pfglyph *glyphs, int numglyphs, pfglyph *find)
void pfSetAngleR(SUMOReal a)
int pfDrawString(const char *c)
SUMOReal pfGetCharDescent(wchar_t c)
static pfglyph * pfGetGlyph(wchar_t c)
static int getStringBox(char *c, SUMOReal *minx, SUMOReal *miny, SUMOReal *maxx, SUMOReal *maxy)
static pffont * pfCurrentFont
static nameValue glPrims[]
static void validate(pffont *font)
SUMOReal pfGetCharAdvance(wchar_t c)
static int getStringBoxW(wchar_t *c, SUMOReal *minx, SUMOReal *miny, SUMOReal *maxx, SUMOReal *maxy)
void pfGetPosition(SUMOReal *x, SUMOReal *y)
void pfSetPosition(SUMOReal x, SUMOReal y)
static pffont * pfDefaultFont
static int getCharBBox(wchar_t c, SUMOReal *minx, SUMOReal *miny, SUMOReal *maxx, SUMOReal *maxy)
static SUMOReal pfTextSin
SUMOReal pfGetFontDescent()
int pfGetCharBBox(wchar_t c, SUMOReal *minx, SUMOReal *miny, SUMOReal *maxx, SUMOReal *maxy)
unsigned short int pfuint16
void pfSetAngleD(SUMOReal a)
static SUMOReal pfSkew(SUMOReal x, SUMOReal y)
void pfSetCenter(int onOff)
static int lookupGlOp(char *op)
int pfDrawChar(wchar_t c)
SUMOReal pfGetFontHeight()
static int drawWideChar(wchar_t c)
static SUMOReal pfTextCos
void pfSetScaleXY(SUMOReal sx, SUMOReal sy)
static int comp(const void *key, const void *target)
pffont * pfGetCurrentFont()
int pfGetFontBBox(SUMOReal *minx, SUMOReal *miny, SUMOReal *maxx, SUMOReal *maxy)
void pfUnloadFont(pffont *font)
SUMOReal pfGetFontWidth()
void pfSetScale(SUMOReal s)
SUMOReal pfdkGetStringWidth(const char *c)
SUMOReal pfGetCharWidth(wchar_t c)
int pfDrawStringW(wchar_t *c)
void pfSetSkew(SUMOReal s)
static SUMOReal pfTextSkew
int pfSetScaleBoxW(wchar_t *c, SUMOReal w, SUMOReal h)
int pfSetScaleBox(char *c, SUMOReal w, SUMOReal h)
SUMOReal pfGetCharHeight(wchar_t c)
SUMOReal pfGetCharAscent(wchar_t c)
SUMOReal pfGetFontAscent()
static SUMOReal getCharAdvance(wchar_t c)