4#ifndef _XVERTEXT_INCLUDED_ 
    5#define _XVERTEXT_INCLUDED_ 
   46      "xvertext routines Copyright (c) 1993 Alan Richardson" 
   74#ifndef CACHE_SIZE_LIMIT 
   75#define CACHE_SIZE_LIMIT 0 
   96#define DEBUG_PRINT1(a) if (gRotatedDebug) printf (a) 
   97#define DEBUG_PRINT2(a, b) if (gRotatedDebug) printf (a, b) 
   98#define DEBUG_PRINT3(a, b, c) if (gRotatedDebug) printf (a, b, c) 
   99#define DEBUG_PRINT4(a, b, c, d) if (gRotatedDebug) printf (a, b, c, d) 
  100#define DEBUG_PRINT5(a, b, c, d, e) if (gRotatedDebug) printf (a, b, c, d, e) 
  105#define M_PI 3.14159265358979323846 
  164XPoint                   *
XRotTextExtents(Display*, XFontStruct*, 
float,
int, 
int, 
char*, 
int);
 
  185   s=(
char *)
malloc((
unsigned)(strlen(str)+1));
 
  186   if(s!=0) strcpy(s, str);
 
  199   static int start, len;
 
  202   if(str2==0) 
return 0;
 
  212   if(start>=len) 
return 0;
 
  215   for(i=start; i<len; i++) {
 
  218      for(j=0; j<(
int)strlen(str2); j++)
 
  219      if(stext[i]==str2[j])
 
  272   data=(
char *)
calloc((
unsigned)(((w-1)/8+1)*
h), 1);
 
  273   if( data==0) 
return 0;
 
  276   image=XCreateImage(dpy, DefaultVisual(dpy, DefaultScreen(dpy)), 1, XYBitmap,
 
  277                   0, data, w, 
h, 8, 0);
 
  283   image->byte_order=image->bitmap_bit_order=MSBFirst;
 
  343   float hot_xp, hot_yp;
 
  344   float sin_angle, cos_angle;
 
  346   Pixmap bitmap_to_paint;
 
  349   if(
text==0) 
return 0;
 
  351   if(strlen(
text)==0) 
return 0;
 
  354   while(angle<0) angle+=360;
 
  356   while(angle>=360) angle-=360;
 
  367   if(item==0) 
return 0;
 
  370   my_gc=XCreateGC(dpy, drawable, 0, 0);
 
  371   XCopyGC(dpy, gc, GCForeground|GCBackground|GCFunction|GCPlaneMask,
 
  408   hot_xp= hot_x*cos_angle - hot_y*sin_angle;
 
  409   hot_yp= hot_x*sin_angle + hot_y*cos_angle;
 
  415      Pixmap empty_stipple;
 
  418      xpoints=(XPoint *)
malloc((
unsigned)(4*item->
fNl*
sizeof(XPoint)));
 
  419      if(!xpoints) 
return 1;
 
  422      for(i=0; i<4*item->
fNl; i++) {
 
  423         xpoints[i].x=
int((
float)
x + ( (item->
fCornersX[i]-hot_x)*cos_angle +
 
  425         xpoints[i].y=
int((
float)
y + (-(item->
fCornersX[i]-hot_x)*sin_angle +
 
  432      empty_stipple=XCreatePixmap(dpy, drawable, 1, 1, 1);
 
  434      depth_one_gc=XCreateGC(dpy, empty_stipple, 0, 0);
 
  435      XSetForeground(dpy, depth_one_gc, 0);
 
  436      XFillRectangle(dpy, empty_stipple, depth_one_gc, 0, 0, 2, 2);
 
  438      XSetStipple(dpy, my_gc, empty_stipple);
 
  439      XSetFillStyle(dpy, my_gc, FillOpaqueStippled);
 
  441      XFillPolygon(dpy, drawable, my_gc, xpoints, 4*item->
fNl, Nonconvex,
 
  445      free((
char *)xpoints);
 
  446      XFreeGC(dpy, depth_one_gc);
 
  447      XFreePixmap(dpy, empty_stipple);
 
  462      Pixmap new_bitmap, inverse;
 
  465      if(XGetGCValues(dpy, gc,
 
  466                      GCStipple|GCFillStyle|GCForeground|GCBackground|
 
  467                      GCTileStipXOrigin|GCTileStipYOrigin,
 
  471         if((values.fill_style==FillStippled ||
 
  472             values.fill_style==FillOpaqueStippled) && !bg) {
 
  475            if(values.fill_style==FillOpaqueStippled) {
 
  476               XSetForeground(dpy, my_gc, values.background);
 
  477               XSetFillStyle(dpy, my_gc, FillStippled);
 
  478               XSetStipple(dpy, my_gc, item->
fBitmap);
 
  479               XSetTSOrigin(dpy, my_gc, xp, yp);
 
  480               XFillRectangle(dpy, drawable, my_gc, xp, yp,
 
  482               XSetForeground(dpy, my_gc, values.foreground);
 
  486            new_bitmap=XCreatePixmap(dpy, drawable,
 
  490            depth_one_gc=XCreateGC(dpy, new_bitmap, 0, 0);
 
  491            XSetForeground(dpy, depth_one_gc, 1);
 
  492            XSetBackground(dpy, depth_one_gc, 0);
 
  495            XSetTSOrigin(dpy, depth_one_gc,
 
  496                         values.ts_x_origin-xp, values.ts_y_origin-yp);
 
  499            XSetStipple(dpy, depth_one_gc, values.stipple);
 
  500            XSetFillStyle(dpy, depth_one_gc, FillOpaqueStippled);
 
  501            XFillRectangle(dpy, new_bitmap, depth_one_gc,
 
  505            XSetTSOrigin(dpy, depth_one_gc, 0, 0);
 
  508            inverse=XCreatePixmap(dpy, drawable,
 
  512            XSetFillStyle(dpy, depth_one_gc, FillSolid);
 
  513            XSetFunction(dpy, depth_one_gc, GXcopyInverted);
 
  514            XCopyArea(dpy, item->
fBitmap, inverse, depth_one_gc,
 
  518            XSetForeground(dpy, depth_one_gc, 0);
 
  519            XSetBackground(dpy, depth_one_gc, 1);
 
  520            XSetStipple(dpy, depth_one_gc, inverse);
 
  521            XSetFillStyle(dpy, depth_one_gc, FillStippled);
 
  522            XSetFunction(dpy, depth_one_gc, GXcopy);
 
  523            XFillRectangle(dpy, new_bitmap, depth_one_gc,
 
  527            XFreePixmap(dpy, inverse);
 
  528            XFreeGC(dpy, depth_one_gc);
 
  531            bitmap_to_paint=new_bitmap;
 
  538   XSetFillStyle(dpy, my_gc, FillStippled);
 
  539   XSetStipple(dpy, my_gc, bitmap_to_paint);
 
  540   XSetTSOrigin(dpy, my_gc, xp, yp);
 
  541   XFillRectangle(dpy, drawable, my_gc, xp, yp,
 
  548   if(bitmap_to_paint!=item->
fBitmap)
 
  549      XFreePixmap(dpy, bitmap_to_paint);
 
  552   XFreePixmap(dpy, item->
fBitmap);
 
  574   char *str1, *str2, *str3;
 
  575   const char *str2_a=
"\0", *str2_b=
"\n\0";
 
  582   my_gc=XCreateGC(dpy, drawable, 0, 0);
 
  584           GCForeground|GCBackground|GCFunction|GCStipple|GCFillStyle|
 
  585           GCTileStipXOrigin|GCTileStipYOrigin|GCPlaneMask, my_gc);
 
  586   XSetFont(dpy, my_gc, font->fid);
 
  590      for(i=0; i<(
int)strlen(
text)-1; i++)
 
  601   height=font->ascent+font->descent;
 
  610      yp=
y-nl*(height-font->descent)/2+font->ascent;
 
  616      yp=
y-nl*(height-font->descent)+font->ascent;
 
  622   if(str1==0) 
return 1;
 
  629      XTextExtents(font, str3, strlen(str3), &dir, &asc, &desc,
 
  636         xp=
x-overall.rbearing/2;
 
  638         xp=
x-overall.rbearing;
 
  642         XDrawString(dpy, drawable, my_gc, xp, yp, str3, strlen(str3));
 
  644         XDrawImageString(dpy, drawable, my_gc, xp, yp, str3, strlen(str3));
 
  668   unsigned long name_value;
 
  673   if(XGetFontProperty(font, 
XA_FONT, &name_value)) {
 
  675      font_name=XGetAtomName(dpy, name_value);
 
  709         ((align==0)?9:(align-1))%3==
 
  714            if(strcmp(font_name, i1->
font_name)==0) {
 
  722         else if(font_name==0 && i1->
font_name==0) {
 
  781      item->
fBitmap=XCreatePixmap(dpy, DefaultRootWindow(dpy),
 
  785      depth_one_gc=XCreateGC(dpy, item->
fBitmap, 0, 0);
 
  786      XSetBackground(dpy, depth_one_gc, 0);
 
  787      XSetForeground(dpy, depth_one_gc, 1);
 
  790      XPutImage(dpy, item->
fBitmap, depth_one_gc, item->
fXimage, 0, 0, 0, 0,
 
  793      XFreeGC(dpy, depth_one_gc);
 
  811   char *str1, *str2, *str3;
 
  812   const char *str2_a=
"\0", *str2_b=
"\n\0";
 
  814   int byte_w_in, byte_w_out;
 
  816   float sin_angle, cos_angle;
 
  824   int old_cols_in=0, old_rows_in=0;
 
  833      for(i=0; i<(
int)strlen(
text)-1; i++)
 
  856   XTextExtents(font, str3, strlen(str3), &dir, &asc, &desc,
 
  866         XTextExtents(font, str3, strlen(str3), &dir, &asc, &desc,
 
  877   height=font->ascent+font->descent;
 
  884   canvas=XCreatePixmap(dpy, DefaultRootWindow(dpy),
 
  888   font_gc=XCreateGC(dpy, canvas, 0, 0);
 
  889   XSetBackground(dpy, font_gc, 0);
 
  890   XSetFont(dpy, font_gc, font->fid);
 
  893   XSetForeground(dpy, font_gc, 0);
 
  894   XFillRectangle(dpy, canvas, font_gc, 0, 0,
 
  896   XSetForeground(dpy, font_gc, 1);
 
  939      XTextExtents(font, str3, strlen(str3), &dir, &asc, &desc,
 
  951      XDrawString(dpy, canvas, font_gc, xp, yp, str3, strlen(str3));
 
  988                1, XYPixmap, imageIn, 0, 0);
 
  989   imageIn->format=XYBitmap;
 
 1021   byte_w_in=(item->
fColsIn-1)/8+1;
 
 1031   if(angle==0 || angle==
M_PI/2 ||
 
 1037   else if(angle<
M_PI) {
 
 1039         (dj-(
float)item->
fRowsIn/(2*cos_angle))/
 
 1042         (dj+(
float)item->
fRowsIn/(2*cos_angle))/
 
 1048         (dj+(
float)item->
fRowsIn/(2*cos_angle))/
 
 1051         (dj-(
float)item->
fRowsIn/(2*cos_angle))/
 
 1062         di=(float)((xl<0)?0:(
int)xl)+0.5-(float)item->
fColsOut/2;
 
 1063         byte_out=(item->
fRowsOut-j-1)*byte_w_out;
 
 1066         for(i=((xl<0)?0:(
int)xl);
 
 1070            it=
int((
float)item->
fColsIn/2 + ( di*cos_angle + dj*sin_angle));
 
 1071            jt=
int((
float)item->
fRowsIn/2 - (-di*sin_angle + dj*cos_angle));
 
 1074            if(it>=0 && it<item->fColsIn && jt>=0 && jt<item->fRowsIn)
 
 1075               if((imageIn->data[jt*byte_w_in+it/8] & 128>>(it%8))>0)
 
 1076                  item->
fXimage->data[byte_out+i/8]|=128>>i%8;
 
 1084      XDestroyImage(imageIn);
 
 1096   item->
fBitmap=XCreatePixmap(dpy, DefaultRootWindow(dpy),
 
 1100   XPutImage(dpy, item->
fBitmap, font_gc, item->
fXimage, 0, 0, 0, 0,
 
 1107   XFreeGC(dpy, font_gc);
 
 1108   XFreePixmap(dpy, canvas);
 
 1120   static long int current_size=0;
 
 1136      sizeof(
XImage) + strlen(item->text) +
 
 1142      item->
fSize+=
sizeof(Font);
 
 1160   DEBUG_PRINT4(
"current cache size=%ld, new item=%ld, limit=%d\n",
 
 1181         DEBUG_PRINT5(
"  (`%s'\n  FID=%ld\n   angle=%f align=%d)\n",
 
 1182                      i1->
fText, i1->
fid, i1->angle, i1->align);
 
 1185      current_size-=i1->
fSize;
 
 1210   current_size+=item->
fSize;
 
 1232   XFreePixmap(dpy, item->
fBitmap);
 
 1250   int cols_in, rows_in;
 
 1251   int cols_out, rows_out;
 
 1253   float z1, z2, z3, z4;
 
 1254   int byte_width_in, byte_width_out;
 
 1258   cols_in=ximage->width;
 
 1259   rows_in=ximage->height;
 
 1266   imageOut=
MakeXImage(dpy, cols_out, rows_out);
 
 1271   byte_width_in=(cols_in-1)/8+1;
 
 1272   byte_width_out=(cols_out-1)/8+1;
 
 1280   for(j2=0; j2<rows_out; j2++) {
 
 1284      for(i2=0; i2<cols_out; i2++) {
 
 1289         if(i==cols_in-1 && j!=rows_in-1) {
 
 1293            z1=(ximage->data[j*byte_width_in+i/8] & 128>>(i%8))>0;
 
 1295            z3=(ximage->data[(j+1)*byte_width_in+i/8] & 128>>(i%8))>0;
 
 1299         else if(i!=cols_in-1 && j==rows_in-1) {
 
 1303            z1=(ximage->data[j*byte_width_in+i/8] & 128>>(i%8))>0;
 
 1304            z2=(ximage->data[j*byte_width_in+(i+1)/8] & 128>>((i+1)%8))>0;
 
 1309         else if(i==cols_in-1 && j==rows_in-1) {
 
 1313            z1=(ximage->data[j*byte_width_in+i/8] & 128>>(i%8))>0;
 
 1323            z1=(ximage->data[j*byte_width_in+i/8] & 128>>(i%8))>0;
 
 1324            z2=(ximage->data[j*byte_width_in+(i+1)/8] & 128>>((i+1)%8))>0;
 
 1325            z3=(ximage->data[(j+1)*byte_width_in+(i+1)/8] &
 
 1327            z4=(ximage->data[(j+1)*byte_width_in+i/8] & 128>>(i%8))>0;
 
 1331         if(((1-t)*(1-u)*z1 + t*(1-u)*z2 + t*u*z3 + (1-t)*u*z4)>0.5)
 
 1332            imageOut->data[j2*byte_width_out+i2/8]|=128>>i2%8;
 
 1340   XDestroyImage(ximage);
 
 1353   char *str1, *str2, *str3;
 
 1354   const char *str2_a=
"\0", *str2_b=
"\n\0";
 
 1356   float sin_angle, cos_angle;
 
 1358   int cols_in, rows_in;
 
 1360   XPoint *xp_in, *xp_out;
 
 1362   XCharStruct overall;
 
 1365   while(angle<0) angle+=360;
 
 1367   while(angle>360) angle-=360;
 
 1374      for(i=0; i<(
int)strlen(
text)-1; i++)
 
 1380      str2=(
char *)str2_a;
 
 1382      str2=(
char *)str2_b;
 
 1386   if(str1==0) 
return 0;
 
 1391      XTextExtents(font, str1, strlen(str1), &dir, &asc, &desc,
 
 1394      XTextExtents(font, str3, strlen(str3), &dir, &asc, &desc,
 
 1398   max_width=overall.rbearing;
 
 1405         XTextExtents(font, str3, strlen(str3), &dir, &asc, &desc,
 
 1408         if(overall.rbearing>max_width)
 
 1409            max_width=overall.rbearing;
 
 1417   height=font->ascent+font->descent;
 
 1446   xp_in=(XPoint *)
malloc((
unsigned)(5*
sizeof(XPoint)));
 
 1447   if(!xp_in) 
return 0;
 
 1449   xp_out=(XPoint *)
malloc((
unsigned)(5*
sizeof(XPoint)));
 
 1464   xp_in[4].x=xp_in[0].x;
 
 1465   xp_in[4].y=xp_in[0].y;
 
 1468   for(i=0; i<5; i++) {
 
 1469      xp_out[i].x=(
short int)((
float)
x + ( ((float)xp_in[i].
x-hot_x)*cos_angle +
 
 1470                                           ((float)xp_in[i].
y+hot_y)*sin_angle));
 
 1471      xp_out[i].y=(
short int)((
float)
y + (-((float)xp_in[i].
x-hot_x)*sin_angle +
 
 1472                                          ((float)xp_in[i].
y+hot_y)*cos_angle));
 
 1475   free((
char *)xp_in);
 
int XRotDrawImageString(Display *, XFontStruct *, float, Drawable, GC, int, int, char *)
A front end to XRotPaintAlignedString: -no alignment, paints background.
 
int XRotDrawString(Display *, XFontStruct *, float, Drawable, GC, int, int, char *)
A front end to XRotPaintAlignedString: -no alignment, no background.
 
static struct StyleTemplate_t gRotStyle
 
float XRotVersion(char *, int)
Return version/copyright information.
 
int XRotDrawAlignedImageString(Display *, XFontStruct *, float, Drawable, GC, int, int, char *, int)
A front end to XRotPaintAlignedString: -does alignment, paints background.
 
static int XRotPaintAlignedString(Display *dpy, XFontStruct *font, float angle, Drawable drawable, GC gc, int x, int y, char *text, int align, int bg)
Aligns and paints a rotated string.
 
void XRotSetBoundingBoxPad(int)
Set the padding used when calculating bounding boxes.
 
static RotatedTextItem_t * XRotCreateTextItem(Display *dpy, XFontStruct *font, float angle, char *text, int align)
Create a rotated text item.
 
static char * my_strdup(char *)
Routine to mimic ‘strdup()’ (some machines don't have it)
 
struct RotatedTextItemTemplate_t RotatedTextItem_t
 
static RotatedTextItem_t * XRotRetrieveFromCache(Display *dpy, XFontStruct *font, float angle, char *text, int align)
Query cache for a match with this font/text/angle/alignment request, otherwise arrange for its creati...
 
static void XRotFreeTextItem(Display *dpy, RotatedTextItem_t *item)
Free the resources used by a text item.
 
#define DEBUG_PRINT5(a, b, c, d, e)
 
static XImage * XRotMagnifyImage(Display *dpy, XImage *ximage)
Magnify an XImage using bilinear interpolation.
 
#define DEBUG_PRINT2(a, b)
 
int XRotDrawAlignedString(Display *, XFontStruct *, float, Drawable, GC, int, int, char *, int)
A front end to XRotPaintAlignedString: -does alignment, no background.
 
#define DEBUG_PRINT4(a, b, c, d)
 
static RotatedTextItem_t * gFirstTextItem
 
XPoint * XRotTextExtents(Display *, XFontStruct *, float, int, int, char *, int)
Calculate the bounding box some text will have when painted.
 
static char * my_strtok(char *, char *)
Routine to replace ‘strtok’ : this one returns a zero length string if it encounters two consecutive ...
 
static int XRotDrawHorizontalString(Display *dpy, XFontStruct *font, Drawable drawable, GC gc, int x, int y, char *text, int align, int bg)
Draw a horizontal string in a quick fashion.
 
void XRotSetMagnification(float)
Set the font magnification factor for all subsequent operations.
 
static void XRotAddToLinkedList(Display *dpy, RotatedTextItem_t *item)
Adds a text item to the end of the cache, removing as many items from the front as required to keep c...
 
static XImage * MakeXImage(Display *dpy, int w, int h)
Create an XImage structure and allocate memory for it.
 
struct RotatedTextItemTemplate_t * fNext