Back to index

plt-scheme  4.2.1
Defines | Functions
xwTabString.c File Reference
#include <stdlib.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include "xwTabString.h"
#include "wxAllocColor.h"

Go to the source code of this file.

Defines

#define WXTAB_BUF_SIZE   64
#define doDraw(dpy, d, gc, x, y, s, len, i, xf, dw, c)   xdoDraw(0, font, dpy, d, gc, x, y, s, len, i)
#define wxXftTextWidth(dpy, font, s, len, xfont)   xdoDraw(1, font, dpy, 0, 0, 0, 0, s, len, 0)

Functions

int scheme_utf8_decode_all (unsigned char *, int, unsigned int *, int)
int scheme_utf8_decode (const unsigned char *s, int start, int end, unsigned int *us, int dstart, int dend, long *ipos, char utf16, int permissive)
static int leading_utf8_len (char *s, int len)
static int xdoDraw (int measure, XFontStruct *font, Display *display, Drawable drawable, GC gc, int x, int y, String string, int length, image)
static void doDrawImageString (Display *display, Drawable drawable, GC gc, int x, int y, String string, int length, int *tabs, XFontStruct *font, wxExtFont xfont, int line, int image, int xon, Region clip, int doamps)
void XfwfDrawImageString (Display *display, Drawable drawable, GC gc, int x, int y, String string, int length, int *tabs, XFontStruct *fnt, wxExtFont xfnt, int xon, Region clip)
void XfwfDrawString (Display *display, Drawable drawable, GC gc, int x, int y, String string, int length, int *tabs, XFontStruct *fnt, wxExtFont xfnt, int xon, int line, Region clip, int doamps)
intXfwfTablist2Tabs (char *tablist)
int XfwfTextWidth (Display *display, XFontStruct *font, wxExtFont xfont, String str, int length, int *tabs)
char * strnchr (char *s, int c, int n)
int wx_enough_colors (Screen *s)

Define Documentation

#define doDraw (   dpy,
  d,
  gc,
  x,
  y,
  s,
  len,
  i,
  xf,
  dw,
 
)    xdoDraw(0, font, dpy, d, gc, x, y, s, len, i)

Definition at line 162 of file xwTabString.c.

#define WXTAB_BUF_SIZE   64
#define wxXftTextWidth (   dpy,
  font,
  s,
  len,
  xfont 
)    xdoDraw(1, font, dpy, 0, 0, 0, 0, s, len, 0)

Definition at line 168 of file xwTabString.c.


Function Documentation

static void doDrawImageString ( Display *  display,
Drawable  drawable,
GC  gc,
int  x,
int  y,
String  string,
int  length,
int tabs,
XFontStruct *  font,
wxExtFont  xfont,
int  line,
int  image,
int  xon,
Region  clip,
int  doamps 
) [static]

Definition at line 179 of file xwTabString.c.

{
  register char      *p, *ep, *ap;
  register int       tx, tab;
#ifdef WX_USE_XFT
  XftColor col;
  XftDraw *draw;
#endif

  if (!length)
    return;

#ifdef WX_USE_XFT
  if (xfont) {
    Visual *visual;
    Colormap cm;

    cm = wx_default_colormap;
    visual = XcmsVisualOfCCC(XcmsCCCOfColormap(display, cm));
    
    draw = XftDrawCreate(display, drawable, visual, cm);
    if (clip)
      XftDrawSetClip(draw, clip);

    if (xon < 0) {
      col.pixel = 0;
      col.color.red = 0xFFFF;
      col.color.green = 0xFFFF;
      col.color.blue = 0xFFFF;
    } else if (xon) {
      col.pixel = 0;
      col.color.red = 0;
      col.color.green = 0;
      col.color.blue = 0;
    } else {
      col.pixel = 0;
      col.color.red = 0xA0A0;
      col.color.green = 0xA0A0;
      col.color.blue = 0xA0A0;
    }
    col.color.alpha = 0xFFFF;
  } else
    draw = NULL;
#endif
  
  tab = tx = 0;
  for (p = string; length; )
    {
      if (tabs)
       ep = strnchr(p, '\t', length);
      else
       ep = NULL;
      if (doamps)
       ap = strnchr(p, '&', length);
      else
       ap = NULL;

      if (ep && ap) {
       if ((long)ep < (long)ap)
         ap = NULL;
       else
         ep = NULL;
      }

      if (ep) {
       doDraw(display, drawable, gc, x+tx, y, p, ep - p, image, xfont, draw, &col);
       tx = tabs[tab++];
       length -= ep - p + 1;
       p = ep + 1;
      } else if (ap) {
       doDraw(display, drawable, gc, x+tx, y, p, ap - p, image, xfont, draw, &col);
       tx += wxXftTextWidth(display, font, p, ap - p, xfont);
       length -= ap - p + 1;
       p = ap + 1;
       if (length) {
         /* Underline next */
         int ww;
         int csize;
         
         csize = leading_utf8_len(p, length);

         ww = wxXftTextWidth(display, font, p, csize, xfont);
         doDraw(display, drawable, gc, x+tx, y, p, csize, image, xfont, draw, &col);
         if (line && (*p != '&')) {
#ifdef WX_USE_XFT    
           if (xfont)
             XftDrawRect(draw,&col, x+tx, y+1, ww, 1);
           else
#endif
             XDrawLine(display, drawable, gc, x+tx, y+1, x+tx+ww, y+1);
         }
         length -= csize;
         tx += ww;
         p += csize;
       }
      } else {
       doDraw(display, drawable, gc, x+tx, y, p, length, image, xfont, draw, &col);
       break;
      }
    }

#ifdef WX_USE_XFT
  if (draw)
    XftDrawDestroy(draw);
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int leading_utf8_len ( char *  s,
int  len 
) [static]

Definition at line 23 of file xwTabString.c.

{
  long ipos;
  scheme_utf8_decode((const unsigned char *)s, 0, len, 
                   NULL, 0, 1,
                   &ipos, 0, '?');
  return ipos;
}

Here is the caller graph for this function:

int scheme_utf8_decode ( const unsigned char *  s,
int  start,
int  end,
unsigned int us,
int  dstart,
int  dend,
long *  ipos,
char  utf16,
int  permissive 
)

Definition at line 4885 of file string.c.

{
  return utf8_decode_x(s, start, end, us, dstart, dend,
                     ipos, NULL, utf16, utf16, NULL, 0, permissive);
}

Here is the call graph for this function:

int scheme_utf8_decode_all ( unsigned char *  ,
int  ,
unsigned int ,
int   
)
char* strnchr ( char *  s,
int  c,
int  n 
)

Definition at line 447 of file xwTabString.c.

{
       while (n--)
              if (*s == c) return s; else ++s;
       return NULL;
}

Here is the caller graph for this function:

int wx_enough_colors ( Screen *  s)

Definition at line 457 of file xwTabString.c.

{
  if (wx_visual_depth > 8)
    return 1;
  else
    return 0;
}

Here is the caller graph for this function:

static int xdoDraw ( int  measure,
XFontStruct *  font,
Display *  display,
Drawable  drawable,
GC  gc,
int  x,
int  y,
String  string,
int  length,
image   
) [static]

Definition at line 32 of file xwTabString.c.

{
# define WXTAB_BUF_SIZE 64
  unsigned int *us, usbuf[WXTAB_BUF_SIZE];
  long ulen;
  int width = 0;

  ulen = scheme_utf8_decode_all((unsigned char *)string, length, NULL, '?');
  if (ulen <= WXTAB_BUF_SIZE)
    us = usbuf;
  else
    us = (unsigned int *)XtMalloc(ulen * sizeof(unsigned int));
  ulen = scheme_utf8_decode_all((unsigned char *)string, length, us, '?');

#ifdef WX_USE_XFT
  if (!xfont)
#endif
    {
      /* Squash 32-bit encoding into 16-bit encoding.
        Since we overwrite the array, it's important
        to start at position 0 and go up: */
      int i, v;
      for (i = 0; i < ulen; i++) {
       if (us[i] > 0xFFFF)
         v = '?';
       else
         v = us[i];
       ((XChar2b *)us)[i].byte2 = v & 0xff;
       ((XChar2b *)us)[i].byte1 = v >> 8;
      }
    }

  if (measure
#ifdef WX_USE_XFT
      || xfont
#endif
      ) {
#ifdef WX_USE_XFT
    if (xfont) {
      XGlyphInfo overall;
      int i, start = 0;
      
      width = 0;
      while (1) {
       for (i = start; i < ulen; i++) {
         if (!XftGlyphExists(display, xfont, us[i]))
           break;
       }

       if (i > start) {
         XftTextExtents32(display, xfont, us + start, i - start, &overall);
         if (!measure) {
           if (gc) {
             XFillRectangle(display, drawable, gc, x + width, y - xfont->ascent,
                          overall.xOff, xfont->ascent + xfont->descent);
           }
           XftDrawString32(draw, col, xfont, x + width, y, us + start, i - start);
         }
         width += overall.xOff;
       }

       start = i;
       if (start < ulen) {
         /* Substitute */
         wxExtFont sxfont;
         sxfont = wxFindAAFont(display, xfont, us[start]);
         XftTextExtents32(display, sxfont, us + start, 1, &overall);

         if (!measure) {
           if (gc) {
             XFillRectangle(display, drawable, gc, x + width, y - sxfont->ascent,
                          overall.xOff, sxfont->ascent + sxfont->descent);
           }
           XftDrawString32(draw, col, sxfont, x + width, y, us + start, 1);
         }

         width += overall.xOff;
         start++;
       } else
         break;
      }
    } else
#endif
      {
       width = XTextWidth16(font, (XChar2b *)us, ulen);
      }
  }

  if (!measure) {
#ifdef WX_USE_XFT
    if (xfont) {
      /* Done above */
    } else 
#endif
      {
       if (image)
         XDrawImageString16(display, drawable, gc, x, y, (XChar2b*)us, ulen);
       else
         XDrawString16(display, drawable, gc, x, y, (XChar2b*)us, ulen);
      }
  }

  if (us != usbuf)
    XtFree((char *)us);

  return width;
}

Here is the call graph for this function:

void XfwfDrawImageString ( Display *  display,
Drawable  drawable,
GC  gc,
int  x,
int  y,
String  string,
int  length,
int tabs,
XFontStruct *  fnt,
wxExtFont  xfnt,
int  xon,
Region  clip 
)

Definition at line 302 of file xwTabString.c.

{
  doDrawImageString(display, drawable, gc, x, y, string, length, tabs, fnt, xfnt, 1, 1, xon, clip, 1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void XfwfDrawString ( Display *  display,
Drawable  drawable,
GC  gc,
int  x,
int  y,
String  string,
int  length,
int tabs,
XFontStruct *  fnt,
wxExtFont  xfnt,
int  xon,
int  line,
Region  clip,
int  doamps 
)

Definition at line 320 of file xwTabString.c.

{
  doDrawImageString(display, drawable, gc, x, y, string, length, tabs, fnt, xfnt, line, 0, xon, clip, doamps);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int* XfwfTablist2Tabs ( char *  tablist)

Definition at line 343 of file xwTabString.c.

{
       register int  *tabs = NULL;
       register int  ntabs = 0;

       if (!tablist)
              return NULL;
       for (;;)
       {
              /* Skip leading blanks */
              while (*tablist && *tablist == ' ') ++tablist;
              if (!*tablist) break;

              /* Allocate space for the new tab */
              if (ntabs)
                     tabs = (int *) XtRealloc( (char *) tabs,
                                          (ntabs+1) * sizeof(int));
              else
                     tabs = (int *) XtMalloc( (ntabs + 1) * sizeof(int));
              /* Add it to the list */
              tabs[ntabs++] = atoi(tablist);
              /* Skip to the next blank */
              while (*tablist && *tablist != ' ') ++tablist;
       }
       return (tabs);
}

Here is the caller graph for this function:

int XfwfTextWidth ( Display *  display,
XFontStruct *  font,
wxExtFont  xfont,
String  str,
int  length,
int tabs 
)

Definition at line 379 of file xwTabString.c.

{
  register char      *p, *ep, *c = NULL, *pp;
  register int       tx, tab, rc, ll;

  if (!length)
    return 0;
 
  p = pp = str;
  ll = length;

  while (1) {
    ep = strnchr(pp, '&', ll);
    if (ep) {
      int l = ep - p;
      if (!c)
       c = XtMalloc(length + 1);
      memmove(c, p, l);
      memmove(c + l, p + l + 1, length - l); /* gets nul char */
      length -= 1;
      p = c;
      if (length > l) {
       pp = c + l + 1; /* Skip next char */
       ll = length - (l + 1);
      } else {
       pp = p;
       ll = length;
      }
    } else
      break;
  }

  tab = tx = 0;
  if (length == 0) {
    if (c)
      XtFree(c);
    return 0;
  }
  for (; length; ) {
    ep = strnchr(p, '\t', length);
    if (ep && tabs) {
      tx = tabs[tab++];
      length -= ep - p + 1;
      p = ep + 1;
    } else {
      rc = wxXftTextWidth(display, font, p, length, xfont);
      if (c)
       XtFree(c);
      if (rc < 0) return rc; else return rc + tx;
    }
  }

  if (c)
    XtFree(c);

  return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function: