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

  1. /* $XConsortium: omTextEsc.c /main/4 1996/12/05 10:40:59 swick $ */
  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.  * Copyright 1995 by 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 <stdio.h>
  35.  
  36. /* For VW/UDC start */
  37.  
  38. #define    VMAP        0
  39. #define    VROTATE        1
  40. #define    FONTSCOPE    2
  41.  
  42. static int
  43. is_rotate(oc, font)
  44.     XOC         oc;
  45.     XFontStruct *font;
  46. {
  47.     DBUG_ENTER("is_rotate")
  48.     XOCGenericPart      *gen = XOC_GENERIC(oc);
  49.     FontSet             font_set;
  50.     VRotate             vrotate;
  51.     int                 font_set_count;
  52.     int                 vrotate_num;
  53.  
  54.     font_set = gen->font_set;
  55.     font_set_count = gen->font_set_num;
  56.     for( ; font_set_count-- ; font_set++) {
  57.     if((font_set->vrotate_num > 0) && (font_set->vrotate != NULL)) {
  58.         vrotate = font_set->vrotate;
  59.         vrotate_num = font_set->vrotate_num;
  60.         for( ; vrotate_num-- ; vrotate++)
  61.         if(vrotate->font == font)
  62.             DBUG_RETURN(True);
  63.     }
  64.     }
  65.     DBUG_RETURN(False);
  66. }
  67.  
  68. static int
  69. is_codemap(oc, font)
  70.     XOC         oc;
  71.     XFontStruct *font;
  72. {
  73.     DBUG_ENTER("is_codemap")
  74.     XOCGenericPart      *gen = XOC_GENERIC(oc);
  75.     FontSet             font_set;
  76.     FontData            vmap;
  77.     int                 font_set_count;
  78.     int                 vmap_num;
  79.  
  80.     font_set = gen->font_set;
  81.     font_set_count = gen->font_set_num;
  82.     for( ; font_set_count-- ; font_set++) {
  83.     if(font_set->vmap_num > 0) {
  84.         vmap = font_set->vmap;
  85.         vmap_num = font_set->vmap_num;
  86.         for( ; vmap_num-- ; vmap++)
  87.         if(vmap->font == font)
  88.             DBUG_RETURN(True);
  89.     }
  90.     }
  91.     DBUG_RETURN(False);
  92. }
  93.  
  94. static int
  95. escapement_vertical(oc, font, is_xchar2b, text, length)
  96.     XOC         oc;
  97.     XFontStruct *font;
  98.     Bool        is_xchar2b;
  99.     XPointer    text;
  100.     int         length;
  101. {
  102.     DBUG_ENTER("escapement_vertical")
  103.     XChar2b    *buf2b;
  104.     char    *buf;
  105.     int        escapement = 0, i;
  106.  
  107.     if(is_xchar2b) {
  108.     for(i = 0, buf2b = (XChar2b *) text ; i < length ; i++, buf2b++) {
  109.         if(is_rotate(oc, font) == True) {
  110.         escapement += _XTextHeight16(font, buf2b, 1);
  111.         } else {
  112.         escapement += (int) (font->max_bounds.ascent +
  113.                      font->max_bounds.descent);
  114.         }
  115.     }
  116.     } else {
  117.     for(i = 0, buf = (char *)text ; i < length && *buf ; i++, buf++) {
  118.         if(is_rotate(oc, font) == True) {
  119.         escapement += _XTextHeight(font, buf, 1);
  120.         } else {
  121.         escapement += (int) (font->max_bounds.ascent +
  122.                      font->max_bounds.descent);
  123.         }
  124.     }
  125.     }
  126.     DBUG_RETURN(escapement);
  127. }
  128.  
  129.  
  130. extern FontData _XomGetFontDataFromFontSet();
  131.  
  132. static int
  133. TextWidthWithFontSet(font_set, oc, text, length)
  134.     FontSet    font_set;
  135.     XOC        oc;
  136.     XPointer    text;
  137.     int         length;
  138. {
  139.     DBUG_ENTER("TextWidthWithFontSet")
  140.     FontData        fd;
  141.     XFontStruct        *font;
  142.     unsigned char    *ptr = (unsigned char *)text;
  143.     Bool            is_xchar2b;
  144.     int            ptr_len = length;
  145.     int            escapement = 0, char_len = 0;
  146.  
  147.     if(font_set == (FontSet) NULL)
  148.     DBUG_RETURN(escapement);
  149.  
  150.     is_xchar2b = font_set->is_xchar2b;
  151.  
  152.     while(length > 0) {
  153.     fd = _XomGetFontDataFromFontSet(font_set, ptr, length, &ptr_len,
  154.                            is_xchar2b, FONTSCOPE);
  155.     if(ptr_len <= 0)
  156.         break;
  157.     if(fd == (FontData) NULL ||
  158.        (font = fd->font) == (XFontStruct *) NULL) {
  159.  
  160.         if((font = font_set->font) == (XFontStruct *) NULL)
  161.         break;
  162.     }
  163.  
  164.     switch(oc->core.orientation) {
  165.       case XOMOrientation_LTR_TTB:
  166.       case XOMOrientation_RTL_TTB:
  167.         if (is_xchar2b) {
  168.         char_len = ptr_len / sizeof(XChar2b);
  169.         escapement += XTextWidth16(font, (XChar2b *)ptr, char_len);
  170.         } else {
  171.         char_len = ptr_len;
  172.         escapement += XTextWidth(font, (char *)ptr, char_len);
  173.         }
  174.         break;
  175.  
  176.       case XOMOrientation_TTB_LTR:
  177.       case XOMOrientation_TTB_RTL:
  178.         if(font_set->font == font) {
  179.         fd = _XomGetFontDataFromFontSet(font_set, ptr, length, &ptr_len,
  180.                         is_xchar2b, VMAP);
  181.         if(ptr_len <= 0)
  182.             break;
  183.         if(fd == (FontData) NULL ||
  184.            (font = fd->font) == (XFontStruct *) NULL)
  185.             break;
  186.  
  187.         if(is_codemap(oc, fd->font) == False) {
  188.             fd = _XomGetFontDataFromFontSet(font_set, ptr, length,
  189.                             &ptr_len, is_xchar2b,
  190.                             VROTATE);
  191.             if(ptr_len <= 0)
  192.             break;
  193.             if(fd == (FontData) NULL ||
  194.                (font = fd->font) == (XFontStruct *) NULL)
  195.             break;
  196.         }
  197.         }
  198.  
  199.         if(is_xchar2b)
  200.         char_len = ptr_len / sizeof(XChar2b);
  201.         else
  202.         char_len = ptr_len;
  203.         escapement += escapement_vertical(oc, font, is_xchar2b,
  204.                           (XPointer) ptr, char_len);
  205.     }
  206.  
  207.     if(char_len <= 0)
  208.         break;
  209.  
  210.     length -= char_len;
  211.     ptr += ptr_len;
  212.     }
  213.  
  214.     DBUG_RETURN(escapement);
  215. }
  216.  
  217. /* For VW/UDC end */
  218.  
  219. static int
  220. _XomGenericTextEscapement(oc, type, text, length)
  221.     XOC oc;
  222.     XOMTextType type;
  223.     XPointer text;
  224.     int length;
  225. {
  226.     DBUG_ENTER("_XomGenericTextEscapement")
  227.     XlcConv conv;
  228.     XFontStruct *font;
  229.     Bool is_xchar2b;
  230. /* VW/UDC */
  231.     XPointer args[3];
  232.     FontSet font_set;
  233. /* VW/UDC */
  234.     XChar2b xchar2b_buf[BUFSIZ], *buf;
  235.     int escapement = 0;
  236.     int buf_len = 0, left = 0;
  237.  
  238.     conv = _XomInitConverter(oc, type);
  239.     if (conv == NULL)
  240.     DBUG_RETURN(escapement);
  241.     
  242.     args[0] = (XPointer) &font;
  243.     args[1] = (XPointer) &is_xchar2b;
  244.     args[2] = (XPointer) &font_set;
  245.  
  246.     while (length > 0) {
  247.     buf = xchar2b_buf;
  248.     left = buf_len = BUFSIZ;
  249.  
  250.     if (_XomConvert(oc, conv, (XPointer *) &text, &length,
  251.             (XPointer *) &buf, &left, args, 3) < 0)
  252.         break;
  253.     buf_len -= left;
  254.  
  255. /* VW/UDC */
  256.     escapement += TextWidthWithFontSet(font_set, oc,
  257.                        (XPointer) xchar2b_buf, buf_len);
  258. /* VW/UDC */
  259.     }
  260.  
  261.     DBUG_RETURN(escapement);
  262. }
  263.  
  264. int
  265. #if NeedFunctionPrototypes
  266. _XmbGenericTextEscapement(XOC oc, _Xconst char *text, int length)
  267. #else
  268. _XmbGenericTextEscapement(oc, text, length)
  269.     XOC oc;
  270.     char *text;
  271.     int length;
  272. #endif
  273. {
  274.     DBUG_ENTER("_XmbGenericTextEscapement")
  275.     int result = _XomGenericTextEscapement(oc, XOMMultiByte, (XPointer) text, length);
  276.     DBUG_RETURN(result);
  277. }
  278.  
  279. int
  280. #if NeedFunctionPrototypes
  281. _XwcGenericTextEscapement(XOC oc, _Xconst wchar_t *text, int length)
  282. #else
  283. _XwcGenericTextEscapement(oc, text, length)
  284.     XOC oc;
  285.     wchar_t *text;
  286.     int length;
  287. #endif
  288. {
  289.     DBUG_ENTER("_XwcGenericTextEscapement")
  290.     int result = _XomGenericTextEscapement(oc, XOMWideChar, (XPointer) text, length);
  291.     DBUG_RETURN(result);
  292. }
  293.