home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / evbl0627.zip / everblue_20010627.zip / x11 / Xom_Default.c < prev    next >
C/C++ Source or Header  |  1999-11-02  |  11KB  |  423 lines

  1. /* $TOG: omDefault.c /main/6 1997/06/22 15:53:43 kaleb $ */
  2. /*
  3.  * Copyright 1992, 1993 by TOSHIBA Corp.
  4.  *
  5.  * Permission to use, copy, modify, and distribute this software and its
  6.  * documentation for any purpose and without fee is hereby granted, provided
  7.  * that the above copyright notice appear in all copies and that both that
  8.  * copyright notice and this permission notice appear in supporting
  9.  * documentation, and that the name of TOSHIBA not be used in advertising
  10.  * or publicity pertaining to distribution of the software without specific,
  11.  * written prior permission. TOSHIBA make no representations about the
  12.  * suitability of this software for any purpose.  It is provided "as is"
  13.  * without express or implied warranty.
  14.  *
  15.  * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  16.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  17.  * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  18.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  20.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21.  * SOFTWARE.
  22.  *
  23.  * Author: Katsuhisa Yano    TOSHIBA Corp.
  24.  *                   mopi@osa.ilab.toshiba.co.jp
  25.  */
  26. /*
  27.  *  (c) Copyright 1995 FUJITSU LIMITED
  28.  *  This is source code modified by FUJITSU LIMITED under the Joint
  29.  *  Development Agreement for the CDE/Motif PST.
  30.  */
  31.  
  32. #include "Xlib_private.h"
  33. #include "XomGeneric.h"
  34. #include <X11/Xos.h>
  35. #include <X11/Xatom.h>
  36. #include <stdio.h>
  37.  
  38. #define DefineLocalBuf        char local_buf[BUFSIZ]
  39. #define AllocLocalBuf(length)    (length > BUFSIZ ? (char *)Xmalloc(length) : local_buf)
  40. #define FreeLocalBuf(ptr)    if (ptr != local_buf) Xfree(ptr)
  41.  
  42. static Bool
  43. wcs_to_mbs(oc, to, from, length)
  44.     XOC oc;
  45.     char *to;
  46.     wchar_t *from;
  47.     int length;
  48. {
  49.     DBUG_ENTER("wcs_to_mbs")
  50.     XlcConv conv = XOC_GENERIC(oc)->wcs_to_cs;
  51.     XLCd lcd;
  52.     int ret, to_left = length;
  53.  
  54.     if (conv == NULL) {
  55.     lcd = oc->core.om->core.lcd;
  56.     conv = _XlcOpenConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte);
  57.     if (conv == NULL)
  58.          DBUG_RETURN(False);
  59.     XOC_GENERIC(oc)->wcs_to_cs = conv;
  60.     } else
  61.     _XlcResetConverter(conv);
  62.  
  63.     ret = _XlcConvert(conv, (XPointer *) &from, &length, (XPointer *) &to,
  64.               &to_left, NULL, 0);
  65.     if (ret != 0 || length > 0)
  66.     DBUG_RETURN(False);
  67.     
  68.     DBUG_RETURN(True);
  69. }
  70.  
  71. int
  72. #if NeedFunctionPrototypes
  73. _XmbDefaultTextEscapement(XOC oc, _Xconst char *text, int length)
  74. #else
  75. _XmbDefaultTextEscapement(oc, text, length)
  76.     XOC oc;
  77.     char *text;
  78.     int length;
  79. #endif
  80. {
  81.     DBUG_ENTER("_XmbDefaultTextEscapement")
  82.     int result = XTextWidth(*oc->core.font_info.font_struct_list, text, length);
  83.     DBUG_RETURN(result);
  84. }
  85.  
  86. int
  87. #if NeedFunctionPrototypes
  88. _XwcDefaultTextEscapement(XOC oc, _Xconst wchar_t *text, int length)
  89. #else
  90. _XwcDefaultTextEscapement(oc, text, length)
  91.     XOC oc;
  92.     wchar_t *text;
  93.     int length;
  94. #endif
  95. {
  96.     DBUG_ENTER("_XwcDefaultTextEscapement")
  97.     DefineLocalBuf;
  98.     char *buf = AllocLocalBuf(length);
  99.     int ret;
  100.  
  101.     if (buf == NULL)
  102.     DBUG_RETURN(0);
  103.  
  104.     if (wcs_to_mbs(oc, buf, text, length) == False)
  105.     goto err;
  106.  
  107.     ret = _XmbDefaultTextEscapement(oc, buf, length);
  108.  
  109. err:
  110.     FreeLocalBuf(buf);
  111.  
  112.     DBUG_RETURN(ret);
  113. }
  114.  
  115. int
  116. #if NeedFunctionPrototypes
  117. _XmbDefaultTextExtents(XOC oc, _Xconst char *text, int length,
  118.                XRectangle *overall_ink, XRectangle *overall_logical)
  119. #else
  120. _XmbDefaultTextExtents(oc, text, length, overall_ink, overall_logical)
  121.     XOC oc;
  122.     char *text;
  123.     int length;
  124.     XRectangle *overall_ink;
  125.     XRectangle *overall_logical;
  126. #endif
  127. {
  128.     DBUG_ENTER("_XmbDefaultTextExtents")
  129.     int direction, logical_ascent, logical_descent;
  130.     XCharStruct overall;
  131.  
  132.     XTextExtents(*oc->core.font_info.font_struct_list, text, length, &direction,
  133.          &logical_ascent, &logical_descent, &overall);
  134.  
  135.     if (overall_ink) {
  136.     overall_ink->x = overall.lbearing;
  137.     overall_ink->y = -(overall.ascent);
  138.     overall_ink->width = overall.rbearing - overall.lbearing;
  139.     overall_ink->height = overall.ascent + overall.descent;
  140.     }
  141.  
  142.     if (overall_logical) {
  143.     overall_logical->x = 0;
  144.         overall_logical->y = -(logical_ascent);
  145.     overall_logical->width = overall.width;
  146.         overall_logical->height = logical_ascent + logical_descent;
  147.     }
  148.  
  149.     DBUG_RETURN(overall.width);
  150. }
  151.  
  152. int
  153. #if NeedFunctionPrototypes
  154. _XwcDefaultTextExtents(XOC oc, _Xconst wchar_t *text, int length,
  155.                XRectangle *overall_ink, XRectangle *overall_logical)
  156. #else
  157. _XwcDefaultTextExtents(oc, text, length, overall_ink, overall_logical)
  158.     XOC oc;
  159.     wchar_t *text;
  160.     int length;
  161.     XRectangle *overall_ink;
  162.     XRectangle *overall_logical;
  163. #endif
  164. {
  165.     DBUG_ENTER("_XwcDefaultTextExtents")
  166.     DefineLocalBuf;
  167.     char *buf = AllocLocalBuf(length);
  168.     int ret;
  169.  
  170.     if (buf == NULL)
  171.     DBUG_RETURN(0);
  172.  
  173.     if (wcs_to_mbs(oc, buf, text, length) == False)
  174.     goto err;
  175.  
  176.     ret = _XmbDefaultTextExtents(oc, buf, length, overall_ink, overall_logical);
  177.  
  178. err:
  179.     FreeLocalBuf(buf);
  180.  
  181.     DBUG_RETURN(ret);
  182. }
  183.  
  184. Status
  185. #if NeedFunctionPrototypes
  186. _XmbDefaultTextPerCharExtents(XOC oc, _Xconst char *text, int length,
  187.                   XRectangle *ink_buf, XRectangle *logical_buf,
  188.                   int buf_size, int *num_chars,
  189.                   XRectangle *overall_ink,
  190.                   XRectangle *overall_logical)
  191. #else
  192. _XmbDefaultTextPerCharExtents(oc, text, length, ink_buf, logical_buf, buf_size,
  193.                   num_chars, overall_ink, overall_logical)
  194.     XOC oc;
  195.     char *text;    
  196.     int length;
  197.     XRectangle *ink_buf;
  198.     XRectangle *logical_buf;
  199.     int buf_size;
  200.     int *num_chars;
  201.     XRectangle *overall_ink;
  202.     XRectangle *overall_logical;
  203. #endif
  204. {
  205.     DBUG_ENTER("_XmbDefaultTextPerCharExtents")
  206.     XFontStruct *font = *oc->core.font_info.font_struct_list;
  207.     XCharStruct *def, *cs, overall;
  208.     Bool first = True;
  209.  
  210.     if (buf_size < length)
  211.     DBUG_RETURN(0);
  212.  
  213.     bzero((char *) &overall, sizeof(XCharStruct));
  214.     *num_chars = 0;
  215.  
  216.     CI_GET_DEFAULT_INFO_1D(font, def)
  217.  
  218.     while (length-- > 0) {
  219.     CI_GET_CHAR_INFO_1D(font, *text, def, cs)
  220.     text++;
  221.     if (cs == NULL)
  222.         continue;
  223.  
  224.     ink_buf->x = overall.width + cs->lbearing;
  225.     ink_buf->y = -(cs->ascent);
  226.     ink_buf->width = cs->rbearing - cs->lbearing;
  227.     ink_buf->height = cs->ascent + cs->descent;
  228.     ink_buf++;
  229.  
  230.     logical_buf->x = overall.width;
  231.     logical_buf->y = -(font->ascent);
  232.     logical_buf->width = cs->width;
  233.     logical_buf->height = font->ascent + font->descent;
  234.     logical_buf++;
  235.  
  236.     if (first) {
  237.         overall = *cs;
  238.         first = False;
  239.     } else {
  240.         overall.ascent = max(overall.ascent, cs->ascent);
  241.         overall.descent = max(overall.descent, cs->descent);
  242.         overall.lbearing = min(overall.lbearing, overall.width +
  243.                    cs->lbearing);
  244.         overall.rbearing = max(overall.rbearing, overall.width +
  245.                    cs->rbearing);
  246.         overall.width += cs->width;
  247.     }
  248.  
  249.     (*num_chars)++;
  250.     }
  251.  
  252.     if (overall_ink) {
  253.     overall_ink->x = overall.lbearing;
  254.     overall_ink->y = -(overall.ascent);
  255.     overall_ink->width = overall.rbearing - overall.lbearing;
  256.     overall_ink->height = overall.ascent + overall.descent;
  257.     }
  258.  
  259.     if (overall_logical) {
  260.     overall_logical->x = 0;
  261.     overall_logical->y = -(font->ascent);
  262.     overall_logical->width = overall.width;
  263.     overall_logical->height = font->ascent + font->descent;
  264.     }
  265.  
  266.     DBUG_RETURN(1);
  267. }
  268.  
  269. Status
  270. #if NeedFunctionPrototypes
  271. _XwcDefaultTextPerCharExtents(XOC oc, _Xconst wchar_t *text, int length,
  272.                   XRectangle *ink_buf, XRectangle *logical_buf,
  273.                   int buf_size, int *num_chars,
  274.                   XRectangle *overall_ink,
  275.                   XRectangle *overall_logical)
  276. #else
  277. _XwcDefaultTextPerCharExtents(oc, text, length, ink_buf, logical_buf, buf_size,
  278.                   num_chars, overall_ink, overall_logical)
  279.     XOC oc;
  280.     wchar_t *text;
  281.     int length;
  282.     XRectangle *ink_buf;
  283.     XRectangle *logical_buf;
  284.     int buf_size;
  285.     int *num_chars;
  286.     XRectangle *overall_ink;
  287.     XRectangle *overall_logical;
  288. #endif
  289. {
  290.     DBUG_ENTER("_XwcDefaultTextPerCharExtents")
  291.     DefineLocalBuf;
  292.     char *buf = AllocLocalBuf(length);
  293.     Status ret;
  294.  
  295.     if (buf == NULL)
  296.     DBUG_RETURN(0);
  297.  
  298.     if (wcs_to_mbs(oc, buf, text, length) == False)
  299.     goto err;
  300.  
  301.     ret = _XmbDefaultTextPerCharExtents(oc, buf, length, ink_buf, logical_buf,
  302.                     buf_size, num_chars, overall_ink,
  303.                     overall_logical);
  304.  
  305. err:
  306.     FreeLocalBuf(buf);
  307.  
  308.     DBUG_RETURN(ret);
  309. }
  310.  
  311. int
  312. #if NeedFunctionPrototypes
  313. _XmbDefaultDrawString(Display *dpy, Drawable d, XOC oc, GC gc, int x, int y,
  314.               _Xconst char *text, int length)
  315. #else
  316. _XmbDefaultDrawString(dpy, d, oc, gc, x, y, text, length)
  317.     Display *dpy;
  318.     Drawable d;
  319.     XOC oc;
  320.     GC gc;
  321.     int x, y;
  322.     char *text;
  323.     int length;
  324. #endif
  325. {
  326.     DBUG_ENTER("_XmbDefaultDrawString")
  327.     XFontStruct *font = *oc->core.font_info.font_struct_list;
  328.     int result;
  329.  
  330.     XSetFont(dpy, gc, font->fid);
  331.     XDrawString(dpy, d, gc, x, y, text, length);
  332.  
  333.     result = XTextWidth(font, text, length);
  334.     DBUG_RETURN(result);
  335. }
  336.  
  337. int
  338. #if NeedFunctionPrototypes
  339. _XwcDefaultDrawString(Display *dpy, Drawable d, XOC oc, GC gc, int x, int y,
  340.               _Xconst wchar_t *text, int length)
  341. #else
  342. _XwcDefaultDrawString(dpy, d, oc, gc, x, y, text, length)
  343.     Display *dpy;
  344.     Drawable d;
  345.     XOC oc;
  346.     GC gc;
  347.     int x, y;
  348.     wchar_t *text;
  349.     int length;
  350. #endif
  351. {
  352.     DBUG_ENTER("_XwcDefaultDrawString")
  353.     DefineLocalBuf;
  354.     char *buf = AllocLocalBuf(length);
  355.     int ret;
  356.  
  357.     if (buf == NULL)
  358.     DBUG_RETURN(0);
  359.  
  360.     if (wcs_to_mbs(oc, buf, text, length) == False)
  361.     goto err;
  362.  
  363.     ret = _XmbDefaultDrawString(dpy, d, oc, gc, x, y, buf, length);
  364.  
  365. err:
  366.     FreeLocalBuf(buf);
  367.  
  368.     DBUG_RETURN(ret);
  369. }
  370.  
  371. void
  372. #if NeedFunctionPrototypes
  373. _XmbDefaultDrawImageString(Display *dpy, Drawable d, XOC oc, GC gc, int x,
  374.                int y, _Xconst char *text, int length)
  375. #else
  376. _XmbDefaultDrawImageString(dpy, d, oc, gc, x, y, text, length)
  377.     Display *dpy;
  378.     Drawable d;
  379.     XOC oc;
  380.     GC gc;
  381.     int x, y;
  382.     char *text;
  383.     int length;
  384. #endif
  385. {
  386.     DBUG_ENTER("_XmbDefaultDrawImageString")
  387.     XSetFont(dpy, gc, (*oc->core.font_info.font_struct_list)->fid);
  388.     XDrawImageString(dpy, d, gc, x, y, text, length);
  389.     DBUG_VOID_RETURN;
  390. }
  391.  
  392. void
  393. #if NeedFunctionPrototypes
  394. _XwcDefaultDrawImageString(Display *dpy, Drawable d, XOC oc, GC gc, int x,
  395.                int y, _Xconst wchar_t *text, int length)
  396. #else
  397. _XwcDefaultDrawImageString(dpy, d, oc, gc, x, y, text, length)
  398.     Display *dpy;
  399.     Drawable d;
  400.     XOC oc;
  401.     GC gc;
  402.     int x, y;
  403.     wchar_t *text;
  404.     int length;
  405. #endif
  406. {
  407.     DBUG_ENTER("_XwcDefaultDrawImageString")
  408.     DefineLocalBuf;
  409.     char *buf = AllocLocalBuf(length);
  410.  
  411.     if (buf == NULL)
  412.     DBUG_VOID_RETURN;
  413.  
  414.     if (wcs_to_mbs(oc, buf, text, length) == False)
  415.     goto err;
  416.  
  417.     _XmbDefaultDrawImageString(dpy, d, oc, gc, x, y, buf, length);
  418.  
  419. err:
  420.     FreeLocalBuf(buf);
  421.     DBUG_VOID_RETURN;
  422. }
  423.