<commit_before>// @(#)root/x11:$Id$
// Author: O.Couet   17/11/93

#ifndef _XVERTEXT_INCLUDED_
#define _XVERTEXT_INCLUDED_

//______________________________________________________________________________
/* ********************************************************************** *
 *
 * xvertext 5.0, Copyright (c) 1993 <NAME> (<EMAIL>)
 *
 * Alignment definition modified by O.Couet.
 * Mods IBM/VM by O.Couet.
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose and without fee is hereby granted, provided
 * that the above copyright notice appear in all copies and that both the
 * copyright notice and this permission notice appear in supporting
 * documentation.  All work developed as a consequence of the use of
 * this program should duly acknowledge such use. No representations are
 * made about the suitability of this software for any purpose.  It is
 * provided "as is" without express or implied warranty.
 *
 * ********************************************************************** */

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "TMath.h"

/* ************************************************************************ *
 *
 * Header file for the `xvertext 5.0' routines.
 *
 * Copyright (c) 1993 <NAME> (<EMAIL>)
 *
 * ************************************************************************ */

#define XV_VERSION      5.0
#define XV_COPYRIGHT \
      "xvertext routines Copyright (c) 1993 <NAME>"

/* ---------------------------------------------------------------------- */

/* text alignment */

#define NONE             0
#define TLEFT            1
#define TCENTRE          2
#define TRIGHT           3
#define MLEFT            4
#define MCENTRE          5
#define MRIGHT           6
#define BLEFT            7
#define BCENTRE          8
#define BRIGHT           9

#ifdef VAX
#define X11R3
#endif


#endif /* _XVERTEXT_INCLUDED_ */

/* ---------------------------------------------------------------------- */

/* Make sure cache size is set */

#ifndef CACHE_SIZE_LIMIT
#define CACHE_SIZE_LIMIT 0
#endif /*CACHE_SIZE_LIMIT */

/* Make sure a cache method is specified */

#ifndef CACHE_XIMAGES
#ifndef CACHE_BITMAPS
#define CACHE_BITMAPS
#endif /*CACHE_BITMAPS*/
#endif /*CACHE_XIMAGES*/

/* ---------------------------------------------------------------------- */

/* Debugging macros */

#ifdef DEBUG
static int gRotatedDebug=1;
#else
static int gRotatedDebug=0;
#endif /*DEBUG*/

#define DEBUG_PRINT1(a) if (gRotatedDebug) printf (a)
#define DEBUG_PRINT2(a, b) if (gRotatedDebug) printf (a, b)
#define DEBUG_PRINT3(a, b, c) if (gRotatedDebug) printf (a, b, c)
#define DEBUG_PRINT4(a, b, c, d) if (gRotatedDebug) printf (a, b, c, d)
#define DEBUG_PRINT5(a, b, c, d, e) if (gRotatedDebug) printf (a, b, c, d, e)

/* ---------------------------------------------------------------------- */

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

/* ---------------------------------------------------------------------- */

/* A structure holding everything needed for a rotated string */

typedef struct RotatedTextItemTemplate_t {
   Pixmap fBitmap;
   XImage *fXimage;

   char *fText;
   char *font_name;
   Font fid;
   float fAngle;
   int fAlign;
   float fMagnify;

   int fColsIn;
   int fRowsIn;
   int fColsOut;
   int fRowsOut;

   int fNl;
   int fMaxWidth;
   float *fCornersX;
   float *fCornersY;

   long int fSize;
   int fCached;

   struct RotatedTextItemTemplate_t *fNext;
} RotatedTextItem_t;

static RotatedTextItem_t *gFirstTextItem=0;

/* ---------------------------------------------------------------------- */

/* A structure holding current magnification and bounding box padding */

static struct StyleTemplate_t {
   float fMagnify;
   int fBbxPadl;
} gRotStyle={
   1.,
   0
   };

/* ---------------------------------------------------------------------- */
static char              *my_strdup(char *);
static char              *my_strtok(char *, char *);

float                     XRotVersion(char*, int);
void                      XRotSetMagnification(float);
void                      XRotSetBoundingBoxPad(int);
int                       XRotDrawString(Display*, XFontStruct*, float,Drawable, GC, int, int, char*);
int                       XRotDrawImageString(Display*, XFontStruct*, float,Drawable, GC, int, int, char*);
int                       XRotDrawAlignedString(Display*, XFontStruct*, float,Drawable, GC, int, int, char*, int);
int                       XRotDrawAlignedImageString(Display*, XFontStruct*, float,Drawable, GC, int, int, char*, int);
XPoint                   *XRotTextExtents(Display*, XFontStruct*, float,int, int, char*, int);

static XImage            *MakeXImage(Display *dpy,int  w, int h);
static int                XRotPaintAlignedString(Display *dpy, XFontStruct *font, float angle, Drawable drawable, GC gc, int x,int y, char *text,int align, int bg);
static int                XRotDrawHorizontalString(Display *dpy, XFontStruct *font, Drawable drawable, GC gc, int x, int y, char *text,int align, int bg);
static RotatedTextItem_t *XRotRetrieveFromCache(Display *dpy, XFontStruct *font, float angle, char *text, int align);
static RotatedTextItem_t *XRotCreateTextItem(Display *dpy, XFontStruct *font, float angle, char *text, int align);
static void               XRotAddToLinkedList(Display *dpy, RotatedTextItem_t *item);
static void               XRotFreeTextItem(Display *dpy, RotatedTextItem_t *item);
static XImage            *XRotMagnifyImage(Display *dpy, XImage *ximage);


//______________________________________________________________________________
static char *my_strdup(char *str)
{
   // Routine to mimic `strdup()' (some machines don't have it)

   char *s;

   if(str==0) return 0;

   s=(char *)malloc((unsigned)(strlen(str)+1));
   if(s!=0) strcpy(s, str);

   return s;
}

//______________________________________________________________________________
static char *my_strtok(char *str1, char *str2)
{
   // Routine to replace `strtok' : this one returns a zero length string if
   // it encounters two consecutive delimiters

   char *ret;
   int i, j, stop;
   static int start, len;
   static char *stext;

   if(str2==0) return 0;

   /* initialise if str1 not 0 */
   if(str1!=0) {
      start=0;
      stext=str1;
      len=strlen(str1);
   }

   /* run out of tokens ? */
   if(start>=len) return 0;

   /* loop through characters */
   for(i=start; i<len; i++) {
      /* loop through delimiters */
      stop=0;
      for(j=0; j<(int)strlen(str2); j++)
      if(stext[i]==str2[j])
      stop=1;

      if(stop) break;
   }

   stext[i]='\0';

   ret=stext+start;

   start=i+1;

   return ret;
}


//______________________________________________________________________________
float XRotVersion(char *str,int n)
{
   // Return version/copyright information

   if(str!=0) strncpy(str, XV_COPYRIGHT, n);
   return XV_VERSION;
}


//______________________________________________________________________________
void XRotSetMagnification(float m)
{
   // Set the font magnification factor for all subsequent operations

   if(m>0.) gRotStyle.fMagnify=m;
}


//______________________________________________________________________________
void XRotSetBoundingBoxPad(int p)
{
   // Set the padding used when calculating bounding boxes

   if(p>=0) gRotStyle.fBbxPadl=p;
}


//______________________________________________________________________________
static XImage *MakeXImage(Display *dpy,int  w, int h)
{
   // Create an XImage structure and allocate memory for it

   XImage *image;
   char *data;

   /* reserve memory for image */
   data=(char *)calloc((unsigned)(((w-1)/8+1)*h), 1);
   if( data==0) return 0;

   /* create the XImage */
   image=XCreateImage(dpy, DefaultVisual(dpy, DefaultScreen(dpy)), 1, XYBitmap,
                   0, data, w, h, 8, 0);
   if (image==0) {
      free(data);
      return 0;
   }

   image->byte_order=image->bitmap_bit_order=MSBFirst;
   free(data);
   return image;<commit_msg>http://root.cern.ch/viewvc?view=rev&revision=41296 made a problem in cas of rotated text.<commit_after>// @(#)root/x11:$Id$
// Author: O.Couet   17/11/93

#ifndef _XVERTEXT_INCLUDED_
#define _XVERTEXT_INCLUDED_

//______________________________________________________________________________
/* ********************************************************************** *
 *
 * xvertext 5.0, Copyright (c) 1993 <NAME> (<EMAIL>)
 *
 * Alignment definition modified by O.Couet.
 * Mods IBM/VM by O.Couet.
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose and without fee is hereby granted, provided
 * that the above copyright notice appear in all copies and that both the
 * copyright notice and this permission notice appear in supporting
 * documentation.  All work developed as a consequence of the use of
 * this program should duly acknowledge such use. No representations are
 * made about the suitability of this software for any purpose.  It is
 * provided "as is" without express or implied warranty.
 *
 * ********************************************************************** */

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "TMath.h"

/* ************************************************************************ *
 *
 * Header file for the `xvertext 5.0' routines.
 *
 * Copyright (c) 1993 <NAME> (<EMAIL>)
 *
 * ************************************************************************ */

#define XV_VERSION      5.0
#define XV_COPYRIGHT \
      "xvertext routines Copyright (c) 1993 <NAME>"

/* ---------------------------------------------------------------------- */

/* text alignment */

#define NONE             0
#define TLEFT            1
#define TCENTRE          2
#define TRIGHT           3
#define MLEFT            4
#define MCENTRE          5
#define MRIGHT           6
#define BLEFT            7
#define BCENTRE          8
#define BRIGHT           9

#ifdef VAX
#define X11R3
#endif


#endif /* _XVERTEXT_INCLUDED_ */

/* ---------------------------------------------------------------------- */

/* Make sure cache size is set */

#ifndef CACHE_SIZE_LIMIT
#define CACHE_SIZE_LIMIT 0
#endif /*CACHE_SIZE_LIMIT */

/* Make sure a cache method is specified */

#ifndef CACHE_XIMAGES
#ifndef CACHE_BITMAPS
#define CACHE_BITMAPS
#endif /*CACHE_BITMAPS*/
#endif /*CACHE_XIMAGES*/

/* ---------------------------------------------------------------------- */

/* Debugging macros */

#ifdef DEBUG
static int gRotatedDebug=1;
#else
static int gRotatedDebug=0;
#endif /*DEBUG*/

#define DEBUG_PRINT1(a) if (gRotatedDebug) printf (a)
#define DEBUG_PRINT2(a, b) if (gRotatedDebug) printf (a, b)
#define DEBUG_PRINT3(a, b, c) if (gRotatedDebug) printf (a, b, c)
#define DEBUG_PRINT4(a, b, c, d) if (gRotatedDebug) printf (a, b, c, d)
#define DEBUG_PRINT5(a, b, c, d, e) if (gRotatedDebug) printf (a, b, c, d, e)

/* ---------------------------------------------------------------------- */

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

/* ---------------------------------------------------------------------- */

/* A structure holding everything needed for a rotated string */

typedef struct RotatedTextItemTemplate_t {
   Pixmap fBitmap;
   XImage *fXimage;

   char *fText;
   char *font_name;
   Font fid;
   float fAngle;
   int fAlign;
   float fMagnify;

   int fColsIn;
   int fRowsIn;
   int fColsOut;
   int fRowsOut;

   int fNl;
   int fMaxWidth;
   float *fCornersX;
   float *fCornersY;

   long int fSize;
   int fCached;

   struct RotatedTextItemTemplate_t *fNext;
} RotatedTextItem_t;

static RotatedTextItem_t *gFirstTextItem=0;

/* ---------------------------------------------------------------------- */

/* A structure holding current magnification and bounding box padding */

static struct StyleTemplate_t {
   float fMagnify;
   int fBbxPadl;
} gRotStyle={
   1.,
   0
   };

/* ---------------------------------------------------------------------- */
static char              *my_strdup(char *);
static char              *my_strtok(char *, char *);

float                     XRotVersion(char*, int);
void                      XRotSetMagnification(float);
void                      XRotSetBoundingBoxPad(int);
int                       XRotDrawString(Display*, XFontStruct*, float,Drawable, GC, int, int, char*);
int                       XRotDrawImageString(Display*, XFontStruct*, float,Drawable, GC, int, int, char*);
int                       XRotDrawAlignedString(Display*, XFontStruct*, float,Drawable, GC, int, int, char*, int);
int                       XRotDrawAlignedImageString(Display*, XFontStruct*, float,Drawable, GC, int, int, char*, int);
XPoint                   *XRotTextExtents(Display*, XFontStruct*, float,int, int, char*, int);

static XImage            *MakeXImage(Display *dpy,int  w, int h);
static int                XRotPaintAlignedString(Display *dpy, XFontStruct *font, float angle, Drawable drawable, GC gc, int x,int y, char *text,int align, int bg);
static int                XRotDrawHorizontalString(Display *dpy, XFontStruct *font, Drawable drawable, GC gc, int x, int y, char *text,int align, int bg);
static RotatedTextItem_t *XRotRetrieveFromCache(Display *dpy, XFontStruct *font, float angle, char *text, int align);
static RotatedTextItem_t *XRotCreateTextItem(Display *dpy, XFontStruct *font, float angle, char *text, int align);
static void               XRotAddToLinkedList(Display *dpy, RotatedTextItem_t *item);
static void               XRotFreeTextItem(Display *dpy, RotatedTextItem_t *item);
static XImage            *XRotMagnifyImage(Display *dpy, XImage *ximage);


//______________________________________________________________________________
static char *my_strdup(char *str)
{
   // Routine to mimic `strdup()' (some machines don't have it)

   char *s;

   if(str==0) return 0;

   s=(char *)malloc((unsigned)(strlen(str)+1));
   if(s!=0) strcpy(s, str);

   return s;
}

//______________________________________________________________________________
static char *my_strtok(char *str1, char *str2)
{
   // Routine to replace `strtok' : this one returns a zero length string if
   // it encounters two consecutive delimiters

   char *ret;
   int i, j, stop;
   static int start, len;
   static char *stext;

   if(str2==0) return 0;

   /* initialise if str1 not 0 */
   if(str1!=0) {
      start=0;
      stext=str1;
      len=strlen(str1);
   }

   /* run out of tokens ? */
   if(start>=len) return 0;

   /* loop through characters */
   for(i=start; i<len; i++) {
      /* loop through delimiters */
      stop=0;
      for(j=0; j<(int)strlen(str2); j++)
      if(stext[i]==str2[j])
      stop=1;

      if(stop) break;
   }

   stext[i]='\0';

   ret=stext+start;

   start=i+1;

   return ret;
}


//______________________________________________________________________________
float XRotVersion(char *str,int n)
{
   // Return version/copyright information

   if(str!=0) strncpy(str, XV_COPYRIGHT, n);
   return XV_VERSION;
}


//______________________________________________________________________________
void XRotSetMagnification(float m)
{
   // Set the font magnification factor for all subsequent operations

   if(m>0.) gRotStyle.fMagnify=m;
}


//______________________________________________________________________________
void XRotSetBoundingBoxPad(int p)
{
   // Set the padding used when calculating bounding boxes

   if(p>=0) gRotStyle.fBbxPadl=p;
}


//______________________________________________________________________________
static XImage *MakeXImage(Display *dpy,int  w, int h)
{
   // Create an XImage structure and allocate memory for it

   XImage *image;
   char *data;

   /* reserve memory for image */
   data=(char *)calloc((unsigned)(((w-1)/8+1)*h), 1);
   if( data==0) return 0;

   /* create the XImage */
   image=XCreateImage(dpy, DefaultVisual(dpy, DefaultScreen(dpy)), 1, XYBitmap,
                   0, data, w, h, 8, 0);
   if (image==0) {
      free(data);
      return 0;
   }

   image->byte_order=image->bitmap_bit_order=MSBFirst;
   return image;
{'fraction_non_alphanumeric': 0.1944324955447674, 'fraction_numerical': 0.014564001720641553, 'mean_word_length': 2.671103090457929, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6928917', 'n_tokens_mistral': 4943, 'n_tokens_neox': 4674, 'n_words': 1404}