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
161XPoint *
XRotTextExtents(Display*, XFontStruct*,
float,
int,
int,
char*,
int);
178 if(!str)
return nullptr;
180 char *s = (
char *)
malloc((
unsigned)(strlen(str)+1));
181 if(s) strcpy(s, str);
193 static int start,
len;
196 if(!str2)
return nullptr;
206 if(start>=
len)
return nullptr;
209 for(i=start; i<
len; i++) {
212 for(j=0; j<(
int)strlen(str2); j++)
213 if(stext[i]==str2[j])
221 char *ret = stext+start;
263 char *
data = (
char *)
calloc((
unsigned)(((
w-1)/8+1)*
h), 1);
264 if(!
data)
return nullptr;
267 XImage *image = XCreateImage(dpy, DefaultVisual(dpy, DefaultScreen(dpy)), 1, XYBitmap,
274 image->byte_order=image->bitmap_bit_order=MSBFirst;
333 float hot_xp, hot_yp;
334 float sin_angle, cos_angle;
335 Pixmap bitmap_to_paint;
357 GC my_gc = XCreateGC(dpy, drawable, 0,
nullptr);
358 XCopyGC(dpy,
gc, GCForeground|GCBackground|GCFunction|GCPlaneMask, my_gc);
394 hot_xp= hot_x*cos_angle - hot_y*sin_angle;
395 hot_yp= hot_x*sin_angle + hot_y*cos_angle;
401 Pixmap empty_stipple;
404 xpoints=(XPoint *)
malloc((
unsigned)(4*item->
fNl*
sizeof(XPoint)));
405 if(!xpoints)
return 1;
408 for(i=0; i<4*item->
fNl; i++) {
409 xpoints[i].x=
int((
float)
x + ( (item->
fCornersX[i]-hot_x)*cos_angle +
411 xpoints[i].y=
int((
float)
y + (-(item->
fCornersX[i]-hot_x)*sin_angle +
418 empty_stipple=XCreatePixmap(dpy, drawable, 1, 1, 1);
420 depth_one_gc=XCreateGC(dpy, empty_stipple, 0,
nullptr);
421 XSetForeground(dpy, depth_one_gc, 0);
422 XFillRectangle(dpy, empty_stipple, depth_one_gc, 0, 0, 2, 2);
424 XSetStipple(dpy, my_gc, empty_stipple);
425 XSetFillStyle(dpy, my_gc, FillOpaqueStippled);
427 XFillPolygon(dpy, drawable, my_gc, xpoints, 4*item->
fNl, Nonconvex,
432 XFreeGC(dpy, depth_one_gc);
433 XFreePixmap(dpy, empty_stipple);
448 Pixmap new_bitmap, inverse;
451 if(XGetGCValues(dpy,
gc,
452 GCStipple|GCFillStyle|GCForeground|GCBackground|
453 GCTileStipXOrigin|GCTileStipYOrigin,
457 if((values.fill_style==FillStippled ||
458 values.fill_style==FillOpaqueStippled) && !bg) {
461 if(values.fill_style==FillOpaqueStippled) {
462 XSetForeground(dpy, my_gc, values.background);
463 XSetFillStyle(dpy, my_gc, FillStippled);
464 XSetStipple(dpy, my_gc, item->
fBitmap);
465 XSetTSOrigin(dpy, my_gc, xp, yp);
466 XFillRectangle(dpy, drawable, my_gc, xp, yp,
468 XSetForeground(dpy, my_gc, values.foreground);
472 new_bitmap=XCreatePixmap(dpy, drawable,
476 depth_one_gc=XCreateGC(dpy, new_bitmap, 0,
nullptr);
477 XSetForeground(dpy, depth_one_gc, 1);
478 XSetBackground(dpy, depth_one_gc, 0);
481 XSetTSOrigin(dpy, depth_one_gc,
482 values.ts_x_origin-xp, values.ts_y_origin-yp);
485 XSetStipple(dpy, depth_one_gc, values.stipple);
486 XSetFillStyle(dpy, depth_one_gc, FillOpaqueStippled);
487 XFillRectangle(dpy, new_bitmap, depth_one_gc,
491 XSetTSOrigin(dpy, depth_one_gc, 0, 0);
494 inverse=XCreatePixmap(dpy, drawable,
498 XSetFillStyle(dpy, depth_one_gc, FillSolid);
499 XSetFunction(dpy, depth_one_gc, GXcopyInverted);
500 XCopyArea(dpy, item->
fBitmap, inverse, depth_one_gc,
504 XSetForeground(dpy, depth_one_gc, 0);
505 XSetBackground(dpy, depth_one_gc, 1);
506 XSetStipple(dpy, depth_one_gc, inverse);
507 XSetFillStyle(dpy, depth_one_gc, FillStippled);
508 XSetFunction(dpy, depth_one_gc, GXcopy);
509 XFillRectangle(dpy, new_bitmap, depth_one_gc,
513 XFreePixmap(dpy, inverse);
514 XFreeGC(dpy, depth_one_gc);
517 bitmap_to_paint=new_bitmap;
524 XSetFillStyle(dpy, my_gc, FillStippled);
525 XSetStipple(dpy, my_gc, bitmap_to_paint);
526 XSetTSOrigin(dpy, my_gc, xp, yp);
527 XFillRectangle(dpy, drawable, my_gc, xp, yp,
534 if(bitmap_to_paint!=item->
fBitmap)
535 XFreePixmap(dpy, bitmap_to_paint);
538 XFreePixmap(dpy, item->
fBitmap);
559 char *str1, *str2, *str3;
560 const char *str2_a=
"\0", *str2_b=
"\n\0";
567 GC my_gc = XCreateGC(dpy, drawable, 0,
nullptr);
569 GCForeground|GCBackground|GCFunction|GCStipple|GCFillStyle|
570 GCTileStipXOrigin|GCTileStipYOrigin|GCPlaneMask, my_gc);
571 XSetFont(dpy, my_gc, font->fid);
575 for(i=0; i<(
int)strlen(
text)-1; i++)
586 height=font->ascent+font->descent;
595 yp=
y-nl*(
height-font->descent)/2+font->ascent;
601 yp=
y-nl*(
height-font->descent)+font->ascent;
617 XTextExtents(font, str3, strlen(str3), &dir, &asc, &desc,
624 xp=
x-overall.rbearing/2;
626 xp=
x-overall.rbearing;
630 XDrawString(dpy, drawable, my_gc, xp, yp, str3, strlen(str3));
632 XDrawImageString(dpy, drawable, my_gc, xp, yp, str3, strlen(str3));
656 unsigned long name_value;
661 if(XGetFontProperty(font,
XA_FONT, &name_value)) {
663 font_name=XGetAtomName(dpy, name_value);
697 ((align==0)?9:(align-1))%3==
702 if(strcmp(font_name, i1->
font_name)==0) {
768 item->
fBitmap=XCreatePixmap(dpy, DefaultRootWindow(dpy),
772 depth_one_gc=XCreateGC(dpy, item->
fBitmap, 0, 0);
773 XSetBackground(dpy, depth_one_gc, 0);
774 XSetForeground(dpy, depth_one_gc, 1);
777 XPutImage(dpy, item->
fBitmap, depth_one_gc, item->
fXimage, 0, 0, 0, 0,
780 XFreeGC(dpy, depth_one_gc);
797 char *str1, *str2, *str3;
798 const char *str2_a=
"\0", *str2_b=
"\n\0";
800 int byte_w_in, byte_w_out;
802 float sin_angle, cos_angle;
810 int old_cols_in=0, old_rows_in=0;
814 if(!item)
return nullptr;
819 for(i=0; i<(
int)strlen(
text)-1; i++)
825 str2 = (
char *)str2_a;
827 str2 = (
char *)str2_b;
843 XTextExtents(font, str3, strlen(str3), &dir, &asc, &desc,
853 XTextExtents(font, str3, strlen(str3), &dir, &asc, &desc,
863 height=font->ascent+font->descent;
870 canvas=XCreatePixmap(dpy, DefaultRootWindow(dpy),
874 font_gc = XCreateGC(dpy, canvas, 0,
nullptr);
875 XSetBackground(dpy, font_gc, 0);
876 XSetFont(dpy, font_gc, font->fid);
879 XSetForeground(dpy, font_gc, 0);
880 XFillRectangle(dpy, canvas, font_gc, 0, 0,
882 XSetForeground(dpy, font_gc, 1);
926 XTextExtents(font, str3, strlen(str3), &dir, &asc, &desc,
938 XDrawString(dpy, canvas, font_gc, xp, yp, str3, strlen(str3));
974 1, XYPixmap, imageIn, 0, 0);
975 imageIn->format=XYBitmap;
1007 byte_w_in = (item->
fColsIn-1)/8+1;
1008 byte_w_out = (item->
fColsOut-1)/8+1;
1025 (dj-(
float)item->
fRowsIn/(2*cos_angle))/
1028 (dj+(
float)item->
fRowsIn/(2*cos_angle))/
1034 (dj+(
float)item->
fRowsIn/(2*cos_angle))/
1037 (dj-(
float)item->
fRowsIn/(2*cos_angle))/
1048 di=(float)((xl<0)?0:(
int)xl)+0.5-(float)item->
fColsOut/2;
1049 byte_out=(item->
fRowsOut-j-1)*byte_w_out;
1052 for(i=((xl<0)?0:(
int)xl);
1056 it=
int((
float)item->
fColsIn/2 + ( di*cos_angle + dj*sin_angle));
1057 jt=
int((
float)item->
fRowsIn/2 - (-di*sin_angle + dj*cos_angle));
1060 if(it>=0 && it<item->fColsIn && jt>=0 && jt<item->fRowsIn)
1061 if((imageIn->data[jt*byte_w_in+it/8] & 128>>(it%8))>0)
1062 item->
fXimage->data[byte_out+i/8]|=128>>i%8;
1070 XDestroyImage(imageIn);
1082 item->
fBitmap=XCreatePixmap(dpy, DefaultRootWindow(dpy),
1086 XPutImage(dpy, item->
fBitmap, font_gc, item->
fXimage, 0, 0, 0, 0,
1093 XFreeGC(dpy, font_gc);
1094 XFreePixmap(dpy, canvas);
1106 static long int current_size = 0;
1122 sizeof(
XImage) + strlen(item->text) +
1128 item->
fSize+=
sizeof(Font);
1146 DEBUG_PRINT4(
"current cache size=%ld, new item=%ld, limit=%d\n",
1167 DEBUG_PRINT5(
" (`%s'\n FID=%ld\n angle=%f align=%d)\n",
1168 i1->
fText, i1->
fid, i1->angle, i1->align);
1171 current_size-=i1->
fSize;
1185 item->
fNext =
nullptr;
1189 item->
fNext =
nullptr;
1195 current_size+=item->
fSize;
1217 XFreePixmap(dpy, item->
fBitmap);
1235 int cols_in, rows_in;
1236 int cols_out, rows_out;
1238 float z1, z2, z3, z4;
1239 int byte_width_in, byte_width_out;
1243 cols_in=ximage->width;
1244 rows_in=ximage->height;
1251 imageOut =
MakeXImage(dpy, cols_out, rows_out);
1256 byte_width_in=(cols_in-1)/8+1;
1257 byte_width_out=(cols_out-1)/8+1;
1265 for(j2=0; j2<rows_out; j2++) {
1269 for(i2=0; i2<cols_out; i2++) {
1274 if(i==cols_in-1 && j!=rows_in-1) {
1278 z1=(ximage->data[j*byte_width_in+i/8] & 128>>(i%8))>0;
1280 z3=(ximage->data[(j+1)*byte_width_in+i/8] & 128>>(i%8))>0;
1284 else if(i!=cols_in-1 && j==rows_in-1) {
1288 z1=(ximage->data[j*byte_width_in+i/8] & 128>>(i%8))>0;
1289 z2=(ximage->data[j*byte_width_in+(i+1)/8] & 128>>((i+1)%8))>0;
1294 else if(i==cols_in-1 && j==rows_in-1) {
1298 z1=(ximage->data[j*byte_width_in+i/8] & 128>>(i%8))>0;
1308 z1=(ximage->data[j*byte_width_in+i/8] & 128>>(i%8))>0;
1309 z2=(ximage->data[j*byte_width_in+(i+1)/8] & 128>>((i+1)%8))>0;
1310 z3=(ximage->data[(j+1)*byte_width_in+(i+1)/8] &
1312 z4=(ximage->data[(j+1)*byte_width_in+i/8] & 128>>(i%8))>0;
1316 if(((1-t)*(1-u)*z1 + t*(1-u)*z2 + t*u*z3 + (1-t)*u*z4)>0.5)
1317 imageOut->data[j2*byte_width_out+i2/8]|=128>>i2%8;
1325 XDestroyImage(ximage);
1338 char *str1, *str2, *str3;
1339 const char *str2_a=
"\0", *str2_b=
"\n\0";
1341 float sin_angle, cos_angle;
1343 int cols_in, rows_in;
1345 XPoint *xp_in, *xp_out;
1347 XCharStruct overall;
1359 for(i=0; i<(
int)strlen(
text)-1; i++)
1365 str2=(
char *)str2_a;
1367 str2=(
char *)str2_b;
1371 if(!str1)
return nullptr;
1376 XTextExtents(font, str1, strlen(str1), &dir, &asc, &desc,
1379 XTextExtents(font, str3, strlen(str3), &dir, &asc, &desc,
1383 max_width = overall.rbearing;
1390 XTextExtents(font, str3, strlen(str3), &dir, &asc, &desc,
1393 if(overall.rbearing>max_width)
1394 max_width=overall.rbearing;
1401 height=font->ascent+font->descent;
1430 xp_in=(XPoint *)
malloc((
unsigned)(5*
sizeof(XPoint)));
1431 if(!xp_in)
return nullptr;
1433 xp_out = (XPoint *)
malloc((
unsigned)(5*
sizeof(XPoint)));
1448 xp_in[4].x = xp_in[0].x;
1449 xp_in[4].y = xp_in[0].y;
1452 for(i=0; i<5; i++) {
1453 xp_out[i].x=(
short int)((
float)
x + ( ((float)xp_in[i].
x-hot_x)*cos_angle +
1454 ((float)xp_in[i].
y+hot_y)*sin_angle));
1455 xp_out[i].y=(
short int)((
float)
y + (-((float)xp_in[i].
x-hot_x)*sin_angle +
1456 ((float)xp_in[i].
y+hot_y)*cos_angle));
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
char * my_strtok(char *str1, const char *str2)
Routine to replace ‘strtok’ : this one returns a zero length string if it encounters two consecutive ...
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.
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...
char * my_strdup(const char *str)
Routine to mimic ‘strdup()’ (some machines don't have it)
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 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.
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint angle
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void gc
Option_t Option_t TPoint TPoint const char text
Double_t Cos(Double_t)
Returns the cosine of an angle of x radians.
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.
Double_t Tan(Double_t)
Returns the tangent of an angle of x radians.
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
struct RotatedTextItemTemplate_t * fNext