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

  1. /* $XConsortium: omTextPer.c,v 1.2 94/01/20 18:08:28 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. static Status
  32. _XomGenericTextPerCharExtents(oc, type, text, length, ink_buf, logical_buf,
  33.                   buf_size, num_chars, overall_ink, overall_logical)
  34.     XOC oc;
  35.     XOMTextType type;
  36.     XPointer text;
  37.     int length;
  38.     XRectangle *ink_buf;
  39.     XRectangle *logical_buf;
  40.     int buf_size;
  41.     int *num_chars;
  42.     XRectangle *overall_ink;
  43.     XRectangle *overall_logical;
  44. {
  45.     DBUG_ENTER("_XomGenericTextPerCharExtents")
  46.     XlcConv conv;
  47.     XFontStruct *font;
  48.     Bool is_xchar2b;
  49.     XPointer args[2];
  50.     XChar2b xchar2b_buf[BUFSIZ], *xchar2b_ptr;
  51.     char *xchar_ptr;
  52.     XCharStruct *def, *cs, overall;
  53.     int buf_len, left, require_num;
  54.     int logical_ascent, logical_descent;
  55.     Bool first = True;
  56.  
  57.     conv = _XomInitConverter(oc, type);
  58.     if (conv == NULL)
  59.     DBUG_RETURN(0);
  60.     
  61.     bzero((char *) &overall, sizeof(XCharStruct));
  62.     logical_ascent = logical_descent = require_num = *num_chars = 0;
  63.  
  64.     args[0] = (XPointer) &font;
  65.     args[1] = (XPointer) &is_xchar2b;
  66.  
  67.     while (length > 0) {
  68.     xchar2b_ptr = xchar2b_buf;
  69.     left = buf_len = BUFSIZ;
  70.  
  71.     if (_XomConvert(oc, conv, (XPointer *) &text, &length,
  72.             (XPointer *) &xchar2b_ptr, &left, args, 2) < 0)
  73.         break;
  74.     buf_len -= left;
  75.  
  76.     if (require_num) {
  77.         require_num += buf_len;
  78.         continue;
  79.     }
  80.     if (buf_size < buf_len) {
  81.         require_num = *num_chars + buf_len;
  82.         continue;
  83.     }
  84.     buf_size -= buf_len;
  85.  
  86.     if (first) {
  87.         logical_ascent = font->ascent;
  88.         logical_descent = font->descent;
  89.     } else {
  90.         logical_ascent = max(logical_ascent, font->ascent);
  91.         logical_descent = max(logical_descent, font->descent);
  92.     }
  93.  
  94.     if (is_xchar2b) {
  95.         CI_GET_DEFAULT_INFO_2D(font, def)
  96.         xchar2b_ptr = xchar2b_buf;
  97.     } else {
  98.         CI_GET_DEFAULT_INFO_1D(font, def)
  99.         xchar_ptr = (char *) xchar2b_buf;
  100.     }
  101.  
  102.     while (buf_len-- > 0) {
  103.         if (is_xchar2b) {
  104.         CI_GET_CHAR_INFO_2D(font, xchar2b_ptr->byte1,
  105.                     xchar2b_ptr->byte2, def, cs)
  106.         xchar2b_ptr++;
  107.         } else {
  108.         CI_GET_CHAR_INFO_1D(font, *xchar_ptr, def, cs)
  109.         xchar_ptr++;
  110.         }
  111.         if (cs == NULL)
  112.         continue;
  113.  
  114.         ink_buf->x = overall.width + cs->lbearing;
  115.         ink_buf->y = -(cs->ascent);
  116.         ink_buf->width = cs->rbearing - cs->lbearing;
  117.         ink_buf->height = cs->ascent + cs->descent;
  118.         ink_buf++;
  119.  
  120.         logical_buf->x = overall.width;
  121.         logical_buf->y = -(font->ascent);
  122.         logical_buf->width = cs->width;
  123.         logical_buf->height = font->ascent + font->descent;
  124.         logical_buf++;
  125.  
  126.         if (first) {
  127.         overall = *cs;
  128.         first = False;
  129.         } else {
  130.         overall.ascent = max(overall.ascent, cs->ascent);
  131.         overall.descent = max(overall.descent, cs->descent);
  132.         overall.lbearing = min(overall.lbearing,
  133.                        overall.width + cs->lbearing);
  134.         overall.rbearing = max(overall.rbearing,
  135.                        overall.width + cs->rbearing);
  136.         overall.width += cs->width;
  137.         }
  138.  
  139.         (*num_chars)++;
  140.     }
  141.     }
  142.  
  143.     if (require_num) {
  144.     *num_chars = require_num;
  145.     DBUG_RETURN(0);
  146.     } else {
  147.     if (overall_ink) {
  148.         overall_ink->x = overall.lbearing;
  149.         overall_ink->y = -(overall.ascent);
  150.         overall_ink->width = overall.rbearing - overall.lbearing;
  151.         overall_ink->height = overall.ascent + overall.descent;
  152.     }
  153.  
  154.     if (overall_logical) {
  155.         overall_logical->x = 0;
  156.         overall_logical->y = -(logical_ascent);
  157.         overall_logical->width = overall.width;
  158.         overall_logical->height = logical_ascent + logical_descent;
  159.     }
  160.     }
  161.  
  162.     DBUG_RETURN(1);
  163. }
  164.  
  165. Status
  166. #if NeedFunctionPrototypes
  167. _XmbGenericTextPerCharExtents(XOC oc, _Xconst char *text, int length,
  168.                   XRectangle *ink_buf, XRectangle *logical_buf,
  169.                   int buf_size, int *num_chars,
  170.                   XRectangle *overall_ink,
  171.                   XRectangle *overall_logical)
  172. #else
  173. _XmbGenericTextPerCharExtents(oc, text, length, ink_buf, logical_buf,
  174.                   buf_size, num_chars, overall_ink, overall_logical)
  175.     XOC oc;
  176.     char *text;    
  177.     int length;
  178.     XRectangle *ink_buf;
  179.     XRectangle *logical_buf;
  180.     int buf_size;
  181.     int *num_chars;
  182.     XRectangle *overall_ink;
  183.     XRectangle *overall_logical;
  184. #endif
  185. {
  186.     DBUG_ENTER("_XmbGenericTextPerCharExtents")
  187.     Status result = _XomGenericTextPerCharExtents(oc, XOMMultiByte, (XPointer) text,
  188.                      length, ink_buf, logical_buf, buf_size,
  189.                      num_chars, overall_ink,
  190.                      overall_logical);
  191.     DBUG_RETURN(result);
  192. }
  193.  
  194. Status
  195. #if NeedFunctionPrototypes
  196. _XwcGenericTextPerCharExtents(XOC oc, _Xconst wchar_t *text, int length,
  197.                   XRectangle *ink_buf, XRectangle *logical_buf,
  198.                   int buf_size, int *num_chars,
  199.                   XRectangle *overall_ink,
  200.                   XRectangle *overall_logical)
  201. #else
  202. _XwcGenericTextPerCharExtents(oc, text, length, ink_buf, logical_buf,
  203.                   buf_size, num_chars, overall_ink, overall_logical)
  204.     XOC oc;
  205.     wchar_t *text;
  206.     int length;
  207.     XRectangle *ink_buf;
  208.     XRectangle *logical_buf;
  209.     int buf_size;
  210.     int *num_chars;
  211.     XRectangle *overall_ink;
  212.     XRectangle *overall_logical;
  213. #endif
  214. {
  215.     DBUG_ENTER("_XwcGenericTextPerCharExtents")
  216.     Status result = _XomGenericTextPerCharExtents(oc, XOMWideChar, (XPointer) text,
  217.                      length, ink_buf, logical_buf, buf_size,
  218.                      num_chars, overall_ink,
  219.                      overall_logical);
  220.     DBUG_RETURN(result);
  221. }
  222.