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