SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
polyfonts.c
Go to the documentation of this file.
1 /*
2  Polyfonts is a polygon font drawing library for use with SDL. Any
3  TTF font can be converted for use with this library. Contact the
4  author for details.
5 
6  Copyright (C) 2003 Bob Pendleton
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public License
10  as published by the Free Software Foundation; either version 2.1
11  of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free
20  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21  02111-1307 USA
22 
23  If you do not wish to comply with the terms of the LGPL please
24  contact the author as other terms are available for a fee.
25 
26  Bob Pendleton
27  Bob@Pendleton.com
28 */
29 
30 // ===========================================================================
31 // included modules
32 // ===========================================================================
33 #ifdef _MSC_VER
34 #include <windows_config.h>
35 #else
36 #include <config.h>
37 #endif
38 
39 #include <stdlib.h>
40 #include <stdio.h>
41 #include <math.h>
42 #include <string.h>
43 
44 #ifdef WIN32
45 #include <windows.h>
46 #endif
47 
48 #ifdef __APPLE__
49 #include <OpenGL/gl.h>
50 #else
51 #include <GL/gl.h>
52 #endif
53 
54 //#include "SDL.h"
55 //#include "sgl.h"
56 
57 #include "polyfonts.h"
58 
59 /*-----------------------------------------------*/
60 
61 #define PI (3.1415926535897932384626433)
62 #define RtoD (180.0/PI)
63 #define DtoR (PI/180.0)
64 
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)
69 
70 /*-----------------------------------------------*/
71 /*
72  The following code sets the default compiled in
73  font. You can change the default font by
74  including a different font and changing the
75  declaration of the two variables. Or, you can
76  set them both to NULL if you don't want a
77  default font.
78 */
79 
80 // changes for SUMO begin
81 #include "pfPSansBold16.h"
82 
85 
86 
87 /* =========================================================================
88  * compiler pragmas
89  * ======================================================================= */
90 #pragma warning(disable: 4244) // !!! should be replaced by a stronger type binding
91 
92 
93 // changes for SUMO end
94 
95 /*
96 static pffont *pfCurrentFont = NULL;
97 static pffont *pfDefaultFont = NULL;
98 */
99 
100 /*-----------------------------------------------*/
101 
102 static SUMOReal pfScaleX = 20.0;
103 static SUMOReal pfScaleY = 20.0;
104 
105 static SUMOReal pfTextX = 0.0;
106 static SUMOReal pfTextY = 0.0;
107 
108 static SUMOReal pfTextSkew = 0.0;
109 static int pfTextWeight = 1;
110 
111 typedef struct
112 {
114 } vertex;
115 
117  {0.0, 0.0},
118  {0.0, 1.0},
119  {1.0, 1.0},
120  {1.0, 0.0},
121  /*-------*/
122  {0.0, 2.0},
123  {1.0, 2.0},
124  {2.0, 2.0},
125  {1.0, 2.0},
126  {0.0, 2.0},
127 };
128 
129 #define numWeights (sizeof(weightOffset) / sizeof(vertex))
130 
131 static SUMOReal pfTextSin = 0.0;
132 static SUMOReal pfTextCos = 1.0;
133 
134 static int pfCenter = 0;
135 
136 #define unfix(value) ((SUMOReal)(value)) / ((SUMOReal)pfFixScale)
137 
138 /*-----------------------------------------------*/
139 
140 static pfglyph *pfGetGlyph(wchar_t c);
141 static SUMOReal getCharAdvance(wchar_t c);
142 
143 /*-----------------------------------------------*/
144 
146 {
147  return x + (pfTextSkew * y);
148 }
149 
150 /*-----------------------------------------------*/
151 
153 {
154  if (NULL != f)
155  {
156  pfCurrentFont = f;
157 
158  return 0;
159  }
160 
161  return -1;
162 }
163 
164 /*-----------------------------------------------*/
165 
166 typedef struct
167 {
168  char *name;
169  int value;
170 } nameValue;
171 
172 static nameValue glPrims[] =
173  {
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},
184  };
185 
186 /*-----------------------------------------------*/
187 
188 static int lookupGlOp(char *op)
189 {
190  int i;
191 
192  for (i = 0; i < (sizeof(glPrims) / sizeof(nameValue)); i++)
193  {
194  if (0 == strcmp(glPrims[i].name, op))
195  {
196  return i;
197  }
198  }
199 
200  return -1;
201 }
202 
203 /*-----------------------------------------------*/
204 
205 static void validate(pffont *font)
206 {
207  int i;
208 
209  pfglyph *glyph = NULL;
210 
211  if (NULL == font)
212  {
213  printf("font is NULL\n");
214  }
215 
216  if (NULL == font->name)
217  {
218  printf("fontname is NULL\n");
219  }
220 
221  printf("fontinfo = %s %f, %f, %f, %f, %d %p\n",
222  font->name,
223  font->minx, font->miny,
224  font->maxx, font->maxy,
225  font->numglyphs,
226  font->glyphs);
227 
228  glyph = font->glyphs;
229  if (NULL == glyph)
230  {
231  printf("glyph point is NULL\n");
232  }
233 
234  printf("NumGlyphs = %d\n", font->numglyphs);
235 
236  for (i = 0; i < font->numglyphs; i++)
237  {
238  if (NULL == glyph[i].segments)
239  {
240  printf("glyph[%d].segments = NULL\n", i);
241  }
242 
243  printf("glyph[%d] = %f, %f, %f, %f, %f, %hu, %hu %p\n",
244  i,
245  glyph[i].minx, glyph[i].miny,
246  glyph[i].maxx, glyph[i].maxy,
247  glyph[i].advance,
248  glyph[i].glyph,
249  glyph[i].numsegments,
250  glyph[i].segments);
251  }
252 }
253 
254 /*-----------------------------------------------*/
255 
256 void pfUnloadFont(pffont *font)
257 {
258  int i;
259 
260  pfglyph *glyphs = NULL;
261 
262  if (NULL == font)
263  {
264  return;
265  }
266 
267  if (pfDefaultFont == font)
268  {
269  return;
270  }
271 
272  if (1 != font->loaded)
273  {
274  return;
275  }
276 
277  if (NULL == font->name)
278  {
279  return;
280  }
281  free(font->name);
282 
283  if (NULL == font->glyphs)
284  {
285  return;
286  }
287 
288  glyphs = font->glyphs;
289  for (i = 0; i < font->numglyphs; i++)
290  {
291  if (NULL != glyphs[i].segments)
292  {
293  free(glyphs[i].segments);
294  }
295  }
296 
297  free(font->glyphs);
298 
299  free(font);
300 }
301 
302 /*-----------------------------------------------*/
303 
304 #ifdef POLYFONTS_WANTS_IO
305 pffont *pfLoadFont(char *fileName)
306 {
307  FILE *f = NULL;
308  char buf[1024];
309 
310  SUMOReal version = 0;
311  int glyphcount = 0;
312  char *fontname = NULL;
313  pffont *fontinfo = NULL;
314  pfglyph *glyphs = NULL;
315 
316  f = fopen(fileName, "r");
317  if (NULL == f)
318  {
319  return NULL;
320  }
321 
322  while (NULL != fgets(buf, sizeof(buf), f))
323  {
324  if (0 == strcmp("/*PolyFontVersion\n", buf)) /*--------*/
325  {
326  fscanf(f, "%f\n", &version);
327  }
328  else if (0 == strcmp("/*fontinfo\n", buf)) /*--------*/
329  {
330  fontinfo = (pffont *)calloc(1, sizeof(pffont));
331  if (NULL == fontinfo)
332  {
333  fclose(f);
334  return NULL;
335  }
336  fgets(buf, sizeof(buf), f); /* skip a line */
337  fscanf(f,
338  "%f, %f, %f, %f, %d\n",
339  &fontinfo->minx, &fontinfo->miny,
340  &fontinfo->maxx, &fontinfo->maxy,
341  &fontinfo->numglyphs);
342  /*
343  printf("fontinfo = %f, %f, %f, %f, %d\n",
344  fontinfo->minx, fontinfo->miny,
345  fontinfo->maxx, fontinfo->maxy,
346  fontinfo->numglyphs);
347  */
348  fontinfo->name = fontname;
349  fontinfo->glyphs = glyphs;
350  fontinfo->loaded = 1;
351  }
352  else if (0 == strcmp("/*fontname\n", buf)) /*--------*/
353  {
354  if (NULL != fgets(buf, sizeof(buf), f))
355  {
356  int len = strlen(buf);
357 
358  if (len >= sizeof(buf))
359  {
360  fclose(f);
361  return NULL;
362  }
363 
364  buf[len - 1] = '\0';
365 
366  fontname = calloc(len, sizeof(char));
367  if (NULL == fontname)
368  {
369  fclose(f);
370  return NULL;
371  }
372 
373  strncpy(fontname, buf, len);
374  }
375  }
376  else if (0 == strcmp("/*glyphcount\n", buf)) /*--------*/
377  {
378  fscanf(f, "%d\n", &glyphcount);
379 
380  glyphs = (pfglyph *)calloc(glyphcount, sizeof(pfglyph));
381  if (NULL == glyphs)
382  {
383  fclose(f);
384  return NULL;
385  }
386  }
387  else if (0 == strcmp("/*glyphinfo\n", buf)) /*--------*/
388  {
389  int n = 0;
390  fscanf(f, "%d\n", &n); /* glyph index */
391 
392  fgets(buf, sizeof(buf), f); /* skip a line */
393  fscanf(f,
394  "%f, %f, %f, %f, %f, %hu, %hu\n",
395  &glyphs[n].minx, &glyphs[n].miny,
396  &glyphs[n].maxx, &glyphs[n].maxy,
397  &glyphs[n].advance,
398  &glyphs[n].glyph,
399  &glyphs[n].numsegments);
400  /*
401  printf("glyphinfo = %f, %f, %f, %f, %f, %hu, %hu\n",
402  glyphs[n].minx, glyphs[n].miny,
403  glyphs[n].maxx, glyphs[n].maxy,
404  glyphs[n].advance,
405  glyphs[n].glyph,
406  glyphs[n].numsegments);
407  */
408  }
409  else if (0 == strcmp("/*glyphdata\n", buf)) /*--------*/
410  {
411  int n;
412  int size;
413  int i, j;
414  int segs;
415  char op[1024];
416  int points;
417  pfint16 *data = NULL;
418 
419  fscanf(f, "%d,%d\n", &n, &size);
420 
421  data = (pfint16 *)calloc(size, sizeof(pfuint16));
422  if (NULL == data)
423  {
424  fclose(f);
425  return NULL;
426  }
427  glyphs[n].segments = data;
428 
429  for (i = 0; i < size; )
430  {
431  while ((NULL != fgets(buf, sizeof(buf), f)) &&
432  (0 != strcmp("/*segment\n", buf)))
433  {
434  }
435  fscanf(f, "%d\n", &segs);
436 
437  fgets(buf, sizeof(buf), f); /* skip a line */
438  fscanf(f, "%s\n", &op[0]);
439  fgets(buf, sizeof(buf), f); /* skip a line */
440  fscanf(f, "%d\n", &points);
441 
442  data[i] = lookupGlOp(op);
443  i++;
444  data[i] = points;
445  i++;
446 
447  for (j = 0; j < points; j++)
448  {
449  fgets(buf, sizeof(buf), f); /* skip a line */
450  fscanf(f, "%hd,%hd\n", &data[i], &data[i + 1]);
451 
452  i += 2;
453  }
454  }
455  }
456  }
457 
458  fclose(f);
459  return fontinfo;
460 }
461 #endif
462 
463 /*-----------------------------------------------*/
464 
466 {
467  pfScaleX = pfScaleY = s;
468 }
469 
470 /*-----------------------------------------------*/
471 
473 {
474  pfScaleX = sx;
475  pfScaleY = sy;
476 }
477 
478 /*-----------------------------------------------*/
479 
481 {
482  pfTextX = x;
483  pfTextY = y;
484 }
485 
486 /*-----------------------------------------------*/
487 
489 {
490  *x = pfTextX;
491  *y = pfTextY;
492 }
493 
494 /*-----------------------------------------------*/
495 
497 {
498  pfTextSkew = min(1.0, max(-1.0, s));
499 }
500 
501 /*-----------------------------------------------*/
502 
503 void pfSetWeight(int w)
504 {
505  pfTextWeight = min(numWeights, max(1, w));
506 }
507 
508 /*-----------------------------------------------*/
509 
511 {
512  pfTextSin = sin(a);
513  pfTextCos = cos(a);
514 }
515 
516 /*-----------------------------------------------*/
517 
519 {
520  pfSetAngleR(a * DtoR);
521 }
522 
523 /*-----------------------------------------------*/
524 
525 void pfSetCenter(int onOff)
526 {
527  pfCenter = onOff;
528 }
529 
530 /*-----------------------------------------------*/
531 
532 static int getCharBBox(wchar_t c, SUMOReal *minx, SUMOReal *miny, SUMOReal *maxx, SUMOReal *maxy)
533 {
534  if (NULL != pfCurrentFont)
535  {
536  pfglyph *g = pfGetGlyph(c);
537  if (NULL != g)
538  {
539  *minx = g->minx;
540  *miny = g->miny;
541 
542  *maxx = g->maxx;
543  *maxy = g->maxy;
544  }
545  return 0;
546  }
547 
548  *minx = 0;
549  *miny = 0;
550  *maxx = 0;
551  *maxy = 0;
552 
553  return -1;
554 }
555 
556 /*-----------------------------------------------*/
557 
558 static int getStringBox(char *c, SUMOReal *minx, SUMOReal *miny, SUMOReal *maxx, SUMOReal *maxy)
559 {
560  SUMOReal x1, y1, x2, y2;
561 
562  if (NULL == c)
563  {
564  return -1;
565  }
566 
567  if (-1 == getCharBBox(*c, &x1, &y1, &x2, &y2))
568  {
569  return -1;
570  }
571 
572  *minx = x1;
573  *miny = y1;
574  *maxx = getCharAdvance(*c);
575  *maxy = y2;
576 
577  c++;
578 
579  while (0 != *c)
580  {
581  if (-1 == getCharBBox(*c, &x1, &y1, &x2, &y2))
582  {
583  return -1;
584  }
585 
586  *miny = min(*miny, y1);
587  *maxx += getCharAdvance(*c);
588  *maxy = max(*maxy, y2);
589 
590  c++;
591  }
592 
593  return 0;
594 }
595 
596 /*-----------------------------------------------*/
597 
598 static int getStringBoxW(wchar_t *c, SUMOReal *minx, SUMOReal *miny, SUMOReal *maxx, SUMOReal *maxy)
599 {
600  SUMOReal x1, y1, x2, y2;
601 
602  if (NULL == c)
603  {
604  return -1;
605  }
606 
607  if (-1 == getCharBBox(*c, &x1, &y1, &x2, &y2))
608  {
609  return -1;
610  }
611 
612  *minx = x1;
613  *miny = y1;
614  *maxx = getCharAdvance(*c);
615  *maxy = y2;
616 
617  c++;
618 
619  while (0 != *c)
620  {
621  if (-1 == getCharBBox(*c, &x1, &y1, &x2, &y2))
622  {
623  return -1;
624  }
625 
626  *miny = min(*miny, y1);
627  *maxx += getCharAdvance(*c);
628  *maxy = max(*maxy, y2);
629 
630  c++;
631  }
632 
633  return 0;
634 }
635 
636 /*-----------------------------------------------*/
637 
638 int pfSetScaleBox(char *c, SUMOReal w, SUMOReal h)
639 {
640  SUMOReal x1, y1, x2, y2;
641 
642  if (NULL == c)
643  {
644  return -1;
645  }
646 
647  if (-1 == getStringBox(c, &x1, &y1, &x2, &y2))
648  {
649  return -1;
650  }
651 
652  pfSetScaleXY((w / (x2 - x1)), (h / (y2 - y1)));
653  return 0;
654 }
655 
656 /*-----------------------------------------------*/
657 
658 int pfSetScaleBoxW(wchar_t *c, SUMOReal w, SUMOReal h)
659 {
660  SUMOReal x1, y1, x2, y2;
661 
662  if (NULL == c)
663  {
664  return -1;
665  }
666 
667  if (-1 == getStringBoxW(c, &x1, &y1, &x2, &y2))
668  {
669  return -1;
670  }
671 
672  pfSetScaleXY((w / (x2 - x1)), (h / (y2 - y1)));
673  return 0;
674 }
675 
676 /*-----------------------------------------------*/
677 
679 {
680  char *name = NULL;
681 
682  if (NULL != pfCurrentFont)
683  {
684  name = pfCurrentFont->name;
685  }
686 
687  return name;
688 }
689 
690 /*-----------------------------------------------*/
691 
693 {
694  return pfCurrentFont;
695 }
696 
697 /*-----------------------------------------------*/
698 
699 int pfGetFontBBox(SUMOReal *minx, SUMOReal *miny, SUMOReal *maxx, SUMOReal *maxy)
700 {
701  if (NULL != pfCurrentFont)
702  {
703  *minx = pfScaleX * pfCurrentFont->minx;
704  *miny = pfScaleY * pfCurrentFont->miny;
705 
706  *maxx = pfScaleX * pfCurrentFont->maxx;
707  *maxy = pfScaleY * pfCurrentFont->maxy;
708 
709  if (pfTextSkew > 0)
710  {
711  *minx = pfSkew(*minx, *miny);
712  *maxx = pfSkew(*maxx, *maxy);
713  }
714  else
715  {
716  *minx = pfSkew(*minx, *maxy);
717  *maxx = pfSkew(*maxx, *miny);
718  }
719 
720  return 0;
721  }
722 
723  *minx = 0;
724  *miny = 0;
725  *maxx = 0;
726  *maxy = 0;
727 
728  return -1;
729 }
730 
731 /*-----------------------------------------------*/
732 
734 {
735  SUMOReal minx, miny, maxx, maxy;
736 
737  if (-1 != pfGetFontBBox(&minx, &miny, &maxx, &maxy))
738  {
739  return maxy - miny;
740  }
741 
742  return 0.0;
743 }
744 
745 /*-----------------------------------------------*/
746 
748 {
749  SUMOReal minx, miny, maxx, maxy;
750 
751  if (-1 != pfGetFontBBox(&minx, &miny, &maxx, &maxy))
752  {
753  return maxx - minx;
754  }
755 
756  return 0.0;
757 }
758 
759 /*-----------------------------------------------*/
760 
762 {
763  SUMOReal minx, miny, maxx, maxy;
764 
765  if (-1 != pfGetFontBBox(&minx, &miny, &maxx, &maxy))
766  {
767  return maxy;
768  }
769 
770  return 0.0;
771 }
772 
773 /*-----------------------------------------------*/
774 
776 {
777  SUMOReal minx, miny, maxx, maxy;
778 
779  if (-1 != pfGetFontBBox(&minx, &miny, &maxx, &maxy))
780  {
781  return miny;
782  }
783 
784  return 0.0;
785 }
786 
787 /*-----------------------------------------------*/
788 
790 {
791  if (NULL != pfCurrentFont)
792  {
793  return pfCurrentFont->numglyphs;
794  }
795 
796  return 0;
797 }
798 
799 /*-----------------------------------------------*/
800 
801 wchar_t pfGetChar(int g)
802 {
803  wchar_t c = 0;
804  int ng = -1;
805 
806  if (NULL != pfCurrentFont)
807  {
808  ng = pfCurrentFont->numglyphs;
809  if ((g >= 0) && (g < ng))
810  {
811  c = pfCurrentFont->glyphs[g].glyph;
812  }
813  }
814 
815  return c;
816 }
817 
818 /*-----------------------------------------------*/
819 
820 static int comp(const void *key, const void *target)
821 {
822  pfglyph *k = (pfglyph *)key;
823  pfglyph *t = (pfglyph *)target;
824 
825  return (k->glyph) - (t->glyph);
826 }
827 
828 /*-----------------------------------------------*/
829 
830 static pfglyph *pfFindGlyph(pfglyph *glyphs, int numglyphs, pfglyph *find)
831 {
832  return (pfglyph *) bsearch((void *)find, (void *)glyphs, numglyphs, sizeof(pfglyph), comp);
833 }
834 
835 /*-----------------------------------------------*/
836 
837 static pfglyph *pfGetGlyph(wchar_t c)
838 {
839  pfglyph *g = NULL;
840  pfglyph key;
841 
842  if (NULL == pfCurrentFont)
843  {
844  return NULL;
845  }
846 
847  key.glyph = c;
848  g = pfFindGlyph(pfCurrentFont->glyphs, pfCurrentFont->numglyphs, &key);
849 
850  return g;
851 }
852 
853 /*-----------------------------------------------*/
854 
855 static SUMOReal getCharAdvance(wchar_t c)
856 {
857  pfglyph *g = pfGetGlyph(c);
858 
859  if (NULL == g)
860  {
861  return 0.0;
862  }
863 
864  return g->advance;
865 }
866 
867 /*-----------------------------------------------*/
868 
870 {
871  pfglyph *g = pfGetGlyph(c);
872 
873  if (NULL == g)
874  {
875  return 0.0;
876  }
877 
878  return (g->advance * pfScaleX);
879 }
880 
881 /*-----------------------------------------------*/
882 
883 int pfGetCharBBox(wchar_t c, SUMOReal *minx, SUMOReal *miny, SUMOReal *maxx, SUMOReal *maxy)
884 {
885  if (0 == getCharBBox(c, minx, miny, maxx, maxy))
886  {
887  *minx = pfScaleX * (*minx);
888  *miny = pfScaleY * (*miny);
889 
890  *maxx = pfScaleX * (*maxx);
891  *maxy = pfScaleY * (*maxy);
892 
893  if (pfTextSkew > 0)
894  {
895  *minx = pfSkew(*minx, *miny);
896  *maxx = pfSkew(*maxx, *maxy);
897  }
898  else
899  {
900  *minx = pfSkew(*minx, *maxy);
901  *maxx = pfSkew(*maxx, *miny);
902  }
903 
904 
905  return 0;
906  }
907 
908  *minx = 0;
909  *miny = 0;
910  *maxx = 0;
911  *maxy = 0;
912 
913  return -1;
914 }
915 
916 /*-----------------------------------------------*/
917 
919 {
920  SUMOReal minx, miny, maxx, maxy;
921 
922  if (-1 != pfGetCharBBox(c, &minx, &miny, &maxx, &maxy))
923  {
924  return maxy - miny;
925  }
926 
927  return 0.0;
928 }
929 
930 /*-----------------------------------------------*/
931 
933 {
934  SUMOReal minx, miny, maxx, maxy;
935 
936  if (-1 != pfGetCharBBox(c, &minx, &miny, &maxx, &maxy))
937  {
938  return maxx - minx;
939  }
940 
941  return 0.0;
942 }
943 
944 /*-----------------------------------------------*/
945 
947 {
948  SUMOReal minx, miny, maxx, maxy;
949 
950  if (-1 != pfGetCharBBox(c, &minx, &miny, &maxx, &maxy))
951  {
952  return maxy;
953  }
954 
955  return 0.0;
956 }
957 
958 /*-----------------------------------------------*/
959 
961 {
962  SUMOReal minx, miny, maxx, maxy;
963 
964  if (-1 != pfGetCharBBox(c, &minx, &miny, &maxx, &maxy))
965  {
966  return miny;
967  }
968 
969  return 0.0;
970 }
971 
972 /*-----------------------------------------------*/
973 
974 static int drawWideChar(/*SDL_Surface *s,*/ wchar_t c)
975 {
976  int i;
977  int j;
978  int k;
979  pfglyph *g = pfGetGlyph(c);
980  pfint16 *d = NULL;
981  int segs = 0;
982  int prim = 0;
983  int points = 0;
984  SUMOReal gx, gy;
985  SUMOReal ox, oy;
986  SUMOReal tmp = -100.0;
987 
988  if (NULL == g)
989  {
990  return -1;
991  }
992 
993  ox = 0.0;
994  oy = 0.0;
995  if (pfCenter)
996  {
997  oy = pfScaleY * ((g->maxy + g->miny) / 2.0);
998  ox = pfScaleX * ((g->maxx + g->minx) / 2.0);
999  }
1000 
1001  for (k = 0; k < pfTextWeight; k++)
1002  {
1003  segs = g->numsegments;
1004  d = g->segments;
1005 
1006  for (i = 0; i < segs; i++)
1007  {
1008  prim = *d++;
1009  points = *d++;
1010 
1011  glBegin(prim);//sglBegin(s, prim);
1012  for (j = 0; j < points; j++)
1013  {
1014  gx = unfix(*d++);
1015  gy = unfix(*d++);
1016 
1017  gx = (gx * pfScaleX);
1018  gy = (gy * pfScaleY);
1019 
1020  gx += weightOffset[k].x;
1021  gy += weightOffset[k].y;
1022 
1023  gx = pfSkew(gx, gy);
1024 
1025  tmp = gx;
1026  gx = (pfTextX - ox) + ((pfTextCos * tmp) - (pfTextSin * gy));
1027  gy = (pfTextY + oy) - ((pfTextSin * tmp) + (pfTextCos * gy));
1028 
1029  glVertex2f(gx, gy);//sglVertex2f(gx, gy);
1030  }
1031  glEnd();//sglEnd();
1032  }
1033  }
1034 
1035  /*
1036  sglColor3f(0.0, 1.0, 0.0);
1037  sglBegin(s, GL_LINES);
1038  sglVertex2f(pfTextX - pfScaleX, pfTextY);
1039  sglVertex2f(pfTextX + pfScaleX, pfTextY);
1040  sglEnd();
1041 
1042  sglColor3f(0.0, 1.0, 0.0);
1043  sglBegin(s, GL_LINES);
1044  sglVertex2f(pfTextX, pfTextY - pfScaleY);
1045  sglVertex2f(pfTextX, pfTextY + pfScaleX);
1046  sglEnd();
1047  */
1048 
1049  tmp = (g->advance * pfScaleX);
1050  pfTextX += tmp * pfTextCos;
1051  pfTextY -= tmp * pfTextSin;
1052 
1053  return 0;
1054 }
1055 
1056 /*-----------------------------------------------*/
1057 
1058 int pfDrawChar(/*SDL_Surface *s,*/ wchar_t c)
1059 {
1060  int value = 0;
1061 /*
1062  if (NULL == s)
1063  {
1064  return -1;
1065  }
1066 */
1067  value = drawWideChar(/*s,*/ c);
1068 
1069  return value;
1070 }
1071 
1072 /*-----------------------------------------------*/
1073 
1074 int pfDrawString(/*SDL_Surface *s,*/ const char *c)
1075 {
1076  /*
1077  if ((NULL == s) || (NULL == c))
1078  {
1079  return -1;
1080  }
1081 */
1082  while (0 != *c)
1083  {
1084  drawWideChar(/*s,*/ *c);
1085  c++;
1086  }
1087 
1088  return 0;
1089 }
1090 
1091 /*-----------------------------------------------*/
1092 
1093 int pfDrawStringW(/*SDL_Surface *s, */wchar_t *c)
1094 {
1095  /*
1096  if ((NULL == s) || (NULL == c))
1097  {
1098  return -1;
1099  }
1100 */
1101  while (0 != *c)
1102  {
1103  drawWideChar(/*s,*/ *c);
1104  c++;
1105  }
1106 
1107  return 0;
1108 }
1109 
1110 /*-----------------------------------------------*/
1111 
1112 SUMOReal
1113 pfdkGetStringWidth(const char *c)
1114 {
1115  SUMOReal w = 0;
1116  while (0 != *c) {
1117  w += pfGetCharAdvance(/*s,*/ *c);
1118  c++;
1119  }
1120  return w;
1121 }
1122 
static pfglyph * pfFindGlyph(pfglyph *glyphs, int numglyphs, pfglyph *find)
Definition: polyfonts.c:830
void pfSetAngleR(SUMOReal a)
Definition: polyfonts.c:510
int pfDrawString(const char *c)
Definition: polyfonts.c:1074
SUMOReal pfGetCharDescent(wchar_t c)
Definition: polyfonts.c:960
static pfglyph * pfGetGlyph(wchar_t c)
Definition: polyfonts.c:837
static int getStringBox(char *c, SUMOReal *minx, SUMOReal *miny, SUMOReal *maxx, SUMOReal *maxy)
Definition: polyfonts.c:558
SUMOReal maxx
Definition: polyfonttypes.h:69
static pffont * pfCurrentFont
Definition: polyfonts.c:83
#define min(a, b)
Definition: polyfonts.c:66
SUMOReal minx
Definition: polyfonttypes.h:52
#define DtoR
Definition: polyfonts.c:63
vertex weightOffset[]
Definition: polyfonts.c:116
static nameValue glPrims[]
Definition: polyfonts.c:172
static void validate(pffont *font)
Definition: polyfonts.c:205
SUMOReal pfGetCharAdvance(wchar_t c)
Definition: polyfonts.c:869
static int getStringBoxW(wchar_t *c, SUMOReal *minx, SUMOReal *miny, SUMOReal *maxx, SUMOReal *maxy)
Definition: polyfonts.c:598
pfuint16 numsegments
Definition: polyfonttypes.h:58
static SUMOReal pfScaleY
Definition: polyfonts.c:103
void pfGetPosition(SUMOReal *x, SUMOReal *y)
Definition: polyfonts.c:488
char * name
Definition: polyfonttypes.h:65
void pfSetPosition(SUMOReal x, SUMOReal y)
Definition: polyfonts.c:480
static pffont * pfDefaultFont
Definition: polyfonts.c:84
int value
Definition: polyfonts.c:169
SUMOReal advance
Definition: polyfonttypes.h:56
static int getCharBBox(wchar_t c, SUMOReal *minx, SUMOReal *miny, SUMOReal *maxx, SUMOReal *maxy)
Definition: polyfonts.c:532
static SUMOReal pfTextY
Definition: polyfonts.c:106
#define unfix(value)
Definition: polyfonts.c:136
static SUMOReal pfTextSin
Definition: polyfonts.c:131
pfglyph * glyphs
Definition: polyfonttypes.h:72
SUMOReal pfGetFontDescent()
Definition: polyfonts.c:775
char * pfGetFontName()
Definition: polyfonts.c:678
SUMOReal minx
Definition: polyfonttypes.h:67
wchar_t pfGetChar(int g)
Definition: polyfonts.c:801
static int pfCenter
Definition: polyfonts.c:134
SUMOReal maxy
Definition: polyfonttypes.h:55
int numglyphs
Definition: polyfonttypes.h:71
int pfGetCharBBox(wchar_t c, SUMOReal *minx, SUMOReal *miny, SUMOReal *maxx, SUMOReal *maxy)
Definition: polyfonts.c:883
SUMOReal y
Definition: polyfonts.c:113
unsigned short int pfuint16
Definition: polyfonttypes.h:45
void pfSetAngleD(SUMOReal a)
Definition: polyfonts.c:518
static SUMOReal pfTextX
Definition: polyfonts.c:105
signed short int pfint16
Definition: polyfonttypes.h:46
SUMOReal x
Definition: polyfonts.c:113
#define max(a, b)
Definition: polyfonts.c:65
static SUMOReal pfSkew(SUMOReal x, SUMOReal y)
Definition: polyfonts.c:145
void pfSetCenter(int onOff)
Definition: polyfonts.c:525
void pfSetWeight(int w)
Definition: polyfonts.c:503
static int lookupGlOp(char *op)
Definition: polyfonts.c:188
pfuint16 glyph
Definition: polyfonttypes.h:57
int pfDrawChar(wchar_t c)
Definition: polyfonts.c:1058
static int pfTextWeight
Definition: polyfonts.c:109
int pfGetFontNumGlyphs()
Definition: polyfonts.c:789
char * name
Definition: polyfonts.c:168
SUMOReal pfGetFontHeight()
Definition: polyfonts.c:733
static int drawWideChar(wchar_t c)
Definition: polyfonts.c:974
static SUMOReal pfTextCos
Definition: polyfonts.c:132
void pfSetScaleXY(SUMOReal sx, SUMOReal sy)
Definition: polyfonts.c:472
static int comp(const void *key, const void *target)
Definition: polyfonts.c:820
pffont * pfGetCurrentFont()
Definition: polyfonts.c:692
int pfGetFontBBox(SUMOReal *minx, SUMOReal *miny, SUMOReal *maxx, SUMOReal *maxy)
Definition: polyfonts.c:699
void pfUnloadFont(pffont *font)
Definition: polyfonts.c:256
int pfSetFont(pffont *f)
Definition: polyfonts.c:152
SUMOReal pfGetFontWidth()
Definition: polyfonts.c:747
static SUMOReal pfScaleX
Definition: polyfonts.c:102
void pfSetScale(SUMOReal s)
Definition: polyfonts.c:465
SUMOReal miny
Definition: polyfonttypes.h:53
pffont pfPSansBold16
SUMOReal pfdkGetStringWidth(const char *c)
Definition: polyfonts.c:1113
SUMOReal pfGetCharWidth(wchar_t c)
Definition: polyfonts.c:932
int pfDrawStringW(wchar_t *c)
Definition: polyfonts.c:1093
#define SUMOReal
Definition: config.h:215
void pfSetSkew(SUMOReal s)
Definition: polyfonts.c:496
pfint16 * segments
Definition: polyfonttypes.h:59
static SUMOReal pfTextSkew
Definition: polyfonts.c:108
int pfSetScaleBoxW(wchar_t *c, SUMOReal w, SUMOReal h)
Definition: polyfonts.c:658
int pfSetScaleBox(char *c, SUMOReal w, SUMOReal h)
Definition: polyfonts.c:638
#define numWeights
Definition: polyfonts.c:129
int loaded
Definition: polyfonttypes.h:66
SUMOReal pfGetCharHeight(wchar_t c)
Definition: polyfonts.c:918
SUMOReal pfGetCharAscent(wchar_t c)
Definition: polyfonts.c:946
SUMOReal pfGetFontAscent()
Definition: polyfonts.c:761
SUMOReal maxy
Definition: polyfonttypes.h:70
SUMOReal maxx
Definition: polyfonttypes.h:54
SUMOReal miny
Definition: polyfonttypes.h:68
static SUMOReal getCharAdvance(wchar_t c)
Definition: polyfonts.c:855