Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

Hershey.C

Go to the documentation of this file.
00001 /*
00002 * Modified Hershey Roman font rendering code.
00003 *
00004 * $Id: Hershey.C,v 1.20 2015年12月03日 18:03:14 johns Exp $
00005 */
00006 
00007 //
00008 // Hershey.C
00009 // extracted from the hershey font
00010 // 
00011 // Charles Schwieters 6/14/99
00012 // Various tweaks and updates by John Stone
00013 //
00014 // font info:
00015 //
00016 //Peter Holzmann, Octopus Enterprises
00017 //USPS: 19611 La Mar Court, Cupertino, CA 95014
00018 //UUCP: {hplabs!hpdsd,pyramid}!octopus!pete
00019 //Phone: 408/996-7746
00020 //
00021 //This distribution is made possible through the collective encouragement
00022 //of the Usenet Font Consortium, a mailing list that sprang to life to get
00023 //this accomplished and that will now most likely disappear into the mists
00024 //of time... Thanks are especially due to Jim Hurt, who provided the packed
00025 //font data for the distribution, along with a lot of other help.
00026 //
00027 //This file describes the Hershey Fonts in general, along with a description of
00028 //the other files in this distribution and a simple re-distribution restriction.
00029 //
00030 //USE RESTRICTION:
00031 // This distribution of the Hershey Fonts may be used by anyone for
00032 // any purpose, commercial or otherwise, providing that:
00033 // 1. The following acknowledgements must be distributed with
00034 // the font data:
00035 // - The Hershey Fonts were originally created by Dr.
00036 // A. V. Hershey while working at the U. S.
00037 // National Bureau of Standards.
00038 // - The format of the Font data in this distribution
00039 // was originally created by
00040 // James Hurt
00041 // Cognition, Inc.
00042 // 900 Technology Park Drive
00043 // Billerica, MA 01821
00044 // (mit-eddie!ci-dandelion!hurt)
00045 // 2. The font data in this distribution may be converted into
00046 // any other format *EXCEPT* the format distributed by
00047 // the U.S. NTIS (which organization holds the rights
00048 // to the distribution and use of the font data in that
00049 // particular format). Not that anybody would really
00050 // *want* to use their format... each point is described
00051 // in eight bytes as "xxx yyy:", where xxx and yyy are
00052 // the coordinate values as ASCII numbers.
00053 //
00054 //*PLEASE* be reassured: The legal implications of NTIS' attempt to control
00055 //a particular form of the Hershey Fonts *are* troubling. HOWEVER: We have
00056 //been endlessly and repeatedly assured by NTIS that they do not care what
00057 //we do with our version of the font data, they do not want to know about it,
00058 //they understand that we are distributing this information all over the world,
00059 //etc etc etc... but because it isn't in their *exact* distribution format, they
00060 //just don't care!!! So go ahead and use the data with a clear conscience! (If
00061 //you feel bad about it, take a smaller deduction for something on your taxes
00062 //next week...)
00063 //
00064 //The Hershey Fonts:
00065 // - are a set of more than 2000 glyph (symbol) descriptions in vector
00066 // ( <x,y> point-to-point ) format
00067 // - can be grouped as almost 20 'occidental' (english, greek,
00068 // cyrillic) fonts, 3 or more 'oriental' (Kanji, Hiragana,
00069 // and Katakana) fonts, and a few hundred miscellaneous
00070 // symbols (mathematical, musical, cartographic, etc etc)
00071 // - are suitable for typographic quality output on a vector device
00072 // (such as a plotter) when used at an appropriate scale.
00073 // - were digitized by Dr. A. V. Hershey while working for the U.S.
00074 // Government National Bureau of Standards (NBS).
00075 // - are in the public domain, with a few caveats:
00076 // - They are available from NTIS (National Technical Info.
00077 // Service) in a computer-readable from which is *not*
00078 // in the public domain. This format is described in
00079 // a hardcopy publication "Tables of Coordinates for
00080 // Hershey's Repertory of Occidental Type Fonts and
00081 // Graphic Symbols" available from NTIS for less than
00082 // 20ドル US (phone number +1 703 487 4763).
00083 // - NTIS does not care about and doesn't want to know about
00084 // what happens to Hershey Font data that is not
00085 // distributed in their exact format.
00086 // - This distribution is not in the NTIS format, and thus is
00087 // only subject to the simple restriction described
00088 // at the top of this file.
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 * The Hershey romans font in ascii order (first 32 places held by space)
00107 * NOTE: This font has been modified to yield fixed-width numeric 
00108 * characters. This makes it possible to produce justified numeric 
00109 * text that correctly lines up in columns.
00110 * The font was specifically changed for:
00111 * ' ' (ascii 32), '+' (ascii 43), '-' (ascii 45), and '.' (ascii 46)
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 /* force constant width for ' ' (ascii 32) */
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 /* force constant width for '+' (ascii 43) */
00167 (char *) "H\\RIR[ RIR[R",
00168 #else
00169 (char *) "E_RIR[ RIR[R",
00170 #endif
00171 (char *) "NVSWRXQWRVSWSYQ[",
00172 #if defined(VMDHERSHEYFIXEDNUMERICS)
00173 /* force constant width for '-' (ascii 45) */
00174 (char *) "H\\IR[R",
00175 #else
00176 (char *) "E_IR[R",
00177 #endif
00178 #if defined(VMDHERSHEYFIXEDNUMERICS)
00179 /* force constant width for '.' (ascii 46) */
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 //note the arbitrary scaling
00270 inline float h2float(char c) { return VMD_DEFAULT_FONT_SCALE * (c-'R'); }
00271 
00272 
00273 // hersheyDrawLetter() interprets the instructions from the array
00274 // for that letter and renders the letter with line segments.
00275 void hersheyDrawLetterOpenGL(unsigned char ch, int drawendpoints) {
00276 #if defined(VMDOPENGL) || defined(VMDOPENGLPBUFFER) || defined(VMDEGLPBUFFER)
00277 // note: we map same set of glyphs twice here (using modulo operator)
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 // draw font vectors for this glyph
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 // Draw points at each vector endpoint for this glyph, so
00300 // that we don't get "cracks" between the vectors when
00301 // rendering with much larger line widths. This is a 
00302 // significant improvement for antialiased line/point
00303 // widths >= 2.0, but non-antialiased lines of width 1.0 or
00304 // 2.0 often look better without the end points drawn.
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 } /* drawLetter */
00323 
00324 
00325 
00326 // font drawing for non-OpenGL renderers
00327 void hersheyDrawInitLetter(hersheyhandle *hh, const char ch, float *lm, float *rm) {
00328 // note: we map same set of glyphs twice here (using modulo operator)
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 // interprets the instructions from the array
00358 // for that letter and prints the translation offsets segments.
00359 void hersheyPrintLetterInfo(char ch) {
00360 // note: we map same set of glyphs twice here (using modulo operator)
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

Generated on Mon Nov 17 02:46:17 2025 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002

AltStyle によって変換されたページ (->オリジナル) /