GRASS Programmer's Manual  6.4.2(2012)
text2.c
Go to the documentation of this file.
00001 #include <math.h>
00002 
00003 #include <grass/gis.h>
00004 #include "driver.h"
00005 #include "driverlib.h"
00006 
00007 static int am_inside;
00008 static int dont_draw;
00009 static int t, b, l, r;
00010 static double basex, basey;
00011 static double curx, cury;
00012 
00013 static void remember(double x, double y)
00014 {
00015     if ((int)x > r)
00016         r = (int)x;
00017     if ((int)x < l)
00018         l = (int)x;
00019     if ((int)y > b)
00020         b = (int)y;
00021     if ((int)y < t)
00022         t = (int)y;
00023 
00024     curx = x;
00025     cury = y;
00026 }
00027 
00028 static void text_draw(double x, double y)
00029 {
00030     int X1 = (int)x;
00031     int Y1 = (int)y;
00032     int X2 = (int)curx;
00033     int Y2 = (int)cury;
00034 
00035     if (am_inside) {
00036         COM_Cont_abs(X1, Y1);
00037     }
00038     else {
00039         COM_Move_abs(X2, Y2);
00040         COM_Cont_abs(X1, Y1);
00041         am_inside = 1;
00042     }
00043 
00044     curx = x;
00045     cury = y;
00046 }
00047 
00048 static void text_move(double x, double y)
00049 {
00050     int X1 = (int)x;
00051     int Y1 = (int)y;
00052 
00053     if (am_inside)
00054         COM_Move_abs(X1, Y1);
00055 
00056     curx = x;
00057     cury = y;
00058 }
00059 
00060 void drawchar(double text_size_x, double text_size_y,
00061               double sinrot, double cosrot, unsigned char character)
00062 {
00063     unsigned char *X;
00064     unsigned char *Y;
00065     int n_vects;
00066     int i;
00067     int ax, ay;
00068     double x, y;
00069     void (*Do) (double, double);
00070     int ix, iy;
00071 
00072     x = basex;
00073     y = basey;
00074 
00075     get_char_vects(character, &n_vects, &X, &Y);
00076 
00077     Do = text_move;
00078 
00079     for (i = 1; i < n_vects; i++) {
00080         if (X[i] == ' ') {
00081             Do = text_move;
00082             continue;
00083         }
00084 
00085         ix = 10 + X[i] - 'R';
00086         iy = 10 - Y[i] + 'R';
00087         ax = (int)(text_size_x * (double)ix);
00088         ay = (int)(text_size_y * (double)iy);
00089 
00090         if (dont_draw) {
00091             remember(x + (ax * cosrot - ay * sinrot),
00092                      y - (ax * sinrot + ay * cosrot));
00093         }
00094         else {
00095             (*Do) (x + (ax * cosrot - ay * sinrot),
00096                    y - (ax * sinrot + ay * cosrot));
00097             Do = text_draw;
00098         }
00099     }
00100     /*  This seems to do variable spacing
00101        ix = 10 + X[i] - 'R';
00102      */
00103     ix = 20;
00104     iy = 0;
00105     ax = (int)(text_size_x * (double)ix);
00106     ay = (int)(text_size_y * (double)iy);
00107     if (!dont_draw)
00108         text_move(basex + (ax * cosrot - ay * sinrot),
00109                   basey - (ax * sinrot + ay * cosrot));
00110     else
00111         remember(basex + (ax * cosrot - ay * sinrot),
00112                  basey - (ax * sinrot + ay * cosrot));
00113 }
00114 
00115 void soft_text_ext(int x, int y,
00116                    double text_size_x, double text_size_y,
00117                    double text_rotation, const char *string)
00118 {
00119     t = 999999;
00120     b = 0;
00121     l = 999999;
00122     r = 0;
00123     dont_draw = 1;
00124     soft_text(x, y, text_size_x, text_size_y, text_rotation, string);
00125     dont_draw = 0;
00126 }
00127 
00128 void get_text_ext(int *top, int *bot, int *left, int *rite)
00129 {
00130     *top = t;
00131     *bot = b;
00132     *left = l;
00133     *rite = r;
00134 }
00135 
00136 # define RpD ((2 * M_PI) / 360.)        /* radians/degree */
00137 # define D2R(d) (double)(d * RpD)       /* degrees->radians */
00138 
00139 void soft_text(int x, int y,
00140                double text_size_x, double text_size_y, double text_rotation,
00141                const char *string)
00142 {
00143     double sinrot = sin(D2R(text_rotation));
00144     double cosrot = cos(D2R(text_rotation));
00145 
00146     am_inside = 0;
00147     curx = basex = (double)x;
00148     cury = basey = (double)y;
00149     while (*string) {
00150         drawchar(text_size_x, text_size_y, sinrot, cosrot, *string++);
00151         basex = curx;
00152         basey = cury;
00153     }
00154 }
00155 
00156 void onechar(int x, int y,
00157              double text_size_x, double text_size_y, double text_rotation,
00158              unsigned char achar)
00159 {
00160     double sinrot = sin(D2R(text_rotation));
00161     double cosrot = cos(D2R(text_rotation));
00162 
00163     am_inside = 0;
00164     curx = basex = (double)x;
00165     cury = basey = (double)y;
00166     drawchar(text_size_x, text_size_y, sinrot, cosrot, achar);
00167 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines