#include <stdio.h>
#include <string.h>
#include <GL/gl.h>
#include "duplex.def"

void bbox(double size,double *xmin,double *xmax,double *ymin,double *ymax,char *text)
{
  int i,j,ic;
  double x,y;
  x = 0;
  y = 0;
  *xmin = 1e100;
  *ymin = 1e100;
  *xmax = -1e100;
  *ymax = -1e100;

  for(i=0;i<strlen(text);i++)
  {
    ic=(int) text[i];
    for(j=0;j<dlength[ic];j++)
    {
      x+=duplex[j+dstart[ic]][1]/24.0*size;
      y+=duplex[j+dstart[ic]][2]/24.0*size;
      if(x < *xmin) *xmin = x;
      if(x > *xmax) *xmax = x;
      if(y < *ymin) *ymin = y;
      if(y > *ymax) *ymax = y;
    }
    x+=size;
  }
}

void stroke(double size,double x,double y,double z,char *text)
{
  int i,j,ic;
  double lastx,lasty;
  lastx=x;
  lasty=y;

  for(i=0;i<strlen(text);i++)
  {
    ic=(int) text[i];
    for(j=0;j<dlength[ic];j++)
    {
      x+=duplex[j+dstart[ic]][1]/24.0*size;
      y+=duplex[j+dstart[ic]][2]/24.0*size;
      if(duplex[j+dstart[ic]][0])
      {
	glVertex3d(lastx,lasty,z);
	glVertex3d(x,y,z);
      }
      lastx=x;
      lasty=y;
    }
    x+=size;
  }
}

