Loading...
Searching...
No Matches
text2.c
Go to the documentation of this file.
#include <math.h>
#include <grass/gis.h>
#include "driver.h"
#include "driverlib.h"
struct rectangle {
double t, b, l, r;
};
static void remember(struct rectangle *box, double x, double y)
{
if (x > box->r)
box->r = x;
if (x < box->l)
box->l = x;
if (y > box->b)
box->b = y;
if (y < box->t)
box->t = y;
}
static void transform(double *x, double *y, int ix, int iy, double orig_x,
double orig_y)
{
double ax = text_size_x * ix / 25;
double ay = text_size_y * iy / 25;
double rx = ax * text_cosrot - ay * text_sinrot;
double ry = ax * text_sinrot + ay * text_cosrot;
*x = orig_x + rx;
*y = orig_y - ry;
}
static void draw_char(double *px, double *py, unsigned char character,
struct rectangle *box)
{
unsigned char *X;
unsigned char *Y;
int n_vects;
int i;
void (*func)(double, double);
get_char_vects(character, &n_vects, &X, &Y);
if (!box)
COM_Begin();
func = COM_Move;
for (i = 1; i < n_vects; i++) {
int ix, iy;
double x, y;
if (X[i] == ' ') {
func = COM_Move;
continue;
}
ix = 10 + X[i] - 'R';
iy = 10 - Y[i] + 'R';
transform(&x, &y, ix, iy, *px, *py);
if (box)
remember(box, x, y);
else {
(*func)(x, y);
func = COM_Cont;
}
}
transform(px, py, 20, 0, *px, *py);
if (box)
remember(box, *px, *py);
else
COM_Stroke();
}
static void draw_text(const char *string, struct rectangle *box)
{
double base_x = cur_x;
double base_y = cur_y;
const unsigned char *p;
for (p = (const unsigned char *)string; *p; p++)
draw_char(&base_x, &base_y, *p, box);
}
void get_text_ext(const char *string, double *top, double *bot, double *left,
double *rite)
{
struct rectangle box;
box.t = 1e300;
box.b = -1e300;
box.l = 1e300;
box.r = -1e300;
draw_text(string, &box);
*top = box.t;
*bot = box.b;
*left = box.l;
*rite = box.r;
}
void soft_text(const char *string)
{
draw_text(string, NULL);
}
NULL
#define NULL
Definition ccmath.h:32
COM_Cont
void COM_Cont(double x, double y)
Definition driver/draw.c:22
COM_Stroke
void COM_Stroke(void)
Definition driver/draw.c:34
COM_Move
void COM_Move(double x, double y)
Definition driver/draw.c:16
COM_Begin
void COM_Begin(void)
Definition driver/draw.c:10
l
double l
Definition driver/set_window.c:5
t
double t
Definition driver/set_window.c:5
driver.h
text_size_y
double text_size_y
Definition driver/init.c:36
text_cosrot
double text_cosrot
Definition driver/init.c:39
text_size_x
double text_size_x
Definition driver/init.c:35
cur_x
double cur_x
Definition driver/init.c:32
text_sinrot
double text_sinrot
Definition driver/init.c:38
cur_y
double cur_y
Definition driver/init.c:33
driverlib.h
get_char_vects
int get_char_vects(unsigned char, int *, unsigned char **, unsigned char **)
Definition font2.c:195
get_text_ext
void get_text_ext(const char *string, double *top, double *bot, double *left, double *rite)
Definition text2.c:90
soft_text
void soft_text(const char *string)
Definition text2.c:108
X
#define X(j)
x
#define x
Y
#define Y(j)