00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 #include "Hershey.h"
00092
00093 #if defined(_MSC_VER)
00094 #include <windows.h>
00095 #endif
00096
00097 #if defined(VMDOPENGL) || defined(VMDOPENGLPBUFFER) || defined(VMDEGLPBUFFER)
00098 #if defined(__APPLE__) && !defined (VMDMESA)
00099 #include <OpenGL/gl.h>
00100 #else
00101 #include <GL/gl.h>
00102 #endif
00103 #endif
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 #define VMDHERSHEYFIXEDNUMERICS 1
00115
00116 char* hersheyFontData[] = {
00117 (char *) "JZ",
00118 (char *) "JZ",
00119 (char *) "JZ",
00120 (char *) "JZ",
00121 (char *) "JZ",
00122 (char *) "JZ",
00123 (char *) "JZ",
00124 (char *) "JZ",
00125 (char *) "JZ",
00126 (char *) "JZ",
00127 (char *) "JZ",
00128 (char *) "JZ",
00129 (char *) "JZ",
00130 (char *) "JZ",
00131 (char *) "JZ",
00132 (char *) "JZ",
00133 (char *) "JZ",
00134 (char *) "JZ",
00135 (char *) "JZ",
00136 (char *) "JZ",
00137 (char *) "JZ",
00138 (char *) "JZ",
00139 (char *) "JZ",
00140 (char *) "JZ",
00141 (char *) "JZ",
00142 (char *) "JZ",
00143 (char *) "JZ",
00144 (char *) "JZ",
00145 (char *) "JZ",
00146 (char *) "JZ",
00147 (char *) "JZ",
00148 (char *) "JZ",
00149 #if defined(VMDHERSHEYFIXEDNUMERICS)
00150
00151 (char *) "H\\",
00152 #else
00153 (char *) "JZ",
00154 #endif
00155 (char *) "MWRFRT RRYQZR[SZRY",
00156 (char *) "JZNFNM RVFVM",
00157 (char *) "H]SBLb RYBRb RLOZO RKUYU",
00158 (char *) "H\\PBP_ RTBT_ RYIWGTFPFMGKIKKLMMNOOUQWRXSYUYXWZT[P[MZKX",
00159 (char *) "F^[FI[ RNFPHPJOLMMKMIKIIJGLFNFPGSHVHYG[F RWTUUTWTYV[X[ZZ[X[VYTWT",
00160 (char *) "E_\\O\\N[MZMYNXPVUTXRZP[L[JZIYHWHUISJRQNRMSKSIRGPFNGMIMKNNPQUXWZY[",
00161 (char *) "MWRHQGRFSGSIRKQL",
00162 (char *) "KYVBTDRGPKOPOTPYR]T`Vb",
00163 (char *) "KYNBPDRGTKUPUTTYR]P`Nb",
00164 (char *) "JZRLRX RMOWU RWOMU",
00165 #if defined(VMDHERSHEYFIXEDNUMERICS)
00166
00167 (char *) "H\\RIR[ RIR[R",
00168 #else
00169 (char *) "E_RIR[ RIR[R",
00170 #endif
00171 (char *) "NVSWRXQWRVSWSYQ[",
00172 #if defined(VMDHERSHEYFIXEDNUMERICS)
00173
00174 (char *) "H\\IR[R",
00175 #else
00176 (char *) "E_IR[R",
00177 #endif
00178 #if defined(VMDHERSHEYFIXEDNUMERICS)
00179
00180 (char *) "H\\RVQWRXSWRV",
00181 #else
00182 (char *) "NVRVQWRXSWRV",
00183 #endif
00184 (char *) "G][BIb",
00185 (char *) "H\\QFNGLJKOKRLWNZQ[S[VZXWYRYOXJVGSFQF",
00186 (char *) "H\\NJPISFS[",
00187 (char *) "H\\LKLJMHNGPFTFVGWHXJXLWNUQK[Y[",
00188 (char *) "H\\MFXFRNUNWOXPYSYUXXVZS[P[MZLYKW",
00189 (char *) "H\\UFKTZT RUFU[",
00190 (char *) "H\\WFMFLOMNPMSMVNXPYSYUXXVZS[P[MZLYKW",
00191 (char *) "H\\XIWGTFRFOGMJLOLTMXOZR[S[VZXXYUYTXQVOSNRNOOMQLT",
00192 (char *) "H\\YFO[ RKFYF",
00193 (char *) "H\\PFMGLILKMMONSOVPXRYTYWXYWZT[P[MZLYKWKTLRNPQOUNWMXKXIWGTFPF",
00194 (char *) "H\\XMWPURRSQSNRLPKMKLLINGQFRFUGWIXMXRWWUZR[P[MZLX",
00195 (char *) "NVROQPRQSPRO RRVQWRXSWRV",
00196 (char *) "NVROQPRQSPRO RSWRXQWRVSWSYQ[",
00197 (char *) "F^ZIJRZ[",
00198 (char *) "E_IO[O RIU[U",
00199 (char *) "F^JIZRJ[",
00200 (char *) "I[LKLJMHNGPFTFVGWHXJXLWNVORQRT RRYQZR[SZRY",
00201 (char *) "E`WNVLTKQKOLNMMPMSNUPVSVUUVS RQKOMNPNSOUPV RWKVSVUXVZV\\T]Q]O\\L[J",
00202 (char *) "I[RFJ[ RRFZ[ RMTWT",
00203 (char *) "G\\KFK[ RKFTFWGXHYJYLXNWOTP RKPTPWQXRYTYWXYWZT[K[",
00204 (char *) "H]ZKYIWGUFQFOGMILKKNKSLVMXOZQ[U[WZYXZV",
00205 (char *) "G\\KFK[ RKFRFUGWIXKYNYSXVWXUZR[K[",
00206 (char *) "H[LFL[ RLFYF RLPTP RL[Y[",
00207 (char *) "HZLFL[ RLFYF RLPTP",
00208 (char *) "H]ZKYIWGUFQFOGMILKKNKSLVMXOZQ[U[WZYXZVZS RUSZS",
00209 (char *) "G]KFK[ RYFY[ RKPYP",
00210 (char *) "NVRFR[",
00211 (char *) "JZVFVVUYTZR[P[NZMYLVLT",
00212 (char *) "G\\KFK[ RYFKT RPOY[",
00213 (char *) "HYLFL[ RL[X[",
00214 (char *) "F^JFJ[ RJFR[ RZFR[ RZFZ[",
00215 (char *) "G]KFK[ RKFY[ RYFY[",
00216 (char *) "G]PFNGLIKKJNJSKVLXNZP[T[VZXXYVZSZNYKXIVGTFPF",
00217 (char *) "G\\KFK[ RKFTFWGXHYJYMXOWPTQKQ",
00218 (char *) "G]PFNGLIKKJNJSKVLXNZP[T[VZXXYVZSZNYKXIVGTFPF RSWY]",
00219 (char *) "G\\KFK[ RKFTFWGXHYJYLXNWOTPKP RRPY[",
00220 (char *) "H\\YIWGTFPFMGKIKKLMMNOOUQWRXSYUYXWZT[P[MZKX",
00221 (char *) "JZRFR[ RKFYF",
00222 (char *) "G]KFKULXNZQ[S[VZXXYUYF",
00223 (char *) "I[JFR[ RZFR[",
00224 (char *) "F^HFM[ RRFM[ RRFW[ R\\FW[",
00225 (char *) "H\\KFY[ RYFK[",
00226 (char *) "I[JFRPR[ RZFRP",
00227 (char *) "H\\YFK[ RKFYF RK[Y[",
00228 (char *) "KYOBOb RPBPb ROBVB RObVb",
00229 (char *) "KYKFY^",
00230 (char *) "KYTBTb RUBUb RNBUB RNbUb",
00231 (char *) "JZRDJR RRDZR",
00232 (char *) "I[Ib[b",
00233 (char *) "NVSKQMQORPSORNQO",
00234 (char *) "I\\XMX[ RXPVNTMQMONMPLSLUMXOZQ[T[VZXX",
00235 (char *) "H[LFL[ RLPNNPMSMUNWPXSXUWXUZS[P[NZLX",
00236 (char *) "I[XPVNTMQMONMPLSLUMXOZQ[T[VZXX",
00237 (char *) "I\\XFX[ RXPVNTMQMONMPLSLUMXOZQ[T[VZXX",
00238 (char *) "I[LSXSXQWOVNTMQMONMPLSLUMXOZQ[T[VZXX",
00239 (char *) "MYWFUFSGRJR[ ROMVM",
00240 (char *) "I\\XMX]W`VaTbQbOa RXPVNTMQMONMPLSLUMXOZQ[T[VZXX",
00241 (char *) "I\\MFM[ RMQPNRMUMWNXQX[",
00242 (char *) "NVQFRGSFREQF RRMR[",
00243 (char *) "MWRFSGTFSERF RSMS^RaPbNb",
00244 (char *) "IZMFM[ RWMMW RQSX[",
00245 (char *) "NVRFR[",
00246 (char *) "CaGMG[ RGQJNLMOMQNRQR[ RRQUNWMZM\\N]Q][",
00247 (char *) "I\\MMM[ RMQPNRMUMWNXQX[",
00248 (char *) "I\\QMONMPLSLUMXOZQ[T[VZXXYUYSXPVNTMQM",
00249 (char *) "H[LMLb RLPNNPMSMUNWPXSXUWXUZS[P[NZLX",
00250 (char *) "I\\XMXb RXPVNTMQMONMPLSLUMXOZQ[T[VZXX",
00251 (char *) "KXOMO[ ROSPPRNTMWM",
00252 (char *) "J[XPWNTMQMNNMPNRPSUTWUXWXXWZT[Q[NZMX",
00253 (char *) "MYRFRWSZU[W[ ROMVM",
00254 (char *) "I\\MMMWNZP[S[UZXW RXMX[",
00255 (char *) "JZLMR[ RXMR[",
00256 (char *) "G]JMN[ RRMN[ RRMV[ RZMV[",
00257 (char *) "J[MMX[ RXMM[",
00258 (char *) "JZLMR[ RXMR[P_NaLbKb",
00259 (char *) "J[XMM[ RMMXM RM[X[",
00260 (char *) "KYTBRCQDPFPHQJRKSMSOQQ RRCQEQGRISJTLTNSPORSTTVTXSZR[Q]Q_Ra RQSSU",
00261 (char *) "NVRBRb",
00262 (char *) "KYPBRCSDTFTHSJRKQMQOSQ RRCSESGRIQJPLPNQPURQTPVPXQZR[S]S_Ra RSSQU",
00263 (char *) "F^IUISJPLONOPPTSVTXTZS[Q RISJQLPNPPQTTVUXUZT[Q[O",
00264 (char *) "JZJFJ[K[KFLFL[M[MFNFN[O[OFPFP[Q[QFRFR[S[SFTFT[U[UFVFV[W[WFXFX[Y[YFZFZ[" };
00265
00266
00267 #define VMD_DEFAULT_FONT_SCALE 0.0015f
00268
00269
00270 inline float h2float(char c) { return VMD_DEFAULT_FONT_SCALE * (c-'R'); }
00271
00272
00273
00274
00275 void hersheyDrawLetterOpenGL(unsigned char ch, int drawendpoints) {
00276 #if defined(VMDOPENGL) || defined(VMDOPENGLPBUFFER) || defined(VMDEGLPBUFFER)
00277
00278 const char *cp = hersheyFontData[ch % 128];
00279 float lm = h2float(cp[0]);
00280 float rm = h2float(cp[1]);
00281 const char *p;
00282
00283 glTranslatef(-lm,0,0);
00284
00285
00286 glBegin(GL_LINE_STRIP);
00287 for (p=cp+2; (*p); p+=2) {
00288 if (p[0] == ' ' && p[1] == 'R') {
00289 glEnd();
00290 glBegin(GL_LINE_STRIP);
00291 } else {
00292 float x = h2float( p[0] );
00293 float y = -h2float( p[1] );
00294 glVertex2f(x,y);
00295 }
00296 }
00297 glEnd();
00298
00299
00300
00301
00302
00303
00304
00305 if (drawendpoints) {
00306 glBegin(GL_POINTS);
00307 for (p=cp+2; (*p); p+=2) {
00308 if (p[0] == ' ' && p[1] == 'R') {
00309 glEnd();
00310 glBegin(GL_POINTS);
00311 } else {
00312 float x = h2float( p[0] );
00313 float y = -h2float( p[1] );
00314 glVertex2f(x,y);
00315 }
00316 }
00317 glEnd();
00318 }
00319
00320 glTranslatef(rm,0,0);
00321 #endif
00322 }
00323
00324
00325
00326
00327 void hersheyDrawInitLetter(hersheyhandle *hh, const char ch, float *lm, float *rm) {
00328
00329 const char *cp = hersheyFontData[ch % 128];
00330 hh->lm = h2float(cp[0]);
00331 *lm = hh->lm;
00332 hh->rm = h2float(cp[1]);
00333 *rm = hh->rm;
00334 hh->p=cp+2;
00335 }
00336
00337 int hersheyDrawNextLine(hersheyhandle *hh, int *draw, float *x, float *y) {
00338 if (*(hh->p)) {
00339 if ( hh->p[0] == ' ' && hh->p[1] == 'R' ) {
00340 *draw = 0;
00341 } else {
00342 *draw = 1;
00343 *x = h2float( hh->p[0] );
00344 *y = -h2float( hh->p[1] );
00345 }
00346 hh->p += 2;
00347 return 0;
00348 } else {
00349 hh->p += 2;
00350 return 1;
00351 }
00352 }
00353
00354
00355 #if 0
00356 #include <stdio.h>
00357
00358
00359 void hersheyPrintLetterInfo(char ch) {
00360
00361 const char *cp = hersheyFontData[ch % 128];
00362 float lm = h2float(cp[0]);
00363 float rm = h2float(cp[1]);
00364 printf("hershey char: '%c'\n", ch);
00365 printf("hershey cmds: '%s'\n", cp);
00366 printf("lm: %f\n", lm);
00367 printf("rm: %f\n", rm);
00368
00369 #if 0
00370 printf("pretranslate(%f, %f, %f)\n", -lm, 0.0, 0.0);
00371 for (const char* p=cp+2 ; *p ; p+=2) {
00372 if ( p[0] == ' ' && p[1] == 'R' ) {
00373 printf("\nlinestrip: ");
00374 } else {
00375 float x = h2float( p[0] );
00376 float y = -h2float( p[1] );
00377 printf("(%f,%f) ", x, y);
00378 }
00379 }
00380 printf("\nposttranslate(%f, %f, %f)\n", rm, 0.0, 0.0);
00381 #endif
00382
00383 printf("\n");
00384 }
00385
00386 void hersheyPrintLetterInfo2(char ch) {
00387 float lm, rm, x, y, ox, oy;
00388 int draw, odraw;
00389 hersheyhandle hh;
00390
00391 hersheyDrawInitLetter(&hh, ch, &lm, &rm);
00392 printf("pretranslate(%f, %f, %f)\n", -lm, 0.0, 0.0);
00393 ox=0;
00394 oy=0;
00395 odraw=0;
00396 while (!hersheyDrawNextLine(&hh, &draw, &x, &y)) {
00397 if (draw && odraw) {
00398 printf("line: %g %g -> %g %g\n", ox, oy, x, y);
00399 }
00400
00401 ox=x;
00402 oy=y;
00403 odraw=draw;
00404 }
00405
00406 printf("\nposttranslate(%f, %f, %f)\n", rm, 0.0, 0.0);
00407 }
00408
00409 int main() {
00410 const char *str="X. ";
00411 const char *cp=str;
00412
00413 while (*cp != '\0') {
00414 hersheyPrintLetterInfo(*cp);
00415 hersheyPrintLetterInfo2(*cp);
00416 cp++;
00417 }
00418
00419 return 0;
00420 }
00421 #endif