|
|
1.1 ! root 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: /* $Header: glyphcurs.c,v 1.8 87/09/07 18:54:49 rws Exp $ */ ! 26: ! 27: #include "X.h" ! 28: #include "Xmd.h" ! 29: #include "Xproto.h" ! 30: #include "dixfontstr.h" ! 31: #include "fontstruct.h" ! 32: #include "scrnintstr.h" ! 33: #include "gcstruct.h" ! 34: #include "resource.h" ! 35: #include "dix.h" ! 36: #include "cursorstr.h" ! 37: #include "misc.h" ! 38: #include "opaque.h" ! 39: #include "servermd.h" ! 40: ! 41: ! 42: /* ! 43: get the bits out of the font in a portable way. to avoid ! 44: dealing with padding and such-like, we draw the glyph into ! 45: a bitmap, then read the bits out with GetImage, which ! 46: uses server-natural format. ! 47: since all screens return the same bitmap format, we'll just use ! 48: the first one we find. ! 49: if the font isn't there, it's probably been sent from ! 50: the mask part of CreateGlyphCursor, so we return a bitmap ! 51: filled with 1s. ! 52: the character origin lines up with the hotspot in the ! 53: cursor metrics. ! 54: */ ! 55: ! 56: int ! 57: ServerBitsFromGlyph(fontID, pfont, ch, cm, ppbits) ! 58: XID fontID; ! 59: FontPtr pfont; ! 60: unsigned short ch; ! 61: register CursorMetricPtr cm; ! 62: unsigned char **ppbits; ! 63: { ! 64: register ScreenPtr pScreen; ! 65: register GCPtr pGC; ! 66: xRectangle rect; ! 67: PixmapPtr ppix; ! 68: int nby; ! 69: unsigned char *pbits; ! 70: int gcval[3]; ! 71: unsigned char char2b[2]; ! 72: ! 73: /* this takes in a short, which needs to be made into a char2b ! 74: the msb of the short is byte1, the lsb is byte2 ! 75: this is the way a short is on the 68000 anyway. not a whole lot ! 76: of time here, so just do it always to cut down on extra flags in the ! 77: compilation. the glyph access code might turn this all back into ! 78: a short; this routine takes a short for the beneffit of application ! 79: writers using a linear cursor font, so they don't have to think ! 80: about 2-byte characters. ! 81: sigh. ! 82: */ ! 83: char2b[0] = (unsigned char)(ch >> 8); ! 84: char2b[1] = (unsigned char)(ch & 0xff); ! 85: ! 86: pScreen = &screenInfo.screen[0]; ! 87: nby = PixmapBytePad(cm->width, 1) * cm->height; ! 88: pbits = (unsigned char *)Xalloc(nby); ! 89: if (!pbits) ! 90: return BadAlloc; ! 91: ! 92: ppix = (PixmapPtr)(*pScreen->CreatePixmap)(pScreen, cm->width, ! 93: cm->height, 1); ! 94: if (!ppix) ! 95: { ! 96: Xfree(pbits); ! 97: return BadAlloc; ! 98: } ! 99: pGC = GetScratchGC(1, pScreen); ! 100: ! 101: rect.x = 0; ! 102: rect.y = 0; ! 103: rect.width = cm->width; ! 104: rect.height = cm->height; ! 105: ! 106: if (!pfont) ! 107: { ! 108: /* fill the pixmap with 1 */ ! 109: gcval[0] = GXcopy; ! 110: gcval[1] = 1; ! 111: DoChangeGC(pGC, GCFunction | GCForeground, gcval, 0); ! 112: ValidateGC(ppix, pGC); ! 113: (*pGC->PolyFillRect)(ppix, pGC, 1, &rect); ! 114: } ! 115: else ! 116: { ! 117: /* fill the pixmap with 0 */ ! 118: gcval[0] = GXcopy; ! 119: gcval[1] = 0; ! 120: gcval[2] = fontID; ! 121: DoChangeGC(pGC, GCFunction | GCForeground | GCFont, gcval, 0); ! 122: ValidateGC(ppix, pGC); ! 123: (*pGC->PolyFillRect)(ppix, pGC, 1, &rect); ! 124: ! 125: /* draw the glyph */ ! 126: gcval[0] = 1; ! 127: DoChangeGC(pGC, GCForeground, gcval, 0); ! 128: ValidateGC(ppix, pGC); ! 129: (*pGC->PolyText16)(ppix, pGC, cm->xhot, cm->yhot, 1, char2b); ! 130: } ! 131: (*pScreen->GetImage)(ppix, 0, 0, cm->width, cm->height, ! 132: ZPixmap, 0xffffffff, pbits); ! 133: *ppbits = pbits; ! 134: FreeScratchGC(pGC); ! 135: (*pScreen->DestroyPixmap)(ppix); ! 136: return Success; ! 137: } ! 138: ! 139: ! 140: Bool ! 141: CursorMetricsFromGlyph( pfont, ch, cm) ! 142: register FontPtr pfont; ! 143: int ch; ! 144: register CursorMetricPtr cm; ! 145: { ! 146: register CharInfoPtr pci = ADDRXTHISCHARINFO(pfont, ch); ! 147: ! 148: if ( ch < pfont->pFI->chFirst ! 149: || ch >= pfont->pFI->chFirst + n1dChars(pfont->pFI)) ! 150: { ! 151: cm->width = 0; ! 152: cm->height = 0; ! 153: cm->xhot = 0; ! 154: cm->yhot = 0; ! 155: return FALSE; ! 156: } ! 157: cm->xhot = - pci->metrics.leftSideBearing; ! 158: cm->yhot = pci->metrics.ascent; ! 159: cm->width = pci->metrics.rightSideBearing + cm->xhot; ! 160: cm->height = pci->metrics.descent + cm->yhot; ! 161: ! 162: return TRUE; ! 163: } ! 164: ! 165: ! 166:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.