PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/nx-3.5.0/nx-X11/programs/Xserver/hw/nxagent/NXglyphcurs.c

#
C | 252 lines | 145 code | 31 blank | 76 comment | 21 complexity | 9ec841619eaa677f922c61f9e056a12f MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, LGPL-2.0
  1. #ifdef NXAGENT_UPGRADE
  2. #include "X/NXglyphcurs.c"
  3. #else
  4. /**************************************************************************/
  5. /* */
  6. /* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */
  7. /* */
  8. /* NXAGENT, NX protocol compression and NX extensions to this software */
  9. /* are copyright of NoMachine. Redistribution and use of the present */
  10. /* software is allowed according to terms specified in the file LICENSE */
  11. /* which comes in the source distribution. */
  12. /* */
  13. /* Check http://www.nomachine.com/licensing.html for applicability. */
  14. /* */
  15. /* NX and NoMachine are trademarks of Medialogic S.p.A. */
  16. /* */
  17. /* All rights reserved. */
  18. /* */
  19. /**************************************************************************/
  20. /************************************************************************
  21. Copyright 1987, 1998 The Open Group
  22. Permission to use, copy, modify, distribute, and sell this software and its
  23. documentation for any purpose is hereby granted without fee, provided that
  24. the above copyright notice appear in all copies and that both that
  25. copyright notice and this permission notice appear in supporting
  26. documentation.
  27. The above copyright notice and this permission notice shall be included in
  28. all copies or substantial portions of the Software.
  29. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  30. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  31. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  32. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  33. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  34. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  35. Except as contained in this notice, the name of The Open Group shall not be
  36. used in advertising or otherwise to promote the sale, use or other dealings
  37. in this Software without prior written authorization from The Open Group.
  38. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
  39. All Rights Reserved
  40. Permission to use, copy, modify, and distribute this software and its
  41. documentation for any purpose and without fee is hereby granted,
  42. provided that the above copyright notice appear in all copies and that
  43. both that copyright notice and this permission notice appear in
  44. supporting documentation, and that the name of Digital not be
  45. used in advertising or publicity pertaining to distribution of the
  46. software without specific, written prior permission.
  47. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  48. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  49. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  50. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  51. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  52. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  53. SOFTWARE.
  54. ************************************************************************/
  55. /* $Xorg: glyphcurs.c,v 1.4 2001/02/09 02:04:40 xorgcvs Exp $ */
  56. #include "misc.h"
  57. #include "fontstruct.h"
  58. #include "dixfontstr.h"
  59. #include "scrnintstr.h"
  60. #include "gcstruct.h"
  61. #include "resource.h"
  62. #include "dix.h"
  63. #include "cursorstr.h"
  64. #include "opaque.h"
  65. #include "servermd.h"
  66. #include "../../fb/fb.h"
  67. #include "Pixmaps.h"
  68. #ifndef True
  69. #define True 1
  70. #endif
  71. /*
  72. get the bits out of the font in a portable way. to avoid
  73. dealing with padding and such-like, we draw the glyph into
  74. a bitmap, then read the bits out with GetImage, which
  75. uses server-natural format.
  76. since all screens return the same bitmap format, we'll just use
  77. the first one we find.
  78. the character origin lines up with the hotspot in the
  79. cursor metrics.
  80. */
  81. int
  82. ServerBitsFromGlyph(pfont, ch, cm, ppbits)
  83. FontPtr pfont;
  84. unsigned int ch;
  85. register CursorMetricPtr cm;
  86. unsigned char **ppbits;
  87. {
  88. register ScreenPtr pScreen;
  89. register GCPtr pGC;
  90. xRectangle rect;
  91. PixmapPtr ppix;
  92. long nby;
  93. char *pbits;
  94. ChangeGCVal gcval[3];
  95. unsigned char char2b[2];
  96. /* turn glyph index into a protocol-format char2b */
  97. char2b[0] = (unsigned char)(ch >> 8);
  98. char2b[1] = (unsigned char)(ch & 0xff);
  99. pScreen = screenInfo.screens[0];
  100. nby = BitmapBytePad(cm->width) * (long)cm->height;
  101. pbits = (char *)xalloc(nby);
  102. if (!pbits)
  103. return BadAlloc;
  104. /* zeroing the (pad) bits seems to help some ddx cursor handling */
  105. bzero(pbits, nby);
  106. ppix = fbCreatePixmap(pScreen, cm->width, cm->height, 1);
  107. pGC = GetScratchGC(1, pScreen);
  108. if (!ppix || !pGC)
  109. {
  110. if (ppix)
  111. fbDestroyPixmap(ppix);
  112. if (pGC)
  113. FreeScratchGC(pGC);
  114. xfree(pbits);
  115. return BadAlloc;
  116. }
  117. #ifdef TEST
  118. fprintf(stderr, "ServerBitsFromGlyph: Created virtual pixmap at [%p] with width [%d] height [%d] depth [%d].\n",
  119. (void *) ppix, cm->width, cm->height, 1);
  120. #endif
  121. nxagentPixmapPriv(ppix) -> id = 0;
  122. nxagentPixmapPriv(ppix) -> mid = 0;
  123. nxagentPixmapPriv(ppix) -> isVirtual = True;
  124. nxagentPixmapPriv(ppix) -> pRealPixmap = NULL;
  125. nxagentPixmapPriv(ppix) -> pVirtualPixmap = NULL;
  126. rect.x = 0;
  127. rect.y = 0;
  128. rect.width = cm->width;
  129. rect.height = cm->height;
  130. pGC->stateChanges |= GCFunction | GCForeground | GCFont;
  131. pGC->alu = GXcopy;
  132. pGC->fgPixel = 0;
  133. pfont->refcnt++;
  134. if (pGC->font)
  135. CloseFont(pGC->font, (Font)0);
  136. pGC->font = pfont;
  137. ValidateGC((DrawablePtr)ppix, pGC);
  138. fbPolyFillRect((DrawablePtr)ppix, pGC, 1, &rect);
  139. /* draw the glyph */
  140. gcval[0].val = 1;
  141. pGC->fgPixel = 1;
  142. pGC->stateChanges |= GCForeground;
  143. ValidateGC((DrawablePtr)ppix, pGC);
  144. miPolyText16((DrawablePtr)ppix, pGC, (int)cm->xhot, (int)cm->yhot, (int)1, (unsigned short*)char2b);
  145. fbGetImage((DrawablePtr)ppix, 0, 0, cm->width, cm->height,
  146. XYPixmap, 1, pbits);
  147. *ppbits = (unsigned char *)pbits;
  148. FreeScratchGC(pGC);
  149. fbDestroyPixmap(ppix);
  150. #ifdef TEST
  151. fprintf(stderr, "ServerBitsFromGlyph: Destroyed virtual pixmap at [%p].\n",
  152. (void *) ppix);
  153. #endif
  154. return Success;
  155. }
  156. Bool
  157. CursorMetricsFromGlyph( pfont, ch, cm)
  158. register FontPtr pfont;
  159. unsigned ch;
  160. register CursorMetricPtr cm;
  161. {
  162. CharInfoPtr pci;
  163. unsigned long nglyphs;
  164. CARD8 chs[2];
  165. FontEncoding encoding;
  166. chs[0] = ch >> 8;
  167. chs[1] = ch;
  168. encoding = (FONTLASTROW(pfont) == 0) ? Linear16Bit : TwoD16Bit;
  169. if (encoding == Linear16Bit)
  170. {
  171. if (ch < pfont->info.firstCol || pfont->info.lastCol < ch)
  172. return FALSE;
  173. }
  174. else
  175. {
  176. if (chs[0] < pfont->info.firstRow || pfont->info.lastRow < chs[0])
  177. return FALSE;
  178. if (chs[1] < pfont->info.firstCol || pfont->info.lastCol < chs[1])
  179. return FALSE;
  180. }
  181. (*pfont->get_glyphs) (pfont, 1, chs, encoding, &nglyphs, &pci);
  182. if (nglyphs == 0)
  183. return FALSE;
  184. cm->width = pci->metrics.rightSideBearing - pci->metrics.leftSideBearing;
  185. cm->height = pci->metrics.descent + pci->metrics.ascent;
  186. if (pci->metrics.leftSideBearing > 0)
  187. {
  188. cm->width += pci->metrics.leftSideBearing;
  189. cm->xhot = 0;
  190. }
  191. else
  192. {
  193. cm->xhot = -pci->metrics.leftSideBearing;
  194. if (pci->metrics.rightSideBearing < 0)
  195. cm->width -= pci->metrics.rightSideBearing;
  196. }
  197. if (pci->metrics.ascent < 0)
  198. {
  199. cm->height -= pci->metrics.ascent;
  200. cm->yhot = 0;
  201. }
  202. else
  203. {
  204. cm->yhot = pci->metrics.ascent;
  205. if (pci->metrics.descent < 0)
  206. cm->height -= pci->metrics.descent;
  207. }
  208. return TRUE;
  209. }
  210. #endif /* #ifdef NXAGENT_UPGRADE */