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

  1. /* $XConsortium: omText.c /main/4 1996/12/05 10:40:52 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 */
  37.  
  38. static int
  39. is_rotate(oc, font)
  40.     XOC        oc;
  41.     XFontStruct    *font;
  42. {
  43.     DBUG_ENTER("is_rotate")
  44.     XOCGenericPart    *gen = XOC_GENERIC(oc);
  45.     FontSet        font_set;
  46.     VRotate        vrotate;
  47.     int            font_set_count;
  48.     int            vrotate_num;
  49.  
  50.     font_set = gen->font_set;
  51.     font_set_count = gen->font_set_num;
  52.     for( ; font_set_count-- ; font_set++) {
  53.     if((font_set->vrotate_num > 0) && (font_set->vrotate)) {
  54.         vrotate = font_set->vrotate;
  55.         vrotate_num = font_set->vrotate_num;
  56.         for( ; vrotate_num-- ; vrotate++)
  57.         if(vrotate->font == font)
  58.             DBUG_RETURN(True);
  59.     }
  60.     }
  61.     DBUG_RETURN(False);
  62. }
  63.  
  64. static int
  65. is_codemap(oc, font)
  66.     XOC        oc;
  67.     XFontStruct    *font;
  68. {
  69.     DBUG_ENTER("is_codemap")
  70.     XOCGenericPart    *gen = XOC_GENERIC(oc);
  71.     FontSet        font_set;
  72.     FontData        vmap;
  73.     int            font_set_count;
  74.     int            vmap_num;
  75.  
  76.     font_set = gen->font_set;
  77.     font_set_count = gen->font_set_num;
  78.     for( ; font_set_count-- ; font_set++) {
  79.     if(font_set->vmap_num > 0) {
  80.         vmap = font_set->vmap;
  81.         vmap_num = font_set->vmap_num;
  82.         for( ; vmap_num-- ; vmap++)
  83.         if(vmap->font == font)
  84.             DBUG_RETURN(True);
  85.     }
  86.     }
  87.     DBUG_RETURN(False);
  88. }
  89.  
  90. static int
  91. draw_vertical(dpy, d, oc, gc, font, is_xchar2b, x, y, text, length)
  92.     Display    *dpy;
  93.     Drawable    d;
  94.     XOC        oc;
  95.     GC        gc;
  96.     XFontStruct    *font;
  97.     Bool    is_xchar2b;
  98.     int        x, y;
  99.     XPointer    text;
  100.     int        length;
  101. {
  102.     DBUG_ENTER("draw_vertical")
  103.     XChar2b    *buf2b;
  104.     char    *buf;
  105.     int        wx = 0, wy = 0;
  106.     int        direction = 0;
  107.     int        font_ascent_return = 0, font_descent_return = 0;
  108.     int        i;
  109.     XCharStruct    overall;        
  110.  
  111.     wy = y;
  112.     if (is_xchar2b) {
  113.     for(i = 0, buf2b = (XChar2b *) text ; i < length ; i++, buf2b++) {
  114.         if(is_rotate(oc, font) == True) {
  115.         XTextExtents16(font, buf2b, 1,
  116.                    &direction, &font_ascent_return,
  117.                    &font_descent_return, &overall);
  118.         wx = x - (int)((overall.rbearing - overall.lbearing) >> 1) -
  119.              (int) overall.lbearing;
  120.         wy += overall.ascent;
  121.         XDrawString16(dpy, d, gc, wx, wy, buf2b, 1);
  122.         wy += overall.descent;
  123.         } else {
  124.         wx = x - (int)((font->max_bounds.rbearing -
  125.                 font->min_bounds.lbearing) >> 1) -
  126.              (int) font->min_bounds.lbearing;
  127.         wy += font->max_bounds.ascent;
  128.         XDrawString16(dpy, d, gc, wx, wy, buf2b, 1);
  129.         wy += font->max_bounds.descent;
  130.         }
  131.     }
  132.     } else {
  133.     for(i = 0, buf = (char *)text ; i < length && *buf ; i++, buf++) {
  134.         if(is_rotate(oc, font) == True) {
  135.         XTextExtents(font, buf, 1,
  136.                  &direction, &font_ascent_return,
  137.                  &font_descent_return, &overall);
  138.         wx = x - (int)((overall.rbearing - overall.lbearing) >> 1) -
  139.              (int) overall.lbearing;
  140.         wy += overall.ascent;
  141.         XDrawString(dpy, d, gc, wx, wy, buf, 1);
  142.         wy += overall.descent;
  143.         } else {
  144.         wx = x - (int)((font->max_bounds.rbearing -
  145.                 font->min_bounds.lbearing) >> 1) -
  146.              (int) font->min_bounds.lbearing;
  147.         wy += font->max_bounds.ascent;
  148.         XDrawString(dpy, d, gc, wx, wy, buf, 1);
  149.         wy += font->max_bounds.descent;
  150.         }
  151.     }
  152.     }
  153.     DBUG_RETURN(wy);
  154. }
  155.  
  156. #define VMAP          0
  157. #define VROTATE       1
  158. #define FONTSCOPE     2
  159.  
  160. extern FontData _XomGetFontDataFromFontSet();
  161.  
  162. static int
  163. DrawStringWithFontSet(dpy, d, oc, fs, gc, x, y, text, length)
  164.     Display *dpy;
  165.     Drawable d;
  166.     XOC oc;
  167.     FontSet fs;
  168.     GC gc;
  169.     int x, y;
  170.     XPointer text;
  171.     int length;
  172. {
  173.     DBUG_ENTER("DrawStringWithFontSet")
  174.     XFontStruct *font;
  175.     Bool is_xchar2b;
  176.     unsigned char *ptr;
  177.     int ptr_len, char_len = 0;
  178.     FontData fd;
  179.     int ret;
  180.  
  181.     ptr = (unsigned char *)text;
  182.     is_xchar2b = fs->is_xchar2b;
  183.  
  184.     while (length > 0) {
  185.         fd = _XomGetFontDataFromFontSet(fs,
  186.             (char *)ptr,length,&ptr_len,is_xchar2b,FONTSCOPE);
  187.     if(ptr_len <= 0)
  188.         break;
  189.         if(fd == (FontData) NULL ||
  190.        (font = fd->font) == (XFontStruct *) NULL){
  191.  
  192.         if((font = fs->font) == (XFontStruct *) NULL)
  193.         break;
  194.         }
  195.  
  196.     switch(oc->core.orientation) {
  197.       case XOMOrientation_LTR_TTB:
  198.       case XOMOrientation_RTL_TTB:
  199.             XSetFont(dpy, gc, font->fid);
  200.  
  201.         if (is_xchar2b) {
  202.         char_len = ptr_len / sizeof(XChar2b);
  203.         XDrawString16(dpy, d, gc, x, y, (XChar2b *)ptr, char_len);
  204.         x += XTextWidth16(font, (XChar2b *)ptr, char_len);
  205.             } else {
  206.         char_len = ptr_len;
  207.         XDrawString(dpy, d, gc, x, y, (char *)ptr, char_len);
  208.         x += XTextWidth(font, (char *)ptr, char_len);
  209.         }
  210.         break;
  211.       case XOMOrientation_TTB_RTL:
  212.       case XOMOrientation_TTB_LTR:
  213.         if(fs->font == font) {
  214.         fd = _XomGetFontDataFromFontSet(fs,
  215.             (char *)ptr,length,&ptr_len,is_xchar2b,VMAP);
  216.         if(ptr_len <= 0)
  217.             break;
  218.         if(fd == (FontData) NULL ||
  219.            (font = fd->font) == (XFontStruct *) NULL)
  220.             break;
  221.  
  222.         if(is_codemap(oc, fd->font) == False) {
  223.             fd = _XomGetFontDataFromFontSet(fs,
  224.                  (char *)ptr,length,&ptr_len,is_xchar2b,VROTATE);
  225.             if(ptr_len <= 0)
  226.             break;
  227.             if(fd == (FontData) NULL ||
  228.                (font = fd->font) == (XFontStruct *) NULL)
  229.             break;
  230.         }
  231.         }
  232.  
  233.         if(is_xchar2b)
  234.         char_len = ptr_len / sizeof(XChar2b);
  235.         else
  236.         char_len = ptr_len;
  237.             XSetFont(dpy, gc, font->fid);
  238.         y = draw_vertical(dpy, d, oc, gc, font, is_xchar2b, x, y,
  239.                    (char *)ptr, char_len);
  240.         break;
  241.     }
  242.  
  243.     if(char_len <= 0)
  244.         break;
  245.  
  246.         length -= char_len;
  247.         ptr += ptr_len;
  248.     }
  249.  
  250.     switch(oc->core.orientation) {
  251.       case XOMOrientation_LTR_TTB:
  252.       case XOMOrientation_RTL_TTB:
  253.     ret = x;
  254.     break;
  255.       case XOMOrientation_TTB_RTL:
  256.       case XOMOrientation_TTB_LTR:
  257.     ret = y;
  258.     }
  259.     DBUG_RETURN(ret);
  260. }
  261.  
  262. /* For VW/UDC */
  263.  
  264. int
  265. _XomGenericDrawString(dpy, d, oc, gc, x, y, type, text, length)
  266.     Display *dpy;
  267.     Drawable d;
  268.     XOC oc;
  269.     GC gc;
  270.     int x, y;
  271.     XOMTextType type;
  272.     XPointer text;
  273.     int length;
  274. {
  275.     DBUG_ENTER("_XomGenericDrawString")
  276.     XlcConv conv;
  277.     XFontStruct *font;
  278.     Bool is_xchar2b;
  279. /* VW/UDC */
  280.     XPointer args[3];
  281.     FontSet fs;
  282. /* VW/UDC */
  283.     XChar2b xchar2b_buf[BUFSIZ], *buf;
  284.     int start_x = x;
  285.     int start_y = y;
  286.     int left = 0, buf_len = 0;
  287.     int next = 0;
  288.  
  289.     conv = _XomInitConverter(oc, type);
  290.     if (conv == NULL)
  291.     DBUG_RETURN(-1);
  292.     
  293.     args[0] = (XPointer) &font;
  294.     args[1] = (XPointer) &is_xchar2b;
  295.     args[2] = (XPointer) &fs;
  296.  
  297.     while (length > 0) {
  298.     buf = xchar2b_buf;
  299.     left = buf_len = BUFSIZ;
  300.  
  301.     if (_XomConvert(oc, conv, (XPointer *) &text, &length,
  302.             (XPointer *) &buf, &left, args, 3) < 0)
  303.         break;
  304.     buf_len -= left;
  305.  
  306. /* For VW/UDC */
  307.     next = DrawStringWithFontSet(dpy, d, oc, fs, gc, x, y,
  308.                      (XPointer)xchar2b_buf, buf_len);
  309.  
  310.     switch(oc->core.orientation) {
  311.       case XOMOrientation_LTR_TTB:
  312.       case XOMOrientation_RTL_TTB:
  313.         x = next;
  314.         break;
  315.       case XOMOrientation_TTB_RTL:
  316.       case XOMOrientation_TTB_LTR:
  317.         y = next;
  318.         break;
  319.     }
  320. /* For VW/UDC */
  321.     }
  322.  
  323.     x -= start_x;
  324.     y -= start_y;
  325.  
  326.     DBUG_RETURN(x);
  327. }
  328.  
  329. int
  330. #if NeedFunctionPrototypes
  331. _XmbGenericDrawString(Display *dpy, Drawable d, XOC oc, GC gc, int x, int y,
  332.               _Xconst char *text, int length)
  333. #else
  334. _XmbGenericDrawString(dpy, d, oc, gc, x, y, text, length)
  335.     Display *dpy;
  336.     Drawable d;
  337.     XOC oc;
  338.     GC gc;
  339.     int x, y;
  340.     char *text;
  341.     int length;
  342. #endif
  343. {
  344.     DBUG_ENTER("_XmbGenericDrawString")
  345.     int result = _XomGenericDrawString(dpy, d, oc, gc, x, y, XOMMultiByte,
  346.                  (XPointer) text, length);
  347.     DBUG_RETURN(result);
  348. }
  349.  
  350. int
  351. #if NeedFunctionPrototypes
  352. _XwcGenericDrawString(Display *dpy, Drawable d, XOC oc, GC gc, int x, int y,
  353.               _Xconst wchar_t *text, int length)
  354. #else
  355. _XwcGenericDrawString(dpy, d, oc, gc, x, y, text, length)
  356.     Display *dpy;
  357.     Drawable d;
  358.     XOC oc;
  359.     GC gc;
  360.     int x, y;
  361.     wchar_t *text;
  362.     int length;
  363. #endif
  364. {
  365.     DBUG_ENTER("_XwcGenericDrawString")
  366.     int result = _XomGenericDrawString(dpy, d, oc, gc, x, y, XOMWideChar,
  367.                  (XPointer) text, length);
  368.     DBUG_RETURN(result);
  369. }
  370.