font.c

Go to the documentation of this file.
00001 /*                          F O N T . C
00002  * BRL-CAD
00003  *
00004  * Copyright (c) 2004-2006 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  * as published by the Free Software Foundation; either version 2 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this file; see the file named COPYING for more
00019  * information.
00020  */
00021 
00022 /** \addtogroup vlist */
00023 /*@{*/
00024 /** @file font.c
00025  *
00026  *
00027  *  @author     Michael John Muuss
00028  *  @author     John Anderson
00029  *
00030  *  @par Source -
00031  *      The U. S. Army Research Laboratory
00032  *@n    Aberdeen Proving Ground, Maryland  21005-5068  USA
00033  *
00034  */
00035 
00036 
00037 #ifndef lint
00038 static const char RCSid[] = "@(#)$Header: /cvsroot/brlcad/brlcad/src/libbn/font.c,v 14.12 2006/09/07 01:19:17 lbutler Exp $ (ARL)";
00039 #endif
00040 
00041 #include "common.h"
00042 
00043 
00044 
00045 #include <stdio.h>
00046 #include <math.h>
00047 #ifdef HAVE_STRING_H
00048 #include <string.h>
00049 #endif
00050 
00051 #include "machine.h"
00052 #include "vmath.h"
00053 #include "bu.h"
00054 #include "bn.h"
00055 #include "vectfont.h"
00056 
00057 /* References tp_xxx symbols from libbn/vectfont.c */
00058 
00059 /**
00060  *                      B N _ V L I S T _ 3 S T R I N G
00061  *@brief
00062  * Convert a string to a vlist.
00063  * 
00064  *  'scale' is the width, in mm, of one character.
00065  *
00066  * @param vhead
00067  * @param free_hd source of free vlists
00068  * @param string  string of chars to be plotted
00069  * @param origin         lower left corner of 1st char
00070  * @param rot    Transform matrix (WARNING: may xlate)
00071  * @param scale    scale factor to change 1x1 char sz
00072  *
00073  */
00074 void
00075 bn_vlist_3string(struct bu_list *vhead,  
00076                  struct bu_list *free_hd,/* source of free vlists */ 
00077                  const char *string,    /* string of chars to be plotted */
00078                  const vect_t origin,   /* lower left corner of 1st char */
00079                  const mat_t rot,       /* Transform matrix (WARNING: may xlate) */
00080                  double scale)          /* scale factor to change 1x1 char sz */
00081 
00082 
00083 {
00084         register unsigned char *cp;
00085         double  offset;                 /* offset of char from given x,y */
00086         int     ysign;                  /* sign of y motion, either +1 or -1 */
00087         vect_t  temp;
00088         vect_t  loc;
00089         mat_t   xlate_to_origin;
00090         mat_t   mat;
00091 
00092         if( string == NULL || *string == '\0' )
00093                 return;                 /* done before begun! */
00094 
00095         /*
00096          *  The point "origin" will be the center of the axis rotation.
00097          *  The text is located in a local coordinate system with the
00098          *  lower left corner of the first character at (0,0,0), with
00099          *  the text proceeding onward towards +X.
00100          *  We need to rotate the text around it's local (0,0,0),
00101          *  and then translate to the user's designated "origin".
00102          *  If the user provided translation or
00103          *  scaling in his matrix, it will *also* be applied.
00104          */
00105         MAT_IDN( xlate_to_origin );
00106         MAT_DELTAS( xlate_to_origin,    origin[X], origin[Y], origin[Z] );
00107         bn_mat_mul( mat, xlate_to_origin, rot );
00108 
00109         /* Check to see if initialization is needed */
00110         if( tp_cindex[040] == 0 )  tp_setup();
00111 
00112         /* Draw each character in the input string */
00113         offset = 0;
00114         for( cp = (unsigned char *)string ; *cp; cp++, offset += scale )  {
00115                 register TINY   *p;     /* pointer to stroke table */
00116                 register int    stroke;
00117 
00118                 VSET( temp, offset, 0, 0 );
00119                 MAT4X3PNT( loc, mat, temp );
00120                 BN_ADD_VLIST(free_hd, vhead, loc, BN_VLIST_LINE_MOVE );
00121 
00122                 for( p = tp_cindex[*cp]; ((stroke= *p)) != LAST; p++ )  {
00123                         int     draw;
00124 
00125                         if( (stroke)==NEGY )  {
00126                                 ysign = (-1);
00127                                 stroke = *++p;
00128                         } else
00129                                 ysign = 1;
00130 
00131                         /* Detect & process pen control */
00132                         if( stroke < 0 )  {
00133                                 stroke = -stroke;
00134                                 draw = 0;
00135                         } else
00136                                 draw = 1;
00137 
00138                         /* stroke co-ordinates in string coord system */
00139                         VSET( temp, (stroke/11) * 0.1 * scale + offset,
00140                                    (ysign * (stroke%11)) * 0.1 * scale, 0 );
00141                         MAT4X3PNT( loc, mat, temp );
00142                         if( draw )  {
00143                                 BN_ADD_VLIST( free_hd, vhead, loc, BN_VLIST_LINE_DRAW );
00144                         } else {
00145                                 BN_ADD_VLIST( free_hd, vhead, loc, BN_VLIST_LINE_MOVE );
00146                         }
00147                 }
00148         }
00149 }
00150 
00151 
00152 /**
00153  *                      B N _ V L I S T _ 2 S T R I N G
00154  * @brief
00155  * Convert string to vlist in 2D
00156  *
00157  *  A simpler interface, for those cases where the text lies
00158  *  in the X-Y plane.
00159  * 
00160  * @param vhead
00161  * @param free_hd       source of free vlists
00162  * @param string        string of chars to be plotted
00163  * @param x             lower left corner of 1st char
00164  * @param y             lower left corner of 1st char
00165  * @param scale         scale factor to change 1x1 char sz
00166  * @param theta         degrees ccw from X-axis
00167  *
00168  */
00169 void
00170 bn_vlist_2string(struct bu_list *vhead,
00171                  struct bu_list *free_hd,
00172                  const char *string,
00173                  double x,
00174                  double y,
00175                  double scale,
00176                  double theta)
00177 {
00178         mat_t   mat;
00179         vect_t  p;
00180 
00181         bn_mat_angles( mat, 0.0, 0.0, theta );
00182         VSET( p, x, y, 0 );
00183         bn_vlist_3string( vhead, free_hd, string, p, mat, scale );
00184 }
00185 /*@}*/
00186 /*
00187  * Local Variables:
00188  * mode: C
00189  * tab-width: 8
00190  * c-basic-offset: 4
00191  * indent-tabs-mode: t
00192  * End:
00193  * ex: shiftwidth=4 tabstop=8
00194  */

Generated on Mon Sep 18 01:24:47 2006 for BRL-CAD by  doxygen 1.4.6