gxvectorfont.cc

Go to the documentation of this file.
00001 
00003 
00004 //
00005 // Copyright (c) 2002-2004 California Institute of Technology
00006 // Copyright (c) 2004-2007 University of Southern California
00007 // Rob Peters <rjpeters at usc dot edu>
00008 //
00009 // created: Wed Nov 13 20:05:41 2002
00010 // commit: $Id: gxvectorfont.cc 10065 2007-04-12 05:54:56Z rjpeters $
00011 // $HeadURL: file:///lab/rjpeters/svnrepo/code/trunk/groovx/src/gfx/gxvectorfont.cc $
00012 //
00013 // --------------------------------------------------------------------
00014 //
00015 // This file is part of GroovX.
00016 //   [http://ilab.usc.edu/rjpeters/groovx/]
00017 //
00018 // GroovX is free software; you can redistribute it and/or modify it
00019 // under the terms of the GNU General Public License as published by
00020 // the Free Software Foundation; either version 2 of the License, or
00021 // (at your option) any later version.
00022 //
00023 // GroovX is distributed in the hope that it will be useful, but
00024 // WITHOUT ANY WARRANTY; without even the implied warranty of
00025 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00026 // General Public License for more details.
00027 //
00028 // You should have received a copy of the GNU General Public License
00029 // along with GroovX; if not, write to the Free Software Foundation,
00030 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00031 //
00033 
00034 #ifndef GROOVX_GFX_GXVECTORFONT_CC_UTC20050626084024_DEFINED
00035 #define GROOVX_GFX_GXVECTORFONT_CC_UTC20050626084024_DEFINED
00036 
00037 #include "gxvectorfont.h"
00038 
00039 #include "geom/rect.h"
00040 
00041 #include "gfx/bbox.h"
00042 #include "gfx/canvas.h"
00043 
00044 #include "rutz/fstring.h"
00045 
00046 #include <cstring>
00047 
00048 #if defined(GVX_GL_PLATFORM_GLX)
00049 #  include <GL/gl.h>
00050 #elif defined(GVX_GL_PLATFORM_AGL)
00051 #  include <AGL/gl.h>
00052 #endif
00053 
00054 #include "rutz/debug.h"
00055 GVX_DBG_REGISTER
00056 #include "rutz/trace.h"
00057 
00058 namespace
00059 {
00060 
00061 //---------------------------------------------------------------------
00062 //
00063 // pointtype struct
00064 //
00065 //---------------------------------------------------------------------
00066 
00067   enum pointtype {PT, STROKE, END};
00068   struct CP
00069   {
00070     GLfloat x,y;
00071     pointtype type;
00072   };
00073 
00074 //---------------------------------------------------------------------
00075 //
00076 // uppercase stroke data
00077 //
00078 //---------------------------------------------------------------------
00079 
00080   CP Adata[] =
00081   {
00082     {0, 0, PT}, {0, 3, PT}, {2, 6, PT}, {4, 3, PT}, {4, 0, STROKE},
00083     {0, 3, PT}, {4, 3, END}
00084   };
00085 
00086   CP Bdata[] =
00087   {
00088     {0, 0, PT}, {0, 6, PT}, {3, 6, PT}, {4, 5, PT}, {4, 4, PT}, {3, 3, PT}, {4, 2, PT}, {4, 1, PT}, {3, 0, PT}, {0, 0, STROKE},
00089     {0, 3, PT}, {3, 3, END}
00090   };
00091 
00092   CP Cdata[] =
00093   {
00094     {4, 1, PT}, {3, 0, PT}, {1, 0, PT}, {0, 1, PT}, {0, 5, PT}, {1, 6, PT}, {3, 6, PT}, {4, 5, END}
00095   };
00096 
00097   CP Ddata[] =
00098   {
00099     {0, 0, PT}, {0, 6, PT}, {3, 6, PT}, {4, 5, PT}, {4, 1, PT}, {3, 0, PT}, {0, 0, END}
00100   };
00101 
00102   CP Edata[] =
00103   {
00104     {4, 0, PT}, {0, 0, PT}, {0, 6, PT}, {4, 6, STROKE},
00105     {0, 3, PT}, {3, 3, END}
00106   };
00107 
00108   CP Fdata[] =
00109   {
00110     {0, 0, PT}, {0, 6, PT}, {4, 6, STROKE},
00111     {0, 3, PT}, {3, 3, END}
00112   };
00113 
00114   CP Gdata[] =
00115   {
00116     {2, 3, PT}, {4, 3, PT}, {4, 1, PT}, {3, 0, PT}, {1, 0, PT}, {0, 1, PT}, {0, 5, PT}, {1, 6, PT}, {3, 6, PT}, {4, 5, END}
00117   };
00118 
00119   CP Hdata[] =
00120   {
00121     {0, 0, PT}, {0, 6, STROKE},
00122     {4, 0, PT}, {4, 6, STROKE},
00123     {0, 3, PT}, {4, 3, END}
00124   };
00125 
00126   CP Idata[] =
00127   {
00128     {2, 6, PT}, {2, 0, STROKE},
00129     {0, 0, PT}, {4, 0, STROKE},
00130     {0, 6, PT}, {4, 6, END},
00131   };
00132 
00133   CP Jdata[] =
00134   {
00135     {0, 1, PT}, {1, 0, PT}, {3, 0, PT}, {4, 1, PT}, {4, 6, END}
00136   };
00137 
00138   CP Kdata[] =
00139   {
00140     {0, 0, PT}, {0, 6, STROKE},
00141     {4, 6, PT}, {0, 3, PT}, {4, 0, END}
00142   };
00143 
00144   CP Ldata[] =
00145   {
00146     {4, 0, PT}, {0, 0, PT}, {0, 6, END}
00147   };
00148 
00149   CP Mdata[] =
00150   {
00151     {0, 0, PT}, {0, 6, PT}, {2, 3, PT}, {4, 6, PT}, {4, 0, END}
00152   };
00153 
00154   CP Ndata[] =
00155   {
00156     {0, 0, PT}, {0, 6, PT}, {4, 0, PT}, {4, 6, END}
00157   };
00158 
00159   CP Odata[] =
00160   {
00161     {1, 0, PT}, {0, 1, PT}, {0, 5, PT}, {1, 6, PT}, {3, 6, PT}, {4, 5, PT}, {4, 1, PT}, {3, 0, PT}, {1, 0, END}
00162   };
00163 
00164   CP Pdata[] =
00165   {
00166     {0, 0, PT}, {0, 6, PT}, {3, 6, PT}, {4, 5, PT}, {4, 4, PT}, {3, 3, PT}, {0, 3, END}
00167   };
00168 
00169   CP Qdata[] =
00170   {
00171     {1, 0, PT}, {0, 1, PT}, {0, 5, PT}, {1, 6, PT}, {3, 6, PT}, {4, 5, PT}, {4, 1, PT}, {3, 0, PT}, {1, 0, STROKE},
00172     {3, 1, PT}, {4, 0, END}
00173   };
00174 
00175   CP Rdata[] =
00176   {
00177     {0, 0, PT}, {0, 6, PT}, {3, 6, PT}, {4, 5, PT}, {4, 4, PT}, {3, 3, PT}, {0, 3, STROKE},
00178     {1, 3, PT}, {4, 0, END}
00179   };
00180 
00181   CP Sdata[] =
00182   {
00183     {0, 1, PT}, {1, 0, PT}, {3, 0, PT}, {4, 1, PT}, {4, 2, PT}, {3, 3, PT}, {1, 3, PT}, {0, 4, PT}, {0, 5, PT}, {1, 6, PT}, {3, 6, PT}, {4, 5, END}
00184   };
00185 
00186   CP Tdata[] =
00187   {
00188     {2, 0, PT}, {2, 6, STROKE},
00189     {0, 6, PT}, {4, 6, END},
00190   };
00191 
00192   CP Udata[] =
00193   {
00194     {0, 6, PT}, {0, 1, PT}, {1, 0, PT}, {3, 0, PT}, {4, 1, PT}, {4, 6, END}
00195   };
00196 
00197   CP Vdata[] =
00198   {
00199     {0, 6, PT}, {2, 0, PT}, {4, 6, END}
00200   };
00201 
00202   CP Wdata[] =
00203   {
00204     {0, 6, PT}, {0, 0, PT}, {2, 3, PT}, {4, 0, PT}, {4, 6, END}
00205   };
00206 
00207   CP Xdata[] =
00208   {
00209     {0, 0, PT}, {4, 6, STROKE},
00210     {0, 6, PT}, {4, 0, END}
00211   };
00212 
00213   CP Ydata[] =
00214   {
00215     {0, 6, PT}, {2, 3, PT}, {4, 6, STROKE},
00216     {2, 3, PT}, {2, 0, END}
00217   };
00218 
00219   CP Zdata[] =
00220   {
00221     {4, 0, PT}, {0, 0, PT}, {4, 6, PT}, {0, 6, STROKE},
00222     {1, 3, PT}, {3, 3, END}
00223   };
00224 
00225 //---------------------------------------------------------------------
00226 //
00227 // lowercase stroke data
00228 //
00229 //---------------------------------------------------------------------
00230 
00231   CP adata[] =
00232   {
00233     {1, 4, PT}, {3, 4, PT}, {4, 3, PT}, {4, 0, STROKE},
00234     {4, 3, PT}, {1, 3, PT}, {0, 2, PT}, {0, 1, PT}, {1, 0, PT}, {3, 0, PT}, {4, 1, END}
00235   };
00236 
00237   CP bdata[] =
00238   {
00239     {0, 0, PT}, {0, 6, STROKE},
00240     {0, 3, PT}, {1, 4, PT}, {3, 4, PT}, {4, 3, PT}, {4, 1, PT}, {3, 0, PT}, {1, 0, PT}, {0, 1, END}
00241   };
00242 
00243   CP cdata[] =
00244   {
00245     {4, 1, PT}, {3, 0, PT}, {1, 0, PT}, {0, 1, PT}, {0, 3, PT}, {1, 4, PT}, {3, 4, PT}, {4, 3, END}
00246   };
00247 
00248   CP ddata[] =
00249   {
00250     {4, 0, PT}, {4, 6, STROKE},
00251     {4, 1, PT}, {3, 0, PT}, {1, 0, PT}, {0, 1, PT}, {0, 3, PT}, {1, 4, PT}, {3, 4, PT}, {4, 3, END}
00252   };
00253 
00254   CP edata[] =
00255   {
00256     {3, 0, PT}, {1, 0, PT}, {0, 1, PT}, {0, 3, PT}, {1, 4, PT}, {3, 4, PT}, {4, 3, PT}, {4, 2, PT}, {0, 2, END}
00257   };
00258 
00259   CP fdata[] =
00260   {
00261     {1, 0, PT}, {1, 5, PT}, {2, 6, PT}, {3, 6, PT}, {4, 5, STROKE},
00262     {0, 3, PT}, {3, 3, END}
00263   };
00264 
00265   CP gdata[] =
00266   {
00267     {4, 2, PT}, {3, 1, PT}, {1, 1, PT}, {0, 2, PT}, {0, 3, PT}, {1, 4, PT}, {3, 4, PT}, {4, 3, PT}, {4, 0, PT}, {3, -1, PT}, {1, -1, PT}, {0, 0, END}
00268   };
00269 
00270   CP hdata[] =
00271   {
00272     {0, 0, PT}, {0, 6, STROKE},
00273     {0, 3, PT}, {1, 4, PT}, {3, 4, PT}, {4, 3, PT}, {4, 0, END}
00274   };
00275 
00276   CP idata[] =
00277   {
00278     {0, 0, PT}, {4, 0, STROKE},
00279     {1, 4, PT}, {2, 4, PT}, {2, 0, STROKE},
00280     {2, 6, PT}, {2.25, 5.75, PT}, {2, 5.5, PT}, {1.75, 5.75, PT}, {2, 6, END}
00281   };
00282 
00283   CP jdata[] =
00284   {
00285     {3, 4, PT}, {4, 4, PT}, {4, 0, PT}, {3, -1, PT}, {1, -1, PT}, {0, 0, STROKE},
00286     {4, 6, PT}, {4.25, 5.75, PT}, {4, 5.5, PT}, {3.75, 5.75, PT}, {4, 6, END}
00287   };
00288 
00289   CP kdata[] =
00290   {
00291     {0, 0, PT}, {0, 6, STROKE},
00292     {0, 2, PT}, {1, 2, PT}, {4, 4, STROKE},
00293     {1, 2, PT}, {4, 0, END}
00294   };
00295 
00296   CP ldata[] =
00297   {
00298     {0, 0, PT}, {4, 0, STROKE},
00299     {1, 6, PT}, {2, 6, PT}, {2, 0, END}
00300   };
00301 
00302   CP mdata[] =
00303   {
00304     {0, 0, PT}, {0, 4, PT}, {2, 4, PT}, {2, 1, STROKE},
00305     {2, 4, PT}, {3, 4, PT}, {4, 3, PT}, {4, 0, END}
00306   };
00307 
00308   CP ndata[] =
00309   {
00310     {0, 0, PT}, {0, 4, STROKE},
00311     {0, 3, PT}, {1, 4, PT}, {3, 4, PT}, {4, 3, PT}, {4, 0, END}
00312   };
00313 
00314   CP odata[] =
00315   {
00316     {1.5, 0, PT}, {0.5, 0.5, PT}, {0, 1.5, PT}, {0, 2.5, PT}, {0.5, 3.5, PT},
00317     {1.5, 4, PT}, {2.5, 4, PT}, {3.5, 3.5, PT}, {4, 2.5, PT}, {4, 1.5, PT},
00318     {3.5, 0.5, PT}, {2.5, 0, PT}, {1.5, 0, END}
00319   };
00320 
00321   CP pdata[] =
00322   {
00323     {0, -1, PT}, {0, 4, STROKE},
00324     {0, 3, PT}, {1, 4, PT}, {3, 4, PT}, {4, 3, PT}, {4, 2, PT}, {3, 1, PT}, {1, 1, PT}, {0, 2, END}
00325   };
00326 
00327   CP qdata[] =
00328   {
00329     {4, -1, PT}, {4, 4, STROKE},
00330     {4, 3, PT}, {3, 4, PT}, {1, 4, PT}, {0, 3, PT}, {0, 2, PT}, {1, 1, PT}, {3, 1, PT}, {4, 2, END}
00331   };
00332 
00333   CP rdata[] =
00334   {
00335     {0, 0, PT}, {0, 4, STROKE},
00336     {0, 3, PT}, {1, 4, PT}, {3, 4, PT}, {4, 3, END}
00337   };
00338 
00339   CP sdata[] =
00340   {
00341     {0, 0.5, PT}, {1, 0, PT}, {3, 0, PT}, {4, 0.5, PT}, {4, 1.5, PT}, {3, 2, PT}, {1, 2, PT}, {0, 2.5, PT}, {0, 3.5, PT}, {1, 4, PT}, {3, 4, PT}, {4, 3.5, END}
00342   };
00343 
00344   CP tdata[] =
00345   {
00346     {0, 4, PT}, {3.5, 4, STROKE},
00347     {1.5, 5, PT}, {1.5, 0.5, PT}, {2.0, 0, PT}, {3.5, 0, PT}, {4, 0.5, END}
00348   };
00349 
00350   CP udata[] =
00351   {
00352     {0, 4, PT}, {0, 1, PT}, {1, 0, PT}, {3, 0, PT}, {4, 1, STROKE},
00353     {4, 0, PT}, {4, 4, END}
00354   };
00355 
00356   CP vdata[] =
00357   {
00358     {0, 4, PT}, {2, 0, PT}, {4, 4, END}
00359   };
00360 
00361   CP wdata[] =
00362   {
00363     {0, 4, PT}, {0, 1, PT}, {1, 0, PT}, {2, 1, STROKE},
00364     {2, 3, PT}, {2, 1, PT}, {3, 0, PT}, {4, 1, PT}, {4, 4, END}
00365   };
00366 
00367   CP xdata[] =
00368   {
00369     {0, 4, PT}, {4, 0, STROKE},
00370     {0, 0, PT}, {4, 4, END}
00371   };
00372 
00373   CP ydata[] =
00374   {
00375     {0, 4, PT}, {0, 2, PT}, {1, 1, PT}, {3, 1, PT}, {4, 2, STROKE},
00376     {4, 4, PT}, {4, 0, PT}, {3, -1, PT}, {1, -1, PT}, {0, 0, END}
00377   };
00378 
00379   CP zdata[] =
00380   {
00381     {0, 4, PT}, {4, 4, PT}, {0, 0, PT}, {4, 0, STROKE},
00382     {1, 2, PT}, {3, 2, END}
00383   };
00384 
00385 //---------------------------------------------------------------------
00386 //
00387 // numeric stroke data
00388 //
00389 //---------------------------------------------------------------------
00390 
00391   CP n0data[] =
00392   {
00393     {1, 0, PT}, {0, 1, PT}, {0, 5, PT}, {1, 6, PT}, {3, 6, PT}, {4, 5, PT}, {4, 1, PT}, {3, 0, PT}, {1, 0, STROKE},
00394     {0, 0, PT}, {4, 6, END}
00395   };
00396 
00397   CP n1data[] =
00398   {
00399     {0, 0, PT}, {4, 0, STROKE},
00400     {0, 4, PT}, {2, 6, PT}, {2, 0, END}
00401   };
00402 
00403   CP n2data[] =
00404   {
00405     {0, 5, PT}, {1, 6, PT}, {3, 6, PT}, {4, 5, PT}, {4, 4, PT}, {0, 1, PT}, {0, 0, PT}, {4, 0, END}
00406   };
00407 
00408   CP n3data[] =
00409   {
00410     {0, 6, PT}, {4, 6, PT}, {2, 3, PT}, {3, 3, PT}, {4, 2, PT}, {4, 1, PT}, {3, 0, PT}, {1, 0, PT}, {0, 1, END}
00411   };
00412 
00413   CP n4data[] =
00414   {
00415     {3, 0, PT}, {3, 6, PT}, {0, 3, PT}, {0, 2, PT}, {4, 2, END}
00416   };
00417 
00418   CP n5data[] =
00419   {
00420     {4, 6, PT}, {0, 6, PT}, {0, 3, PT}, {1, 4, PT}, {3, 4, PT}, {4, 3, PT}, {4, 1, PT}, {3, 0, PT}, {1, 0, PT}, {0, 1, END}
00421   };
00422 
00423   CP n6data[] =
00424   {
00425     {3, 6, PT}, {2, 6, PT}, {0, 4, PT}, {0, 1, PT}, {1, 0, PT}, {3, 0, PT}, {4, 1, PT}, {4, 2, PT}, {3, 3, PT}, {1, 3, PT}, {0, 2, END}
00426   };
00427 
00428   CP n7data[] =
00429   {
00430     {0, 6, PT}, {4, 6, PT}, {1, 0, STROKE},
00431     {1.5, 3, PT}, {3.5, 3, END}
00432   };
00433 
00434   CP n8data[] =
00435   {
00436     {1, 3, PT}, {0, 4, PT}, {0, 5, PT}, {1, 6, PT}, {3, 6, PT}, {4, 5, PT}, {4, 4, PT}, {3, 3, PT}, {1, 3, PT},
00437                 {0, 2, PT}, {0, 1, PT}, {1, 0, PT}, {3, 0, PT}, {4, 1, PT}, {4, 2, PT}, {3, 3, END}
00438   };
00439 
00440   CP n9data[] =
00441   {
00442     {1, 0, PT}, {2, 0, PT}, {4, 2, PT}, {4, 5, PT}, {3, 6, PT}, {1, 6, PT}, {0, 5, PT}, {0, 4, PT}, {1, 3, PT}, {3, 3, PT}, {4, 4, END}
00443   };
00444 
00445 
00446 //---------------------------------------------------------------------
00447 //
00448 // punctuation data
00449 //
00450 // !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
00451 //
00452 //---------------------------------------------------------------------
00453 
00454   CP space_data[] = { {0, 0, END} };
00455 
00456   CP exclamation_data[] =
00457   {
00458     {2, 6, PT}, {2, 2, STROKE},
00459     {2, 0, PT}, {2.25, 0.25, PT}, {2, 0.5, PT}, {1.75, 0.25, PT}, {2, 0, END}
00460   };
00461 
00462   CP double_quote_data[] =
00463   {
00464     {1, 6, PT}, {1, 4, STROKE},
00465     {3, 6, PT}, {3, 4, END}
00466   };
00467 
00468   CP pound_sign_data[] =
00469   {
00470     {0.5, 1, PT}, {1.5, 5, STROKE},
00471     {2.5, 1, PT}, {3.5, 5, STROKE},
00472     {0, 2, PT}, {4, 2, STROKE},
00473     {0, 4, PT}, {4, 4, END}
00474   };
00475 
00476   CP dollar_sign_data[] =
00477   {
00478     {4, 5, PT}, {1, 5, PT}, {0, 4, PT}, {1, 3, PT}, {3, 3, PT}, {4, 2, PT}, {3, 1, PT}, {0, 1, STROKE},
00479     {2, 6, PT}, {2, 0, END}
00480   };
00481 
00482   CP percent_data[] =
00483   {
00484     {0, 0, PT}, {4, 6, STROKE},
00485     {1, 5.5, PT}, {1.5, 5, PT}, {1, 4.5, PT}, {0.5, 5, PT}, {1, 5.5, STROKE},
00486     {3, 1.5, PT}, {3.5, 1, PT}, {3, 0.5, PT}, {2.5, 1, PT}, {3, 1.5, END}
00487   };
00488 
00489   CP ampersand_data[] =
00490   {
00491     {4, 2, PT}, {2, 0, PT}, {1, 0, PT}, {0, 1, PT}, {0, 2, PT}, {3, 4, PT}, {3, 5, PT}, {2, 6, PT}, {1, 6, PT}, {0, 5, PT}, {0, 4, PT}, {4, 0, END}
00492   };
00493 
00494   CP apostrophe_data[] =
00495   {
00496     {2, 6, PT}, {2, 5, PT}, {1, 4, END}
00497   };
00498 
00499   CP left_paren_data[] =
00500   {
00501     {3, 6, PT}, {1, 4, PT}, {1, 2, PT}, {3, 0, END}
00502   };
00503 
00504   CP right_paren_data[] =
00505   {
00506     {1, 6, PT}, {3, 4, PT}, {3, 2, PT}, {1, 0, END}
00507   };
00508 
00509   CP asterisk_data[] =
00510   {
00511     {0, 3, PT}, {4, 3, STROKE},
00512     {0.5, 1.5, PT}, {3.5, 4.5, STROKE},
00513     {0.5, 4.5, PT}, {3.5, 1.5, END}
00514   };
00515 
00516   CP plus_data[] =
00517   {
00518     {0, 3, PT}, {4, 3, STROKE},
00519     {2, 5, PT}, {2, 1, END}
00520   };
00521 
00522   CP comma_data[] =
00523   {
00524     {2, 1, PT}, {2, 0, PT}, {1, -1, END}
00525   };
00526 
00527   CP hyphen_data[] =
00528   {
00529     {0, 3, PT}, {4, 3, END}
00530   };
00531 
00532   CP period_data[] =
00533   {
00534     {2, 0.25, PT}, {2.25, 0, PT}, {2, -0.25, PT}, {1.75, 0, PT}, {2, 0.25, END}
00535   };
00536 
00537   CP slash_data[] =
00538   {
00539     {0, 0, PT}, {4, 6, END}
00540   };
00541 
00542   CP colon_data[] =
00543   {
00544     {2, 0.25, PT}, {2.25, 0, PT}, {2, -0.25, PT}, {1.75, 0, PT}, {2, 0.25, STROKE},
00545     {2, 4.25, PT}, {2.25, 4, PT}, {2, 3.75, PT}, {1.75, 4, PT}, {2, 4.25, END}
00546   };
00547 
00548   CP semicolon_data[] =
00549   {
00550     {2, 4.25, PT}, {2.25, 4, PT}, {2, 3.75, PT}, {1.75, 4, PT}, {2, 4.25, STROKE},
00551     {2, 1, PT}, {2, 0, PT}, {1, -1, END}
00552   };
00553 
00554   CP left_angle_data[] =
00555   {
00556     {4, 6, PT}, {0, 3, PT}, {4, 0, END}
00557   };
00558 
00559   CP equal_data_data[] =
00560   {
00561     {0, 2, PT}, {4, 2, STROKE},
00562     {0, 4, PT}, {4, 4, END}
00563   };
00564 
00565   CP right_angle_data[] =
00566   {
00567     {0, 6, PT}, {4, 3, PT}, {0, 0, END}
00568   };
00569 
00570   CP question_data[] =
00571   {
00572     {0, 5, PT}, {1, 6, PT}, {3, 6, PT}, {4, 5, PT}, {4, 4, PT}, {2, 3, PT}, {2, 2, STROKE},
00573     {2, 0.25, PT}, {2.25, 0, PT}, {2, -0.25, PT}, {1.75, 0, PT}, {2, 0.25, END}
00574   };
00575 
00576   CP at_data[] =
00577   {
00578     {3, 0, PT}, {1, 0, PT}, {0, 1, PT}, {0, 5, PT}, {1, 6, PT}, {3, 6, PT}, {4, 5, PT}, {4, 2, PT}, {1.5, 2, PT}, {1, 2.5, PT}, {1, 3.5, PT},
00579                 {1.5, 4, PT}, {3, 4, PT}, {3, 2, END}
00580   };
00581 
00582   CP left_square_data[] =
00583   {
00584     {4, 0, PT}, {1, 0, PT}, {1, 6, PT}, {4, 6, END}
00585   };
00586 
00587   CP backslash_data[] =
00588   {
00589     {0, 6, PT}, {4, 0, END}
00590   };
00591 
00592   CP right_square_data[] =
00593   {
00594     {0, 0, PT}, {3, 0, PT}, {3, 6, PT}, {0, 6, END}
00595   };
00596 
00597   CP caret_data[] =
00598   {
00599     {0.5, 4.5, PT}, {2, 6, PT}, {3.5, 4.5, END}
00600   };
00601 
00602   CP underscore_data[] =
00603   {
00604     {0, 0, PT}, {4, 0, END}
00605   };
00606 
00607   CP backquote_data[] =
00608   {
00609     {2, 6, PT}, {2, 5, PT}, {3, 4, END}
00610   };
00611 
00612   CP left_curly_data[] =
00613   {
00614     {4, 6, PT}, {2.5, 6, PT}, {2, 5.5, PT}, {2, 4, PT}, {2.5, 3.5, PT}, {1.5, 3, PT},
00615     {2.5, 2.5, PT}, {2, 2, PT}, {2, 0.5, PT}, {2.5, 0, PT}, {4, 0, END}
00616   };
00617 
00618   CP vertical_bar_data[] =
00619   {
00620     {2, 0, PT}, {2, 6, END}
00621   };
00622 
00623   CP right_curly_data[] =
00624   {
00625     {0, 6, PT}, {1.5, 6, PT}, {2, 5.5, PT}, {2, 4, PT}, {1.5, 3.5, PT}, {2.5, 3, PT},
00626     {1.5, 2.5, PT}, {2, 2, PT}, {2, 0.5, PT}, {1.5, 0, PT}, {0, 0, END}
00627   };
00628 
00629   CP tilde_data[] =
00630   {
00631     {0.5, 5, PT}, {1.5, 6, PT}, {2.5, 5, PT}, {3.5, 6, END}
00632   };
00633 
00634 //---------------------------------------------------------------------
00635 //
00636 // drawLetter -- parses stroke data into OpenGL code
00637 //
00638 //---------------------------------------------------------------------
00639 
00640   void drawLetter(CP* cp)
00641   {
00642     GVX_TRACE("<gxvectorfont.cc>::drawLetter");
00643 
00644     glBegin(GL_LINE_STRIP);
00645     while (1)
00646     {
00647       glVertex2fv(&cp->x);
00648 
00649       switch (cp->type)
00650       {
00651       case PT:
00652         break;
00653       case STROKE:
00654         glEnd();
00655         glBegin(GL_LINE_STRIP);
00656         break;
00657       case END:
00658         glEnd();
00659         glTranslatef(5.0, 0.0, 0.0);
00660         return;
00661       }
00662 
00663       cp++;
00664     }
00665   }
00666 
00667   GLuint getStrokeFontListBase()
00668   {
00669     GVX_TRACE("<gxvectorfont.cc>::getStrokeFontListBase");
00670 
00671     static GLuint listBase = 0;
00672 
00673     if (listBase != 0) return listBase;
00674 
00675     listBase = glGenLists(128);
00676 
00677     dbg_eval_nl(3, listBase);
00678 
00679     // Start off with this first phony list to work around bug in OSX
00680     // Aqua; without this phony call first, the first display list
00681     // (for 'A') doesn't get compiled correctly.
00682     glNewList(listBase + 0, GL_COMPILE); glEndList();
00683 
00684     glNewList(listBase + 'A', GL_COMPILE); drawLetter(Adata); glEndList();
00685     glNewList(listBase + 'B', GL_COMPILE); drawLetter(Bdata); glEndList();
00686     glNewList(listBase + 'C', GL_COMPILE); drawLetter(Cdata); glEndList();
00687     glNewList(listBase + 'D', GL_COMPILE); drawLetter(Ddata); glEndList();
00688     glNewList(listBase + 'E', GL_COMPILE); drawLetter(Edata); glEndList();
00689     glNewList(listBase + 'F', GL_COMPILE); drawLetter(Fdata); glEndList();
00690     glNewList(listBase + 'G', GL_COMPILE); drawLetter(Gdata); glEndList();
00691     glNewList(listBase + 'H', GL_COMPILE); drawLetter(Hdata); glEndList();
00692     glNewList(listBase + 'I', GL_COMPILE); drawLetter(Idata); glEndList();
00693     glNewList(listBase + 'J', GL_COMPILE); drawLetter(Jdata); glEndList();
00694     glNewList(listBase + 'K', GL_COMPILE); drawLetter(Kdata); glEndList();
00695     glNewList(listBase + 'L', GL_COMPILE); drawLetter(Ldata); glEndList();
00696     glNewList(listBase + 'M', GL_COMPILE); drawLetter(Mdata); glEndList();
00697     glNewList(listBase + 'N', GL_COMPILE); drawLetter(Ndata); glEndList();
00698     glNewList(listBase + 'O', GL_COMPILE); drawLetter(Odata); glEndList();
00699     glNewList(listBase + 'P', GL_COMPILE); drawLetter(Pdata); glEndList();
00700     glNewList(listBase + 'Q', GL_COMPILE); drawLetter(Qdata); glEndList();
00701     glNewList(listBase + 'R', GL_COMPILE); drawLetter(Rdata); glEndList();
00702     glNewList(listBase + 'S', GL_COMPILE); drawLetter(Sdata); glEndList();
00703     glNewList(listBase + 'T', GL_COMPILE); drawLetter(Tdata); glEndList();
00704     glNewList(listBase + 'U', GL_COMPILE); drawLetter(Udata); glEndList();
00705     glNewList(listBase + 'V', GL_COMPILE); drawLetter(Vdata); glEndList();
00706     glNewList(listBase + 'W', GL_COMPILE); drawLetter(Wdata); glEndList();
00707     glNewList(listBase + 'X', GL_COMPILE); drawLetter(Xdata); glEndList();
00708     glNewList(listBase + 'Y', GL_COMPILE); drawLetter(Ydata); glEndList();
00709     glNewList(listBase + 'Z', GL_COMPILE); drawLetter(Zdata); glEndList();
00710 
00711     glNewList(listBase + 'a', GL_COMPILE); drawLetter(adata); glEndList();
00712     glNewList(listBase + 'b', GL_COMPILE); drawLetter(bdata); glEndList();
00713     glNewList(listBase + 'c', GL_COMPILE); drawLetter(cdata); glEndList();
00714     glNewList(listBase + 'd', GL_COMPILE); drawLetter(ddata); glEndList();
00715     glNewList(listBase + 'e', GL_COMPILE); drawLetter(edata); glEndList();
00716     glNewList(listBase + 'f', GL_COMPILE); drawLetter(fdata); glEndList();
00717     glNewList(listBase + 'g', GL_COMPILE); drawLetter(gdata); glEndList();
00718     glNewList(listBase + 'h', GL_COMPILE); drawLetter(hdata); glEndList();
00719     glNewList(listBase + 'i', GL_COMPILE); drawLetter(idata); glEndList();
00720     glNewList(listBase + 'j', GL_COMPILE); drawLetter(jdata); glEndList();
00721     glNewList(listBase + 'k', GL_COMPILE); drawLetter(kdata); glEndList();
00722     glNewList(listBase + 'l', GL_COMPILE); drawLetter(ldata); glEndList();
00723     glNewList(listBase + 'm', GL_COMPILE); drawLetter(mdata); glEndList();
00724     glNewList(listBase + 'n', GL_COMPILE); drawLetter(ndata); glEndList();
00725     glNewList(listBase + 'o', GL_COMPILE); drawLetter(odata); glEndList();
00726     glNewList(listBase + 'p', GL_COMPILE); drawLetter(pdata); glEndList();
00727     glNewList(listBase + 'q', GL_COMPILE); drawLetter(qdata); glEndList();
00728     glNewList(listBase + 'r', GL_COMPILE); drawLetter(rdata); glEndList();
00729     glNewList(listBase + 's', GL_COMPILE); drawLetter(sdata); glEndList();
00730     glNewList(listBase + 't', GL_COMPILE); drawLetter(tdata); glEndList();
00731     glNewList(listBase + 'u', GL_COMPILE); drawLetter(udata); glEndList();
00732     glNewList(listBase + 'v', GL_COMPILE); drawLetter(vdata); glEndList();
00733     glNewList(listBase + 'w', GL_COMPILE); drawLetter(wdata); glEndList();
00734     glNewList(listBase + 'x', GL_COMPILE); drawLetter(xdata); glEndList();
00735     glNewList(listBase + 'y', GL_COMPILE); drawLetter(ydata); glEndList();
00736     glNewList(listBase + 'z', GL_COMPILE); drawLetter(zdata); glEndList();
00737 
00738     glNewList(listBase + '0', GL_COMPILE); drawLetter(n0data); glEndList();
00739     glNewList(listBase + '1', GL_COMPILE); drawLetter(n1data); glEndList();
00740     glNewList(listBase + '2', GL_COMPILE); drawLetter(n2data); glEndList();
00741     glNewList(listBase + '3', GL_COMPILE); drawLetter(n3data); glEndList();
00742     glNewList(listBase + '4', GL_COMPILE); drawLetter(n4data); glEndList();
00743     glNewList(listBase + '5', GL_COMPILE); drawLetter(n5data); glEndList();
00744     glNewList(listBase + '6', GL_COMPILE); drawLetter(n6data); glEndList();
00745     glNewList(listBase + '7', GL_COMPILE); drawLetter(n7data); glEndList();
00746     glNewList(listBase + '8', GL_COMPILE); drawLetter(n8data); glEndList();
00747     glNewList(listBase + '9', GL_COMPILE); drawLetter(n9data); glEndList();
00748 
00749     glNewList(listBase + ' ', GL_COMPILE); drawLetter(space_data); glEndList();
00750     glNewList(listBase + '!', GL_COMPILE); drawLetter(exclamation_data); glEndList();
00751     glNewList(listBase + '"', GL_COMPILE); drawLetter(double_quote_data); glEndList();
00752     glNewList(listBase + '#', GL_COMPILE); drawLetter(pound_sign_data); glEndList();
00753     glNewList(listBase + '$', GL_COMPILE); drawLetter(dollar_sign_data); glEndList();
00754     glNewList(listBase + '%', GL_COMPILE); drawLetter(percent_data); glEndList();
00755     glNewList(listBase + '&', GL_COMPILE); drawLetter(ampersand_data); glEndList();
00756     glNewList(listBase + '\'', GL_COMPILE); drawLetter(apostrophe_data); glEndList();
00757     glNewList(listBase + '(', GL_COMPILE); drawLetter(left_paren_data); glEndList();
00758     glNewList(listBase + ')', GL_COMPILE); drawLetter(right_paren_data); glEndList();
00759     glNewList(listBase + '*', GL_COMPILE); drawLetter(asterisk_data); glEndList();
00760     glNewList(listBase + '+', GL_COMPILE); drawLetter(plus_data); glEndList();
00761     glNewList(listBase + ',', GL_COMPILE); drawLetter(comma_data); glEndList();
00762     glNewList(listBase + '-', GL_COMPILE); drawLetter(hyphen_data); glEndList();
00763     glNewList(listBase + '.', GL_COMPILE); drawLetter(period_data); glEndList();
00764     glNewList(listBase + '/', GL_COMPILE); drawLetter(slash_data); glEndList();
00765     glNewList(listBase + ':', GL_COMPILE); drawLetter(colon_data); glEndList();
00766     glNewList(listBase + ';', GL_COMPILE); drawLetter(semicolon_data); glEndList();
00767     glNewList(listBase + '<', GL_COMPILE); drawLetter(left_angle_data); glEndList();
00768     glNewList(listBase + '=', GL_COMPILE); drawLetter(equal_data_data); glEndList();
00769     glNewList(listBase + '>', GL_COMPILE); drawLetter(right_angle_data); glEndList();
00770     glNewList(listBase + '?', GL_COMPILE); drawLetter(question_data); glEndList();
00771     glNewList(listBase + '@', GL_COMPILE); drawLetter(at_data); glEndList();
00772     glNewList(listBase + '[', GL_COMPILE); drawLetter(left_square_data); glEndList();
00773     glNewList(listBase + '\\', GL_COMPILE); drawLetter(backslash_data); glEndList();
00774     glNewList(listBase + ']', GL_COMPILE); drawLetter(right_square_data); glEndList();
00775     glNewList(listBase + '^', GL_COMPILE); drawLetter(caret_data); glEndList();
00776     glNewList(listBase + '_', GL_COMPILE); drawLetter(underscore_data); glEndList();
00777     glNewList(listBase + '`', GL_COMPILE); drawLetter(backquote_data); glEndList();
00778     glNewList(listBase + '{', GL_COMPILE); drawLetter(left_curly_data); glEndList();
00779     glNewList(listBase + '|', GL_COMPILE); drawLetter(vertical_bar_data); glEndList();
00780     glNewList(listBase + '}', GL_COMPILE); drawLetter(right_curly_data); glEndList();
00781     glNewList(listBase + '~', GL_COMPILE); drawLetter(tilde_data); glEndList();
00782 
00783     return listBase;
00784   }
00785 }
00786 
00787 
00789 //
00790 // GxVectorFont member definitions
00791 //
00793 
00794 
00795 GxVectorFont::GxVectorFont()
00796 {
00797 GVX_TRACE("GxVectorFont::GxVectorFont");
00798 }
00799 
00800 GxVectorFont::~GxVectorFont() throw()
00801 {
00802 GVX_TRACE("GxVectorFont::~GxVectorFont");
00803 }
00804 
00805 const char* GxVectorFont::fontName() const
00806 {
00807 GVX_TRACE("GxVectorFont::fontName");
00808   return "vector";
00809 }
00810 
00811 unsigned int GxVectorFont::listBase() const
00812 {
00813 GVX_TRACE("GxVectorFont::listBase");
00814   return getStrokeFontListBase();
00815 }
00816 
00817 void GxVectorFont::bboxOf(const char* text, Gfx::Bbox& bbox) const
00818 {
00819 GVX_TRACE("GxVectorFont::bboxOf");
00820   int longest = 0;
00821   int current = 0;
00822   int lines = 1;
00823   const char* p = text;
00824 
00825   while (*p != '\0')
00826     {
00827       if (*p == '\n')
00828         {
00829           if (current > longest)
00830             longest = current;
00831           current = 0;
00832           ++lines;
00833         }
00834       else
00835         {
00836           ++current;
00837         }
00838       ++p;
00839     }
00840 
00841   if (current > longest)
00842     longest = current;
00843 
00844   unsigned int len = longest;
00845 
00846   const double l = 0.0;
00847   const double r = len > 0 ? (5*len) - 1 : 1.0;
00848   const double b = -1.0 - (lines - 1) * 8.0;
00849   const double t = 6.0;
00850 
00851   bbox.drawRect(geom::rect<double>::ltrb(l,t,r,b));
00852 }
00853 
00854 void GxVectorFont::drawText(const char* text, Gfx::Canvas& canvas) const
00855 {
00856 GVX_TRACE("GxVectorFont::drawText");
00857 
00858   dbg_eval_nl(3, text);
00859   canvas.drawVectorText(text, *this);
00860 }
00861 
00862 double GxVectorFont::vectorHeight() const
00863 {
00864 GVX_TRACE("GxVectorFont::vectorHeight");
00865   return 8.0;
00866 }
00867 
00868 static const char __attribute__((used)) vcid_groovx_gfx_gxvectorfont_cc_utc20050626084024[] = "$Id: gxvectorfont.cc 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00869 #endif // !GROOVX_GFX_GXVECTORFONT_CC_UTC20050626084024_DEFINED

The software described here is Copyright (c) 1998-2005, Rob Peters.
This page was generated Wed Dec 3 06:49:39 2008 by Doxygen version 1.5.5.