00001 /* S Y M B O L . C 00002 * BRL-CAD 00003 * 00004 * Copyright (c) 2004-2012 United States Government as represented by 00005 * the U.S. Army Research Laboratory. 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public License 00009 * version 2.1 as published by the Free Software Foundation. 00010 * 00011 * This library is distributed in the hope that it will be useful, but 00012 * WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this file; see the file named COPYING for more 00018 * information. 00019 */ 00020 /** @addtogroup plot */ 00021 /** @{ */ 00022 /** @file libbn/symbol.c 00023 * 00024 * Terminal Independant Graphics Display Package. 00025 * Mike Muuss July 31, 1978 00026 * 00027 * This routine is used to plot a string of ASCII symbols 00028 * on the plot being generated, using a built-in set of fonts 00029 * drawn as vector lists. 00030 * 00031 * Internally, the basic font resides in a 10x10 unit square. 00032 * Externally, each character can be thought to occupy one square 00033 * plotting unit; the 'scale' 00034 * parameter allows this to be changed as desired, although scale 00035 * factors less than 10.0 are unlikely to be legible. 00036 * 00037 */ 00038 00039 #include "common.h" 00040 00041 #include <stdio.h> 00042 #include <string.h> 00043 #include <math.h> 00044 00045 #include "vmath.h" 00046 #include "plot3.h" 00047 #include "vectfont.h" 00048 00049 /* 00050 * T P _ 3 S Y M B O L 00051 */ 00052 void 00053 tp_3symbol(FILE *fp, char *string, fastf_t *origin, fastf_t *rot, double scale) 00054 00055 /* string of chars to be plotted */ 00056 /* lower left corner of 1st char */ 00057 /* Transform matrix (WARNING: may xlate) */ 00058 /* scale factor to change 1x1 char sz */ 00059 { 00060 register unsigned char *cp; 00061 double offset; /* offset of char from given x, y */ 00062 int ysign; /* sign of y motion, either +1 or -1 */ 00063 vect_t temp; 00064 vect_t loc; 00065 mat_t xlate_to_origin; 00066 mat_t mat; 00067 00068 if ( string == NULL || *string == '\0' ) 00069 return; /* done before begun! */ 00070 00071 /* 00072 * The point "origin" will be the center of the axis rotation. 00073 * The text is located in a local coordinate system with the 00074 * lower left corner of the first character at (0, 0, 0), with 00075 * the text proceeding onward towards +X. 00076 * We need to rotate the text around its local (0, 0, 0), 00077 * and then translate to the user's designated "origin". 00078 * If the user provided translation or 00079 * scaling in his matrix, it will *also* be applied. 00080 */ 00081 MAT_IDN( xlate_to_origin ); 00082 MAT_DELTAS_VEC( xlate_to_origin, origin ); 00083 bn_mat_mul( mat, xlate_to_origin, rot ); 00084 00085 /* Check to see if initialization is needed */ 00086 if ( tp_cindex[040] == 0 ) tp_setup(); 00087 00088 /* Draw each character in the input string */ 00089 offset = 0; 00090 for ( cp = (unsigned char *)string; *cp; cp++, offset += scale ) { 00091 register int *p; /* pointer to stroke table */ 00092 register int stroke; 00093 00094 VSET( temp, offset, 0, 0 ); 00095 MAT4X3PNT( loc, mat, temp ); 00096 pdv_3move( fp, loc ); 00097 00098 for ( p = tp_cindex[*cp]; (stroke= *p) != LAST; p++ ) { 00099 int draw; 00100 00101 if ( stroke==NEGY ) { 00102 ysign = (-1); 00103 stroke = *++p; 00104 } else 00105 ysign = 1; 00106 00107 /* Detect & process pen control */ 00108 if ( stroke < 0 ) { 00109 stroke = -stroke; 00110 draw = 0; 00111 } else 00112 draw = 1; 00113 00114 /* stroke co-ordinates in string coord system */ 00115 VSET( temp, (stroke/11) * 0.1 * scale + offset, 00116 (ysign * (stroke%11)) * 0.1 * scale, 0 ); 00117 MAT4X3PNT( loc, mat, temp ); 00118 if ( draw ) 00119 pdv_3cont( fp, loc ); 00120 else 00121 pdv_3move( fp, loc ); 00122 } 00123 } 00124 } 00125 00126 00127 /* 00128 * T P _ 2 S Y M B O L 00129 */ 00130 void 00131 tp_2symbol(FILE *fp, char *string, double x, double y, double scale, double theta) 00132 00133 /* string of chars to be plotted */ 00134 /* x, y of lower left corner of 1st char */ 00135 00136 /* scale factor to change 1x1 char sz */ 00137 /* degrees ccw from X-axis */ 00138 { 00139 mat_t mat; 00140 vect_t p; 00141 00142 bn_mat_angles( mat, 0.0, 0.0, theta ); 00143 VSET( p, x, y, 0 ); 00144 tp_3symbol( fp, string, p, mat, scale ); 00145 } 00146 00147 /* 00148 * This FORTRAN interface expects REAL args (single precision). 00149 */ 00150 void 00151 PL_FORTRAN(f2symb, F2SYMB)(FILE **fp, char *string, float *x, float *y, float *scale, float *theta) 00152 { 00153 char buf[128] = {0}; 00154 00155 bu_strlcpy( buf, string, sizeof(buf) ); 00156 tp_2symbol( *fp, buf, *x, *y, *scale, *theta ); 00157 } 00158 /** @} */ 00159 /* 00160 * Local Variables: 00161 * mode: C 00162 * tab-width: 8 00163 * indent-tabs-mode: t 00164 * c-file-style: "stroustrup" 00165 * End: 00166 * ex: shiftwidth=4 tabstop=8 00167 */