home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xibm.zip / apa16 / apa16PGBlt.c < prev    next >
C/C++ Source or Header  |  1992-03-09  |  13KB  |  450 lines

  1. /***********************************************************
  2. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  3. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Digital or MIT not be
  12. used in advertising or publicity pertaining to distribution of the
  13. software without specific, written prior permission.  
  14.  
  15. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  16. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  17. DIGITAL 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. ******************************************************************/
  24. /***********************************************************
  25.         Copyright IBM Corporation 1987,1988
  26.  
  27.                       All Rights Reserved
  28.  
  29. Permission to use, copy, modify, and distribute this software and its 
  30. documentation for any purpose and without fee is hereby granted, 
  31. provided that the above copyright notice appear in all copies and that
  32. both that copyright notice and this permission notice appear in 
  33. supporting documentation, and that the name of IBM not be
  34. used in advertising or publicity pertaining to distribution of the
  35. software without specific, written prior permission.  
  36.  
  37. IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  38. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  39. IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  40. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  41. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  42. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  43. SOFTWARE.
  44.  
  45. ******************************************************************/
  46. /***********************************************************
  47. Copyright 1989 by the Massachusetts Institute of Technology
  48.  
  49.                      All rights reserved.
  50.  
  51. Permission to use, copy, modify, and distribute this software and its
  52. documentation for any purpose and without fee is hereby granted,
  53. provided that the above copyright notice appear in all copies and that
  54. both that copyright notice and this permission notice appear in
  55. supporting documentation, and that the name of the Massachusetts
  56. Institute of Technology (M.I.T.) not be used in advertising or publicity
  57. pertaining to distribution of the software without specific, written
  58. prior permission.
  59.  
  60. M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  61. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  62. M.I.T. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  63. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  64. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  65. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  66. SOFTWARE.
  67.  
  68. ******************************************************************/
  69.  
  70. /* $Header: /afs/athena.mit.edu/astaff/project/x11r5/src/athena/ibm/apa16/RCS/apa16PGBlt.c,v 5.1 1992/03/09 23:55:20 jfc Exp $ */
  71. /* $Source: /afs/athena.mit.edu/astaff/project/x11r5/src/athena/ibm/apa16/RCS/apa16PGBlt.c,v $ */
  72.  
  73. #ifndef lint
  74. static char *rcsid = "$Id: apa16PGBlt.c,v 5.1 1992/03/09 23:55:20 jfc Exp $";
  75. #endif
  76.  
  77. #include "X.h"
  78. #include "Xmd.h"
  79. #include "Xproto.h"
  80. #include "misc.h"
  81. #include "dixfontstr.h"
  82. #include "gcstruct.h"
  83. #include "windowstr.h"
  84. #include "pixmapstr.h"
  85. #include "scrnintstr.h"
  86. #include "regionstr.h"
  87. #include "mfb.h"
  88. #include "maskbits.h"
  89. #include "miscstruct.h"
  90.  
  91. #include "OScompiler.h"
  92.  
  93. #include "ibmTrace.h"
  94.  
  95. #include "apa16Hdwr.h"
  96. #include "apa16GBlt.h"
  97.  
  98. /*
  99.     we should eventually special-case fixed-width fonts, although
  100. its more important for ImageText, which is meant for terminal
  101. emulators.
  102.  
  103.     the clipping calculations are done for worst-case fonts.
  104. we make no assumptions about the heights, widths, or bearings
  105. of the glyphs.  if we knew that the glyphs are all the same height,
  106. we could clip the tops and bottoms per clipping box, rather
  107. than per character per clipping box.  if we knew that the glyphs'
  108. left and right bearings were well-behaved, we could clip a single
  109. character at the start, output until the last unclipped
  110. character, and then clip the last one.  this is all straightforward
  111. to determine based on max-bounds and min-bounds from the font.
  112.     there is some inefficiency introduced in the per-character
  113. clipping to make what's going on clearer.
  114.  
  115.     (it is possible, for example, for a font to be defined in which the
  116. next-to-last character in a font would be clipped out, but the last
  117. one wouldn't.  the code below deals with this.)
  118.  
  119.     PolyText looks at the fg color and the rasterop; mfbValidateGC
  120. swaps in the right routine after looking at the reduced ratserop
  121. in the private field of the GC.  
  122.  
  123. */
  124.  
  125. void
  126. apa16PolyGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pGlyphBase)
  127.     DrawablePtr pDrawable;
  128.     GCPtr    pGC;
  129.     int     x, y;
  130.     unsigned int nglyph;
  131.     CharInfoPtr *ppci;        /* array of character info */
  132.     pointer      pGlyphBase;    /* start of array of glyphs */
  133. {
  134.     ExtentInfoRec info;    /* used by QueryGlyphExtents() */
  135.     BoxRec bbox;        /* string's bounding box */
  136.  
  137.     CharInfoPtr pci;
  138.     int xorg, yorg;    /* origin of drawable in bitmap */
  139.  
  140.             /* these keep track of the character origin */
  141.     unsigned int *pDstBase;
  142.             /* points to longword with character origin */
  143.     int xchar;        /* xorigin of char (mod 32) */
  144.  
  145.             /* these are used for placing the glyph */
  146.     int xOff;        /* x offset of left edge of glyph (mod 32) */
  147.     unsigned int *pDst;    /* pointer to current longword in dst */
  148.  
  149.     int w;        /* width of glyph in bits */
  150.     int h;        /* height of glyph */
  151.     int widthGlyph;    /* width of glyph, in bytes */
  152.     pointer pGlyph;    /* pointer to current row of glyph */
  153.  
  154.     int startmask;    /* used for putting down glyph */
  155.     int endmask;
  156.     int nFirst;        /* bits of glyph in current longword */
  157.     int tmpSrc;        /* for getting bits from glyph */
  158.     int    rrop;
  159.  
  160.     if (!(pGC->planemask & 1))
  161.     return;
  162.  
  163.     rrop= ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->rop;
  164.     if (rrop==RROP_NOP)
  165.     return;
  166.  
  167.     if (pDrawable->type != DRAWABLE_WINDOW)
  168.     {
  169.     if (rrop==RROP_WHITE) 
  170.         mfbPolyGlyphBltWhite(pDrawable,pGC,x,y,nglyph,ppci,pGlyphBase);
  171.     else if (rrop==RROP_BLACK)
  172.         mfbPolyGlyphBltBlack(pDrawable,pGC,x,y,nglyph,ppci,pGlyphBase);
  173.     else /* rrop==RROP_INVERT */
  174.         mfbPolyGlyphBltInvert(pDrawable,pGC,x,y,nglyph,ppci,pGlyphBase);
  175.     return;
  176.     }
  177.  
  178.     TRACE(("apa16PolyGlyphBlt(%x, %x, x=%d, y=%d, nglyph=%d, ppci=%x)\n",pDrawable,pGC,x,y,nglyph,ppci));
  179.  
  180.     if (rrop==RROP_WHITE)    { SET_MERGE_MODE(MERGE_WHITE); }
  181.     else if (rrop==RROP_BLACK)    { SET_MERGE_MODE(MERGE_BLACK); }
  182.     else /* RROP_INVERT */    { SET_MERGE_MODE(MERGE_INVERT); }
  183.     xorg = pDrawable->x;
  184.     yorg = pDrawable->y;
  185.  
  186.     x += xorg;
  187.     y += yorg;
  188.  
  189.     QueryGlyphExtents(pGC->font, ppci, nglyph, &info);
  190.     bbox.x1 = x + info.overallLeft;
  191.     bbox.x2 = x + info.overallRight;
  192.     bbox.y1 = y - info.overallAscent;
  193.     bbox.y2 = y + info.overallDescent;
  194.  
  195.     switch ((*pGC->pScreen->RectIn)(
  196.         ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip, &bbox))
  197.     {
  198.       case rgnOUT:
  199.     break;
  200.       case rgnIN:
  201.     pDstBase = (unsigned int *)APA16_BASE + (APA16_WIDTH / 32 * y) + (x >> 5);
  202.     xchar = x & 0x1f;
  203.  
  204.     while(nglyph--)
  205.       {
  206.         pci = *ppci;
  207.         pGlyph = FONTGLYPHBITS(pGlyphBase, pci);
  208.         w = GLYPHWIDTHPIXELS(pci);
  209.         h = GLYPHHEIGHTPIXELS(pci);
  210.         widthGlyph = GLYPHWIDTHBYTESPADDED(pci);
  211.  
  212.         /* start at top scanline of glyph */
  213.         pDst = pDstBase - (pci->metrics.ascent * APA16_WIDTH / 32);
  214.  
  215.         /* find correct word in scanline and x offset within it
  216.            for left edge of glyph
  217.         */
  218.         xOff = xchar + pci->metrics.leftSideBearing;
  219.         while (xOff > 31)
  220.         {
  221.             pDst++;
  222.             xOff -= 32;
  223.         }
  224.         while (xOff < 0)
  225.         {
  226.             xOff += 32;
  227.             pDst--;
  228.         }
  229.  
  230.         if ((xOff + w) <= 32) {
  231.         GLYPH_NARROW(UNCLIPPED);
  232.         }
  233.         else if (w<=32) {
  234.         GLYPH_CROSSES(UNCLIPPED);
  235.         } else {
  236.         GLYPH_WIDE();
  237.         }
  238.  
  239.         /* update character origin */
  240.         x += pci->metrics.characterWidth;
  241.         xchar += pci->metrics.characterWidth;
  242.         while (xchar > 31)
  243.         {
  244.             xchar -= 32;
  245.             pDstBase++;
  246.         }
  247.         while (xchar < 0)
  248.         {
  249.             xchar += 32;
  250.             pDstBase--;
  251.         }
  252.         ppci++;
  253.         } /* while nglyph-- */
  254.     break;
  255.       case rgnPART:
  256.       {
  257.     TEXTPOS *ppos;
  258.     int nbox;
  259.     BoxPtr pbox;
  260.     int xpos;        /* x position of char origin */
  261.     int i;
  262.     BoxRec clip;
  263.     int leftEdge, rightEdge;
  264.     int topEdge, bottomEdge;
  265.     int glyphRow;        /* first row of glyph not wholly
  266.                    clipped out */
  267.     int glyphCol;        /* leftmost visible column of glyph */
  268.  
  269.     if(!(ppos = (TEXTPOS *)ALLOCATE_LOCAL(nglyph * sizeof(TEXTPOS))))
  270.         return;
  271.  
  272.         pDstBase = (unsigned int *)APA16_BASE + (APA16_WIDTH / 32 * y) + (x >> 5);
  273.         xpos = x;
  274.     xchar = xpos & 0x1f;
  275.  
  276.     for (i=0; i<nglyph; i++)
  277.     {
  278.         pci = ppci[i];
  279.  
  280.         ppos[i].xpos = xpos;
  281.         ppos[i].xchar = xchar;
  282.         ppos[i].leftEdge = xpos + pci->metrics.leftSideBearing;
  283.         ppos[i].rightEdge = xpos + pci->metrics.rightSideBearing;
  284.         ppos[i].topEdge = y - pci->metrics.ascent;
  285.         ppos[i].bottomEdge = y + pci->metrics.descent;
  286.         ppos[i].pdstBase = pDstBase;
  287.         ppos[i].widthGlyph = GLYPHWIDTHBYTESPADDED(pci);
  288.  
  289.         xpos += pci->metrics.characterWidth;
  290.         xchar += pci->metrics.characterWidth;
  291.         while (xchar > 31)
  292.         {
  293.         xchar -= 32;
  294.         pDstBase++;
  295.         }
  296.         while (xchar < 0)
  297.         {
  298.         xchar += 32;
  299.         pDstBase--;
  300.         }
  301.     }
  302.  
  303.     pbox = REGION_RECTS(((mfbPrivGC *)
  304.                  (pGC->devPrivates[mfbGCPrivateIndex].ptr))->
  305.                 pCompositeClip);
  306.     nbox = REGION_NUM_RECTS(((mfbPrivGC *)
  307.                  (pGC->devPrivates[mfbGCPrivateIndex].ptr))->
  308.                 pCompositeClip);
  309.  
  310.     /* HACK ALERT
  311.        since we continue out of the loop below so often, it
  312.        is easier to increment pbox at the  top than at the end.
  313.        don't try this at home.
  314.     */
  315.     pbox--;
  316.     while(nbox--)
  317.     {
  318.         pbox++;
  319.         clip.x1 = MAX(bbox.x1, pbox->x1);
  320.         clip.y1 = MAX(bbox.y1, pbox->y1);
  321.         clip.x2 = MIN(bbox.x2, pbox->x2);
  322.         clip.y2 = MIN(bbox.y2, pbox->y2);
  323.         if ((clip.x2<=clip.x1) || (clip.y2<=clip.y1))
  324.         continue;
  325.  
  326.         for(i=0; i<nglyph; i++)
  327.         {
  328.         pci = ppci[i];
  329.         xchar = ppos[i].xchar;
  330.  
  331.         /* clip the left and right edges */
  332.         if (ppos[i].leftEdge < clip.x1)
  333.             leftEdge = clip.x1;
  334.         else
  335.             leftEdge = ppos[i].leftEdge;
  336.  
  337.         if (ppos[i].rightEdge > clip.x2)
  338.             rightEdge = clip.x2;
  339.         else
  340.             rightEdge = ppos[i].rightEdge;
  341.  
  342.         w = rightEdge - leftEdge;
  343.         if (w <= 0)
  344.             continue;
  345.  
  346.         /* clip the top and bottom edges */
  347.         if (ppos[i].topEdge < clip.y1)
  348.             topEdge = clip.y1;
  349.         else
  350.             topEdge = ppos[i].topEdge;
  351.  
  352.         if (ppos[i].bottomEdge > clip.y2)
  353.             bottomEdge = clip.y2;
  354.         else
  355.             bottomEdge = ppos[i].bottomEdge;
  356.  
  357.         h = bottomEdge - topEdge;
  358.         if (h <= 0)
  359.             continue;
  360.  
  361.         glyphRow = (topEdge - y) + pci->metrics.ascent;
  362.         widthGlyph = ppos[i].widthGlyph;
  363.         pGlyph = FONTGLYPHBITS(pGlyphBase, pci);
  364.         pGlyph += (glyphRow * widthGlyph);
  365.  
  366.         pDst = ppos[i].pdstBase - ((y-topEdge) * APA16_WIDTH / 32);
  367.  
  368.         glyphCol = (leftEdge - ppos[i].xpos) -
  369.                (pci->metrics.leftSideBearing);
  370.         xOff = xchar + (leftEdge - ppos[i].xpos);
  371.         while (xOff > 31) {
  372.             xOff -= 32;
  373.             pDst++;
  374.         }
  375.         while  (xOff < 0) {
  376.             xOff += 32;
  377.             pDst--;
  378.         }
  379.  
  380.         if ((xOff + w) <= 32) {
  381.             GLYPH_NARROW(CLIPPED);
  382.         }
  383.         else if (w<=32) {
  384.             GLYPH_CROSSES(CLIPPED);
  385.         } else {
  386.             GLYPH_WIDE();
  387.         } 
  388.         } /* for each glyph */
  389.     } /* while nbox-- */
  390.     DEALLOCATE_LOCAL(ppos);
  391.     break;
  392.       }
  393.       default:
  394.     break;
  395.     }
  396.     SET_MERGE_MODE(MERGE_COPY);
  397. }
  398.  
  399.  
  400. /***==================================================================***/
  401.  
  402. void
  403. apa16PutGlyph(x, y, ci, font_descent)
  404. unsigned x, y;
  405. CharInfoPtr ci;
  406. int font_descent;
  407. {
  408.     int              w,h,nFirst;
  409.     int             widthGlyph;
  410.     unsigned long    *pDst;
  411.     int              xOff,xEdge;
  412.     unsigned char    *pGlyph;
  413.     unsigned         startmask,endmask,tmpSrc;
  414.  
  415.     w = GLYPHWIDTHPIXELS(ci);
  416.     h = ci->metrics.ascent + ci->metrics.descent;
  417.  
  418.     if (w == 0 || h == 0)
  419.       return;
  420.  
  421.     x -= w;
  422.     y -= h + (font_descent - ci->metrics.descent);
  423.  
  424.     xEdge=    x&~31;
  425.     xOff=    x&31;
  426.     pDst=    (unsigned long *)SCREEN_ADDR(xEdge,y);
  427.     pGlyph=    FONTGLYPHBITS(0,ci);
  428.     widthGlyph=    GLYPHWIDTHBYTESPADDED(ci);
  429.  
  430. #ifdef TRACE_X
  431.     if (ibmTrace)
  432.       {
  433.     int i;
  434.     ErrorF("apa16PutGlyph(%d,%d,%x) w = %d, h = %d\n\t", x, y, ci, w, h);
  435.     for (i = 0; i < h;i++)
  436.       ErrorF("%08x ", pGlyph[i]);
  437.     ErrorF("\n");
  438.   }
  439. #endif
  440.     if ((xOff + w) <= 32) {        /* glyph all in one longword */
  441.     GLYPH_NARROW(UNCLIPPED);
  442.     }
  443.     else if (w<=32) {            /* glyph crosses longword boundary */
  444.     GLYPH_CROSSES(UNCLIPPED);
  445.     } 
  446.     else {                /* WIDE LOAD */
  447.     GLYPH_WIDE();
  448.     }
  449. }
  450.