miglblt.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /***********************************************************
  2. Copyright 1987, 1998 The Open Group
  3. Permission to use, copy, modify, distribute, and sell this software and its
  4. documentation for any purpose is hereby granted without fee, provided that
  5. the above copyright notice appear in all copies and that both that
  6. copyright notice and this permission notice appear in supporting
  7. documentation.
  8. The above copyright notice and this permission notice shall be included in
  9. all copies or substantial portions of the Software.
  10. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  11. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  12. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  13. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  14. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  15. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. Except as contained in this notice, the name of The Open Group shall not be
  17. used in advertising or otherwise to promote the sale, use or other dealings
  18. in this Software without prior written authorization from The Open Group.
  19. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
  20. All Rights Reserved
  21. Permission to use, copy, modify, and distribute this software and its
  22. documentation for any purpose and without fee is hereby granted,
  23. provided that the above copyright notice appear in all copies and that
  24. both that copyright notice and this permission notice appear in
  25. supporting documentation, and that the name of Digital not be
  26. used in advertising or publicity pertaining to distribution of the
  27. software without specific, written prior permission.
  28. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  29. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  30. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  31. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  32. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  33. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  34. SOFTWARE.
  35. ******************************************************************/
  36. #ifdef HAVE_DIX_CONFIG_H
  37. #include <dix-config.h>
  38. #endif
  39. #include <X11/X.h>
  40. #include <X11/Xmd.h>
  41. #include <X11/Xproto.h>
  42. #include "misc.h"
  43. #include <X11/fonts/fontstruct.h>
  44. #include "dixfontstr.h"
  45. #include "gcstruct.h"
  46. #include "windowstr.h"
  47. #include "scrnintstr.h"
  48. #include "pixmap.h"
  49. #include "servermd.h"
  50. #include "mi.h"
  51. /*
  52. machine-independent glyph blt.
  53. assumes that glyph bits in snf are written in bytes,
  54. have same bit order as the server's bitmap format,
  55. and are byte padded. this corresponds to the snf distributed
  56. with the sample server.
  57. get a scratch GC.
  58. in the scratch GC set alu = GXcopy, fg = 1, bg = 0
  59. allocate a bitmap big enough to hold the largest glyph in the font
  60. validate the scratch gc with the bitmap
  61. for each glyph
  62. carefully put the bits of the glyph in a buffer,
  63. padded to the server pixmap scanline padding rules
  64. fake a call to PutImage from the buffer into the bitmap
  65. use the bitmap in a call to PushPixels
  66. */
  67. _X_EXPORT void
  68. miPolyGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
  69. DrawablePtr pDrawable;
  70. GC *pGC;
  71. int x, y;
  72. unsigned int nglyph;
  73. CharInfoPtr *ppci; /* array of character info */
  74. pointer pglyphBase; /* start of array of glyphs */
  75. {
  76. int width, height;
  77. PixmapPtr pPixmap;
  78. int nbyLine; /* bytes per line of padded pixmap */
  79. FontPtr pfont;
  80. GCPtr pGCtmp;
  81. int i;
  82. int j;
  83. unsigned char *pbits; /* buffer for PutImage */
  84. unsigned char *pb; /* temp pointer into buffer */
  85. CharInfoPtr pci; /* currect char info */
  86. unsigned char *pglyph; /* pointer bits in glyph */
  87. int gWidth, gHeight; /* width and height of glyph */
  88. int nbyGlyphWidth; /* bytes per scanline of glyph */
  89. int nbyPadGlyph; /* server padded line of glyph */
  90. XID gcvals[3];
  91. if (pGC->miTranslate)
  92. {
  93. x += pDrawable->x;
  94. y += pDrawable->y;
  95. }
  96. pfont = pGC->font;
  97. width = FONTMAXBOUNDS(pfont,rightSideBearing) -
  98. FONTMINBOUNDS(pfont,leftSideBearing);
  99. height = FONTMAXBOUNDS(pfont,ascent) +
  100. FONTMAXBOUNDS(pfont,descent);
  101. pPixmap = (*pDrawable->pScreen->CreatePixmap)(pDrawable->pScreen,
  102. width, height, 1);
  103. if (!pPixmap)
  104. return;
  105. pGCtmp = GetScratchGC(1, pDrawable->pScreen);
  106. if (!pGCtmp)
  107. {
  108. (*pDrawable->pScreen->DestroyPixmap)(pPixmap);
  109. return;
  110. }
  111. gcvals[0] = GXcopy;
  112. gcvals[1] = 1;
  113. gcvals[2] = 0;
  114. DoChangeGC(pGCtmp, GCFunction|GCForeground|GCBackground, gcvals, 0);
  115. nbyLine = BitmapBytePad(width);
  116. pbits = (unsigned char *)ALLOCATE_LOCAL(height*nbyLine);
  117. if (!pbits)
  118. {
  119. (*pDrawable->pScreen->DestroyPixmap)(pPixmap);
  120. FreeScratchGC(pGCtmp);
  121. return;
  122. }
  123. while(nglyph--)
  124. {
  125. pci = *ppci++;
  126. pglyph = FONTGLYPHBITS(pglyphBase, pci);
  127. gWidth = GLYPHWIDTHPIXELS(pci);
  128. gHeight = GLYPHHEIGHTPIXELS(pci);
  129. if (gWidth && gHeight)
  130. {
  131. nbyGlyphWidth = GLYPHWIDTHBYTESPADDED(pci);
  132. nbyPadGlyph = BitmapBytePad(gWidth);
  133. if (nbyGlyphWidth == nbyPadGlyph
  134. #if GLYPHPADBYTES != 4
  135. && (((int) pglyph) & 3) == 0
  136. #endif
  137. )
  138. {
  139. pb = pglyph;
  140. }
  141. else
  142. {
  143. for (i=0, pb = pbits; i<gHeight; i++, pb = pbits+(i*nbyPadGlyph))
  144. for (j = 0; j < nbyGlyphWidth; j++)
  145. *pb++ = *pglyph++;
  146. pb = pbits;
  147. }
  148. if ((pGCtmp->serialNumber) != (pPixmap->drawable.serialNumber))
  149. ValidateGC((DrawablePtr)pPixmap, pGCtmp);
  150. (*pGCtmp->ops->PutImage)((DrawablePtr)pPixmap, pGCtmp,
  151. pPixmap->drawable.depth,
  152. 0, 0, gWidth, gHeight,
  153. 0, XYBitmap, (char *)pb);
  154. if ((pGC->serialNumber) != (pDrawable->serialNumber))
  155. ValidateGC(pDrawable, pGC);
  156. (*pGC->ops->PushPixels)(pGC, pPixmap, pDrawable,
  157. gWidth, gHeight,
  158. x + pci->metrics.leftSideBearing,
  159. y - pci->metrics.ascent);
  160. }
  161. x += pci->metrics.characterWidth;
  162. }
  163. (*pDrawable->pScreen->DestroyPixmap)(pPixmap);
  164. DEALLOCATE_LOCAL(pbits);
  165. FreeScratchGC(pGCtmp);
  166. }
  167. _X_EXPORT void
  168. miImageGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
  169. DrawablePtr pDrawable;
  170. GC *pGC;
  171. int x, y;
  172. unsigned int nglyph;
  173. CharInfoPtr *ppci; /* array of character info */
  174. pointer pglyphBase; /* start of array of glyphs */
  175. {
  176. ExtentInfoRec info; /* used by QueryGlyphExtents() */
  177. XID gcvals[3];
  178. int oldAlu, oldFS;
  179. unsigned long oldFG;
  180. xRectangle backrect;
  181. QueryGlyphExtents(pGC->font, ppci, (unsigned long)nglyph, &info);
  182. if (info.overallWidth >= 0)
  183. {
  184. backrect.x = x;
  185. backrect.width = info.overallWidth;
  186. }
  187. else
  188. {
  189. backrect.x = x + info.overallWidth;
  190. backrect.width = -info.overallWidth;
  191. }
  192. backrect.y = y - FONTASCENT(pGC->font);
  193. backrect.height = FONTASCENT(pGC->font) + FONTDESCENT(pGC->font);
  194. oldAlu = pGC->alu;
  195. oldFG = pGC->fgPixel;
  196. oldFS = pGC->fillStyle;
  197. /* fill in the background */
  198. gcvals[0] = GXcopy;
  199. gcvals[1] = pGC->bgPixel;
  200. gcvals[2] = FillSolid;
  201. DoChangeGC(pGC, GCFunction|GCForeground|GCFillStyle, gcvals, 0);
  202. ValidateGC(pDrawable, pGC);
  203. (*pGC->ops->PolyFillRect)(pDrawable, pGC, 1, &backrect);
  204. /* put down the glyphs */
  205. gcvals[0] = oldFG;
  206. DoChangeGC(pGC, GCForeground, gcvals, 0);
  207. ValidateGC(pDrawable, pGC);
  208. (*pGC->ops->PolyGlyphBlt)(pDrawable, pGC, x, y, nglyph, ppci,
  209. pglyphBase);
  210. /* put all the toys away when done playing */
  211. gcvals[0] = oldAlu;
  212. gcvals[1] = oldFG;
  213. gcvals[2] = oldFS;
  214. DoChangeGC(pGC, GCFunction|GCForeground|GCFillStyle, gcvals, 0);
  215. ValidateGC(pDrawable, pGC);
  216. }