home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / evbl0627.zip / everblue_20010627.zip / x11 / Xlib_Text.c < prev    next >
C/C++ Source or Header  |  2001-01-29  |  5KB  |  159 lines

  1.  
  2. #include <alloca.h>
  3. #include "Xlib_private.h"
  4.  
  5. int Xlib_SetFont(Pixmap, Font);
  6.  
  7. static int Xlib_DrawText(Drawable d, GC gc, int x, int y,
  8.     char* string, int length, ULONG flOptions, int *return_x)
  9. {
  10.     DBUG_ENTER("Xlib_DrawText")
  11.     HPS hps;
  12.     Xlib_GC *xgc = (Xlib_GC *)gc;
  13.     int viewheight = GetDrawableHeight(d, gc, &hps, GC_NOPATH);
  14.     POINTL ptl, aptl[TXTBOX_COUNT];
  15.     RECTL rectl;
  16.     if (!viewheight || !string || !length || !hps) DBUG_RETURN(False);
  17.     Xlib_SetGC(hps, xgc);
  18.     /*if (xgc->pixmap && xgc->values.font)
  19.         Xlib_SetFont((Pixmap)xgc->pixmap, xgc->values.font);
  20.     else
  21.     if (xgc->winattrib && xgc->values.font)
  22.         Xlib_SetFont((Pixmap)xgc->winattrib, xgc->values.font);*/
  23.     if (GpiQueryTextBox(hps, length, (char *)string, TXTBOX_COUNT, aptl)) {
  24.         ptl.x = x; ptl.y = viewheight - y;
  25.         rectl.xLeft = ptl.x+ aptl[TXTBOX_TOPLEFT].x;
  26.         rectl.yTop = ptl.y + aptl[TXTBOX_TOPRIGHT].y;
  27.         rectl.xRight=ptl.x + aptl[TXTBOX_BOTTOMRIGHT].x;
  28.         rectl.yBottom=ptl.y+ aptl[TXTBOX_BOTTOMLEFT].y;
  29.         aptl[TXTBOX_CONCAT].x += ptl.x;
  30.         aptl[TXTBOX_CONCAT].y += ptl.y;
  31.         ptl.y++;
  32.         GpiCharStringPosAt(hps, &ptl, &rectl, flOptions, length, string, NULL);
  33.         GpiMove(hps,&aptl[TXTBOX_CONCAT]);
  34.         if (return_x) *return_x = aptl[TXTBOX_CONCAT].x;
  35.         DBUG_RETURN(True);
  36.     }
  37.     DBUG_RETURN(True);
  38. }
  39.  
  40. int XDrawString(Display* display, Drawable d, GC gc, int x, int y,
  41.         _Xconst char* string, int length)
  42. {
  43.     DBUG_ENTER("XDrawString")
  44.     int result;
  45. #ifdef OS2I18N
  46.     int tmplen = (length+1)*2;
  47.     char *str = alloca(tmplen);
  48.     length = Xlib_XlatISO8859_1(str, tmplen, (char *)string, length);
  49. #else
  50.     char *str = (char *)string;
  51. #endif
  52.     result = Xlib_DrawText(d, gc, x, y, str, length, CHS_CLIP, NULL);
  53.     DBUG_RETURN(result);
  54. }
  55.  
  56. int XDrawImageString(Display* display, Drawable d, GC gc, int x, int y,
  57.         _Xconst char* string, int length)
  58. {
  59.     DBUG_ENTER("XDrawImageString")
  60.     int result;
  61. #ifdef OS2I18N
  62.     int tmplen = (length+1)*2;
  63.     char *str = alloca(tmplen);
  64.     length = Xlib_XlatISO8859_1(str, tmplen, (char *)string, length);
  65. #else
  66.     char *str = (char *)string;
  67. #endif
  68.     result = Xlib_DrawText(d, gc, x, y, str, length, CHS_CLIP | CHS_OPAQUE, NULL);
  69.     DBUG_RETURN(result);
  70. }
  71.  
  72. int XDrawText(Display* display, Drawable d, GC gc, int x, int y,
  73.         XTextItem* items, int nitems)
  74. {
  75.     DBUG_ENTER("XDrawText")
  76.     Pixmap pixmap = None;
  77.     HPS hps;
  78.     int result = 0, cx = x;
  79.     if (GetDrawableHeight(d, gc, &hps, GC_NOPATH)) {
  80.         Xlib_GC *xgc = (Xlib_GC *)gc;
  81.         Xlib_SetGC(hps, xgc);
  82.         if (xgc->pixmap) pixmap = (Pixmap)xgc->pixmap; else
  83.         if (xgc->winattrib) pixmap = (Pixmap)xgc->winattrib;
  84.     }
  85.     while (nitems && items) {
  86. #ifdef OS2I18N
  87.         int tmplen = (items->nchars+1)*2;
  88.         char *str = alloca(tmplen);
  89.         int length = Xlib_XlatISO8859_1(str, tmplen, (char *)items->chars, items->nchars);
  90. #else
  91.         char *str = (char *)items->chars;
  92.         int length = items->nchars;
  93. #endif
  94.         if (items->font != None && pixmap) {
  95.             Xlib_SetFont(pixmap, items->font);
  96.         }
  97.         cx += items->delta;
  98.         result = Xlib_DrawText(d, gc, cx, y, str, length, CHS_CLIP, &cx);
  99.         items++; nitems--;
  100.     }
  101.     DBUG_RETURN(result);
  102. }
  103.  
  104.  
  105. #ifdef OS2I18N
  106.  
  107. int XDrawString16(Display* display, Drawable d, GC gc, int x, int y,
  108.         _Xconst XChar2b* string, int length)
  109. {
  110.     DBUG_ENTER("XDrawString16")
  111.     int result;
  112.     int tmplen = (length+1)*2;
  113.     char *str = alloca(tmplen);
  114.     length = Xlib_XlatUCS_2(str, tmplen, (void *)string, length);
  115.     result = Xlib_DrawText(d, gc, x, y, str, length, CHS_CLIP, NULL);
  116.     DBUG_RETURN(result);
  117. }
  118.  
  119. int XDrawImageString16(Display* display, Drawable d, GC gc, int x, int y,
  120.         _Xconst XChar2b* string, int length)
  121. {
  122.     DBUG_ENTER("XDrawImageString16")
  123.     int result;
  124.     int tmplen = (length+1)*2;
  125.     char *str = alloca(tmplen);
  126.     length = Xlib_XlatUCS_2(str, tmplen, (void *)string, length);
  127.     result = Xlib_DrawText(d, gc, x, y, str, length, CHS_CLIP | CHS_OPAQUE, NULL);
  128.     DBUG_RETURN(result);
  129. }
  130.  
  131. int XDrawText16(Display* display, Drawable d, GC gc, int x, int y, 
  132.         XTextItem16* items, int nitems)
  133. {
  134.     DBUG_ENTER("XDrawText16")
  135.     Pixmap pixmap = None;
  136.     HPS hps;
  137.     int result = 0, cx = x;
  138.     if (GetDrawableHeight(d, gc, &hps, GC_NOPATH)) {
  139.         Xlib_GC *xgc = (Xlib_GC *)gc;
  140.         Xlib_SetGC(hps, xgc);
  141.         if (xgc->pixmap) pixmap = (Pixmap)xgc->pixmap; else
  142.         if (xgc->winattrib) pixmap = (Pixmap)xgc->winattrib;
  143.     }
  144.     while (nitems && items) {
  145.         int tmplen = (items->nchars+1)*2;
  146.         char *str = alloca(tmplen);
  147.         int length = Xlib_XlatUCS_2(str, tmplen, (void *)items->chars, items->nchars);
  148.         if (items->font != None && pixmap) {
  149.             Xlib_SetFont(pixmap, items->font);
  150.         }
  151.         cx += items->delta;
  152.         result = Xlib_DrawText(d, gc, cx, y, str, length, CHS_CLIP, &cx);
  153.         items++; nitems--;
  154.     }
  155.     DBUG_RETURN(result);
  156. }
  157.  
  158. #endif /* OS2I18N */
  159.