BRL-CAD
symbol.c
Go to the documentation of this file.
1 /* S Y M B O L . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2004-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @addtogroup plot */
21 /** @{ */
22 /** @file libbn/symbol.c
23  *
24  * Terminal Independent Graphics Display Package.
25  * Mike Muuss July 31, 1978
26  *
27  * This routine is used to plot a string of ASCII symbols
28  * on the plot being generated, using a built-in set of fonts
29  * drawn as vector lists.
30  *
31  * Internally, the basic font resides in a 10x10 unit square.
32  * Externally, each character can be thought to occupy one square
33  * plotting unit; the 'scale'
34  * parameter allows this to be changed as desired, although scale
35  * factors less than 10.0 are unlikely to be legible.
36  *
37  */
38 
39 #include "common.h"
40 
41 #include <stdio.h>
42 #include <string.h>
43 #include <math.h>
44 
45 #include "bu/str.h"
46 #include "vmath.h"
47 #include "plot3.h"
48 #include "vectfont.h"
49 
50 void
51 tp_3symbol(FILE *fp, char *string, fastf_t *origin, fastf_t *rot, double scale)
52 
53 /* string of chars to be plotted */
54 /* lower left corner of 1st char */
55 /* Transform matrix (WARNING: may xlate) */
56 /* scale factor to change 1x1 char sz */
57 {
58  register unsigned char *cp;
59  double offset; /* offset of char from given x, y */
60  int ysign; /* sign of y motion, either +1 or -1 */
61  vect_t temp;
62  vect_t loc;
63  mat_t xlate_to_origin;
64  mat_t mat;
65 
66  if ( string == NULL || *string == '\0' )
67  return; /* done before begun! */
68 
69  /*
70  * The point "origin" will be the center of the axis rotation.
71  * The text is located in a local coordinate system with the
72  * lower left corner of the first character at (0, 0, 0), with
73  * the text proceeding onward towards +X.
74  * We need to rotate the text around its local (0, 0, 0),
75  * and then translate to the user's designated "origin".
76  * If the user provided translation or
77  * scaling in his matrix, it will *also* be applied.
78  */
79  MAT_IDN( xlate_to_origin );
80  MAT_DELTAS_VEC( xlate_to_origin, origin );
81  bn_mat_mul( mat, xlate_to_origin, rot );
82 
83  /* Draw each character in the input string */
84  offset = 0;
85  for ( cp = (unsigned char *)string; *cp; cp++, offset += scale ) {
86  register int *p; /* pointer to stroke table */
87  register int stroke;
88 
89  VSET( temp, offset, 0, 0 );
90  MAT4X3PNT( loc, mat, temp );
91  pdv_3move( fp, loc );
92 
93  for ( p = tp_getchar(cp); (stroke= *p) != LAST; p++ ) {
94  int draw;
95 
96  if ( stroke==NEGY ) {
97  ysign = (-1);
98  stroke = *++p;
99  } else
100  ysign = 1;
101 
102  /* Detect & process pen control */
103  if ( stroke < 0 ) {
104  stroke = -stroke;
105  draw = 0;
106  } else
107  draw = 1;
108 
109  /* stroke co-ordinates in string coord system */
110  VSET( temp, (stroke/11) * 0.1 * scale + offset,
111  (ysign * (stroke%11)) * 0.1 * scale, 0 );
112  MAT4X3PNT( loc, mat, temp );
113  if ( draw )
114  pdv_3cont( fp, loc );
115  else
116  pdv_3move( fp, loc );
117  }
118  }
119 }
120 
121 
122 void
123 tp_2symbol(FILE *fp, char *string, double x, double y, double scale, double theta)
124 
125 /* string of chars to be plotted */
126 /* x, y of lower left corner of 1st char */
127 
128 /* scale factor to change 1x1 char sz */
129 /* degrees ccw from X-axis */
130 {
131  mat_t mat;
132  vect_t p;
133 
134  bn_mat_angles( mat, 0.0, 0.0, theta );
135  VSET( p, x, y, 0 );
136  tp_3symbol( fp, string, p, mat, scale );
137 }
138 
139 /*
140  * This FORTRAN interface expects REAL args (single precision).
141  */
142 void
143 PL_FORTRAN(f2symb, F2SYMB)(FILE **fp, char *string, float *x, float *y, float *scale, float *theta)
144 {
145  char buf[128] = {0};
146 
147  bu_strlcpy( buf, string, sizeof(buf) );
148  tp_2symbol( *fp, buf, *x, *y, *scale, *theta );
149 }
150 /** @} */
151 /*
152  * Local Variables:
153  * mode: C
154  * tab-width: 8
155  * indent-tabs-mode: t
156  * c-file-style: "stroustrup"
157  * End:
158  * ex: shiftwidth=4 tabstop=8
159  */
void pdv_3move(register FILE *plotfp, const fastf_t *pt)
Definition: plot3.c:618
#define VSET(a, b, c, d)
Definition: color.c:53
void PL_FORTRAN(f2symb, F2SYMB)
Definition: symbol.c:143
Header file for the BRL-CAD common definitions.
void tp_2symbol(FILE *fp, char *string, double x, double y, double scale, double theta)
Definition: symbol.c:123
int * tp_getchar(const unsigned char *c)
Definition: vectfont.c:1104
#define bu_strlcpy(dst, src, size)
Definition: str.h:60
void pdv_3cont(register FILE *plotfp, const fastf_t *pt)
Definition: plot3.c:630
void bn_mat_mul(mat_t o, const mat_t a, const mat_t b)
void bn_mat_angles(mat_t mat, double alpha, double beta, double ggamma)
void tp_3symbol(FILE *fp, char *string, fastf_t *origin, fastf_t *rot, double scale)
Definition: symbol.c:51
double fastf_t
Definition: defines.h:300