glyphcurs.c revision 6747b715
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 2505b261ecSmrg 2605b261ecSmrgCopyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. 2705b261ecSmrg 2805b261ecSmrg All Rights Reserved 2905b261ecSmrg 3005b261ecSmrgPermission to use, copy, modify, and distribute this software and its 3105b261ecSmrgdocumentation for any purpose and without fee is hereby granted, 3205b261ecSmrgprovided that the above copyright notice appear in all copies and that 3305b261ecSmrgboth that copyright notice and this permission notice appear in 3405b261ecSmrgsupporting documentation, and that the name of Digital not be 3505b261ecSmrgused in advertising or publicity pertaining to distribution of the 3605b261ecSmrgsoftware without specific, written prior permission. 3705b261ecSmrg 3805b261ecSmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 3905b261ecSmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 4005b261ecSmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 4105b261ecSmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 4205b261ecSmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 4305b261ecSmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 4405b261ecSmrgSOFTWARE. 4505b261ecSmrg 4605b261ecSmrg************************************************************************/ 4705b261ecSmrg 4805b261ecSmrg 4905b261ecSmrg#ifdef HAVE_DIX_CONFIG_H 5005b261ecSmrg#include <dix-config.h> 5105b261ecSmrg#endif 5205b261ecSmrg 5305b261ecSmrg#include "misc.h" 5405b261ecSmrg#include <X11/fonts/fontstruct.h> 5505b261ecSmrg#include "dixfontstr.h" 5605b261ecSmrg#include "scrnintstr.h" 5705b261ecSmrg#include "gcstruct.h" 5805b261ecSmrg#include "resource.h" 5905b261ecSmrg#include "dix.h" 6005b261ecSmrg#include "cursorstr.h" 6105b261ecSmrg#include "opaque.h" 6205b261ecSmrg#include "servermd.h" 6305b261ecSmrg 6405b261ecSmrg 6505b261ecSmrg/* 6605b261ecSmrg get the bits out of the font in a portable way. to avoid 6705b261ecSmrgdealing with padding and such-like, we draw the glyph into 6805b261ecSmrga bitmap, then read the bits out with GetImage, which 6905b261ecSmrguses server-natural format. 7005b261ecSmrg since all screens return the same bitmap format, we'll just use 7105b261ecSmrgthe first one we find. 7205b261ecSmrg the character origin lines up with the hotspot in the 7305b261ecSmrgcursor metrics. 7405b261ecSmrg*/ 7505b261ecSmrg 7605b261ecSmrgint 7705b261ecSmrgServerBitsFromGlyph(FontPtr pfont, unsigned ch, CursorMetricPtr cm, unsigned char **ppbits) 7805b261ecSmrg{ 7905b261ecSmrg ScreenPtr pScreen; 8005b261ecSmrg GCPtr pGC; 8105b261ecSmrg xRectangle rect; 8205b261ecSmrg PixmapPtr ppix; 8305b261ecSmrg long nby; 8405b261ecSmrg char *pbits; 8505b261ecSmrg ChangeGCVal gcval[3]; 8605b261ecSmrg unsigned char char2b[2]; 8705b261ecSmrg 8805b261ecSmrg /* turn glyph index into a protocol-format char2b */ 8905b261ecSmrg char2b[0] = (unsigned char)(ch >> 8); 9005b261ecSmrg char2b[1] = (unsigned char)(ch & 0xff); 9105b261ecSmrg 9205b261ecSmrg pScreen = screenInfo.screens[0]; 9305b261ecSmrg nby = BitmapBytePad(cm->width) * (long)cm->height; 946747b715Smrg pbits = calloc(1, nby); 9505b261ecSmrg if (!pbits) 9605b261ecSmrg return BadAlloc; 9705b261ecSmrg 9805b261ecSmrg ppix = (PixmapPtr)(*pScreen->CreatePixmap)(pScreen, cm->width, 994642e01fSmrg cm->height, 1, 1004642e01fSmrg CREATE_PIXMAP_USAGE_SCRATCH); 10105b261ecSmrg pGC = GetScratchGC(1, pScreen); 10205b261ecSmrg if (!ppix || !pGC) 10305b261ecSmrg { 10405b261ecSmrg if (ppix) 10505b261ecSmrg (*pScreen->DestroyPixmap)(ppix); 10605b261ecSmrg if (pGC) 10705b261ecSmrg FreeScratchGC(pGC); 1086747b715Smrg free(pbits); 10905b261ecSmrg return BadAlloc; 11005b261ecSmrg } 11105b261ecSmrg 11205b261ecSmrg rect.x = 0; 11305b261ecSmrg rect.y = 0; 11405b261ecSmrg rect.width = cm->width; 11505b261ecSmrg rect.height = cm->height; 11605b261ecSmrg 11705b261ecSmrg /* fill the pixmap with 0 */ 11805b261ecSmrg gcval[0].val = GXcopy; 11905b261ecSmrg gcval[1].val = 0; 12005b261ecSmrg gcval[2].ptr = (pointer)pfont; 1216747b715Smrg ChangeGC(NullClient, pGC, GCFunction | GCForeground | GCFont, gcval); 12205b261ecSmrg ValidateGC((DrawablePtr)ppix, pGC); 12305b261ecSmrg (*pGC->ops->PolyFillRect)((DrawablePtr)ppix, pGC, 1, &rect); 12405b261ecSmrg 12505b261ecSmrg /* draw the glyph */ 12605b261ecSmrg gcval[0].val = 1; 1276747b715Smrg ChangeGC(NullClient, pGC, GCForeground, gcval); 12805b261ecSmrg ValidateGC((DrawablePtr)ppix, pGC); 12905b261ecSmrg (*pGC->ops->PolyText16)((DrawablePtr)ppix, pGC, cm->xhot, cm->yhot, 13005b261ecSmrg 1, (unsigned short *)char2b); 13105b261ecSmrg (*pScreen->GetImage)((DrawablePtr)ppix, 0, 0, cm->width, cm->height, 13205b261ecSmrg XYPixmap, 1, pbits); 13305b261ecSmrg *ppbits = (unsigned char *)pbits; 13405b261ecSmrg FreeScratchGC(pGC); 13505b261ecSmrg (*pScreen->DestroyPixmap)(ppix); 13605b261ecSmrg return Success; 13705b261ecSmrg} 13805b261ecSmrg 13905b261ecSmrg 14005b261ecSmrgBool 14105b261ecSmrgCursorMetricsFromGlyph(FontPtr pfont, unsigned ch, CursorMetricPtr cm) 14205b261ecSmrg{ 14305b261ecSmrg CharInfoPtr pci; 14405b261ecSmrg unsigned long nglyphs; 14505b261ecSmrg CARD8 chs[2]; 14605b261ecSmrg FontEncoding encoding; 14705b261ecSmrg 14805b261ecSmrg chs[0] = ch >> 8; 14905b261ecSmrg chs[1] = ch; 15005b261ecSmrg encoding = (FONTLASTROW(pfont) == 0) ? Linear16Bit : TwoD16Bit; 15105b261ecSmrg if (encoding == Linear16Bit) 15205b261ecSmrg { 15305b261ecSmrg if (ch < pfont->info.firstCol || pfont->info.lastCol < ch) 15405b261ecSmrg return FALSE; 15505b261ecSmrg } 15605b261ecSmrg else 15705b261ecSmrg { 15805b261ecSmrg if (chs[0] < pfont->info.firstRow || pfont->info.lastRow < chs[0]) 15905b261ecSmrg return FALSE; 16005b261ecSmrg if (chs[1] < pfont->info.firstCol || pfont->info.lastCol < chs[1]) 16105b261ecSmrg return FALSE; 16205b261ecSmrg } 16305b261ecSmrg (*pfont->get_glyphs) (pfont, 1, chs, encoding, &nglyphs, &pci); 16405b261ecSmrg if (nglyphs == 0) 16505b261ecSmrg return FALSE; 16605b261ecSmrg cm->width = pci->metrics.rightSideBearing - pci->metrics.leftSideBearing; 16705b261ecSmrg cm->height = pci->metrics.descent + pci->metrics.ascent; 16805b261ecSmrg if (pci->metrics.leftSideBearing > 0) 16905b261ecSmrg { 17005b261ecSmrg cm->width += pci->metrics.leftSideBearing; 17105b261ecSmrg cm->xhot = 0; 17205b261ecSmrg } 17305b261ecSmrg else 17405b261ecSmrg { 17505b261ecSmrg cm->xhot = -pci->metrics.leftSideBearing; 17605b261ecSmrg if (pci->metrics.rightSideBearing < 0) 17705b261ecSmrg cm->width -= pci->metrics.rightSideBearing; 17805b261ecSmrg } 17905b261ecSmrg if (pci->metrics.ascent < 0) 18005b261ecSmrg { 18105b261ecSmrg cm->height -= pci->metrics.ascent; 18205b261ecSmrg cm->yhot = 0; 18305b261ecSmrg } 18405b261ecSmrg else 18505b261ecSmrg { 18605b261ecSmrg cm->yhot = pci->metrics.ascent; 18705b261ecSmrg if (pci->metrics.descent < 0) 18805b261ecSmrg cm->height -= pci->metrics.descent; 18905b261ecSmrg } 19005b261ecSmrg return TRUE; 19105b261ecSmrg} 192