home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xibm.zip / ibm8514 / brcText.c < prev    next >
C/C++ Source or Header  |  1991-12-16  |  27KB  |  1,030 lines

  1. /*
  2.  * $Id: brcText.c,v 1.1 1991/09/20 19:10:24 mtranle Exp $
  3.  *
  4.  * Copyright IBM Corporation 1987,1990
  5.  *
  6.  * All Rights Reserved
  7.  *
  8.  * Permission to use, copy, modify, and distribute this software and its
  9.  * documentation for any purpose and without fee is hereby granted,
  10.  * provided that the above copyright notice appear in all copies and that 
  11.  * both that copyright notice and this permission notice appear in
  12.  * supporting documentation, and that the name of IBM not be
  13.  * used in advertising or publicity pertaining to distribution of the
  14.  * software without specific, written prior permission.
  15.  *
  16.  * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  17.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
  18.  * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  19.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  21.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  22.  * SOFTWARE.
  23.  *
  24. */
  25. /*
  26.  * PRPQ 5799-PFF (C) COPYRIGHT IBM CORPORATION 1987,1990
  27.  * LICENSED MATERIALS - PROPERTY OF IBM
  28.  * REFER TO COPYRIGHT INSTRUCTIONS FORM NUMBER G120-2083
  29.  */
  30. /*
  31.  *  Hardware interface routines for IBM 8514/A adapter for
  32.  *  X.11 server(s) on IBM equipment.
  33.  *
  34.  */
  35.  
  36. /* Draw character glyphs on the screen, knowing that they have been
  37.  * cached offscreen.  Worry about traditional X clipping and such.
  38.  * 
  39.  * You may wonder why I figure the background rectangle size every
  40.  * time this is called, rather than just multiplying some font-specific
  41.  * char size times the number of glyphs and using that.  The protocol
  42.  * evidently has other views of this issue, so we do what it says;
  43.  * the protocol is the bible here.  If the glyphs vary widely in size,
  44.  * we come through with flying colors. (figuratively)
  45.  * 
  46.  */
  47. #include    "X.h"
  48. #include    "Xproto.h"
  49. #include    "scrnintstr.h"
  50. #include    "dixfontstr.h"
  51. #include    "gcstruct.h"
  52. #include    "windowstr.h"
  53. #include    "pixmapstr.h"
  54. #include    "regionstr.h"
  55.  
  56. #include    "mfb.h"
  57.  
  58. #include    "OScompiler.h"
  59.  
  60. #include    "ppc.h"
  61.  
  62. #include    "x8514.h"
  63. #include     "brcFonts.h"
  64.  
  65. #include    "ibmTrace.h"
  66.  
  67. extern int ibm8514Disabled ;
  68.  
  69. extern ibm8514FontCacheRec ibm8514FontCacheEntry[];
  70. extern int ibm8514cursorSemaphore ;
  71. extern int mfbGCPrivateIndex ;
  72.  
  73. #if !defined(NO_FUNCTION_PROTOTYPES)
  74. static int ibm8514StipCachedText( DrawablePtr pDraw, GCPtr pGC, int x, int y,
  75.                   int count, unsigned char *chars,
  76.                   FontEncoding fontEncoding);
  77. static int ibm8514CachedPolyText( DrawablePtr pDraw, GCPtr pGC, int x, int y,
  78.                   int count, unsigned char *chars,
  79.                   FontEncoding fontEncoding);
  80. static int ibm8514CachedImageText( DrawablePtr pDraw, GCPtr pGC, int x, int y,
  81.                   int count, unsigned char *chars,
  82.                   FontEncoding fontEncoding);
  83. static int ibm8514PolyText( DrawablePtr pDraw, GCPtr pGC, int x, int y,
  84.                int count, unsigned char *chars,
  85.                FontEncoding fontEncoding );
  86. static int ibm8514ImageText( DrawablePtr pDraw, GCPtr pGC, int x, int y,
  87.                 int count, unsigned char *chars,
  88.                 FontEncoding fontEncoding );
  89. static void GetStippleOnStage(GCPtr pGC, BoxRec *pbox);
  90. static unsigned int miWidth( unsigned int n,
  91.                  CharInfoPtr charinfo[] );
  92. #endif
  93.  
  94. #ifdef i386
  95. #ifdef __GNUC__
  96. #define SWAPBYTE(x) \
  97.     ({ unsigned short __value = (x);                            \
  98.        asm("xchgb %%al,%%ah" : "=a" (__value) : "0" (__value)); \
  99.        __value;                                                 \
  100.        })
  101. #else
  102. #define SWAPBYTE(x) ((unsigned short)(((x) << 8) | ((unsigned char)x >> 8)))
  103. #endif /* __GNUC__ */
  104. #else
  105. #define SWAPBYTE(x) (x)
  106. #endif
  107.  
  108. int
  109. ibm8514PolyText8(pDraw, pGC, x, y, count, chars)
  110.     DrawablePtr pDraw;
  111.     GCPtr    pGC;
  112.     int        x, y;
  113.     int     count;
  114.     unsigned char *chars;
  115. {
  116.     return ibm8514PolyText(pDraw, pGC, x, y, count, chars, Linear8Bit);
  117. }
  118.  
  119. int
  120. ibm8514PolyText16(pDraw, pGC, x, y, count, chars)
  121.     DrawablePtr pDraw;
  122.     GCPtr    pGC;
  123.     int        x, y;
  124.     int        count;
  125.     unsigned short *chars;
  126. {
  127.     return ibm8514PolyText( pDraw, pGC, x, y, count, (unsigned char *)chars,
  128.                ( FONTLASTROW(pGC->font) ?
  129.                  TwoD16Bit : Linear16Bit) ) ;
  130. }
  131.  
  132. void
  133. ibm8514ImageText8(pDraw, pGC, x, y, count, chars)
  134.     DrawablePtr pDraw;
  135.     GCPtr    pGC;
  136.     int        x, y;
  137.     int        count;
  138.     unsigned char *chars;
  139. {
  140.     ibm8514ImageText(pDraw, pGC, x, y, count, chars, Linear8Bit);
  141. }
  142.  
  143. void
  144. ibm8514ImageText16(pDraw, pGC, x, y, count, chars)
  145.     DrawablePtr pDraw;
  146.     GCPtr    pGC;
  147.     int        x, y;
  148.     int        count;
  149.     unsigned short *chars;
  150. {
  151.     ibm8514ImageText( pDraw, pGC, x, y, count, (unsigned char *)chars,
  152.              ( FONTLASTROW(pGC->font)
  153.               ? TwoD16Bit : Linear16Bit) ) ;
  154. }
  155.  
  156.  
  157. static int
  158. ibm8514PolyText(pDraw, pGC, x, y, count, chars, fontEncoding )
  159.     DrawablePtr pDraw;
  160.     GCPtr    pGC;
  161.     int        x, y;
  162.     int        count;
  163.     unsigned char *chars;
  164.     FontEncoding fontEncoding;
  165. {
  166.     CharInfoPtr *charinfo;
  167.     unsigned int n, w = 0;
  168.  
  169.     if ( (long) FontGetPrivate(pGC->font, pDraw->pScreen->myNum) )
  170.     {
  171.     switch (pGC->fillStyle )
  172.     {
  173.       case FillSolid:
  174.         return ibm8514CachedPolyText(pDraw, pGC, 
  175.                      x, y, count, chars, fontEncoding);
  176.       case FillOpaqueStippled :
  177.       case FillStippled :
  178.         return ibm8514StipCachedText( pDraw, pGC, 
  179.                      x, y, count, chars, fontEncoding);
  180.       default:
  181.         break;
  182.     }
  183.     }
  184.  
  185.     charinfo = (CharInfoPtr *) ALLOCATE_LOCAL( count*sizeof(CharInfoPtr ));
  186.     if ( !charinfo )
  187.     return x ;
  188.     GetGlyphs(pGC->font, count, chars, fontEncoding, &n, charinfo);
  189.     if ( n )
  190.     {
  191.     w = miWidth(n, charinfo);
  192.     (*pGC->ops->PolyGlyphBlt)(pDraw, pGC, x, y, n, charinfo,
  193.                   FONTGLYPHS(pGC->font));
  194.     }
  195.  
  196.     DEALLOCATE_LOCAL(charinfo);
  197.     return x + w ;
  198. }
  199.  
  200. static int
  201. ibm8514ImageText(pDraw, pGC, x, y, count, chars, fontEncoding)
  202.     DrawablePtr pDraw;
  203.     GCPtr    pGC;
  204.     int     x, y;
  205.     int     count;
  206.     unsigned char *chars;
  207.     FontEncoding fontEncoding;
  208. {
  209.     CharInfoPtr *charinfo;
  210.     unsigned int n, w = 0;
  211.  
  212.     if( (long)FontGetPrivate(pGC->font, pDraw->pScreen->myNum) < 20 )
  213.     {
  214.     if ( !(charinfo =
  215.            (CharInfoPtr *)ALLOCATE_LOCAL( count*sizeof(CharInfoPtr ))))
  216.         return x ;
  217.     GetGlyphs(pGC->font, count, chars, fontEncoding, &n, charinfo);
  218.     if ( n )
  219.     {
  220.         w = miWidth(n, charinfo);
  221.         (*pGC->ops->ImageGlyphBlt)(pDraw, pGC, x, y, n, charinfo,
  222.                        FONTGLYPHS(pGC->font));
  223.     }
  224.         
  225.     DEALLOCATE_LOCAL(charinfo);
  226.     return x + w ;
  227.     }
  228.     else
  229.     return ibm8514CachedImageText(pDraw, pGC, x, y, count, chars,
  230.                       fontEncoding);
  231. }
  232.  
  233. static unsigned int
  234. miWidth(n, charinfo)
  235.     unsigned int n;
  236.     CharInfoPtr charinfo[];
  237. {
  238.     unsigned int w = 0;
  239.  
  240.     while ( n-- )
  241.     w += charinfo[n]->metrics.characterWidth ;
  242.  
  243.     return w;
  244. }
  245.  
  246. static int 
  247. ibm8514CachedPolyText( pDraw, pGC, x, y, count, chars, fontEncoding)
  248.     DrawablePtr pDraw;
  249.     GCPtr    pGC;
  250.     int        x, y;
  251.     int        count;
  252.     unsigned char *chars;
  253.     FontEncoding fontEncoding;
  254. {
  255.     ExtentInfoRec     info;
  256.     RegionPtr        prgnClip, pCC;
  257.     int            CursorIsSaved ;
  258.     unsigned long int    rPM ;
  259.     int            nbox, x0, y0;
  260.     ScreenPtr        pscr;
  261.     FontPtr        pFont;
  262.     InstalledFontPtr    pInFont;
  263.     InstalledCharPtr    pChar;
  264.     xRectangle        backrect;
  265.     BoxRec        *pbox, bbox, cbox;
  266.     xCharInfo        *pMetrics;
  267.     int            maxw, maxh, charoffset, lineoffset;
  268.     int            charLast;
  269.     unsigned short     *chars16 = (unsigned short *) chars;
  270.     unsigned long    n = count;
  271.  
  272.     CharInfoPtr        *q;
  273.  
  274.     int            index, i;
  275.  
  276.     pCC = ((ppcPrivGC *)pGC->devPrivates[mfbGCPrivateIndex].ptr)->
  277.     pCompositeClip;
  278.     if ( !( nbox = REGION_NUM_RECTS(pCC) ) )
  279.     return 0 ;
  280.     pbox     = REGION_RECTS(pCC);
  281.  
  282.     pscr     = pGC->pScreen;
  283.     pFont     = pGC->font;
  284.     pInFont     = (InstalledFontPtr) FontGetPrivate(pFont, pscr->myNum);
  285.  
  286.     lineoffset     = pInFont->startline;
  287.     charoffset     = pInFont->firstchar;
  288.     charLast       = pInFont->lastchar;
  289.  
  290.     {
  291.     CharInfoPtr *ppci =
  292.         (CharInfoPtr *) ALLOCATE_LOCAL(count*sizeof(CharInfoPtr));
  293.  
  294.     switch ( fontEncoding)
  295.     {
  296.       case Linear16Bit:
  297.         {
  298.         unsigned short *p;
  299.         unsigned short *end = (unsigned short *)chars + count;
  300.         q   = ppci;
  301.         for( p = (unsigned short *)chars ; p < end; p++ )
  302.         {        /* do byte swapping */
  303.             *p = SWAPBYTE(*p);
  304.             if ( (charoffset <= *p) && (charLast  >= *p) )
  305.             *q++ = pInFont->ppCharacter[*p-charoffset]->pInfo;
  306.             else
  307.             n--;    /* ignore this character */
  308.         }
  309.         break;
  310.         }
  311.       case Linear8Bit:
  312.         {
  313.         unsigned char *p;
  314.         unsigned char *end = chars + count;
  315.         q   = ppci;
  316.         for( p = chars; p < end; p++ )
  317.         {
  318.             if ( (charoffset <= *p) && (charLast  >= *p) )
  319.             *q++ = pInFont->ppCharacter[*p-charoffset]->pInfo;
  320.             else
  321.             n--;    /* ignore this character */
  322.         }
  323.         break;
  324.         }
  325.       default:
  326.         ErrorF("ibm8514CachedPolyText: bad font encoding");
  327.         return 0;
  328.     }
  329.  
  330.     QueryGlyphExtents(pFont,ppci,n,&info);
  331.     DEALLOCATE_LOCAL(ppci);
  332.     }
  333.  
  334.     rPM     = ibm8514FontCacheEntry[pInFont->CacheIndex].RPlaneMask;
  335.  
  336.     x         += pDraw->x;
  337.     y         += pDraw->y;
  338.  
  339.     backrect.x = x + info.overallLeft;
  340.     backrect.y = y - FONTASCENT(pFont);
  341.     backrect.width = info.overallRight - info.overallLeft;
  342.     backrect.width = MAX( backrect.width, info.overallWidth );
  343.     backrect.height = FONTASCENT(pFont) + FONTDESCENT(pFont);
  344.  
  345.     maxw = n * FONT_MAX_WIDTH(&pFont->info);
  346.     maxh = FONT_MAX_HEIGHT(&pFont->info);
  347.  
  348.     CursorIsSaved = !ibm8514cursorSemaphore
  349.     && ( ibm8514CheckCursor( backrect.x, backrect.y,
  350.                 backrect.width, backrect.height )
  351.         /* if fonts are correct, the next line may get deleted someday */
  352.         || ibm8514CheckCursor(x, y, maxw, maxh) ) ;
  353.     ibm8514cursorSemaphore++ ;
  354.  
  355.     bbox.x1 = x + info.overallLeft;
  356.     bbox.y1 = y - info.overallAscent;
  357.     bbox.x2 = x + info.overallRight;
  358.     bbox.y2 = y + info.overallDescent;
  359.  
  360.     switch( (*pscr->RectIn)(pCC, &bbox) )
  361.     {
  362.       case rgnOUT: 
  363.     break;
  364.       case rgnIN:
  365.     while( count-- )
  366.     {
  367.         index = ( fontEncoding == Linear8Bit ) ? *chars++ : *chars16++;
  368.         if( (index < charoffset) || (index > charLast) )
  369.         continue;
  370.         else
  371.         index -= charoffset;
  372.  
  373.         pChar    = (InstalledCharPtr)pInFont->ppCharacter[index];
  374.         pMetrics = (xCharInfo *)(&(pChar->pInfo->metrics));
  375.         if( !ibm8514Disabled && pMetrics->characterWidth)
  376.         {
  377.         x0 = x + pMetrics->leftSideBearing;
  378.         y0 = y - pMetrics->ascent;
  379.         ibm8514BlitFG(rPM,pGC->planemask,pGC->fgPixel,pGC->alu,
  380.                   pChar->x, lineoffset + pChar->y, 
  381.                   x0, y0, pChar->w, pChar->h);
  382.         }
  383.         x += pMetrics->characterWidth;
  384.     }     
  385.     break;
  386.       case rgnPART:
  387.     prgnClip = (*(pscr->RegionCreate))((BoxRec *)NULL,1);
  388.     while( count-- )
  389.     {
  390.         index = ( fontEncoding == Linear8Bit ) ? *chars++ : *chars16++;
  391.         if( (index < charoffset) || (index > charLast) )
  392.         continue;
  393.         else
  394.         index -= charoffset;
  395.  
  396.         pChar    = (InstalledCharPtr)pInFont->ppCharacter[index];
  397.         pMetrics = (xCharInfo *)(&(pChar->pInfo->metrics));
  398.         if( !ibm8514Disabled && pMetrics->characterWidth )
  399.         {
  400.         cbox.x1 = x0 = x + pMetrics->leftSideBearing;
  401.         cbox.y1 = y0 = y - pMetrics->ascent;
  402.         cbox.x2 = cbox.x1 + pChar->w;
  403.         cbox.y2 = cbox.y1 + pChar->h;
  404.  
  405.         switch( (*pscr->RectIn)(pCC, &cbox) )
  406.         {
  407.           case rgnOUT:
  408.             break;
  409.           case rgnIN:
  410.             ibm8514BlitFG(rPM,pGC->planemask,pGC->fgPixel,pGC->alu,
  411.                   pChar->x, lineoffset+pChar->y, 
  412.                   x0, y0, 
  413.                   pChar->w, pChar->h);
  414.             break;
  415.           case rgnPART:
  416.             (*(pscr->RegionReset))( prgnClip, &cbox);
  417.             (*(pscr->Intersect))( prgnClip,prgnClip,pCC);
  418.             pbox = REGION_RECTS(prgnClip);
  419.             nbox = REGION_NUM_RECTS(prgnClip);
  420.             if( nbox==0 ) break;
  421.             for( i = 0 ; i <nbox; i++, pbox++ )
  422.             {
  423.             ibm8514ClearQueue(4);
  424.             SETXMIN(pbox->x1);
  425.             SETYMIN(pbox->y1);
  426.             SETXMAX(pbox->x2-1);
  427.             SETYMAX(pbox->y2-1);
  428.             ibm8514BlitFG(rPM,pGC->planemask,pGC->fgPixel,pGC->alu,
  429.                       pChar->x, lineoffset + pChar->y, 
  430.                       x0, y0, 
  431.                       pChar->w, pChar->h);
  432.             }
  433.             ibm8514ClearQueue(4);
  434.             SETXMIN(0);
  435.             SETYMIN(0);
  436.             SETXMAX(_8514_SCREENWIDTH-1);
  437.             SETYMAX( 1023 );
  438.             break;
  439.         }        /* end second switch */
  440.         }
  441.         x += pMetrics->characterWidth;
  442.     }
  443.     (*(pscr->RegionDestroy))(prgnClip);
  444.       default:
  445.     break;
  446.     }                /* end main switch */
  447.     if ( !(--ibm8514cursorSemaphore) && CursorIsSaved )
  448.     ibm8514ReplaceCursor();
  449.  
  450.     return x- pDraw->x;
  451. }
  452.  
  453. static int
  454. ibm8514CachedImageText( pDraw, pGC, x, y, count, chars, fontEncoding)
  455.     DrawablePtr pDraw;
  456.     GCPtr    pGC;
  457.     int        x, y;
  458.     int        count;
  459.     unsigned char *chars;
  460.     FontEncoding fontEncoding;
  461. {
  462.     ExtentInfoRec     info;
  463.     RegionPtr        prgnClip, pCC;
  464.     int            CursorIsSaved;
  465.     unsigned long int    rPM ;
  466.     int            nbox, x0, y0;
  467.     ScreenPtr        pscr;
  468.     FontPtr        pFont;
  469.     InstalledFontPtr    pInFont;
  470.     InstalledCharPtr    pChar;
  471.     xRectangle        backrect;
  472.     BoxRec        *pbox, bbox, cbox;
  473.     xCharInfo        *pMetrics;
  474.     int            maxw, maxh, charoffset, lineoffset;
  475.     int            charLast;
  476.     unsigned short     *chars16 = (unsigned short *) chars;
  477.     unsigned long    n = count;
  478.  
  479.     CharInfoPtr        *q;
  480.  
  481.     int            index, i;
  482.  
  483.     pCC = ((ppcPrivGC *)pGC->devPrivates[mfbGCPrivateIndex].ptr)->
  484.     pCompositeClip;
  485.     if ( !( nbox = REGION_NUM_RECTS(pCC) ) )
  486.     return 0 ;
  487.     pbox     = REGION_RECTS(pCC);
  488.  
  489.     pscr     = pGC->pScreen;
  490.     pFont     = pGC->font;
  491.     pInFont     = (InstalledFontPtr) FontGetPrivate(pFont, pscr->myNum);
  492.  
  493.     lineoffset     = pInFont->startline;
  494.     charoffset     = pInFont->firstchar;
  495.     charLast       = pInFont->lastchar;
  496.  
  497.     {
  498.     CharInfoPtr *ppci =
  499.         (CharInfoPtr *) ALLOCATE_LOCAL(count*sizeof(CharInfoPtr));
  500.  
  501.     switch ( fontEncoding)
  502.     {
  503.       case Linear16Bit:
  504.         {
  505.         unsigned short *p;
  506.         unsigned short *end = (unsigned short *)chars + count;
  507.         q   = ppci;
  508.         for( p = (unsigned short *)chars ; p < end; p++ )
  509.         {        /* do byte swapping */
  510.             *p = SWAPBYTE(*p);
  511.             if ( (charoffset <= *p) && (charLast  >= *p) )
  512.             *q++ = pInFont->ppCharacter[*p-charoffset]->pInfo;
  513.             else
  514.             n--;    /* ignore this character */
  515.         }
  516.         break;
  517.         }
  518.  
  519.       case Linear8Bit:
  520.         {
  521.         unsigned char *p;
  522.         unsigned char *end = chars + count;
  523.         q   = ppci;
  524.         for( p = chars; p < end; p++ )
  525.         {
  526.             if ( (charoffset <= *p) && (charLast  >= *p) )
  527.             *q++ = pInFont->ppCharacter[*p-charoffset]->pInfo;
  528.             else
  529.             n--;    /* ignore this character */
  530.         }
  531.         break;
  532.         }
  533.       default:
  534.         ErrorF("ibm8514CachedImageText: bad font encoding");
  535.         return 0;
  536.     }
  537.  
  538.     QueryGlyphExtents(pFont,ppci,n,&info);
  539.     DEALLOCATE_LOCAL(ppci);
  540.     }
  541.  
  542.     rPM     = ibm8514FontCacheEntry[pInFont->CacheIndex].RPlaneMask;
  543.   
  544.     x         += pDraw->x;
  545.     y         += pDraw->y;
  546.  
  547.     backrect.x = x + info.overallLeft;
  548.     backrect.y = y - FONTASCENT(pFont);
  549.     backrect.width = info.overallRight - info.overallLeft;
  550.     backrect.width = MAX( backrect.width, info.overallWidth );
  551.     backrect.height = FONTASCENT(pFont) + FONTDESCENT(pFont);
  552.  
  553.     maxw = n * FONT_MAX_WIDTH(&pFont->info);
  554.     maxh = FONT_MAX_HEIGHT(&pFont->info);
  555.  
  556.     CursorIsSaved = !ibm8514cursorSemaphore
  557.     && ( ibm8514CheckCursor( backrect.x, backrect.y,
  558.                 backrect.width, backrect.height )
  559.         /* if fonts are correct, the next line may get deleted someday */
  560.         || ibm8514CheckCursor(x, y, maxw, maxh) ) ;
  561.     ibm8514cursorSemaphore++ ;
  562.  
  563.     if( !ibm8514Disabled )
  564.     {
  565.     for( i = 0 ; i <nbox; i++, pbox++ )
  566.     {
  567.         ibm8514ClearQueue(4);
  568.         SETXMIN(pbox->x1);
  569.         SETYMIN(pbox->y1);
  570.         SETXMAX(pbox->x2-1);
  571.         SETYMAX(pbox->y2-1);
  572.         ibm8514DrawRectangle(pGC->bgPixel,GXcopy,pGC->planemask,
  573.                  backrect.x, backrect.y,
  574.                  backrect.width, backrect.height);
  575.     }
  576.     ibm8514ClearQueue(4);
  577.     SETXMIN(0);
  578.     SETYMIN(0);
  579.     SETXMAX(_8514_SCREENWIDTH-1);
  580.     SETYMAX( 1023 );
  581.     }
  582.  
  583.     bbox.x1 = x + info.overallLeft;
  584.     bbox.y1 = y - info.overallAscent;
  585.     bbox.x2 = x + info.overallRight;
  586.     bbox.y2 = y + info.overallDescent;
  587.  
  588.     switch ( (*pscr->RectIn)(pCC, &bbox))
  589.     {
  590.       case rgnOUT: 
  591.     break;
  592.       case rgnIN:
  593.     while( count-- )
  594.     {
  595.         index = ( fontEncoding == Linear8Bit ) ? *chars++ : *chars16++;
  596.         if( (index < charoffset) || (index > charLast) )
  597.         continue;
  598.         else
  599.         index -= charoffset;
  600.         pChar    = (InstalledCharPtr)pInFont->ppCharacter[index];
  601.         pMetrics     = (xCharInfo *)(&(pChar->pInfo->metrics));
  602.         if( !ibm8514Disabled && pMetrics->characterWidth )
  603.         {
  604.         x0 = x + pMetrics->leftSideBearing;
  605.         y0 = y - pMetrics->ascent;
  606.         ibm8514BlitFG(rPM,pGC->planemask,pGC->fgPixel,GXcopy,
  607.                   pChar->x, lineoffset + pChar->y, 
  608.                   x0, y0, pChar->w, pChar->h);
  609.         }
  610.         x += pMetrics->characterWidth;
  611.     }     
  612.     break;
  613.       case rgnPART:
  614.     prgnClip = (*(pscr->RegionCreate))(NULL,REGION_NUM_RECTS(pCC));
  615.     while( count-- )
  616.     {
  617.         index = ( fontEncoding == Linear8Bit ) ? *chars++ : *chars16++;
  618.         if( (index < charoffset) || (index > charLast) )
  619.         continue;
  620.         else
  621.         index -= charoffset;
  622.  
  623.         pChar=(InstalledCharPtr)pInFont->ppCharacter[index];
  624.         pMetrics = (xCharInfo *)(&(pChar->pInfo->metrics));
  625.         if( !ibm8514Disabled && pMetrics->characterWidth )
  626.         {
  627.         cbox.x1 = x0 = x + pMetrics->leftSideBearing;
  628.         cbox.y1 = y0 = y - pMetrics->ascent;
  629.         cbox.x2 = cbox.x1 + pChar->w;
  630.         cbox.y2 = cbox.y1 + pChar->h;
  631.  
  632.         switch( (*pscr->RectIn)(pCC, &cbox) )
  633.         {
  634.           case rgnOUT:
  635.             break;
  636.           case rgnIN:
  637.             ibm8514BlitFG(rPM,pGC->planemask,pGC->fgPixel,GXcopy,
  638.                   pChar->x, lineoffset+pChar->y, 
  639.                   x0, y0, 
  640.                   pChar->w, pChar->h);
  641.             break;
  642.           case rgnPART:
  643.             (*(pscr->RegionReset))( prgnClip,&cbox);
  644.             (*(pscr->Intersect))( prgnClip,prgnClip,pCC);
  645.             pbox = REGION_RECTS(prgnClip);
  646.             nbox = REGION_NUM_RECTS(prgnClip);
  647.             if( nbox == 0 ) break;
  648.             for (i = 0 ; i <nbox; i++, pbox++)
  649.             {
  650.             ibm8514ClearQueue(4);
  651.             SETXMIN(pbox->x1);
  652.             SETYMIN(pbox->y1);
  653.             SETXMAX(pbox->x2-1);
  654.             SETYMAX(pbox->y2-1);
  655.             ibm8514BlitFG(rPM,pGC->planemask,pGC->fgPixel,GXcopy,
  656.                       pChar->x, lineoffset + pChar->y, 
  657.                       x0, y0, 
  658.                       pChar->w, pChar->h);
  659.             }
  660.             ibm8514ClearQueue(4);
  661.             SETXMIN(0);
  662.             SETYMIN(0);
  663.             SETXMAX(_8514_SCREENWIDTH-1);
  664.             SETYMAX( 1023 );
  665.  
  666.             break;
  667.         }        /* end second switch */
  668.         }
  669.         x += pMetrics->characterWidth;
  670.     }
  671.     (*(pscr->RegionDestroy))(prgnClip);
  672.       default:
  673.     break;
  674.     }                /* end main switch */
  675.     if( !(--ibm8514cursorSemaphore) && CursorIsSaved )
  676.     ibm8514ReplaceCursor();
  677.  
  678.     return x - pDraw->x;
  679. }
  680.  
  681. static int 
  682. ibm8514StipCachedText( pDraw, pGC, x, y, count, chars, fontEncoding)
  683.     DrawablePtr pDraw;
  684.     GCPtr    pGC;
  685.     int        x, y;
  686.     int        count;
  687.     unsigned char *chars;
  688.     FontEncoding fontEncoding;
  689. {
  690.     ExtentInfoRec     info;
  691.     RegionPtr        prgnDst, pCC;
  692.     int            CursorIsSaved ;
  693.     unsigned long    rPM ;
  694.     int            nbox, x0, y0;
  695.     unsigned char    *ichars = chars;
  696.     ScreenPtr        pscr;
  697.     FontPtr        pFont;
  698.     InstalledFontPtr    pInFont;
  699.     InstalledCharPtr    pChar;
  700.     BoxRec        *pbox, bbox ;
  701.     xCharInfo        *pMetrics;
  702.     int            maxw, maxh, charoffset, lineoffset;
  703.     int            charLast;
  704.     unsigned short     *chars16 = (unsigned short *) chars;
  705.     int            stageX, stageY;
  706.     unsigned long    n = count;
  707.  
  708.     CharInfoPtr        *q;
  709.  
  710.     int            icount, index;
  711.  
  712.     pCC = ((ppcPrivGC *)pGC->devPrivates[mfbGCPrivateIndex].ptr)->
  713.     pCompositeClip;
  714.  
  715.     if (!( REGION_NUM_RECTS(pCC)))  return x;
  716.     if (pGC->alu == GXnoop) return x;
  717.  
  718.     pscr     = pGC->pScreen;
  719.     pFont     = pGC->font;
  720.     pInFont     = (InstalledFontPtr) FontGetPrivate(pFont, pscr->myNum);
  721.  
  722.     lineoffset     = pInFont->startline;
  723.     charoffset     = pInFont->firstchar;
  724.     charLast       = pInFont->lastchar;
  725.  
  726.     {
  727.     CharInfoPtr *ppci =
  728.         (CharInfoPtr *) ALLOCATE_LOCAL(count*sizeof(CharInfoPtr));
  729.  
  730.     switch ( fontEncoding)
  731.     {
  732.       case Linear16Bit:
  733.         {
  734.         unsigned short *p;
  735.         unsigned short *end = (unsigned short *)chars + count;
  736.         q   = ppci;
  737.         for( p = (unsigned short *)chars ; p < end; p++ )
  738.         {        /* do byte swapping */
  739.             *p = SWAPBYTE(*p);
  740.             if ( (charoffset <= *p) && (charLast  >= *p) )
  741.             *q++ = pInFont->ppCharacter[*p-charoffset]->pInfo;
  742.             else
  743.             n--;    /* ignore this character */
  744.         }
  745.         break;
  746.         }
  747.  
  748.       case Linear8Bit:
  749.         {
  750.         unsigned char *p;
  751.         unsigned char *end = chars + count;
  752.         q   = ppci;
  753.         for( p = chars; p < end; p++ )
  754.         {
  755.             if ( (charoffset <= *p) && (charLast  >= *p) )
  756.             *(q++) = pInFont->ppCharacter[*p-charoffset]->pInfo;
  757.             else
  758.             n--;    /* ignore this character */
  759.         }
  760.         break;
  761.         }
  762.       default:
  763.         ErrorF("ibm8514CachedPolyText: bad font encoding");
  764.         return 0;
  765.     }
  766.  
  767.     QueryGlyphExtents(pFont,ppci,n,&info);
  768.     DEALLOCATE_LOCAL(ppci);
  769.     }
  770.  
  771.     rPM     = ibm8514FontCacheEntry[pInFont->CacheIndex].RPlaneMask;
  772.  
  773.     x         += pDraw->x;
  774.     y         += pDraw->y;
  775.  
  776.     maxw = n * FONT_MAX_WIDTH(&pFont->info);
  777.     maxh = FONT_MAX_HEIGHT(&pFont->info);
  778.  
  779.     bbox.x1 = x + info.overallLeft;
  780.     bbox.y1 = y - info.overallAscent;
  781.     bbox.x2 = x + info.overallRight;
  782.     bbox.y2 = y + info.overallDescent;
  783.  
  784.  
  785.     prgnDst = (* pscr->RegionCreate )( &bbox, REGION_NUM_RECTS(pCC)) ;
  786.     (* pscr->Intersect)( prgnDst, prgnDst, pCC ) ;
  787.  
  788.     if (!( REGION_NUM_RECTS(prgnDst)))
  789.     return x- pDraw->x;
  790.  
  791.     CursorIsSaved = !ibm8514cursorSemaphore
  792.     && ( ibm8514CheckCursor( bbox.x1, bbox.y1,
  793.                 bbox.x2 - bbox.x1, bbox.x2 - bbox.x1 )
  794.         /* if fonts are correct, the next line may get deleted someday */
  795.         || ibm8514CheckCursor(x, y, maxw, maxh) ) ;
  796.     ibm8514cursorSemaphore++ ;
  797.  
  798.     switch (pGC->fillStyle)
  799.     {
  800.       case FillOpaqueStippled:
  801.     stageX = 0;
  802.     stageY = MONO_STAGE_Y + info.overallAscent;
  803.     if( !ibm8514Disabled )
  804.     {
  805.         icount = count;
  806.         GetStippleOnStage(pGC, &bbox);
  807.         while ( icount-- )
  808.         {
  809.         index = ( fontEncoding == Linear8Bit ) ? *chars++ : *chars16++;
  810.         if( (index < charoffset) || (index > charLast) )
  811.             continue;
  812.         else
  813.             index -= charoffset;
  814.         
  815.         pChar=(InstalledCharPtr)pInFont->ppCharacter[index];
  816.         pMetrics = (xCharInfo *)(&(pChar->pInfo->metrics));
  817.         if( (pMetrics->characterWidth) && 
  818.             (stageX+x+pChar->w >= bbox.x1) )
  819.         {
  820.             x0 = stageX + pMetrics->leftSideBearing;
  821.             y0 = stageY - pMetrics->ascent;
  822.             ibm8514BlitFGBG(rPM, MONO_STAGE_WPLANE,
  823.                     255,0,GXandInverted,
  824.                     pChar->x, lineoffset + pChar->y, 
  825.                     x0, y0, 
  826.                     pChar->w, pChar->h);
  827.         }
  828.         stageX += pMetrics->characterWidth;
  829.         if( stageX + x > bbox.x2 ) break;
  830.         }     
  831.  
  832.         for( nbox= REGION_NUM_RECTS(prgnDst), pbox= REGION_RECTS(prgnDst);
  833.         nbox--;
  834.         pbox++ )
  835.         {
  836.         x0 = pbox->x1;
  837.         y0 = pbox->y1;
  838.         ibm8514BlitFG(MONO_STAGE_RPLANE,
  839.                   pGC->planemask, pGC->bgPixel, pGC->alu,
  840.                   MONO_STAGE_X + x0 - x,
  841.                   stageY +y0-y,
  842.                   x0, y0,
  843.                   pbox->x2 - x0,
  844.                   pbox->y2 - y0 );
  845.         }
  846.     }
  847.  
  848.                 /* fall through to do the foreground */
  849.       case FillStippled:
  850.     stageX = 0;
  851.     stageY = MONO_STAGE_Y + info.overallAscent;
  852.     if( !ibm8514Disabled )
  853.     {
  854.         icount = count;
  855.         GetStippleOnStage(pGC, &bbox);
  856.         if( fontEncoding == Linear8Bit )
  857.         chars = ichars;
  858.         else
  859.         chars16 = (unsigned short *)ichars;
  860.         while( icount-- )
  861.         {
  862.         index = ( fontEncoding == Linear8Bit ) ? *chars++ : *chars16++;
  863.         if( (index < charoffset) || (index > charLast) )
  864.             continue;
  865.         else
  866.             index -= charoffset;
  867.         
  868.         pChar=(InstalledCharPtr)pInFont->ppCharacter[index];
  869.         pMetrics = (xCharInfo *)(&(pChar->pInfo->metrics));
  870.         if( (pMetrics->characterWidth) && 
  871.             (stageX+x+pChar->w >= bbox.x1) )
  872.         {
  873.             x0 = stageX + pMetrics->leftSideBearing;
  874.             y0 = stageY - pMetrics->ascent;
  875.             ibm8514BlitFGBG(rPM, MONO_STAGE_WPLANE, 255,0,GXand,
  876.                     pChar->x, lineoffset + pChar->y, 
  877.                     x0, y0, 
  878.                     pChar->w, pChar->h);
  879.         }
  880.         stageX += pMetrics->characterWidth;
  881.         if( stageX + x > bbox.x2 ) break;
  882.         }
  883.  
  884.         for( nbox= REGION_NUM_RECTS(prgnDst), pbox= REGION_RECTS(prgnDst);
  885.          nbox--;
  886.          pbox++ )
  887.         {
  888.         x0 = pbox->x1;
  889.         y0 = pbox->y1;
  890.         ibm8514BlitFG(MONO_STAGE_RPLANE,
  891.                   pGC->planemask, pGC->fgPixel, pGC->alu,
  892.                   MONO_STAGE_X + x0 - x,
  893.                   stageY +y0-y,
  894.                   x0, y0,
  895.                   pbox->x2 - x0,
  896.                   pbox->y2 - y0 );
  897.         }
  898.     }
  899.     break;
  900.     }
  901.     if ( !(--ibm8514cursorSemaphore) && CursorIsSaved )
  902.     ibm8514ReplaceCursor();
  903.  
  904.     return x- pDraw->x;
  905. }
  906.  
  907.  
  908. static void
  909. GetStippleOnStage(pGC, pbox)
  910.      GCPtr  pGC;
  911.      BoxRec *pbox;
  912. {
  913.     PixmapPtr     pStipple;
  914.     int     j;
  915.     int     tlx, tly, boxW, boxH, drawW, drawH, grow;
  916.     int     hoffset, voffset, vremaining, hremaining;
  917.     int     xSrc, ySrc;
  918.  
  919.     pStipple = pGC->stipple;
  920.  
  921.     tlx = pStipple->drawable.width;
  922.     tly = pStipple->drawable.height;
  923.     xSrc = pGC->patOrg.x;
  924.     ySrc = pGC->patOrg.y;
  925.  
  926.     boxH = pbox->y2 - pbox->y1;
  927.     boxW = pbox->x2 - pbox->x1;
  928.     drawW = MIN(boxW, tlx);
  929.     drawH = MIN(boxH, tly);
  930.  
  931.     if ((hoffset = ((pbox->x1-xSrc)%tlx)) < 0)
  932.     hoffset += tlx;
  933.     hremaining = tlx-hoffset;
  934.  
  935.     if ((voffset = ((pbox->y1-ySrc)%tly)) < 0)
  936.     voffset += tly;
  937.     vremaining = tly-voffset;
  938.  
  939. #define FILL_STAGE_X 0
  940. #define FILL_STAGE_Y 802
  941.     if (hoffset)
  942.     {
  943.     ibm8514AlignMonoImage(FILL_STAGE_WPLANE, GXcopy,
  944.                   FILL_STAGE_X, FILL_STAGE_Y,
  945.                   tlx, drawH, pStipple->devPrivate.ptr );
  946.     /* LOWER RIGHT RECTANGLE */
  947.         ibm8514Bitblt
  948.         (
  949.          GXcopy, RPLANE1, MONO_STAGE_WPLANE,
  950.          FILL_STAGE_X+hoffset, FILL_STAGE_Y+voffset,
  951.          MONO_STAGE_X, MONO_STAGE_Y,
  952.          MIN(hremaining,drawW), MIN(vremaining,drawH)
  953.          );
  954.  
  955.         /* LOWER LEFT RECTANGLE */
  956.         if (drawW > hremaining)
  957.         ibm8514Bitblt
  958.                 (
  959.          GXcopy, RPLANE1, MONO_STAGE_WPLANE,
  960.          FILL_STAGE_X, FILL_STAGE_Y+voffset,
  961.          MONO_STAGE_X+hremaining, MONO_STAGE_Y,
  962.          drawW-hremaining, MIN(vremaining,drawH)
  963.          );
  964.  
  965.         /* UPPER RIGHT RECTANGLE */
  966.         if (drawH > vremaining)
  967.     {
  968.             ibm8514Bitblt
  969.                 (
  970.          GXcopy, RPLANE1, MONO_STAGE_WPLANE,
  971.          FILL_STAGE_X+hoffset, FILL_STAGE_Y,
  972.          MONO_STAGE_X, MONO_STAGE_Y+vremaining,
  973.          MIN(hremaining,drawW), drawH - vremaining
  974.          );
  975.  
  976.         /* UPPER LEFT RECTANGLE */
  977.             if (drawW > hremaining)
  978.                 ibm8514Bitblt
  979.             (
  980.              GXcopy, RPLANE1, MONO_STAGE_WPLANE,
  981.              FILL_STAGE_X, FILL_STAGE_Y,
  982.              MONO_STAGE_X+hremaining, MONO_STAGE_Y+vremaining,
  983.              drawW-hremaining, drawH-vremaining
  984.              );
  985.     }
  986.     }
  987.     else
  988.     {
  989.     if (voffset)
  990.     {
  991.         j = MIN(vremaining,drawH); 
  992.         ibm8514AlignMonoImage(MONO_STAGE_WPLANE, GXcopy,
  993.                   MONO_STAGE_X, MONO_STAGE_Y,
  994.                   tlx, j,
  995.                   pStipple->devPrivate.ptr +
  996.                   voffset*pStipple->devKind);
  997.         if (j<drawH)
  998.         ibm8514AlignMonoImage(MONO_STAGE_WPLANE, GXcopy,
  999.                       MONO_STAGE_X, MONO_STAGE_Y + j,
  1000.                       tlx, drawH-j,
  1001.                       pStipple->devPrivate.ptr );
  1002.             
  1003.     }
  1004.     else
  1005.         ibm8514AlignMonoImage(MONO_STAGE_WPLANE, GXcopy,
  1006.                   MONO_STAGE_X, MONO_STAGE_Y,
  1007.                   tlx, drawH, pStipple->devPrivate.ptr );
  1008.     }
  1009.     while (  drawW < boxW)
  1010.     {
  1011.     grow = MIN(drawW, boxW-drawW);
  1012.     ibm8514Bitblt(GXcopy,MONO_STAGE_RPLANE, MONO_STAGE_WPLANE,
  1013.               0, MONO_STAGE_Y,
  1014.               drawW, MONO_STAGE_Y,
  1015.               grow, drawH);
  1016.     drawW += grow;
  1017.     }
  1018.     while ( drawH < boxH)
  1019.     {
  1020.     grow = MIN(drawH, boxH-drawH);
  1021.     ibm8514Bitblt(GXcopy,MONO_STAGE_RPLANE, MONO_STAGE_WPLANE,
  1022.               0, MONO_STAGE_Y,
  1023.               0, drawH,
  1024.               drawW, grow);
  1025.     drawH += grow;
  1026.     }
  1027.  
  1028.     return ;
  1029. }
  1030.