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

  1. /* $XConsortium: omTextExt.c,v 1.2 94/01/20 18:08:23 rws Exp $ */
  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. #include "Xlib_private.h"
  28. #include "XomGeneric.h"
  29. #include <stdio.h>
  30.  
  31. int
  32. _XomGenericTextExtents(oc, type, text, length, overall_ink,
  33.                overall_logical)
  34.     XOC oc;
  35.     XOMTextType type;
  36.     XPointer text;
  37.     int length;
  38.     XRectangle *overall_ink;
  39.     XRectangle *overall_logical;
  40. {
  41.     DBUG_ENTER("_XomGenericTextExtents")
  42.     XlcConv conv;
  43.     XFontStruct *font;
  44.     Bool is_xchar2b;
  45.     XPointer args[2];
  46.     XChar2b xchar2b_buf[BUFSIZ], *buf;
  47.     int direction, logical_ascent, logical_descent, tmp_ascent, tmp_descent;
  48.     XCharStruct overall, tmp_overall;
  49.     int buf_len, left;
  50.     Bool first = True;
  51.  
  52.     conv = _XomInitConverter(oc, type);
  53.     if (conv == NULL)
  54.     DBUG_RETURN(0);
  55.  
  56.     bzero((char *) &overall, sizeof(XCharStruct));
  57.     logical_ascent = logical_descent = 0;
  58.  
  59.     args[0] = (XPointer) &font;
  60.     args[1] = (XPointer) &is_xchar2b;
  61.  
  62.     while (length > 0) {
  63.     buf = xchar2b_buf;
  64.     left = buf_len = BUFSIZ;
  65.  
  66.     if (_XomConvert(oc, conv, (XPointer *) &text, &length,
  67.             (XPointer *) &buf, &left, args, 2) < 0)
  68.         break;
  69.     buf_len -= left;
  70.  
  71.     if (is_xchar2b)
  72.         XTextExtents16(font, xchar2b_buf, buf_len, &direction,
  73.                &tmp_ascent, &tmp_descent, &tmp_overall);
  74.     else
  75.         XTextExtents(font, (char *) xchar2b_buf, buf_len, &direction,
  76.              &tmp_ascent, &tmp_descent, &tmp_overall);
  77.  
  78.     if (first) {    /* initialize overall */
  79.         overall = tmp_overall;
  80.         logical_ascent = tmp_ascent;
  81.         logical_descent = tmp_descent;
  82.         first = False;
  83.     } else {
  84.         overall.lbearing = min(overall.lbearing,
  85.                    overall.width + tmp_overall.lbearing);
  86.         overall.rbearing = max(overall.rbearing,
  87.                    overall.width + tmp_overall.rbearing);
  88.         overall.ascent = max(overall.ascent, tmp_overall.ascent);
  89.         overall.descent = max(overall.descent, tmp_overall.descent);
  90.         overall.width += tmp_overall.width;
  91.         logical_ascent = max(logical_ascent, tmp_ascent);
  92.         logical_descent = max(logical_descent, tmp_descent);
  93.     }
  94.     }
  95.  
  96.     if (overall_ink) {
  97.     overall_ink->x = overall.lbearing;
  98.     overall_ink->y = -(overall.ascent);
  99.     overall_ink->width = overall.rbearing - overall.lbearing;
  100.     overall_ink->height = overall.ascent + overall.descent;
  101.     }
  102.  
  103.     if (overall_logical) {
  104.     overall_logical->x = 0;
  105.         overall_logical->y = -(logical_ascent);
  106.     overall_logical->width = overall.width;
  107.         overall_logical->height = logical_ascent + logical_descent;
  108.     }
  109.  
  110.     DBUG_RETURN(overall.width);
  111. }
  112.  
  113. int
  114. #if NeedFunctionPrototypes
  115. _XmbGenericTextExtents(XOC oc, _Xconst char *text, int length,
  116.                XRectangle *overall_ink, XRectangle *overall_logical)
  117. #else
  118. _XmbGenericTextExtents(oc, text, length, overall_ink, overall_logical)
  119.     XOC oc;
  120.     char *text;
  121.     int length;
  122.     XRectangle *overall_ink;
  123.     XRectangle *overall_logical;
  124. #endif
  125. {
  126.     DBUG_ENTER("_XmbGenericTextExtents")
  127.     int result = _XomGenericTextExtents(oc, XOMMultiByte, (XPointer) text, length,
  128.                   overall_ink, overall_logical);
  129.     DBUG_RETURN(result);
  130. }
  131.  
  132. int
  133. #if NeedFunctionPrototypes
  134. _XwcGenericTextExtents(XOC oc, _Xconst wchar_t *text, int length,
  135.                XRectangle *overall_ink, XRectangle *overall_logical)
  136. #else
  137. _XwcGenericTextExtents(oc, text, length, overall_ink, overall_logical)
  138.     XOC oc;
  139.     wchar_t *text;
  140.     int length;
  141.     XRectangle *overall_ink;
  142.     XRectangle *overall_logical;
  143. #endif
  144. {
  145.     DBUG_ENTER("_XwcGenericTextExtents")
  146.     int result = _XomGenericTextExtents(oc, XOMWideChar, (XPointer) text, length,
  147.                   overall_ink, overall_logical);
  148.     DBUG_RETURN(result);
  149. }
  150.