105b261ecSmrg/************************************************************************ 205b261ecSmrg 305b261ecSmrgCopyright 1987, 1998 The Open Group 405b261ecSmrg 505b261ecSmrgPermission to use, copy, modify, distribute, and sell this software and its 605b261ecSmrgdocumentation for any purpose is hereby granted without fee, provided that 705b261ecSmrgthe above copyright notice appear in all copies and that both that 805b261ecSmrgcopyright notice and this permission notice appear in supporting 905b261ecSmrgdocumentation. 1005b261ecSmrg 1105b261ecSmrgThe above copyright notice and this permission notice shall be included in 1205b261ecSmrgall copies or substantial portions of the Software. 1305b261ecSmrg 1405b261ecSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1505b261ecSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1605b261ecSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1705b261ecSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 1805b261ecSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 1905b261ecSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2005b261ecSmrg 2105b261ecSmrgExcept as contained in this notice, the name of The Open Group shall not be 2205b261ecSmrgused in advertising or otherwise to promote the sale, use or other dealings 2305b261ecSmrgin this Software without prior written authorization from The Open Group. 2405b261ecSmrg 2505b261ecSmrgCopyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. 2605b261ecSmrg 2705b261ecSmrg All Rights Reserved 2805b261ecSmrg 2935c4bbdfSmrgPermission to use, copy, modify, and distribute this software and its 3035c4bbdfSmrgdocumentation for any purpose and without fee is hereby granted, 3105b261ecSmrgprovided that the above copyright notice appear in all copies and that 3235c4bbdfSmrgboth that copyright notice and this permission notice appear in 3305b261ecSmrgsupporting documentation, and that the name of Digital not be 3405b261ecSmrgused in advertising or publicity pertaining to distribution of the 3535c4bbdfSmrgsoftware without specific, written prior permission. 3605b261ecSmrg 3705b261ecSmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 3805b261ecSmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 3905b261ecSmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 4005b261ecSmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 4105b261ecSmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 4205b261ecSmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 4305b261ecSmrgSOFTWARE. 4405b261ecSmrg 4505b261ecSmrg************************************************************************/ 4605b261ecSmrg 4705b261ecSmrg#ifdef HAVE_DIX_CONFIG_H 4805b261ecSmrg#include <dix-config.h> 4905b261ecSmrg#endif 5005b261ecSmrg 5105b261ecSmrg#include "misc.h" 5205b261ecSmrg#include <X11/fonts/fontstruct.h> 5305b261ecSmrg#include "dixfontstr.h" 5405b261ecSmrg#include "scrnintstr.h" 5505b261ecSmrg#include "gcstruct.h" 5605b261ecSmrg#include "resource.h" 5705b261ecSmrg#include "dix.h" 5805b261ecSmrg#include "cursorstr.h" 5905b261ecSmrg#include "opaque.h" 6005b261ecSmrg#include "servermd.h" 6105b261ecSmrg 6205b261ecSmrg/* 6305b261ecSmrg get the bits out of the font in a portable way. to avoid 6405b261ecSmrgdealing with padding and such-like, we draw the glyph into 6505b261ecSmrga bitmap, then read the bits out with GetImage, which 6605b261ecSmrguses server-natural format. 6705b261ecSmrg since all screens return the same bitmap format, we'll just use 6805b261ecSmrgthe first one we find. 6905b261ecSmrg the character origin lines up with the hotspot in the 7005b261ecSmrgcursor metrics. 7105b261ecSmrg*/ 7205b261ecSmrg 7305b261ecSmrgint 7435c4bbdfSmrgServerBitsFromGlyph(FontPtr pfont, unsigned ch, CursorMetricPtr cm, 7535c4bbdfSmrg unsigned char **ppbits) 7605b261ecSmrg{ 7705b261ecSmrg ScreenPtr pScreen; 7805b261ecSmrg GCPtr pGC; 7905b261ecSmrg xRectangle rect; 8005b261ecSmrg PixmapPtr ppix; 8105b261ecSmrg char *pbits; 8205b261ecSmrg ChangeGCVal gcval[3]; 8305b261ecSmrg unsigned char char2b[2]; 8405b261ecSmrg 8505b261ecSmrg /* turn glyph index into a protocol-format char2b */ 8635c4bbdfSmrg char2b[0] = (unsigned char) (ch >> 8); 8735c4bbdfSmrg char2b[1] = (unsigned char) (ch & 0xff); 8805b261ecSmrg 8905b261ecSmrg pScreen = screenInfo.screens[0]; 9035c4bbdfSmrg pbits = calloc(BitmapBytePad(cm->width), cm->height); 9105b261ecSmrg if (!pbits) 9235c4bbdfSmrg return BadAlloc; 9305b261ecSmrg 9435c4bbdfSmrg ppix = (PixmapPtr) (*pScreen->CreatePixmap) (pScreen, cm->width, 9535c4bbdfSmrg cm->height, 1, 9635c4bbdfSmrg CREATE_PIXMAP_USAGE_SCRATCH); 9705b261ecSmrg pGC = GetScratchGC(1, pScreen); 9835c4bbdfSmrg if (!ppix || !pGC) { 9935c4bbdfSmrg if (ppix) 10035c4bbdfSmrg (*pScreen->DestroyPixmap) (ppix); 10135c4bbdfSmrg if (pGC) 10235c4bbdfSmrg FreeScratchGC(pGC); 10335c4bbdfSmrg free(pbits); 10435c4bbdfSmrg return BadAlloc; 10505b261ecSmrg } 10605b261ecSmrg 10705b261ecSmrg rect.x = 0; 10805b261ecSmrg rect.y = 0; 10905b261ecSmrg rect.width = cm->width; 11005b261ecSmrg rect.height = cm->height; 11105b261ecSmrg 11205b261ecSmrg /* fill the pixmap with 0 */ 11305b261ecSmrg gcval[0].val = GXcopy; 11405b261ecSmrg gcval[1].val = 0; 11535c4bbdfSmrg gcval[2].ptr = (void *) pfont; 1166747b715Smrg ChangeGC(NullClient, pGC, GCFunction | GCForeground | GCFont, gcval); 11735c4bbdfSmrg ValidateGC((DrawablePtr) ppix, pGC); 11835c4bbdfSmrg (*pGC->ops->PolyFillRect) ((DrawablePtr) ppix, pGC, 1, &rect); 11905b261ecSmrg 12005b261ecSmrg /* draw the glyph */ 12105b261ecSmrg gcval[0].val = 1; 1226747b715Smrg ChangeGC(NullClient, pGC, GCForeground, gcval); 12335c4bbdfSmrg ValidateGC((DrawablePtr) ppix, pGC); 12435c4bbdfSmrg (*pGC->ops->PolyText16) ((DrawablePtr) ppix, pGC, cm->xhot, cm->yhot, 12535c4bbdfSmrg 1, (unsigned short *) char2b); 12635c4bbdfSmrg (*pScreen->GetImage) ((DrawablePtr) ppix, 0, 0, cm->width, cm->height, 12735c4bbdfSmrg XYPixmap, 1, pbits); 12835c4bbdfSmrg *ppbits = (unsigned char *) pbits; 12905b261ecSmrg FreeScratchGC(pGC); 13035c4bbdfSmrg (*pScreen->DestroyPixmap) (ppix); 13105b261ecSmrg return Success; 13205b261ecSmrg} 13305b261ecSmrg 13405b261ecSmrgBool 13505b261ecSmrgCursorMetricsFromGlyph(FontPtr pfont, unsigned ch, CursorMetricPtr cm) 13605b261ecSmrg{ 13735c4bbdfSmrg CharInfoPtr pci; 13835c4bbdfSmrg unsigned long nglyphs; 13935c4bbdfSmrg CARD8 chs[2]; 14035c4bbdfSmrg FontEncoding encoding; 14105b261ecSmrg 14205b261ecSmrg chs[0] = ch >> 8; 14305b261ecSmrg chs[1] = ch; 14405b261ecSmrg encoding = (FONTLASTROW(pfont) == 0) ? Linear16Bit : TwoD16Bit; 14535c4bbdfSmrg if (encoding == Linear16Bit) { 14635c4bbdfSmrg if (ch < pfont->info.firstCol || pfont->info.lastCol < ch) 14735c4bbdfSmrg return FALSE; 14805b261ecSmrg } 14935c4bbdfSmrg else { 15035c4bbdfSmrg if (chs[0] < pfont->info.firstRow || pfont->info.lastRow < chs[0]) 15135c4bbdfSmrg return FALSE; 15235c4bbdfSmrg if (chs[1] < pfont->info.firstCol || pfont->info.lastCol < chs[1]) 15335c4bbdfSmrg return FALSE; 15405b261ecSmrg } 15505b261ecSmrg (*pfont->get_glyphs) (pfont, 1, chs, encoding, &nglyphs, &pci); 15605b261ecSmrg if (nglyphs == 0) 15735c4bbdfSmrg return FALSE; 15805b261ecSmrg cm->width = pci->metrics.rightSideBearing - pci->metrics.leftSideBearing; 15905b261ecSmrg cm->height = pci->metrics.descent + pci->metrics.ascent; 16035c4bbdfSmrg if (pci->metrics.leftSideBearing > 0) { 16135c4bbdfSmrg cm->width += pci->metrics.leftSideBearing; 16235c4bbdfSmrg cm->xhot = 0; 16305b261ecSmrg } 16435c4bbdfSmrg else { 16535c4bbdfSmrg cm->xhot = -pci->metrics.leftSideBearing; 16635c4bbdfSmrg if (pci->metrics.rightSideBearing < 0) 16735c4bbdfSmrg cm->width -= pci->metrics.rightSideBearing; 16805b261ecSmrg } 16935c4bbdfSmrg if (pci->metrics.ascent < 0) { 17035c4bbdfSmrg cm->height -= pci->metrics.ascent; 17135c4bbdfSmrg cm->yhot = 0; 17205b261ecSmrg } 17335c4bbdfSmrg else { 17435c4bbdfSmrg cm->yhot = pci->metrics.ascent; 17535c4bbdfSmrg if (pci->metrics.descent < 0) 17635c4bbdfSmrg cm->height -= pci->metrics.descent; 17705b261ecSmrg } 17805b261ecSmrg return TRUE; 17905b261ecSmrg} 180