49 #include <OpenGL/gl.h>
61 #define PI (3.1415926535897932384626433)
62 #define RtoD (180.0/PI)
63 #define DtoR (PI/180.0)
65 #define max(a,b) (((a) > (b)) ? (a) : (b))
66 #define min(a,b) (((a) < (b)) ? (a) : (b))
67 #define abs(a) (((a)<0) ? -(a) : (a))
68 #define sign(a) (((a)<0) ? -1 : (a)>0 ? 1 : 0)
90 #pragma warning(disable: 4244) // !!! should be replaced by a stronger type binding
129 #define numWeights (sizeof(weightOffset) / sizeof(vertex))
136 #define unfix(value) ((SUMOReal)(value)) / ((SUMOReal)pfFixScale)
174 {
"GL_POINTS", GL_POINTS},
175 {
"GL_LINES", GL_LINES},
176 {
"GL_LINE_LOOP", GL_LINE_LOOP},
177 {
"GL_LINE_STRIP", GL_LINE_STRIP},
178 {
"GL_TRIANGLES", GL_TRIANGLES},
179 {
"GL_TRIANGLE_STRIP", GL_TRIANGLE_STRIP},
180 {
"GL_TRIANGLE_FAN", GL_TRIANGLE_FAN},
181 {
"GL_QUADS", GL_QUADS},
182 {
"GL_QUAD_STRIP", GL_QUAD_STRIP},
183 {
"GL_POLYGON", GL_POLYGON},
194 if (0 == strcmp(glPrims[i].name, op))
213 printf(
"font is NULL\n");
216 if (NULL == font->
name)
218 printf(
"fontname is NULL\n");
221 printf(
"fontinfo = %s %f, %f, %f, %f, %d %p\n",
231 printf(
"glyph point is NULL\n");
234 printf(
"NumGlyphs = %d\n", font->
numglyphs);
238 if (NULL == glyph[i].segments)
240 printf(
"glyph[%d].segments = NULL\n", i);
243 printf(
"glyph[%d] = %f, %f, %f, %f, %f, %hu, %hu %p\n",
245 glyph[i].minx, glyph[i].miny,
246 glyph[i].maxx, glyph[i].maxy,
249 glyph[i].numsegments,
267 if (pfDefaultFont == font)
277 if (NULL == font->
name)
291 if (NULL != glyphs[i].segments)
293 free(glyphs[i].segments);
304 #ifdef POLYFONTS_WANTS_IO
305 pffont *pfLoadFont(
char *fileName)
312 char *fontname = NULL;
316 f = fopen(fileName,
"r");
322 while (NULL != fgets(buf,
sizeof(buf), f))
324 if (0 == strcmp(
"/*PolyFontVersion\n", buf))
326 fscanf(f,
"%f\n", &version);
328 else if (0 == strcmp(
"/*fontinfo\n", buf))
331 if (NULL == fontinfo)
336 fgets(buf,
sizeof(buf), f);
338 "%f, %f, %f, %f, %d\n",
348 fontinfo->
name = fontname;
349 fontinfo->
glyphs = glyphs;
352 else if (0 == strcmp(
"/*fontname\n", buf))
354 if (NULL != fgets(buf,
sizeof(buf), f))
356 int len = strlen(buf);
358 if (len >=
sizeof(buf))
366 fontname = calloc(len,
sizeof(
char));
367 if (NULL == fontname)
373 strncpy(fontname, buf, len);
376 else if (0 == strcmp(
"/*glyphcount\n", buf))
378 fscanf(f,
"%d\n", &glyphcount);
387 else if (0 == strcmp(
"/*glyphinfo\n", buf))
390 fscanf(f,
"%d\n", &n);
392 fgets(buf,
sizeof(buf), f);
394 "%f, %f, %f, %f, %f, %hu, %hu\n",
395 &glyphs[n].minx, &glyphs[n].miny,
396 &glyphs[n].maxx, &glyphs[n].maxy,
399 &glyphs[n].numsegments);
409 else if (0 == strcmp(
"/*glyphdata\n", buf))
419 fscanf(f,
"%d,%d\n", &n, &size);
429 for (i = 0; i < size; )
431 while ((NULL != fgets(buf,
sizeof(buf), f)) &&
432 (0 != strcmp(
"/*segment\n", buf)))
435 fscanf(f,
"%d\n", &segs);
437 fgets(buf,
sizeof(buf), f);
438 fscanf(f,
"%s\n", &op[0]);
439 fgets(buf,
sizeof(buf), f);
440 fscanf(f,
"%d\n", &points);
447 for (j = 0; j < points; j++)
449 fgets(buf,
sizeof(buf), f);
450 fscanf(f,
"%hd,%hd\n", &data[i], &data[i + 1]);
534 if (NULL != pfCurrentFont)
586 *miny =
min(*miny, y1);
588 *maxy =
max(*maxy, y2);
626 *miny =
min(*miny, y1);
628 *maxy =
max(*maxy, y2);
682 if (NULL != pfCurrentFont)
684 name = pfCurrentFont->
name;
701 if (NULL != pfCurrentFont)
711 *minx =
pfSkew(*minx, *miny);
712 *maxx =
pfSkew(*maxx, *maxy);
716 *minx =
pfSkew(*minx, *maxy);
717 *maxx =
pfSkew(*maxx, *miny);
791 if (NULL != pfCurrentFont)
806 if (NULL != pfCurrentFont)
809 if ((g >= 0) && (g < ng))
820 static int comp(
const void *key,
const void *target)
832 return (
pfglyph *) bsearch((
void *)find, (
void *)glyphs, numglyphs,
sizeof(
pfglyph),
comp);
842 if (NULL == pfCurrentFont)
895 *minx =
pfSkew(*minx, *miny);
896 *maxx =
pfSkew(*maxx, *maxy);
900 *minx =
pfSkew(*minx, *maxy);
901 *maxx =
pfSkew(*maxx, *miny);
1006 for (i = 0; i < segs; i++)
1012 for (j = 0; j < points; j++)
1020 gx += weightOffset[k].
x;
1021 gy += weightOffset[k].
y;