Back to index

plt-scheme  4.2.1
Defines | Functions | Variables
WindowDC.cc File Reference
#include "wx.h"
#include "../../../wxcommon/wxGLConfig.h"
#include <X11/Intrinsic.h>
#include "../wx_cairo.h"
#include "wx_rgn.h"
#include <math.h>
#include <string.h>
#include "XWidgets/wxAllocColor.h"
#include "XWidgets/xwTabString.h"
#include "wx_visual.h"
#include <DeviceContexts/bdiag.xbm>
#include <DeviceContexts/fdiag.xbm>
#include <DeviceContexts/cdiag.xbm>
#include <DeviceContexts/horiz.xbm>
#include <DeviceContexts/verti.xbm>
#include <DeviceContexts/cross.xbm>
#include "../../../wxcommon/wxGLConfig.cxx"

Go to the source code of this file.

Defines

#define Uses_XLib
#define Uses_wxWindowDC
#define Uses_wxMemoryDC
#define Uses_wxList
#define UseXtRegions
#define RAD2DEG   57.2957795131
#define SHIFT   (8*(sizeof(short int)-sizeof(char)))
#define num_hatches   6
#define WX_GC_CF   0
#define IS_COLOR   (DEPTH > 1)
#define GETCOLORMAP(x)   wx_default_colormap
#define wxMINI_SIZE   8
#define wxPI   3.141592653589793
#define WX_RENDER_CAN_SCALE   0
#define WX_CVT_BUF_SIZE   1024
#define WX_XFT_ONLY(x)   1
#define MAX_TEXT_LENGTH_FOR_MEASURE   100
#define NUM_GETPIX_CACHE_COLORS   256

Functions

static wxBitmapScaleBitmap (wxBitmap *src, int tw, int th, double xsrc, double ysrc, double w, double h, Display *dpy, wxBitmap **_tmp, int *retval, int forceMono, unsigned long whiteVal)
static wxBitmapIntersectBitmapRegion (GC agc, Region user_reg, Region expose_reg, wxBitmap *bmask, Region *_free_rgn, int *_tx, int *_ty, int *_scaled_width, int *_scaled_height, double *_xsrc, double *_ysrc, Display *dpy, unsigned long whiteVal)
void doDrawBitmapLabel (Display *dpy, Pixmap pixmap, Pixmap maskmap, Drawable drawable, GC agc, int x, int y, int width, int height, int depth, int mask_depth, Region reg, GC gray_gc, Pixel bg_pixel)
void wxDrawBitmapLabel (Display *dpy, Pixmap pixmap, Pixmap maskmap, Drawable drawable, GC agc, int x, int y, int width, int height, int depth, int mask_depth, Region reg, GC gray_gc, Pixel bg)
int scheme_utf8_decode (const unsigned char *s, int start, int len, unsigned int *us, int dstart, int dlen, long *ipos, char utf16, int permissive)
int scheme_utf8_decode_all (const unsigned char *s, int len, unsigned int *us, int permissive)
static unsigned intconvert_to_drawable_format (const char *s, int ds, long *_ulen, unsigned int *buf, int bufsize, int isUnicode, int non_xft)
void wxGetTextExtent (Display *dpy, double scale_x, double scale_y, const char *orig_s, double *_w, double *_h, double *_descent, double *_topspace, wxFont *font_to_use, Bool combine, Bool isUnicode, int dt, int len)

Variables

int wx_alloc_color_is_fast
int wx_simple_r_start
int wx_simple_g_start
int wx_simple_b_start
static int join_style [] = { JoinBevel, JoinMiter, JoinRound }
static int cap_style [] = { CapRound, CapProjecting, CapButt, CapNotLast }
static int fill_rule [] = { EvenOddRule, WindingRule }
static Pixmap * hatch_bitmaps = NULL
static wxDash dashdefs [4][4]
static int num_dashes [] = { 2, 2, 2, 4 }
static unsigned int cvt_buf [WX_CVT_BUF_SIZE]
static Region empty_rgn

Define Documentation

#define GETCOLORMAP (   x)    wx_default_colormap

Definition at line 108 of file WindowDC.cc.

#define IS_COLOR   (DEPTH > 1)

Definition at line 103 of file WindowDC.cc.

#define MAX_TEXT_LENGTH_FOR_MEASURE   100

Definition at line 2231 of file WindowDC.cc.

#define NUM_GETPIX_CACHE_COLORS   256
#define num_hatches   6

Definition at line 93 of file WindowDC.cc.

#define RAD2DEG   57.2957795131

Definition at line 70 of file WindowDC.cc.

#define SHIFT   (8*(sizeof(short int)-sizeof(char)))

Definition at line 74 of file WindowDC.cc.

#define Uses_wxList

Definition at line 35 of file WindowDC.cc.

#define Uses_wxMemoryDC

Definition at line 34 of file WindowDC.cc.

#define Uses_wxWindowDC

Definition at line 33 of file WindowDC.cc.

#define Uses_XLib

Definition at line 32 of file WindowDC.cc.

#define UseXtRegions

Definition at line 55 of file WindowDC.cc.

#define WX_CVT_BUF_SIZE   1024

Definition at line 2221 of file WindowDC.cc.

#define WX_GC_CF   0

Definition at line 100 of file WindowDC.cc.

#define WX_RENDER_CAN_SCALE   0

Definition at line 569 of file WindowDC.cc.

#define WX_XFT_ONLY (   x)    1

Definition at line 2225 of file WindowDC.cc.

#define wxMINI_SIZE   8

Definition at line 110 of file WindowDC.cc.

#define wxPI   3.141592653589793

Definition at line 112 of file WindowDC.cc.


Function Documentation

static unsigned int* convert_to_drawable_format ( const char *  s,
int  ds,
long *  _ulen,
unsigned int buf,
int  bufsize,
int  isUnicode,
int  non_xft 
) [static]

Definition at line 2153 of file WindowDC.cc.

{
  unsigned int *us;
  long ulen = *_ulen;

  if (isUnicode) {
    us = (unsigned int *)s;
    if (ulen < 0) {
      for (ulen = ds; us[ulen]; ulen++) {
      }
      ulen -= ds;
    }
    if (ds) {
      if (ulen <= bufsize)
       us = buf;
      else
       us = new WXGC_ATOMIC unsigned[ulen];
      memcpy(us, s + (ds * sizeof(int)), ulen * sizeof(unsigned int));
    }
  } else {
    int length;

    if (ulen < 0)
      length = strlen(s XFORM_OK_PLUS ds);
    else
      length = ulen;
    
    ulen = scheme_utf8_decode((const unsigned char *)s, ds, ds + length, NULL, 0, -1, NULL, 0, '?');
    if (ulen <= bufsize)
      us = buf;
    else
      us = new WXGC_ATOMIC unsigned[ulen];
    ulen = scheme_utf8_decode((const unsigned char *)s, ds, ds + length, us, 0, -1, NULL, 0, '?');
  }

  if (non_xft) {
    /* 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;
    XChar2b *dest;
    
    if (isUnicode) {
      if (2 * ulen <= bufsize)
       dest = (XChar2b *)buf;
      else
       dest = new WXGC_ATOMIC XChar2b[ulen];
    } else
      dest = (XChar2b *)us;

    for (i = 0; i < ulen; i++) {
      if (us[i] > 0xFFFF)
       v = '?';
      else
       v = us[i];
      dest[i].byte2 = v & 0xff;
      dest[i].byte1 = v >> 8;
    }

    us = (unsigned int *)dest;
  }

  *_ulen = ulen;
  
  return us;
}

Here is the caller graph for this function:

void doDrawBitmapLabel ( Display *  dpy,
Pixmap  pixmap,
Pixmap  maskmap,
Drawable  drawable,
GC  agc,
int  x,
int  y,
int  width,
int  height,
int  depth,
int  mask_depth,
Region  reg,
GC  gray_gc,
Pixel  bg_pixel 
)

Definition at line 1027 of file WindowDC.cc.

{
#ifdef WX_USE_XRENDER
  if (maskmap && (mask_depth > 1)) {
    Picture dest, src, mask;

    dest = (Picture)wxMakeXrenderPicture(drawable, 1);
    src = (Picture)wxMakeXrenderPicture(pixmap, (depth > 1));
    mask = XRenderCreatePicture(wxAPP_DISPLAY,
                            maskmap,
                            alpha_format,
                            0,
                            NULL);

    XRenderSetPictureClipRegion(wxAPP_DISPLAY, dest, reg);

    XRenderComposite(wxAPP_DISPLAY,
                   PictOpOver,
                   src,
                   mask,
                   dest,
                   0, 0,
                   0, 0,
                   x, y, width, height);

    if (gray_gc) {
      XRenderColor col;

      SetToGray(&col, bg_pixel);

      XRenderFillRectangle(wxAPP_DISPLAY, PictOpOver, dest, &col,
                        x, y, width, height);
    }

    XRenderFreePicture(dpy, dest);
    XRenderFreePicture(wxAPP_DISPLAY, src);
    XRenderFreePicture(wxAPP_DISPLAY, mask);
    return;
  }
#endif
   
  if (maskmap && (mask_depth == 1)) {
    XSetClipMask(dpy, agc, maskmap);
    XSetClipOrigin(dpy, agc, x, y);
  }
  
  if (depth == 1) {
    XCopyPlane(dpy, pixmap, drawable, agc,
              0, 0, width, height, x, y, 1);
  } else {
    XCopyArea(dpy, pixmap, drawable, agc,
             0, 0, width, height, x, y);
  }
  
  if (maskmap && (mask_depth == 1)) {
    XSetClipMask(dpy, agc, None);
    XSetClipOrigin(dpy, agc, 0, 0);
  }

  if (gray_gc) {
#ifdef WX_USE_XRENDER
    if (wxXRenderHere()) {
      Picture dest;
      XRenderColor col;
      
      dest = (Picture)wxMakeXrenderPicture(drawable, 1);
      XRenderSetPictureClipRegion(wxAPP_DISPLAY, dest, reg);

      SetToGray(&col, bg_pixel);
      
      XRenderFillRectangle(wxAPP_DISPLAY, PictOpOver, dest, &col,
                        x, y, width, height);
      
      XRenderFreePicture(dpy, dest);
      return;
    }
#endif
    XSetRegion(dpy, gray_gc, reg);
    XFillRectangle(dpy, drawable, gray_gc, x, y, width, height);
    XSetClipMask(dpy, gray_gc, None);
  }
}

Here is the caller graph for this function:

static wxBitmap* IntersectBitmapRegion ( GC  agc,
Region  user_reg,
Region  expose_reg,
wxBitmap bmask,
Region *  _free_rgn,
int _tx,
int _ty,
int _scaled_width,
int _scaled_height,
double *  _xsrc,
double *  _ysrc,
Display *  dpy,
unsigned long  whiteVal 
) [static]

Definition at line 306 of file WindowDC.cc.

{
  int overlap;
  Region free_rgn = *_free_rgn, rgn = NULL;
  int tx = *_tx, ty = *_ty;
  int scaled_width = *_scaled_width, scaled_height = *_scaled_height;
  double xsrc = *_xsrc, ysrc = *_ysrc;

  if (user_reg || expose_reg) {
    if (user_reg && expose_reg) {
      rgn = XCreateRegion();
      free_rgn = rgn;
      XIntersectRegion(expose_reg, user_reg, rgn);
    } else if (user_reg)
      rgn = user_reg;
    else
      rgn = expose_reg;

    if (bmask) {
      overlap = XRectInRegion(rgn, tx, ty, scaled_width, scaled_height);

      if (overlap == RectangleIn) {
       /* Overwriting the region later will be fine. */
       rgn = NULL;
      } else if (overlap == RectangleOut) {
       /* Mask will have no effect - all drawing is masked anyway */
       bmask = NULL;
      } else {
       /* This is the difficult case: mask bitmap and region combine. */
       XRectangle encl;
       long tx2, ty2, sw2, sh2;

       /* Common case: rgn is a sub-rectangle of the target: */
       XClipBox(rgn, &encl);
       tx2 = max(encl.x, tx);
       ty2 = max(encl.y, ty);
       sw2 = min(encl.x + encl.width, tx + scaled_width) - tx2;
       sh2 = min(encl.y + encl.height, ty + scaled_height) - ty2;
       
       if (XRectInRegion(rgn, tx2, ty2, sw2, sh2) == RectangleIn) {
         xsrc += (tx2 - tx);
         ysrc += (ty2 - ty);
         tx = tx2;
         ty = ty2;
         scaled_width = sw2;
         scaled_height = sh2;
         /* clipping is essentially manual, now: */
         rgn = NULL;
       } else {
         /* This is as complex as it gets. */
         /* We create a new region with the pixels of the bitmap. */
         Pixmap bpm;
         XImage *simg;
         Region bmrgn;
         int mi, mj;
         
         bpm = GETPIXMAP(bmask);
         simg = XGetImage(dpy, bpm, (long)xsrc, (long)ysrc, scaled_width, scaled_height, AllPlanes, ZPixmap);
         
         bmrgn = XCreateRegion();

         if (bmask->GetDepth() == 1)
           whiteVal = 0;
         
         for (mj = 0; mj < scaled_height; mj++) {
           encl.y = mj + ty;
           encl.height = 1;
           encl.width = 0;
           for (mi = 0; mi < scaled_width; mi++) {
             if (XGetPixel(simg, mi + (long)xsrc, mj + (long)ysrc) == whiteVal) {
              if (encl.width) {
                XUnionRectWithRegion(&encl, bmrgn, bmrgn);
                encl.width = 0;
              }
             } else {
              if (!encl.width)
                encl.x = mi + tx;
              encl.width++;
             }
           }

           if (encl.width)
             XUnionRectWithRegion(&encl, bmrgn, bmrgn);
         }
         
         if (!free_rgn) {
           free_rgn = XCreateRegion();
           XUnionRegion(free_rgn, rgn, free_rgn);
           rgn = free_rgn;
         }

         /* Insert the bitmap-based region with the old one: */
         XIntersectRegion(bmrgn, rgn, rgn);
         XDestroyRegion(bmrgn);

         XDestroyImage(simg);

         bmask = NULL; /* done via rgn */
       }
      }
    }
  }

  if (rgn)
    XSetRegion(dpy, agc, rgn);

  if (bmask) {
    Pixmap mpm;
    int monoized = 0;

    if (bmask->GetDepth() != 1) {
      int ok;
      wxBitmap *tmp;
      monoized = 1;
      bmask = ScaleBitmap(bmask, bmask->GetWidth(), bmask->GetHeight(), 
                       0, 0, 
                       bmask->GetWidth(), bmask->GetHeight(),
                       dpy, &tmp, &ok,
                       1, whiteVal);
      mpm = GETPIXMAP(bmask);
      bmask = tmp;
    } else
      mpm = GETPIXMAP(bmask);

    XSetClipMask(dpy, agc, mpm);
    XSetClipOrigin(dpy, agc, tx - (long)xsrc, ty - (long)ysrc);

    if (!monoized)
      bmask = NULL; /* => no special mask to free */
  }
  
  *_free_rgn = free_rgn;
  *_tx = tx;
  *_ty = ty;
  *_scaled_width = scaled_width;
  *_scaled_height = scaled_height,
  *_xsrc = xsrc;
  *_ysrc = ysrc;

  return bmask;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static wxBitmap* ScaleBitmap ( wxBitmap src,
int  tw,
int  th,
double  xsrc,
double  ysrc,
double  w,
double  h,
Display *  dpy,
wxBitmap **  _tmp,
int retval,
int  forceMono,
unsigned long  whiteVal 
) [static]

Definition at line 208 of file WindowDC.cc.

{
  int sw, sh, i, j, ti, tj, xs, ys, mono;
  unsigned long pixel;
  wxBitmap *tmp;
  double scale_x, scale_y;

  *retval = TRUE;

  xs = (int)xsrc;
  ys = (int)ysrc;
  
  sw = src->GetWidth();
  sh = src->GetHeight();

  if (xs > sw)
    return NULL;
  if (ys > sh)
    return NULL;

  if (sw > w)
    sw = (int)w;
  if (sh > h)
    sh = (int)h;

  scale_x = (double)tw / sw;
  scale_y = (double)th / sh;

  mono = (src->GetDepth() == 1);
  if (forceMono && !mono)
    mono = 1;
  else
    forceMono = 0;
  tmp = new wxBitmap(tw, th, mono);
  *_tmp = tmp;
      
  if (tmp->Ok()) {
    XImage *simg, *timg;
    XGCValues values;
    GC agc;
    Pixmap spm, tpm;
    
    if (src->selectedTo)
      src->selectedTo->EndSetPixel();
    
    spm = GETPIXMAP(src);
    simg = XGetImage(dpy, spm, xs, ys, sw, sh, AllPlanes, ZPixmap);
    tpm = GETPIXMAP(tmp);
    timg = XGetImage(dpy, tpm, 0, 0, tw, th, AllPlanes, ZPixmap);

    for (ti = 0; ti < tw; ti++) {
      for (tj = 0; tj < th; tj++) {
       i = (int)(ti / scale_x);
       j = (int)(tj / scale_y);
       pixel = XGetPixel(simg, i, j);
       if (forceMono) {
         if (pixel == whiteVal)
           pixel = 0;
         else
           pixel = 1;
       }
       XPutPixel(timg, ti, tj, pixel);
      }
    }

    agc = XCreateGC(dpy, tpm, 0, &values);
    if (agc) {
      XPutImage(dpy, tpm, agc, timg, 0, 0, 0, 0, tw, th);
      XFreeGC(dpy, agc);
      *retval = 1;
    } else
      *retval = 0;

    XDestroyImage(simg);
    XDestroyImage(timg);

    xsrc = ysrc = 0;
    src = tmp;

    if (!*retval) {
      DELETE_OBJ tmp;
      *retval = FALSE;
      return NULL;
    }
  } else {
    DELETE_OBJ tmp;
    *retval = FALSE;
    return NULL;
  }

  return src;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int scheme_utf8_decode ( const unsigned char *  s,
int  start,
int  len,
unsigned int us,
int  dstart,
int  dlen,
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);
}
int scheme_utf8_decode_all ( const unsigned char *  s,
int  len,
unsigned int us,
int  permissive 
)

Definition at line 4904 of file string.c.

{
  return utf8_decode_x(s, 0, len, us, 0, -1, NULL, NULL, 0, 0, NULL, 0, permissive);
}

Here is the call graph for this function:

void wxDrawBitmapLabel ( Display *  dpy,
Pixmap  pixmap,
Pixmap  maskmap,
Drawable  drawable,
GC  agc,
int  x,
int  y,
int  width,
int  height,
int  depth,
int  mask_depth,
Region  reg,
GC  gray_gc,
Pixel  bg 
)

Definition at line 1118 of file WindowDC.cc.

                                                        {
    return doDrawBitmapLabel(dpy, pixmap, maskmap,
                          drawable, agc,
                          x, y, width, height, 
                          depth, mask_depth,
                          reg, gray_gc, bg);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void wxGetTextExtent ( Display *  dpy,
double  scale_x,
double  scale_y,
const char *  orig_s,
double *  _w,
double *  _h,
double *  _descent,
double *  _topspace,
wxFont font_to_use,
Bool  combine,
Bool  isUnicode,
int  dt,
int  len 
)

Definition at line 2532 of file WindowDC.cc.

{
  int         ascent, descent, space = 0;
  long        textlen;
  XFontStruct *fontinfo;
#ifdef WX_USE_XFT
  wxFontStruct *xfontinfo;
#endif
  double w, h;
  unsigned *s;

#ifdef WX_USE_XFT
  xfontinfo = (wxFontStruct*)font_to_use->GetInternalAAFont(scale_x, scale_y);
  if (xfontinfo)
    fontinfo = NULL;
  else
#endif
    fontinfo = (XFontStruct*)font_to_use->GetInternalFont(scale_x, scale_y);

  textlen = len;
  s = convert_to_drawable_format(orig_s, dt, &textlen, cvt_buf, WX_CVT_BUF_SIZE, 
                             isUnicode, WX_XFT_ONLY(!xfontinfo));
  dt = 0;

# ifdef WX_USE_XFT
  if (xfontinfo) {
    XGlyphInfo overall;
    wxFontStruct *this_time;
    int partlen, try_sub;
    
    if ((font_to_use->GetFamily() == wxSYMBOL)) {
      s = XlateSym(s, dt, textlen, cvt_buf, WX_CVT_BUF_SIZE);
      dt = 0;
    }
    try_sub = 1;

    w = 0;

    while (textlen) {
      int nowlen;
      nowlen = textlen;
      if (nowlen > MAX_TEXT_LENGTH_FOR_MEASURE) {
       nowlen = MAX_TEXT_LENGTH_FOR_MEASURE;
      }

      if (try_sub) {
       int index = 1, cval;
       partlen = 1;
       this_time = xfontinfo;
       
       while (1) {
         cval = s[dt];
         if (!XftGlyphExists(dpy, this_time, cval)) {
           this_time = (wxFontStruct*)font_to_use->GetNextAASubstitution(index++, cval, scale_x, scale_y, 0.0);
           if (!this_time) {
             this_time = xfontinfo;
             break;
           }
         } else
           break;
       }

       /* Get a longer range that won't need a substitution */
       if (this_time == xfontinfo) {
         while (partlen < nowlen) {
           cval = s[dt + partlen];
           if (((this_time != xfontinfo)
               && XftGlyphExists(dpy, xfontinfo, cval))
              || !XftGlyphExists(dpy, this_time, cval))
             break;
           partlen++;
         }
       }
      } else {
       partlen = nowlen;
       this_time = xfontinfo;
      }
      
      XftTextExtents32(dpy, this_time, ((XftChar32 *)s) + dt, partlen, &overall);
      w += overall.xOff;

      textlen -= partlen;
      dt += partlen;
    }

    ascent = xfontinfo->ascent;
    descent = xfontinfo->descent;
    space = xfontinfo->height - xfontinfo->ascent - xfontinfo->descent;
    if (space < 0)
      space = -space; /* This means that we're computing the space wrong! */
  } else
#endif
    {
      int direction;
      XCharStruct overall;

      XTextExtents16(fontinfo, (XChar2b *)s + dt, textlen,
                   &direction, &ascent, &descent, &overall);
      w = overall.width;
    }

  *_w = w;
  h = ascent + descent;
  *_h = h;
  if (_descent) {
    double d;
    d = descent;
    *_descent = d;
  }
  if (_topspace)
    *_topspace = space;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

int cap_style[] = { CapRound, CapProjecting, CapButt, CapNotLast } [static]

Definition at line 78 of file WindowDC.cc.

unsigned int cvt_buf[WX_CVT_BUF_SIZE] [static]

Definition at line 2227 of file WindowDC.cc.

wxDash dashdefs[4][4] [static]
Initial value:
 {
  { 2, 5, 0, 0 }, 
  { 4, 8, 0, 0 }, 
  { 4, 4, 0, 0 }, 
  { 6, 6, 2, 6 }  
}

Definition at line 1873 of file WindowDC.cc.

Region empty_rgn [static]

Definition at line 2751 of file WindowDC.cc.

int fill_rule[] = { EvenOddRule, WindingRule } [static]

Definition at line 79 of file WindowDC.cc.

Pixmap* hatch_bitmaps = NULL [static]

Definition at line 105 of file WindowDC.cc.

int join_style[] = { JoinBevel, JoinMiter, JoinRound } [static]

Definition at line 77 of file WindowDC.cc.

int num_dashes[] = { 2, 2, 2, 4 } [static]

Definition at line 1879 of file WindowDC.cc.

Definition at line 91 of file wxAllocColor.c.

Definition at line 89 of file wxAllocColor.c.

Definition at line 89 of file wxAllocColor.c.

Definition at line 89 of file wxAllocColor.c.