PageRenderTime 53ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/nx-3.5.0/nx-X11/programs/Xserver/hw/nxagent/X/NXdixfonts.c

#
C | 2805 lines | 2227 code | 253 blank | 325 comment | 425 complexity | d0adcbee90c15a7b0ede183ca1619154 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, LGPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. /**************************************************************************/
  2. /* */
  3. /* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */
  4. /* */
  5. /* NXAGENT, NX protocol compression and NX extensions to this software */
  6. /* are copyright of NoMachine. Redistribution and use of the present */
  7. /* software is allowed according to terms specified in the file LICENSE */
  8. /* which comes in the source distribution. */
  9. /* */
  10. /* Check http://www.nomachine.com/licensing.html for applicability. */
  11. /* */
  12. /* NX and NoMachine are trademarks of Medialogic S.p.A. */
  13. /* */
  14. /* All rights reserved. */
  15. /* */
  16. /**************************************************************************/
  17. /* $XdotOrg: xc/programs/Xserver/dix/dixfonts.c,v 1.8 2005/07/03 08:53:38 daniels Exp $ */
  18. /* $XFree86: xc/programs/Xserver/dix/dixfonts.c,v 3.28 2003/11/08 02:02:03 dawes Exp $ */
  19. /************************************************************************
  20. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
  21. All Rights Reserved
  22. Permission to use, copy, modify, and distribute this software and its
  23. documentation for any purpose and without fee is hereby granted,
  24. provided that the above copyright notice appear in all copies and that
  25. both that copyright notice and this permission notice appear in
  26. supporting documentation, and that the name of Digital not be
  27. used in advertising or publicity pertaining to distribution of the
  28. software without specific, written prior permission.
  29. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  30. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  31. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  32. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  33. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  34. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  35. SOFTWARE.
  36. ************************************************************************/
  37. /* The panoramix components contained the following notice */
  38. /*
  39. Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts.
  40. Permission is hereby granted, free of charge, to any person obtaining a copy
  41. of this software and associated documentation files (the "Software"), to deal
  42. in the Software without restriction, including without limitation the rights
  43. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  44. copies of the Software.
  45. The above copyright notice and this permission notice shall be included in
  46. all copies or substantial portions of the Software.
  47. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  48. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  49. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  50. DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
  51. BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
  52. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
  53. IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  54. Except as contained in this notice, the name of Digital Equipment Corporation
  55. shall not be used in advertising or otherwise to promote the sale, use or other
  56. dealings in this Software without prior written authorization from Digital
  57. Equipment Corporation.
  58. ******************************************************************/
  59. /* $Xorg: dixfonts.c,v 1.4 2000/08/17 19:48:18 cpqbld Exp $ */
  60. #define NEED_REPLIES
  61. #ifdef HAVE_DIX_CONFIG_H
  62. #include <dix-config.h>
  63. #endif
  64. #include <X11/X.h>
  65. #include <X11/Xmd.h>
  66. #include <X11/Xproto.h>
  67. #include "scrnintstr.h"
  68. #include "resource.h"
  69. #include "dixstruct.h"
  70. #include "cursorstr.h"
  71. #include "misc.h"
  72. #include "opaque.h"
  73. #include "dixfontstr.h"
  74. #include "closestr.h"
  75. /*
  76. #define NXAGENT_DEBUG
  77. */
  78. #ifdef DEBUG
  79. #include <stdio.h>
  80. #endif
  81. #include "Agent.h"
  82. #include "Font.h"
  83. #ifndef NX_TRANS_SOCKET
  84. #define NX_TRANS_SOCKET
  85. #endif
  86. #ifdef NX_TRANS_SOCKET
  87. char _NXFontPath[1024];
  88. /*
  89. * Override the default font path and make
  90. * it configurable at run time, based on
  91. * the NX_FONT environment.
  92. */
  93. static const char *_NXGetFontPath(const char *path)
  94. {
  95. const char *fontEnv;
  96. /*
  97. * Check the environment only once.
  98. */
  99. if (*_NXFontPath != '\0')
  100. {
  101. return _NXFontPath;
  102. }
  103. fontEnv = getenv("NX_FONT");
  104. if (fontEnv != NULL && *fontEnv != '\0')
  105. {
  106. if (strlen(fontEnv) + 1 > 1024)
  107. {
  108. #ifdef NX_TRANS_TEST
  109. fprintf(stderr, "_NXGetFontPath: WARNING! Maximum length of font path exceeded.\n");
  110. #endif
  111. goto _NXGetFontPathError;
  112. }
  113. strcpy(_NXFontPath, fontEnv);
  114. #ifdef NX_TRANS_TEST
  115. fprintf(stderr, "_NXGetFontPath: Using NX font path [%s].\n", _NXFontPath);
  116. #endif
  117. return _NXFontPath;
  118. }
  119. _NXGetFontPathError:
  120. strncpy(_NXFontPath, path, 1023);
  121. _NXFontPath[1023] = '\0';
  122. #ifdef NX_TRANS_TEST
  123. fprintf(stderr, "_NXGetFontPath: Using default font path [%s].\n", _NXFontPath);
  124. #endif
  125. return _NXFontPath;
  126. }
  127. #endif
  128. #ifdef PANORAMIX
  129. #include "../../Xext/panoramiX.h"
  130. #include "../../Xext/panoramiXsrv.h"
  131. #endif
  132. #ifdef LBX
  133. #include "lbxserve.h"
  134. #endif
  135. #ifdef XF86BIGFONT
  136. #define _XF86BIGFONT_SERVER_
  137. #include <X11/extensions/xf86bigfont.h>
  138. #endif
  139. #define QUERYCHARINFO(pci, pr) *(pr) = (pci)->metrics
  140. extern pointer fosNaturalParams;
  141. extern FontPtr defaultFont;
  142. static FontPathElementPtr *font_path_elements = (FontPathElementPtr *) 0;
  143. static int num_fpes = 0;
  144. FPEFunctions *fpe_functions = (FPEFunctions *) 0;
  145. static int num_fpe_types = 0;
  146. static unsigned char *font_path_string;
  147. static int num_slept_fpes = 0;
  148. static int size_slept_fpes = 0;
  149. static FontPathElementPtr *slept_fpes = (FontPathElementPtr *) 0;
  150. static FontPatternCachePtr patternCache;
  151. int
  152. FontToXError(err)
  153. int err;
  154. {
  155. switch (err) {
  156. case Successful:
  157. return Success;
  158. case AllocError:
  159. return BadAlloc;
  160. case BadFontName:
  161. return BadName;
  162. case BadFontPath:
  163. case BadFontFormat: /* is there something better? */
  164. case BadCharRange:
  165. return BadValue;
  166. default:
  167. return err;
  168. }
  169. }
  170. /*
  171. * adding RT_FONT prevents conflict with default cursor font
  172. */
  173. Bool
  174. SetDefaultFont(char *defaultfontname)
  175. {
  176. int err;
  177. FontPtr pf;
  178. XID fid;
  179. fid = FakeClientID(0);
  180. err = OpenFont(serverClient, fid, FontLoadAll | FontOpenSync,
  181. (unsigned) strlen(defaultfontname), defaultfontname);
  182. if (err != Success)
  183. return FALSE;
  184. pf = (FontPtr) LookupIDByType(fid, RT_FONT);
  185. if (pf == (FontPtr) NULL)
  186. return FALSE;
  187. defaultFont = pf;
  188. return TRUE;
  189. }
  190. /*
  191. * note that the font wakeup queue is not refcounted. this is because
  192. * an fpe needs to be added when it's inited, and removed when it's finally
  193. * freed, in order to handle any data that isn't requested, like FS events.
  194. *
  195. * since the only thing that should call these routines is the renderer's
  196. * init_fpe() and free_fpe(), there shouldn't be any problem in using
  197. * freed data.
  198. */
  199. void
  200. QueueFontWakeup(FontPathElementPtr fpe)
  201. {
  202. int i;
  203. FontPathElementPtr *new;
  204. for (i = 0; i < num_slept_fpes; i++) {
  205. if (slept_fpes[i] == fpe) {
  206. #ifdef DEBUG
  207. fprintf(stderr, "re-queueing fpe wakeup\n");
  208. #endif
  209. return;
  210. }
  211. }
  212. if (num_slept_fpes == size_slept_fpes) {
  213. new = (FontPathElementPtr *)
  214. xrealloc(slept_fpes,
  215. sizeof(FontPathElementPtr) * (size_slept_fpes + 4));
  216. if (!new)
  217. return;
  218. slept_fpes = new;
  219. size_slept_fpes += 4;
  220. }
  221. slept_fpes[num_slept_fpes] = fpe;
  222. num_slept_fpes++;
  223. }
  224. void
  225. RemoveFontWakeup(FontPathElementPtr fpe)
  226. {
  227. int i,
  228. j;
  229. for (i = 0; i < num_slept_fpes; i++) {
  230. if (slept_fpes[i] == fpe) {
  231. for (j = i; j < num_slept_fpes; j++) {
  232. slept_fpes[j] = slept_fpes[j + 1];
  233. }
  234. num_slept_fpes--;
  235. return;
  236. }
  237. }
  238. }
  239. void
  240. FontWakeup(pointer data, int count, pointer LastSelectMask)
  241. {
  242. int i;
  243. FontPathElementPtr fpe;
  244. if (count < 0)
  245. return;
  246. /* wake up any fpe's that may be waiting for information */
  247. for (i = 0; i < num_slept_fpes; i++) {
  248. fpe = slept_fpes[i];
  249. (void) (*fpe_functions[fpe->type].wakeup_fpe) (fpe, LastSelectMask);
  250. }
  251. }
  252. /* XXX -- these two funcs may want to be broken into macros */
  253. static void
  254. UseFPE(FontPathElementPtr fpe)
  255. {
  256. fpe->refcount++;
  257. }
  258. static void
  259. FreeFPE (FontPathElementPtr fpe)
  260. {
  261. fpe->refcount--;
  262. if (fpe->refcount == 0) {
  263. (*fpe_functions[fpe->type].free_fpe) (fpe);
  264. xfree(fpe->name);
  265. xfree(fpe);
  266. }
  267. }
  268. static Bool
  269. doOpenFont(ClientPtr client, OFclosurePtr c)
  270. {
  271. FontPtr pfont = NullFont;
  272. FontPathElementPtr fpe = NULL;
  273. ScreenPtr pScr;
  274. int err = Successful;
  275. int i;
  276. char *alias,
  277. *newname;
  278. int newlen;
  279. int aliascount = 20;
  280. char nxagentOrigFontName[256];
  281. int nxagentOrigFontNameLen;
  282. /*
  283. * Decide at runtime what FontFormat to use.
  284. */
  285. Mask FontFormat =
  286. ((screenInfo.imageByteOrder == LSBFirst) ?
  287. BitmapFormatByteOrderLSB : BitmapFormatByteOrderMSB) |
  288. ((screenInfo.bitmapBitOrder == LSBFirst) ?
  289. BitmapFormatBitOrderLSB : BitmapFormatBitOrderMSB) |
  290. BitmapFormatImageRectMin |
  291. #if GLYPHPADBYTES == 1
  292. BitmapFormatScanlinePad8 |
  293. #endif
  294. #if GLYPHPADBYTES == 2
  295. BitmapFormatScanlinePad16 |
  296. #endif
  297. #if GLYPHPADBYTES == 4
  298. BitmapFormatScanlinePad32 |
  299. #endif
  300. #if GLYPHPADBYTES == 8
  301. BitmapFormatScanlinePad64 |
  302. #endif
  303. BitmapFormatScanlineUnit8;
  304. nxagentOrigFontNameLen = (c -> origFontNameLen < 256) ? c -> origFontNameLen : 255;
  305. memcpy(nxagentOrigFontName, c -> origFontName, nxagentOrigFontNameLen);
  306. nxagentOrigFontName[nxagentOrigFontNameLen] = 0;
  307. if (client->clientGone)
  308. {
  309. if (c->current_fpe < c->num_fpes)
  310. {
  311. fpe = c->fpe_list[c->current_fpe];
  312. (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe);
  313. }
  314. err = Successful;
  315. goto bail;
  316. }
  317. while (c->current_fpe < c->num_fpes) {
  318. fpe = c->fpe_list[c->current_fpe];
  319. err = (*fpe_functions[fpe->type].open_font)
  320. ((pointer) client, fpe, c->flags,
  321. c->fontname, c->fnamelen, FontFormat,
  322. BitmapFormatMaskByte |
  323. BitmapFormatMaskBit |
  324. BitmapFormatMaskImageRectangle |
  325. BitmapFormatMaskScanLinePad |
  326. BitmapFormatMaskScanLineUnit,
  327. c->fontid, &pfont, &alias,
  328. c->non_cachable_font && c->non_cachable_font->fpe == fpe ?
  329. c->non_cachable_font :
  330. (FontPtr)0);
  331. if (err == FontNameAlias && alias) {
  332. newlen = strlen(alias);
  333. newname = (char *) xrealloc(c->fontname, newlen);
  334. if (!newname) {
  335. err = AllocError;
  336. break;
  337. }
  338. memmove(newname, alias, newlen);
  339. c->fontname = newname;
  340. c->fnamelen = newlen;
  341. c->current_fpe = 0;
  342. if (--aliascount <= 0)
  343. break;
  344. continue;
  345. }
  346. if (err == BadFontName) {
  347. c->current_fpe++;
  348. continue;
  349. }
  350. if (err == Suspended) {
  351. if (!c->slept) {
  352. c->slept = TRUE;
  353. ClientSleep(client, (ClientSleepProcPtr)doOpenFont, (pointer) c);
  354. #ifdef NXAGENT_DEBUG
  355. fprintf(stderr, " NXdixfonts: doOpenFont: client [%lx] sleeping.\n", client);
  356. #endif
  357. }
  358. return TRUE;
  359. }
  360. break;
  361. }
  362. if (err != Successful)
  363. goto bail;
  364. if (!pfont) {
  365. err = BadFontName;
  366. goto bail;
  367. }
  368. /* check values for firstCol, lastCol, firstRow, and lastRow */
  369. if (pfont->info.firstCol > pfont->info.lastCol ||
  370. pfont->info.firstRow > pfont->info.lastRow ||
  371. pfont->info.lastCol - pfont->info.firstCol > 255) {
  372. err = AllocError;
  373. goto bail;
  374. }
  375. if (!pfont->fpe)
  376. pfont->fpe = fpe;
  377. pfont->refcnt++;
  378. if (pfont->refcnt == 1) {
  379. UseFPE(pfont->fpe);
  380. for (i = 0; i < screenInfo.numScreens; i++) {
  381. pScr = screenInfo.screens[i];
  382. if (pScr->RealizeFont)
  383. {
  384. /* NXAGENT uses useless screen pointer to pass the original font name
  385. * to realizeFont, could be a source of problems in the future.
  386. */
  387. if (!(*pScr->RealizeFont) ((ScreenPtr)nxagentOrigFontName, pfont))
  388. {
  389. CloseFont (pfont, (Font) 0);
  390. err=BadFontName;
  391. goto bail;
  392. }
  393. }
  394. }
  395. }
  396. if (!AddResource(c->fontid, RT_FONT, (pointer) pfont)) {
  397. err = AllocError;
  398. goto bail;
  399. }
  400. if( nxagentFontPriv(pfont) -> mirrorID == 0 )
  401. {
  402. extern RESTYPE RT_NX_FONT;
  403. nxagentFontPriv(pfont) -> mirrorID = FakeClientID(0);
  404. if (!AddResource(nxagentFontPriv(pfont) -> mirrorID, RT_NX_FONT, (pointer) pfont)) {
  405. FreeResource(c->fontid, RT_NONE);
  406. err = AllocError;
  407. goto bail;
  408. }
  409. }
  410. if (patternCache && pfont != c->non_cachable_font)
  411. CacheFontPattern(patternCache, nxagentOrigFontName, nxagentOrigFontNameLen,
  412. pfont);
  413. bail:
  414. if (err != Successful && c->client != serverClient) {
  415. SendErrorToClient(c->client, X_OpenFont, 0,
  416. c->fontid, FontToXError(err));
  417. }
  418. if (c->slept)
  419. {
  420. ClientWakeup(c->client);
  421. #ifdef NXAGENT_DEBUG
  422. fprintf(stderr, " NXdixfonts: doOpenFont: client [%lx] wakeup.\n", client);
  423. #endif
  424. }
  425. for (i = 0; i < c->num_fpes; i++) {
  426. FreeFPE(c->fpe_list[i]);
  427. }
  428. xfree(c->fpe_list);
  429. xfree(c->fontname);
  430. xfree(c);
  431. return TRUE;
  432. }
  433. int
  434. OpenFont(ClientPtr client, XID fid, Mask flags, unsigned lenfname, char *pfontname)
  435. {
  436. OFclosurePtr c;
  437. int i;
  438. FontPtr cached = (FontPtr)0;
  439. #ifdef FONTDEBUG
  440. char *f;
  441. f = (char *)xalloc(lenfname + 1);
  442. memmove(f, pfontname, lenfname);
  443. f[lenfname] = '\0';
  444. ErrorF("OpenFont: fontname is \"%s\"\n", f);
  445. xfree(f);
  446. #endif
  447. if (!lenfname || lenfname > XLFDMAXFONTNAMELEN)
  448. return BadName;
  449. if (patternCache)
  450. {
  451. /*
  452. ** Check name cache. If we find a cached version of this font that
  453. ** is cachable, immediately satisfy the request with it. If we find
  454. ** a cached version of this font that is non-cachable, we do not
  455. ** satisfy the request with it. Instead, we pass the FontPtr to the
  456. ** FPE's open_font code (the fontfile FPE in turn passes the
  457. ** information to the rasterizer; the fserve FPE ignores it).
  458. **
  459. ** Presumably, the font is marked non-cachable because the FPE has
  460. ** put some licensing restrictions on it. If the FPE, using
  461. ** whatever logic it relies on, determines that it is willing to
  462. ** share this existing font with the client, then it has the option
  463. ** to return the FontPtr we passed it as the newly-opened font.
  464. ** This allows the FPE to exercise its licensing logic without
  465. ** having to create another instance of a font that already exists.
  466. */
  467. cached = FindCachedFontPattern(patternCache, pfontname, lenfname);
  468. if (cached && cached->info.cachable)
  469. {
  470. if (!AddResource(fid, RT_FONT, (pointer) cached))
  471. return BadAlloc;
  472. cached->refcnt++;
  473. return Success;
  474. }
  475. }
  476. c = (OFclosurePtr) xalloc(sizeof(OFclosureRec));
  477. if (!c)
  478. return BadAlloc;
  479. c->fontname = (char *) xalloc(lenfname);
  480. c->origFontName = pfontname;
  481. c->origFontNameLen = lenfname;
  482. if (!c->fontname) {
  483. xfree(c);
  484. return BadAlloc;
  485. }
  486. /*
  487. * copy the current FPE list, so that if it gets changed by another client
  488. * while we're blocking, the request still appears atomic
  489. */
  490. c->fpe_list = (FontPathElementPtr *)
  491. xalloc(sizeof(FontPathElementPtr) * num_fpes);
  492. if (!c->fpe_list) {
  493. xfree(c->fontname);
  494. xfree(c);
  495. return BadAlloc;
  496. }
  497. memmove(c->fontname, pfontname, lenfname);
  498. for (i = 0; i < num_fpes; i++) {
  499. c->fpe_list[i] = font_path_elements[i];
  500. UseFPE(c->fpe_list[i]);
  501. }
  502. c->client = client;
  503. c->fontid = fid;
  504. c->current_fpe = 0;
  505. c->num_fpes = num_fpes;
  506. c->fnamelen = lenfname;
  507. c->slept = FALSE;
  508. c->flags = flags;
  509. c->non_cachable_font = cached;
  510. (void) doOpenFont(client, c);
  511. return Success;
  512. }
  513. /**
  514. * Decrement font's ref count, and free storage if ref count equals zero
  515. *
  516. * \param value must conform to DeleteType
  517. */
  518. int
  519. CloseFont(pointer value, XID fid)
  520. {
  521. int nscr;
  522. ScreenPtr pscr;
  523. FontPathElementPtr fpe;
  524. FontPtr pfont = (FontPtr)value;
  525. if (pfont == NullFont)
  526. return (Success);
  527. if (--pfont->refcnt == 0) {
  528. if (patternCache)
  529. RemoveCachedFontPattern (patternCache, pfont);
  530. /*
  531. * since the last reference is gone, ask each screen to free any
  532. * storage it may have allocated locally for it.
  533. */
  534. for (nscr = 0; nscr < screenInfo.numScreens; nscr++) {
  535. pscr = screenInfo.screens[nscr];
  536. if (pscr->UnrealizeFont)
  537. (*pscr->UnrealizeFont) (pscr, pfont);
  538. }
  539. if (pfont == defaultFont)
  540. defaultFont = NULL;
  541. #ifdef LBX
  542. LbxFreeFontTag(pfont);
  543. #endif
  544. #ifdef XF86BIGFONT
  545. {
  546. extern void XF86BigfontFreeFontShm(FontPtr);
  547. XF86BigfontFreeFontShm(pfont);
  548. }
  549. #endif
  550. fpe = pfont->fpe;
  551. (*fpe_functions[fpe->type].close_font) (fpe, pfont);
  552. FreeFPE(fpe);
  553. }
  554. return (Success);
  555. }
  556. /***====================================================================***/
  557. /**
  558. * Sets up pReply as the correct QueryFontReply for pFont with the first
  559. * nProtoCCIStructs char infos.
  560. *
  561. * \param pReply caller must allocate this storage
  562. */
  563. void
  564. QueryFont(FontPtr pFont, xQueryFontReply *pReply, int nProtoCCIStructs)
  565. {
  566. FontPropPtr pFP;
  567. int r,
  568. c,
  569. i;
  570. xFontProp *prFP;
  571. xCharInfo *prCI;
  572. xCharInfo *charInfos[256];
  573. unsigned char chars[512];
  574. int ninfos;
  575. unsigned long ncols;
  576. unsigned long count;
  577. /* pr->length set in dispatch */
  578. pReply->minCharOrByte2 = pFont->info.firstCol;
  579. pReply->defaultChar = pFont->info.defaultCh;
  580. pReply->maxCharOrByte2 = pFont->info.lastCol;
  581. pReply->drawDirection = pFont->info.drawDirection;
  582. pReply->allCharsExist = pFont->info.allExist;
  583. pReply->minByte1 = pFont->info.firstRow;
  584. pReply->maxByte1 = pFont->info.lastRow;
  585. pReply->fontAscent = pFont->info.fontAscent;
  586. pReply->fontDescent = pFont->info.fontDescent;
  587. pReply->minBounds = pFont->info.ink_minbounds;
  588. pReply->maxBounds = pFont->info.ink_maxbounds;
  589. pReply->nFontProps = pFont->info.nprops;
  590. pReply->nCharInfos = nProtoCCIStructs;
  591. for (i = 0, pFP = pFont->info.props, prFP = (xFontProp *) (&pReply[1]);
  592. i < pFont->info.nprops;
  593. i++, pFP++, prFP++) {
  594. prFP->name = pFP->name;
  595. prFP->value = pFP->value;
  596. }
  597. ninfos = 0;
  598. ncols = (unsigned long) (pFont->info.lastCol - pFont->info.firstCol + 1);
  599. prCI = (xCharInfo *) (prFP);
  600. for (r = pFont->info.firstRow;
  601. ninfos < nProtoCCIStructs && r <= (int)pFont->info.lastRow;
  602. r++) {
  603. i = 0;
  604. for (c = pFont->info.firstCol; c <= (int)pFont->info.lastCol; c++) {
  605. chars[i++] = r;
  606. chars[i++] = c;
  607. }
  608. (*pFont->get_metrics) (pFont, ncols, chars,
  609. TwoD16Bit, &count, charInfos);
  610. i = 0;
  611. for (i = 0; i < (int) count && ninfos < nProtoCCIStructs; i++) {
  612. *prCI = *charInfos[i];
  613. prCI++;
  614. ninfos++;
  615. }
  616. }
  617. return;
  618. }
  619. static Bool
  620. doListFontsAndAliases(ClientPtr client, LFclosurePtr c)
  621. {
  622. FontPathElementPtr fpe;
  623. int err = Successful;
  624. FontNamesPtr names = NULL;
  625. char *name, *resolved=NULL;
  626. int namelen, resolvedlen;
  627. int nnames;
  628. int stringLens;
  629. int i;
  630. xListFontsReply reply;
  631. char *bufptr;
  632. char *bufferStart;
  633. int aliascount = 0;
  634. if (client->clientGone)
  635. {
  636. if (c->current.current_fpe < c->num_fpes)
  637. {
  638. fpe = c->fpe_list[c->current.current_fpe];
  639. (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe);
  640. }
  641. err = Successful;
  642. goto bail;
  643. }
  644. if (!c->current.patlen)
  645. goto finish;
  646. while (c->current.current_fpe < c->num_fpes) {
  647. fpe = c->fpe_list[c->current.current_fpe];
  648. err = Successful;
  649. if (!fpe_functions[fpe->type].start_list_fonts_and_aliases)
  650. {
  651. /* This FPE doesn't support/require list_fonts_and_aliases */
  652. err = (*fpe_functions[fpe->type].list_fonts)
  653. ((pointer) c->client, fpe, c->current.pattern,
  654. c->current.patlen, c->current.max_names - c->names->nnames,
  655. c->names);
  656. if (err == Suspended) {
  657. if (!c->slept) {
  658. c->slept = TRUE;
  659. ClientSleep(client,
  660. (ClientSleepProcPtr)doListFontsAndAliases,
  661. (pointer) c);
  662. #ifdef NXAGENT_DEBUG
  663. fprintf(stderr, " NXdixfonts: doListFont (1): client [%lx] sleeping.\n", client);
  664. #endif
  665. }
  666. return TRUE;
  667. }
  668. err = BadFontName;
  669. }
  670. else
  671. {
  672. /* Start of list_fonts_and_aliases functionality. Modeled
  673. after list_fonts_with_info in that it resolves aliases,
  674. except that the information collected from FPEs is just
  675. names, not font info. Each list_next_font_or_alias()
  676. returns either a name into name/namelen or an alias into
  677. name/namelen and its target name into resolved/resolvedlen.
  678. The code at this level then resolves the alias by polling
  679. the FPEs. */
  680. if (!c->current.list_started) {
  681. err = (*fpe_functions[fpe->type].start_list_fonts_and_aliases)
  682. ((pointer) c->client, fpe, c->current.pattern,
  683. c->current.patlen, c->current.max_names - c->names->nnames,
  684. &c->current.private);
  685. if (err == Suspended) {
  686. if (!c->slept) {
  687. ClientSleep(client,
  688. (ClientSleepProcPtr)doListFontsAndAliases,
  689. (pointer) c);
  690. c->slept = TRUE;
  691. }
  692. return TRUE;
  693. }
  694. if (err == Successful)
  695. c->current.list_started = TRUE;
  696. }
  697. if (err == Successful) {
  698. char *tmpname;
  699. name = 0;
  700. err = (*fpe_functions[fpe->type].list_next_font_or_alias)
  701. ((pointer) c->client, fpe, &name, &namelen, &tmpname,
  702. &resolvedlen, c->current.private);
  703. if (err == Suspended) {
  704. if (!c->slept) {
  705. ClientSleep(client,
  706. (ClientSleepProcPtr)doListFontsAndAliases,
  707. (pointer) c);
  708. c->slept = TRUE;
  709. #ifdef NXAGENT_DEBUG
  710. fprintf(stderr, " NXdixfonts: doListFont (2): client [%lx] sleeping.\n", client);
  711. #endif
  712. #ifdef NXAGENT_DEBUG
  713. fprintf(stderr, " NXdixfonts: doListFont (3): client [%lx] sleeping.\n", client);
  714. #endif
  715. }
  716. return TRUE;
  717. }
  718. if (err == FontNameAlias) {
  719. if (resolved) xfree(resolved);
  720. resolved = (char *) xalloc(resolvedlen + 1);
  721. if (resolved)
  722. memmove(resolved, tmpname, resolvedlen + 1);
  723. }
  724. }
  725. if (err == Successful)
  726. {
  727. if (c->haveSaved)
  728. {
  729. if (c->savedName)
  730. (void)AddFontNamesName(c->names, c->savedName,
  731. c->savedNameLen);
  732. }
  733. else
  734. (void)AddFontNamesName(c->names, name, namelen);
  735. }
  736. /*
  737. * When we get an alias back, save our state and reset back to
  738. * the start of the FPE looking for the specified name. As
  739. * soon as a real font is found for the alias, pop back to the
  740. * old state
  741. */
  742. else if (err == FontNameAlias) {
  743. char tmp_pattern[XLFDMAXFONTNAMELEN];
  744. /*
  745. * when an alias recurses, we need to give
  746. * the last FPE a chance to clean up; so we call
  747. * it again, and assume that the error returned
  748. * is BadFontName, indicating the alias resolution
  749. * is complete.
  750. */
  751. memmove(tmp_pattern, resolved, resolvedlen);
  752. if (c->haveSaved)
  753. {
  754. char *tmpname;
  755. int tmpnamelen;
  756. tmpname = 0;
  757. (void) (*fpe_functions[fpe->type].list_next_font_or_alias)
  758. ((pointer) c->client, fpe, &tmpname, &tmpnamelen,
  759. &tmpname, &tmpnamelen, c->current.private);
  760. if (--aliascount <= 0)
  761. {
  762. err = BadFontName;
  763. goto ContBadFontName;
  764. }
  765. }
  766. else
  767. {
  768. c->saved = c->current;
  769. c->haveSaved = TRUE;
  770. if (c->savedName)
  771. xfree(c->savedName);
  772. c->savedName = (char *)xalloc(namelen + 1);
  773. if (c->savedName)
  774. memmove(c->savedName, name, namelen + 1);
  775. c->savedNameLen = namelen;
  776. aliascount = 20;
  777. }
  778. memmove(c->current.pattern, tmp_pattern, resolvedlen);
  779. c->current.patlen = resolvedlen;
  780. c->current.max_names = c->names->nnames + 1;
  781. c->current.current_fpe = -1;
  782. c->current.private = 0;
  783. err = BadFontName;
  784. }
  785. }
  786. /*
  787. * At the end of this FPE, step to the next. If we've finished
  788. * processing an alias, pop state back. If we've collected enough
  789. * font names, quit.
  790. */
  791. if (err == BadFontName) {
  792. ContBadFontName: ;
  793. c->current.list_started = FALSE;
  794. c->current.current_fpe++;
  795. err = Successful;
  796. if (c->haveSaved)
  797. {
  798. if (c->names->nnames == c->current.max_names ||
  799. c->current.current_fpe == c->num_fpes) {
  800. c->haveSaved = FALSE;
  801. c->current = c->saved;
  802. /* Give the saved namelist a chance to clean itself up */
  803. continue;
  804. }
  805. }
  806. if (c->names->nnames == c->current.max_names)
  807. break;
  808. }
  809. }
  810. /*
  811. * send the reply
  812. */
  813. if (err != Successful) {
  814. SendErrorToClient(client, X_ListFonts, 0, 0, FontToXError(err));
  815. goto bail;
  816. }
  817. finish:
  818. names = c->names;
  819. nnames = names->nnames;
  820. client = c->client;
  821. stringLens = 0;
  822. for (i = 0; i < nnames; i++)
  823. stringLens += (names->length[i] <= 255) ? names->length[i] : 0;
  824. reply.type = X_Reply;
  825. reply.length = (stringLens + nnames + 3) >> 2;
  826. reply.nFonts = nnames;
  827. reply.sequenceNumber = client->sequence;
  828. bufptr = bufferStart = (char *) ALLOCATE_LOCAL(reply.length << 2);
  829. if (!bufptr && reply.length) {
  830. SendErrorToClient(client, X_ListFonts, 0, 0, BadAlloc);
  831. goto bail;
  832. }
  833. /*
  834. * since WriteToClient long word aligns things, copy to temp buffer and
  835. * write all at once
  836. */
  837. for (i = 0; i < nnames; i++) {
  838. if (names->length[i] > 255)
  839. reply.nFonts--;
  840. else
  841. {
  842. {
  843. /* dirty hack: don't list to client fonts not existing on the remote side */
  844. char tmp[256];
  845. memcpy(tmp, names->names[i], names->length[i]);
  846. tmp[ names->length[i] ] = 0;
  847. if (nxagentFontLookUp(tmp) == 0)
  848. {
  849. #ifdef NXAGENT_FONTMATCH_DEBUG
  850. fprintf(stderr, "doListFontsAndAliases:\n");
  851. fprintf(stderr, " removing font: %s \n", tmp);
  852. #endif
  853. reply.nFonts--;
  854. stringLens -= names->length[i];
  855. continue;
  856. }
  857. }
  858. *bufptr++ = names->length[i];
  859. memmove( bufptr, names->names[i], names->length[i]);
  860. bufptr += names->length[i];
  861. }
  862. }
  863. nnames = reply.nFonts;
  864. reply.length = (stringLens + nnames + 3) >> 2;
  865. client->pSwapReplyFunc = ReplySwapVector[X_ListFonts];
  866. WriteSwappedDataToClient(client, sizeof(xListFontsReply), &reply);
  867. (void) WriteToClient(client, stringLens + nnames, bufferStart);
  868. DEALLOCATE_LOCAL(bufferStart);
  869. bail:
  870. if (c->slept)
  871. {
  872. ClientWakeup(client);
  873. #ifdef NXAGENT_DEBUG
  874. fprintf(stderr, " NXdixfonts: doListFont: client [%lx] wakeup.\n", client);
  875. #endif
  876. }
  877. for (i = 0; i < c->num_fpes; i++)
  878. FreeFPE(c->fpe_list[i]);
  879. xfree(c->fpe_list);
  880. if (c->savedName) xfree(c->savedName);
  881. FreeFontNames(names);
  882. xfree(c);
  883. if (resolved) xfree(resolved);
  884. return TRUE;
  885. }
  886. int
  887. ListFonts(ClientPtr client, unsigned char *pattern, unsigned length,
  888. unsigned max_names)
  889. {
  890. int i;
  891. LFclosurePtr c;
  892. /*
  893. * The right error to return here would be BadName, however the
  894. * specification does not allow for a Name error on this request.
  895. * Perhaps a better solution would be to return a nil list, i.e.
  896. * a list containing zero fontnames.
  897. */
  898. if (length > XLFDMAXFONTNAMELEN)
  899. return BadAlloc;
  900. if (!(c = (LFclosurePtr) xalloc(sizeof *c)))
  901. return BadAlloc;
  902. c->fpe_list = (FontPathElementPtr *)
  903. xalloc(sizeof(FontPathElementPtr) * num_fpes);
  904. if (!c->fpe_list) {
  905. xfree(c);
  906. return BadAlloc;
  907. }
  908. c->names = MakeFontNamesRecord(max_names < nxagentMaxFontNames ? max_names : nxagentMaxFontNames);
  909. if (!c->names)
  910. {
  911. xfree(c->fpe_list);
  912. xfree(c);
  913. return BadAlloc;
  914. }
  915. memmove( c->current.pattern, pattern, length);
  916. for (i = 0; i < num_fpes; i++) {
  917. c->fpe_list[i] = font_path_elements[i];
  918. UseFPE(c->fpe_list[i]);
  919. }
  920. c->client = client;
  921. c->num_fpes = num_fpes;
  922. c->current.patlen = length;
  923. c->current.current_fpe = 0;
  924. c->current.max_names = max_names;
  925. c->current.list_started = FALSE;
  926. c->current.private = 0;
  927. c->haveSaved = FALSE;
  928. c->slept = FALSE;
  929. c->savedName = 0;
  930. doListFontsAndAliases(client, c);
  931. return Success;
  932. }
  933. int
  934. doListFontsWithInfo(ClientPtr client, LFWIclosurePtr c)
  935. {
  936. FontPathElementPtr fpe;
  937. int err = Successful;
  938. char *name;
  939. int namelen;
  940. int numFonts;
  941. FontInfoRec fontInfo,
  942. *pFontInfo;
  943. xListFontsWithInfoReply *reply;
  944. int length;
  945. xFontProp *pFP;
  946. int i;
  947. int aliascount = 0;
  948. xListFontsWithInfoReply finalReply;
  949. if (client->clientGone)
  950. {
  951. if (c->current.current_fpe < c->num_fpes)
  952. {
  953. fpe = c->fpe_list[c->current.current_fpe];
  954. (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe);
  955. }
  956. err = Successful;
  957. goto bail;
  958. }
  959. client->pSwapReplyFunc = ReplySwapVector[X_ListFontsWithInfo];
  960. if (!c->current.patlen)
  961. goto finish;
  962. while (c->current.current_fpe < c->num_fpes)
  963. {
  964. fpe = c->fpe_list[c->current.current_fpe];
  965. err = Successful;
  966. if (!c->current.list_started)
  967. {
  968. err = (*fpe_functions[fpe->type].start_list_fonts_with_info)
  969. (client, fpe, c->current.pattern, c->current.patlen,
  970. c->current.max_names, &c->current.private);
  971. if (err == Suspended)
  972. {
  973. if (!c->slept)
  974. {
  975. ClientSleep(client, (ClientSleepProcPtr)doListFontsWithInfo, c);
  976. c->slept = TRUE;
  977. #ifdef NXAGENT_DEBUG
  978. fprintf(stderr, " NXdixfonts: doListFontWinfo (1): client [%lx] sleeping.\n", client);
  979. #endif
  980. }
  981. return TRUE;
  982. }
  983. if (err == Successful)
  984. c->current.list_started = TRUE;
  985. }
  986. if (err == Successful)
  987. {
  988. name = 0;
  989. pFontInfo = &fontInfo;
  990. err = (*fpe_functions[fpe->type].list_next_font_with_info)
  991. (client, fpe, &name, &namelen, &pFontInfo,
  992. &numFonts, c->current.private);
  993. if (err == Suspended)
  994. {
  995. if (!c->slept)
  996. {
  997. ClientSleep(client,
  998. (ClientSleepProcPtr)doListFontsWithInfo,
  999. c);
  1000. c->slept = TRUE;
  1001. #ifdef NXAGENT_DEBUG
  1002. fprintf(stderr, " NXdixfonts: doListFontWinfo (2): client [%lx] sleeping.\n", client);
  1003. #endif
  1004. }
  1005. return TRUE;
  1006. }
  1007. }
  1008. /*
  1009. * When we get an alias back, save our state and reset back to the
  1010. * start of the FPE looking for the specified name. As soon as a real
  1011. * font is found for the alias, pop back to the old state
  1012. */
  1013. if (err == FontNameAlias)
  1014. {
  1015. /*
  1016. * when an alias recurses, we need to give
  1017. * the last FPE a chance to clean up; so we call
  1018. * it again, and assume that the error returned
  1019. * is BadFontName, indicating the alias resolution
  1020. * is complete.
  1021. */
  1022. if (c->haveSaved)
  1023. {
  1024. char *tmpname;
  1025. int tmpnamelen;
  1026. FontInfoPtr tmpFontInfo;
  1027. tmpname = 0;
  1028. tmpFontInfo = &fontInfo;
  1029. (void) (*fpe_functions[fpe->type].list_next_font_with_info)
  1030. (client, fpe, &tmpname, &tmpnamelen, &tmpFontInfo,
  1031. &numFonts, c->current.private);
  1032. if (--aliascount <= 0)
  1033. {
  1034. err = BadFontName;
  1035. goto ContBadFontName;
  1036. }
  1037. }
  1038. else
  1039. {
  1040. c->saved = c->current;
  1041. c->haveSaved = TRUE;
  1042. c->savedNumFonts = numFonts;
  1043. if (c->savedName)
  1044. xfree(c->savedName);
  1045. c->savedName = (char *)xalloc(namelen + 1);
  1046. if (c->savedName)
  1047. memmove(c->savedName, name, namelen + 1);
  1048. aliascount = 20;
  1049. }
  1050. memmove(c->current.pattern, name, namelen);
  1051. c->current.patlen = namelen;
  1052. c->current.max_names = 1;
  1053. c->current.current_fpe = 0;
  1054. c->current.private = 0;
  1055. c->current.list_started = FALSE;
  1056. }
  1057. /*
  1058. * At the end of this FPE, step to the next. If we've finished
  1059. * processing an alias, pop state back. If we've sent enough font
  1060. * names, quit. Always wait for BadFontName to let the FPE
  1061. * have a chance to clean up.
  1062. */
  1063. else if (err == BadFontName)
  1064. {
  1065. ContBadFontName: ;
  1066. c->current.list_started = FALSE;
  1067. c->current.current_fpe++;
  1068. err = Successful;
  1069. if (c->haveSaved)
  1070. {
  1071. if (c->current.max_names == 0 ||
  1072. c->current.current_fpe == c->num_fpes)
  1073. {
  1074. c->haveSaved = FALSE;
  1075. c->saved.max_names -= (1 - c->current.max_names);
  1076. c->current = c->saved;
  1077. }
  1078. }
  1079. else if (c->current.max_names == 0)
  1080. break;
  1081. }
  1082. else if (err == Successful)
  1083. {
  1084. if (c->haveSaved)
  1085. {
  1086. numFonts = c->savedNumFonts;
  1087. name = c->savedName;
  1088. namelen = strlen(name);
  1089. }
  1090. if (nxagentFontLookUp(name) == 0)
  1091. {
  1092. #ifdef NXAGENT_FONTMATCH_DEBUG
  1093. fprintf(stderr, "doListFontsAndAliases (with info):\n");
  1094. fprintf(stderr, " removing font: %s \n", name);
  1095. #endif
  1096. continue;
  1097. }
  1098. length = sizeof(*reply) + pFontInfo->nprops * sizeof(xFontProp);
  1099. reply = c->reply;
  1100. if (c->length < length)
  1101. {
  1102. reply = (xListFontsWithInfoReply *) xrealloc(c->reply, length);
  1103. if (!reply)
  1104. {
  1105. err = AllocError;
  1106. break;
  1107. }
  1108. c->reply = reply;
  1109. c->length = length;
  1110. }
  1111. reply->type = X_Reply;
  1112. reply->length = (sizeof *reply - sizeof(xGenericReply) +
  1113. pFontInfo->nprops * sizeof(xFontProp) +
  1114. namelen + 3) >> 2;
  1115. reply->sequenceNumber = client->sequence;
  1116. reply->nameLength = namelen;
  1117. reply->minBounds = pFontInfo->ink_minbounds;
  1118. reply->maxBounds = pFontInfo->ink_maxbounds;
  1119. reply->minCharOrByte2 = pFontInfo->firstCol;
  1120. reply->maxCharOrByte2 = pFontInfo->lastCol;
  1121. reply->defaultChar = pFontInfo->defaultCh;
  1122. reply->nFontProps = pFontInfo->nprops;
  1123. reply->drawDirection = pFontInfo->drawDirection;
  1124. reply->minByte1 = pFontInfo->firstRow;
  1125. reply->maxByte1 = pFontInfo->lastRow;
  1126. reply->allCharsExist = pFontInfo->allExist;
  1127. reply->fontAscent = pFontInfo->fontAscent;
  1128. reply->fontDescent = pFontInfo->fontDescent;
  1129. reply->nReplies = numFonts;
  1130. pFP = (xFontProp *) (reply + 1);
  1131. for (i = 0; i < pFontInfo->nprops; i++)
  1132. {
  1133. pFP->name = pFontInfo->props[i].name;
  1134. pFP->value = pFontInfo->props[i].value;
  1135. pFP++;
  1136. }
  1137. WriteSwappedDataToClient(client, length, reply);
  1138. (void) WriteToClient(client, namelen, name);
  1139. if (pFontInfo == &fontInfo)
  1140. {
  1141. xfree(fontInfo.props);
  1142. xfree(fontInfo.isStringProp);
  1143. }
  1144. --c->current.max_names;
  1145. }
  1146. }
  1147. finish:
  1148. length = sizeof(xListFontsWithInfoReply);
  1149. bzero((char *) &finalReply, sizeof(xListFontsWithInfoReply));
  1150. finalReply.type = X_Reply;
  1151. finalReply.sequenceNumber = client->sequence;
  1152. finalReply.length = (sizeof(xListFontsWithInfoReply)
  1153. - sizeof(xGenericReply)) >> 2;
  1154. WriteSwappedDataToClient(client, length, &finalReply);
  1155. bail:
  1156. if (c->slept)
  1157. {
  1158. ClientWakeup(client);
  1159. #ifdef NXAGENT_DEBUG
  1160. fprintf(stderr, " NXdixfonts: doListFontWinfo: client [%lx] wakeup.\n", client);
  1161. #endif
  1162. }
  1163. for (i = 0; i < c->num_fpes; i++)
  1164. FreeFPE(c->fpe_list[i]);
  1165. xfree(c->reply);
  1166. xfree(c->fpe_list);
  1167. if (c->savedName) xfree(c->savedName);
  1168. xfree(c);
  1169. return TRUE;
  1170. }
  1171. int
  1172. StartListFontsWithInfo(ClientPtr client, int length, unsigned char *pattern,
  1173. int max_names)
  1174. {
  1175. int i;
  1176. LFWIclosurePtr c;
  1177. /*
  1178. * The right error to return here would be BadName, however the
  1179. * specification does not allow for a Name error on this request.
  1180. * Perhaps a better solution would be to return a nil list, i.e.
  1181. * a list containing zero fontnames.
  1182. */
  1183. if (length > XLFDMAXFONTNAMELEN)
  1184. return BadAlloc;
  1185. if (!(c = (LFWIclosurePtr) xalloc(sizeof *c)))
  1186. goto badAlloc;
  1187. c->fpe_list = (FontPathElementPtr *)
  1188. xalloc(sizeof(FontPathElementPtr) * num_fpes);
  1189. if (!c->fpe_list)
  1190. {
  1191. xfree(c);
  1192. goto badAlloc;
  1193. }
  1194. memmove(c->current.pattern, pattern, length);
  1195. for (i = 0; i < num_fpes; i++)
  1196. {
  1197. c->fpe_list[i] = font_path_elements[i];
  1198. UseFPE(c->fpe_list[i]);
  1199. }
  1200. c->client = client;
  1201. c->num_fpes = num_fpes;
  1202. c->reply = 0;
  1203. c->length = 0;
  1204. c->current.patlen = length;
  1205. c->current.current_fpe = 0;
  1206. c->current.max_names = max_names;
  1207. c->current.list_started = FALSE;
  1208. c->current.private = 0;
  1209. c->savedNumFonts = 0;
  1210. c->haveSaved = FALSE;
  1211. c->slept = FALSE;
  1212. c->savedName = 0;
  1213. doListFontsWithInfo(client, c);
  1214. return Success;
  1215. badAlloc:
  1216. return BadAlloc;
  1217. }
  1218. #define TextEltHeader 2
  1219. #define FontShiftSize 5
  1220. static XID clearGC[] = { CT_NONE };
  1221. #define clearGCmask (GCClipMask)
  1222. int
  1223. doPolyText(ClientPtr client, register PTclosurePtr c)
  1224. {
  1225. register FontPtr pFont = c->pGC->font, oldpFont;
  1226. Font fid, oldfid;
  1227. int err = Success, lgerr; /* err is in X error, not font error, space */
  1228. enum { NEVER_SLEPT, START_SLEEP, SLEEPING } client_state = NEVER_SLEPT;
  1229. FontPathElementPtr fpe;
  1230. GC *origGC = NULL;
  1231. if (client->clientGone)
  1232. {
  1233. fpe = c->pGC->font->fpe;
  1234. (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe);
  1235. if (c->slept)
  1236. {
  1237. /* Client has died, but we cannot bail out right now. We
  1238. need to clean up after the work we did when going to
  1239. sleep. Setting the drawable pointer to 0 makes this
  1240. happen without any attempts to render or perform other
  1241. unnecessary activities. */
  1242. c->pDraw = (DrawablePtr)0;
  1243. }
  1244. else
  1245. {
  1246. err = Success;
  1247. goto bail;
  1248. }
  1249. }
  1250. /* Make sure our drawable hasn't disappeared while we slept. */
  1251. if (c->slept &&
  1252. c->pDraw &&
  1253. c->pDraw != (DrawablePtr)SecurityLookupIDByClass(client, c->did,
  1254. RC_DRAWABLE, SecurityWriteAccess))
  1255. {
  1256. /* Our drawable has disappeared. Treat like client died... ask
  1257. the FPE code to clean up after client and avoid further
  1258. rendering while we clean up after ourself. */
  1259. fpe = c->pGC->font->fpe;
  1260. (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe);
  1261. c->pDraw = (DrawablePtr)0;
  1262. }
  1263. client_state = c->slept ? SLEEPING : NEVER_SLEPT;
  1264. while (c->endReq - c->pElt > TextEltHeader)
  1265. {
  1266. if (*c->pElt == FontChange)
  1267. {
  1268. if (c->endReq - c->pElt < FontShiftSize)
  1269. {
  1270. err = BadLength;
  1271. goto bail;
  1272. }
  1273. oldpFont = pFont;
  1274. oldfid = fid;
  1275. fid = ((Font)*(c->pElt+4)) /* big-endian */
  1276. | ((Font)*(c->pElt+3)) << 8
  1277. | ((Font)*(c->pElt+2)) << 16
  1278. | ((Font)*(c->pElt+1)) << 24;
  1279. pFont = (FontPtr)SecurityLookupIDByType(client, fid, RT_FONT,
  1280. SecurityReadAccess);
  1281. if (!pFont)
  1282. {
  1283. client->errorValue = fid;
  1284. err = BadFont;
  1285. /* restore pFont and fid for step 4 (described below) */
  1286. pFont = oldpFont;
  1287. fid = oldfid;
  1288. /* If we're in START_SLEEP mode, the following step
  1289. shortens the request... in the unlikely event that
  1290. the fid somehow becomes valid before we come through
  1291. again to actually execute the polytext, which would
  1292. then mess up our refcounting scheme badly. */
  1293. c->err = err;
  1294. c->endReq = c->pElt;
  1295. goto bail;
  1296. }
  1297. /* Step 3 (described below) on our new font */
  1298. if (client_state == START_SLEEP)
  1299. pFont->refcnt++;
  1300. else
  1301. {
  1302. if (pFont != c->pGC->font && c->pDraw)
  1303. {
  1304. ChangeGC( c->pGC, GCFont, &fid);
  1305. ValidateGC(c->pDraw, c->pGC);
  1306. if (c->reqType == X_PolyText8)
  1307. c->polyText = (PolyTextPtr) c->pGC->ops->PolyText8;
  1308. else
  1309. c->polyText = (PolyTextPtr) c->pGC->ops->PolyText16;
  1310. }
  1311. /* Undo the refcnt++ we performed when going to sleep */
  1312. if (client_state == SLEEPING)
  1313. (void)CloseFont(c->pGC->font, (Font)0);
  1314. }
  1315. c->pElt += FontShiftSize;
  1316. }
  1317. else /* print a string */
  1318. {
  1319. unsigned char *pNextElt;
  1320. pNextElt = c->pElt + TextEltHeader + (*c->pElt)*c->itemSize;
  1321. if ( pNextElt > c->endReq)
  1322. {
  1323. err = BadLength;
  1324. goto bail;
  1325. }
  1326. if (client_state == START_SLEEP)
  1327. {
  1328. c->pElt = pNextElt;
  1329. continue;
  1330. }
  1331. if (c->pDraw)
  1332. {
  1333. lgerr = LoadGlyphs(client, c->pGC->font, *c->pElt, c->itemSize,
  1334. c->pElt + TextEltHeader);
  1335. }
  1336. else lgerr = Successful;
  1337. if (lgerr == Suspended)
  1338. {
  1339. if (!c->slept) {
  1340. int len;
  1341. GC *pGC;
  1342. PTclosurePtr new_closure;
  1343. /* We're putting the client to sleep. We need to do a few things
  1344. to ensure successful and atomic-appearing execution of the
  1345. remainder of the request. First, copy the remainder of the
  1346. request into a safe malloc'd area. Second, create a scratch GC
  1347. to use for the remainder of the request. Third, mark all fonts
  1348. referenced in the remainder of the request to prevent their
  1349. deallocation. Fourth, make the original GC look like the
  1350. request has completed... set its font to the final font value
  1351. from this request. These GC manipulations are for the unlikely
  1352. (but possible) event that some other client is using the GC.
  1353. Steps 3 and 4 are performed by running this procedure through
  1354. the remainder of the request in a special no-render mode
  1355. indicated by client_state = START_SLEEP. */
  1356. /* Step 1 */
  1357. /* Allocate a malloc'd closure structure to replace
  1358. the local one we were passed */
  1359. new_closure = (PTclosurePtr) xalloc(sizeof(PTclosureRec));
  1360. if (!new_closure)
  1361. {
  1362. err = BadAlloc;
  1363. goto bail;
  1364. }
  1365. *new_closure = *c;
  1366. c = new_closure;
  1367. len = c->endReq - c->pElt;
  1368. c->data = (unsigned char *)xalloc(len);
  1369. if (!c->data)
  1370. {
  1371. xfree(c);
  1372. err = BadAlloc;
  1373. goto bail;
  1374. }
  1375. memmove(c->data, c->pElt, len);
  1376. c->pElt = c->data;
  1377. c->endReq = c->pElt + len;
  1378. /* Step 2 */
  1379. pGC = GetScratchGC(c->pGC->depth, c->pGC->pScreen);
  1380. if (!pGC)
  1381. {
  1382. xfree(c->data);
  1383. xfree(c);
  1384. err = BadAlloc;
  1385. goto bail;
  1386. }
  1387. pGC->tileIsPixel = TRUE;
  1388. pGC->tile.pixel = 0;
  1389. pGC->stipple = NullPixmap;
  1390. if ((err = CopyGC(c->pGC, pGC, GCFunction |
  1391. GCPlaneMask | GCForeground |
  1392. GCBackground | GCFillStyle |
  1393. GCTile | GCStipple |
  1394. GCTileStipXOrigin |
  1395. GCTileStipYOrigin | GCFont |
  1396. GCSubwindowMode | GCClipXOrigin |
  1397. GCClipYOrigin | GCClipMask)) !=
  1398. Success)
  1399. {
  1400. FreeScratchGC(pGC);
  1401. xfree(c->data);
  1402. xfree(c);
  1403. err = BadAlloc;
  1404. goto bail;
  1405. }
  1406. origGC = c->pGC;
  1407. c->pGC = pGC;
  1408. ValidateGC(c->pDraw, c->pGC);
  1409. c->slept = TRUE;
  1410. ClientSleep(client,
  1411. (ClientSleepProcPtr)doPolyText,
  1412. (pointer) c);
  1413. #ifdef NXAGENT_DEBUG
  1414. fprintf(stderr, " NXdixfonts: doPolyText (1): client [%lx] sleeping.\n", client);
  1415. #endif
  1416. /* Set up to perform steps 3 and 4 */
  1417. client_state = START_SLEEP;
  1418. continue; /* on to steps 3 and 4 */
  1419. }
  1420. return TRUE;
  1421. }
  1422. else if (lgerr != Successful)
  1423. {
  1424. err = FontToXError(lgerr);
  1425. goto bail;
  1426. }
  1427. if (c->pDraw)
  1428. {
  1429. c->xorg += *((INT8 *)(c->pElt + 1)); /* must be signed */
  1430. c->xorg = (* c->polyText)(c->pDraw, c->pGC, c->xorg, c->yorg,
  1431. *c->pElt, c->pElt + TextEltHeader);
  1432. }
  1433. c->pElt = pNextElt;
  1434. }
  1435. }
  1436. bail:
  1437. if (client_state == START_SLEEP)
  1438. {
  1439. /* Step 4 */
  1440. if (pFont != origGC->font)
  1441. {
  1442. ChangeGC(origGC, GCFont, &fid);
  1443. ValidateGC(c->pDraw, origGC);
  1444. }
  1445. /* restore pElt pointer for execution of remainder of the request */
  1446. c->pElt = c->data;
  1447. return TRUE;
  1448. }
  1449. if (c->err != Success) err = c->err;
  1450. if (err != Success && c->client != serverClient) {
  1451. #ifdef PANORAMIX
  1452. if (noPanoramiXExtension || !c->pGC->pScreen->myNum)
  1453. #endif
  1454. SendErrorToClient(c->client, c->reqType, 0, 0, err);
  1455. }
  1456. if (c->slept)
  1457. {
  1458. ClientWakeup(c->client);
  1459. #ifdef NXAGENT_DEBUG
  1460. fprintf(stderr, " NXdixfonts: doPolytext: client [%lx] wakeup.\n", client);
  1461. #endif
  1462. ChangeGC(c->pGC, clearGCmask, clearGC);
  1463. /* Unreference the font from the scratch GC */
  1464. CloseFont(c->pGC->font, (Font)0);
  1465. c->pGC->font = NullFont;
  1466. FreeScratchGC(c->pGC);
  1467. xfree(c->data);
  1468. xfree(c);
  1469. }
  1470. return TRUE;
  1471. }
  1472. int
  1473. PolyText(ClientPtr client, DrawablePtr pDraw, GC *pGC, unsigned char *pElt,
  1474. unsigned char *endReq, int xorg, int yorg, int reqType, XID did)
  1475. {
  1476. PTclosureRec local_closure;
  1477. local_closure.pElt = pElt;
  1478. local_closure.endReq = endReq;
  1479. local_closure.client = client;
  1480. local_closure.pDraw = pDraw;
  1481. local_closure.xorg = xorg;
  1482. local_closure.yorg = yorg;
  1483. if ((local_closure.reqType = reqType) == X_PolyText8)
  1484. {
  1485. local_closure.polyText = (PolyTextPtr) pGC->ops->PolyText8;
  1486. local_closure.itemSize = 1;
  1487. }
  1488. else
  1489. {
  1490. local_closure.polyText = (PolyTextPtr) pGC->ops->PolyText16;
  1491. local_closure.itemSize = 2;
  1492. }
  1493. local_closure.pGC = pGC;
  1494. local_closure.did = did;
  1495. local_closure.err = Success;
  1496. local_closure.slept = FALSE;
  1497. (void) doPolyText(client, &local_closure);
  1498. return Success;
  1499. }
  1500. #undef TextEltHeader
  1501. #undef FontShiftSize
  1502. int
  1503. doImageText(ClientPtr client, register ITclosurePtr c)
  1504. {
  1505. int err = Success, lgerr; /* err is in X error, not font error, space */
  1506. FontPathElementPtr fpe;
  1507. if (client->clientGone)
  1508. {
  1509. fpe = c->pGC->font->fpe;
  1510. (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe);
  1511. err = Success;
  1512. goto bail;
  1513. }
  1514. /* Make sure our drawable hasn't disappeared while we slept. */
  1515. if (c->slept &&
  1516. c->pDraw &&
  1517. c->pDraw != (DrawablePtr)SecurityLookupIDByClass(client, c->did,
  1518. RC_DRAWABLE, SecurityWriteAccess))
  1519. {
  1520. /* Our drawable has disappeared. Treat like client died... ask
  1521. the FPE code to clean up after client. */
  1522. fpe = c->pGC->font->fpe;
  1523. (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe);
  1524. err = Success;
  1525. goto bail;
  1526. }
  1527. lgerr = LoadGlyphs(client, c->pGC->font, c->nChars, c->itemSize, c->data);
  1528. if (lgerr == Suspended)
  1529. {
  1530. if (!c->slept) {
  1531. GC *pGC;
  1532. unsigned char *data;
  1533. ITclosurePtr new_closure;
  1534. /* We're putting the client to sleep. We need to
  1535. save some state. Similar problem to that handled
  1536. in doPolyText, but much simpler because the
  1537. request structure is much simpler. */
  1538. new_closure = (ITclosurePtr) xalloc(sizeof(ITclosureRec));
  1539. if (!new_closure)
  1540. {
  1541. err = BadAlloc;
  1542. goto bail;
  1543. }
  1544. *new_closure = *c;
  1545. c = new_closure;
  1546. data = (unsigned char *)xalloc(c->nChars * c->itemSize);
  1547. if (!data)
  1548. {
  1549. xfree(c);
  1550. err = BadAlloc;
  1551. goto bail;
  1552. }
  1553. memmove(data, c->data, c->nChars * c->itemSize);
  1554. c->data = data;
  1555. pGC = GetScratchGC(c->pGC->depth, c->pGC->pScreen);
  1556. if (!pGC)
  1557. {
  1558. xfree(c->data);
  1559. xfree(c);
  1560. err = BadAlloc;
  1561. goto bail;
  1562. }
  1563. pGC->tileIsPixel = TRUE;
  1564. pGC->tile.pixel = 0;
  1565. pGC->stipple = NullPixmap;
  1566. if ((err = CopyGC(c->pGC, pGC, GCFunction | GCPlaneMask |
  1567. GCForeground | GCBackground | GCFillStyle |
  1568. GCTile | GCStipple | GCTileStipXOrigin |
  1569. GCTileStipYOrigin | GCFont |
  1570. GCSubwindowMode | GCClipXOrigin |
  1571. GCClipYOrigin | GCClipMask)) != Success)
  1572. {
  1573. FreeScratchGC(pGC);
  1574. xfree(c->data);
  1575. xfree(c);
  1576. err = BadAlloc;
  1577. goto bail;
  1578. }
  1579. c->pGC = pGC;
  1580. ValidateGC(c->pDraw, c->pGC);
  1581. c->slept = TRUE;
  1582. ClientSleep(client, (ClientSleepProcPtr)doImageText, (pointer) c);
  1583. #ifdef NXAGENT_DEBUG
  1584. fprintf(stderr, " NXdixfonts: doImageText (1): client [%lx] sleeping.\n", client);
  1585. #endif
  1586. }
  1587. return TRUE;
  1588. }
  1589. else if (lgerr != Successful)
  1590. {
  1591. err = FontToXError(lgerr);
  1592. goto bail;
  1593. }
  1594. if (c->pDraw)
  1595. {
  1596. (* c->imageText)(c->pDraw, c->pGC, c->xorg, c->yorg,
  1597. c->nChars, c->data);
  1598. }
  1599. bail:
  1600. if (err != Success && c->client != serverClient) {
  1601. SendErrorToClient(c->client, c->reqType, 0, 0, err);
  1602. }
  1603. if (c->slept)
  1604. {
  1605. ClientWakeup(c->client);
  1606. #ifdef NXAGENT_DEBUG
  1607. fprintf(stderr, " NXdixfonts: doImageText: client [%lx] wakeup.\n", client);
  1608. #endif
  1609. ChangeGC(c->pGC, clearGCmask, clearGC);
  1610. /* Unreference the font from the scratch GC */
  1611. CloseFont(c->pGC->font, (Font)0);
  1612. c->pGC->font = NullFont;
  1613. FreeScratchGC(c->pGC);
  1614. xfree(c->data);
  1615. xfree(c);
  1616. }
  1617. return TRUE;
  1618. }
  1619. int
  1620. ImageText(ClientPtr client, DrawablePtr pDraw, GC *pGC, int nChars,
  1621. unsigned char *data, int xorg, int yorg, int reqType, XID did)
  1622. {
  1623. ITclosureRec local_closure;
  1624. local_closure.client = client;
  1625. local_closure.pDraw = pDraw;
  1626. local_closure.pGC = pGC;
  1627. local_closure.nChars = nChars;
  1628. local_closure.data = data;
  1629. local_closure.xorg = xorg;
  1630. local_closure.yorg = yorg;
  1631. if ((local_closure.reqType = reqType) == X_ImageText8)
  1632. {
  1633. local_closure.imageText = (ImageTextPtr) pGC->ops->ImageText8;
  1634. local_closure.itemSize = 1;
  1635. }
  1636. else
  1637. {
  1638. local_closure.imageText = (ImageTextPtr) pGC->ops->ImageText16;
  1639. local_closure.itemSize = 2;
  1640. }
  1641. local_closure.did = did;
  1642. local_closure.slept = FALSE;
  1643. (void) doImageText(client, &local_closure);
  1644. return Success;
  1645. }
  1646. /* does the necessary magic to figure out the fpe type */
  1647. static int
  1648. DetermineFPEType(char *pathname)
  1649. {
  1650. int i;
  1651. for (i = 0; i < num_fpe_types; i++) {
  1652. if ((*fpe_functions[i].name_check) (pathname))
  1653. return i;
  1654. }
  1655. return -1;
  1656. }
  1657. static void
  1658. FreeFontPath(FontPathElementPtr *list, int n, Bool force)
  1659. {
  1660. int i;
  1661. for (i = 0; i < n; i++) {
  1662. if (force) {
  1663. /* Sanity check that all refcounts will be 0 by the time
  1664. we get to the end of the …

Large files files are truncated, but you can click here to view the full file