home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / tcl / 1225 < prev    next >
Encoding:
Text File  |  1992-08-19  |  4.7 KB  |  139 lines

  1. Path: sparky!uunet!charon.amdahl.com!pacbell.com!mips!darwin.sura.net!Sirius.dfn.de!zrz.tu-berlin.de!news.netmbx.de!Germany.EU.net!mcsun!uknet!axion!nwinton
  2. From: n.winton@axion.bt.co.uk (Neil Winton)
  3. Newsgroups: comp.lang.tcl
  4. Subject: Re: Font problem in tk2.2 ? (Workaround)
  5. Keywords: tk2.2, font
  6. Message-ID: <1992Aug19.154953.22010@axion.bt.co.uk>
  7. Date: 19 Aug 92 15:49:53 GMT
  8. References: <1992Aug11.200305.15968@rchland.ibm.com> <16e5u6INN4ge@agate.berkeley.edu> <1992Aug14.133705.22017@rchland.ibm.com>
  9. Sender: nwinton@axion.bt.co.uk (Neil Winton)
  10. Organization: BT Laboratories
  11. Lines: 126
  12.  
  13. In article <1992Aug14.133705.22017@rchland.ibm.com>, shmdgljd@rchland.vnet.ibm.com (Jay Schmidgall) writes:
  14. |> In article <16e5u6INN4ge@agate.berkeley.edu>, ouster@sprite.Berkeley.EDU (John Ousterhout) writes:
  15. |> |> redisplays, so this is a serious problem.  Is there anyone out there with
  16. |> |> contacts at IBM that can see if there's a server patch to fix the problem?
  17. |> 
  18. |> I'm following up on this w/IBM Software Service.  I've just got the ball
  19. |> rolling so I don't know if this problem has been reported and/or any fix.
  20. |> Let you know what happens...
  21. |> 
  22. |> -- 
  23. |> : jay          jay@vnet.ibm.com    My opinions and ideas, not my employer's.
  24. |> : shmdgljd@rchland.vnet.ibm.com    (c) Copyright 1992.  All rights reserved.
  25.  
  26. Thanks to John for investigating and isolating this problem and Jay for raising
  27. this with the `appropriate authoritioes'.  Meanwhile I have developed a
  28. work-around for any other would-be Tk-on-AIX users.  You should recompile Tk with
  29. a -DXDrawString=AIXDrawString and link in the object module from the source
  30. below.  It's as simple as that.  Or at least, it was for me ...
  31.  
  32.     Regards,
  33.  
  34.         Neil
  35.  
  36. *   Neil Winton            306, SSFT, BT Labs, Martlesham Heath    *
  37. *   nwinton@axion.bt.co.uk    IPSWICH IP5, 7RE   (Tel +44 473 646079) *
  38. *   The works of the Lord are great, sought out of all them that have   *
  39. *   pleasure therein.                    Psalm 111 v 2   *
  40. *       (Found at the entrance to the Cavendish Labs, Cambridge.)       *
  41.  
  42. ------ Cut Here for AIXDrawString.c
  43. /*
  44. **  Replacement for XDrawString() for AIX.
  45. **
  46. **  This works around a bug in the AIX3.1 and 3.2 X servers which causes
  47. **  text written to an off-screen pixmap to be mangled (each character
  48. **  truncated to 8 pixels wide).  Substitute this for XDrawString with
  49. **  a suitable macro.
  50. **
  51. **  WARNING: This is neither pretty nor efficient.  Its sole purpose
  52. **  is to make Tk useable.  In particular it will fail miserably if
  53. **  used in a program managing multiple displays.  Use at your own
  54. **  risk.  (That said, it works for me and my RS/6000 320H, AIX 3.2 :-)
  55. **
  56. **  Neil Winton (N.Winton@axion.bt.co.uk)
  57. */
  58.  
  59. #include <X11/Xlib.h>
  60.  
  61. void
  62. AIXDrawString(Display *display, Drawable d, GC gc, int x, int y,
  63.           char *string, int length)
  64. {
  65.     Window root;
  66.     int x_pos, y_pos;
  67.     unsigned int width, height;
  68.     unsigned int border;
  69.     unsigned int depth;
  70.     static Pixmap bm = None;
  71.     static unsigned int bm_w = 0, bm_h = 0;
  72.     static GC bm_gc = (GC) NULL;
  73.     static GC tmpgc = (GC) NULL;
  74.     XGCValues gcv;
  75.     XID fid;
  76.     static XID last_fid = None;
  77.     static int direction, ascent, descent;
  78.     static XCharStruct info;
  79.  
  80.  
  81.     if (XGetGeometry(display, d, &root, &x_pos, &y_pos,
  82.              &width, &height, &border, &depth) != True)
  83.     {
  84.     return;
  85.     }
  86.  
  87.     if (width > bm_w || height > bm_h)
  88.     {
  89.     if (bm != None)
  90.     {
  91.         XFreePixmap(display, bm);
  92.         XFreeGC(display, bm_gc);
  93.     }
  94.     bm = XCreatePixmap(display, d, width, height, 1);
  95.     bm_w = width;
  96.     bm_h = height;
  97.     gcv.function = GXcopy;
  98.     gcv.foreground = 1;
  99.     gcv.background = 0;
  100.     bm_gc = XCreateGC(display, bm, (GCForeground | GCBackground | GCFunction), &gcv); 
  101.     }
  102.  
  103.     XGetGCValues(display, gc, GCFont, &gcv);
  104.     fid = gcv.font;
  105.     gcv.foreground = 0;
  106.     XChangeGC(display, bm_gc, (GCFont | GCForeground), &gcv);
  107.     XFillRectangle(display, bm, bm_gc, 0, 0, bm_w, bm_h);
  108.     XSetForeground(display, bm_gc, 1);
  109.  
  110.     XDrawString(display, bm, bm_gc, x, y, string, length);
  111.  
  112.     if (fid != last_fid)
  113.     {
  114.     XQueryTextExtents(display, fid, string, length, &direction, &ascent,
  115.               &descent, &info);
  116.     }
  117.  
  118.     if (tmpgc == (GC) NULL)
  119.     {
  120.     tmpgc = XCreateGC(display, d, 0, &gcv);
  121.     }
  122.     XCopyGC(display, gc, (GCFunction | GCPlaneMask | GCForeground |
  123.               GCBackground | GCLineWidth | GCLineStyle |
  124.               GCCapStyle | GCJoinStyle | GCFillStyle |
  125.               GCFillRule | GCTile | GCStipple |
  126.               GCTileStipXOrigin | GCTileStipYOrigin |
  127.               GCFont | GCSubwindowMode | GCGraphicsExposures |
  128.               GCClipXOrigin | GCClipYOrigin | GCClipMask |
  129.               GCDashOffset | GCDashList | GCArcMode), tmpgc);
  130.     gcv.clip_mask = bm;
  131.     XChangeGC(display, tmpgc, GCClipMask, &gcv);
  132.     XFillRectangle(display, d, tmpgc, x + info.lbearing,
  133.            y - ascent,
  134.            info.rbearing,
  135.            ascent + descent);
  136.  
  137.     return;
  138. }
  139.