diff options
Diffstat (limited to 'nx-X11/programs/Xserver')
-rw-r--r-- | nx-X11/programs/Xserver/hw/nxagent/Font.c | 2147 |
1 files changed, 1071 insertions, 1076 deletions
diff --git a/nx-X11/programs/Xserver/hw/nxagent/Font.c b/nx-X11/programs/Xserver/hw/nxagent/Font.c index ddae19cf0..9df7380d6 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Font.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Font.c @@ -113,15 +113,15 @@ static void printFontCacheDump(char*); typedef struct _nxagentFontRec { - char *name; - int status; + char *name; + int status; } nxagentFontRec, *nxagentFontRecPtr; typedef struct _nxagentFontList { - nxagentFontRecPtr *list; - int length; - int listSize; + nxagentFontRecPtr *list; + int length; + int listSize; } nxagentFontList, *nxagentFontListPtr; nxagentFontList nxagentRemoteFontList = {NULL, (int)0, (int)0}; @@ -130,16 +130,16 @@ int nxagentFontPrivateIndex; typedef struct _nxCacheFontEntry { - Atom atom; - XFontStruct *font_struct; - char *name; + Atom atom; + XFontStruct *font_struct; + char *name; } nxCacheFontEntryRec, *nxCacheFontEntryRecPtr; static struct _nxagentFontCache { - nxCacheFontEntryRecPtr *entry; - int index; - int size; + nxCacheFontEntryRecPtr *entry; + int index; + int size; } nxagentFontCache = { NULL, (int) 0, (int) 0 }; #define CACHE_ENTRY_PTR (nxagentFontCache.entry) @@ -152,10 +152,10 @@ static struct _nxagentFontCache static struct _nxagentFailedToReconnectFonts { - FontPtr *font; - XID *id; - int size; - int index; + FontPtr *font; + XID *id; + int size; + int index; } nxagentFailedToReconnectFonts = {NULL, NULL, 0, 0}; /* @@ -164,519 +164,521 @@ static struct _nxagentFailedToReconnectFonts void nxagentFreeFontCache(void) { - #ifdef NXAGENT_FONTCACHE_DEBUG - fprintf(stderr, "Font: Freeing nxagent font cache\n"); - #endif - - if (CACHE_INDEX == 0) - return; + #ifdef NXAGENT_FONTCACHE_DEBUG + fprintf(stderr, "Font: Freeing nxagent font cache\n"); + #endif - #ifdef NXAGENT_FONTCACHE_DEBUG - fprintf(stderr, "Font: Freeing nxagent font cache, there are [%d] entries.\n", CACHE_INDEX); - #endif + if (CACHE_INDEX == 0) + return; - for (int i = 0; i < CACHE_INDEX; i++) - { #ifdef NXAGENT_FONTCACHE_DEBUG - fprintf(stderr, "Font: Freeing nxagent font cache entry [%d] entry pointer is [%p], name [%s]\n", - i, CACHE_ENTRY(i), CACHE_NAME(i)); + fprintf(stderr, "Font: Freeing nxagent font cache, there are [%d] entries.\n", CACHE_INDEX); #endif - if (CACHE_FSTRUCT(i)) + for (int i = 0; i < CACHE_INDEX; i++) { - nxagentFreeFont(CACHE_FSTRUCT(i)); - } + #ifdef NXAGENT_FONTCACHE_DEBUG + fprintf(stderr, "Font: Freeing nxagent font cache entry [%d] entry pointer is [%p], name [%s]\n", + i, CACHE_ENTRY(i), CACHE_NAME(i)); + #endif - SAFE_free(CACHE_NAME(i)); - SAFE_free(CACHE_ENTRY(i)); - } + if (CACHE_FSTRUCT(i)) + { + nxagentFreeFont(CACHE_FSTRUCT(i)); + } - SAFE_free(CACHE_ENTRY_PTR); - CACHE_ENTRY_PTR = NULL; - CACHE_INDEX = 0; - CACHE_SIZE = 0; + SAFE_free(CACHE_NAME(i)); + SAFE_free(CACHE_ENTRY(i)); + } - #ifdef NXAGENT_FONTCACHE_DEBUG - fprintf(stderr, "Font: nxagent font cache fully freed\n"); - #endif + SAFE_free(CACHE_ENTRY_PTR); + CACHE_ENTRY_PTR = NULL; + CACHE_INDEX = 0; + CACHE_SIZE = 0; - return; + #ifdef NXAGENT_FONTCACHE_DEBUG + fprintf(stderr, "Font: nxagent font cache fully freed\n"); + #endif + + return; } void nxagentListRemoteFonts(const char *searchPattern, const int maxNames) { - char **xList; - int xLen = 0; + if (NXDisplayError(nxagentDisplay) == 1) + { + return; + } - const char *patterns[] = {"*", "-*-*-*-*-*-*-*-*-*-*-*-*-*-*"}; - int patternsQt = 2; + /* + * Avoid querying again the remote fonts. + */ - if (NXDisplayError(nxagentDisplay) == 1) - { - return; - } + if (nxagentRemoteFontList.length > 0) + { + return; + } - /* - * Avoid querying again the remote fonts. - */ + /* + * We can't retrieve the full remote font list with a single query, + * because the number of dashes in the pattern acts as a rule to + * select how to search for the font names, so the pattern '*' is + * useful to retrieve the font aliases, while the other one will + * select the 'real' fonts. + */ - if (nxagentRemoteFontList.length > 0) - { - return; - } + const char *patterns[] = {"*", "-*-*-*-*-*-*-*-*-*-*-*-*-*-*"}; + const int numPatterns = 2; - /* - * We can't retrieve the full remote font list with a single query, - * because the number of dashes in the pattern acts as a rule to - * select how to search for the font names, so the pattern '*' is - * useful to retrieve the font aliases, while the other one will - * select the 'real' fonts. - */ + for (int p = 0; p < numPatterns; p++) + { + int xLen = 0; + char **xList = XListFonts(nxagentDisplay, patterns[p], maxNames, &xLen); - for (int p = 0; p < patternsQt; p++) - { - xList = XListFonts(nxagentDisplay, patterns[p], maxNames, &xLen); + #ifdef NXAGENT_FONTMATCH_DEBUG + fprintf(stderr, "nxagentListRemoteFonts: NXagent remote list [%s] has %d elements.\n", patterns[p], xLen); + #endif - #ifdef NXAGENT_FONTMATCH_DEBUG - fprintf(stderr, "nxagentListRemoteFonts: NXagent remote list [%s] has %d elements.\n", patterns[p], xLen); - #endif + /* + * Add the ListFont request pattern to the list with the last + * requested maxnames. + */ - /* - * Add the ListFont request pattern to the list with the last - * requested maxnames. - */ + nxagentListRemoteAddName(searchPattern, maxNames); - nxagentListRemoteAddName(searchPattern, maxNames); + for (int i = 0; i < xLen; i++) + { + nxagentListRemoteAddName(xList[i], 1); + } - for (int i = 0; i < xLen; i++) - { - nxagentListRemoteAddName(xList[i], 1); + XFreeFontNames(xList); } - XFreeFontNames(xList); - } - - #ifdef NXAGENT_FONTMATCH_DEBUG + #ifdef NXAGENT_FONTMATCH_DEBUG - fprintf(stderr, "nxagentListRemoteFonts: Printing remote font list.\n"); + fprintf(stderr, "nxagentListRemoteFonts: Printing remote font list.\n"); - for (int i = 0; i < nxagentRemoteFontList.length; i++) - { - fprintf(stderr, "Font# %d, \"%s\"\n", i, nxagentRemoteFontList.list[i]->name); - } + for (int i = 0; i < nxagentRemoteFontList.length; i++) + { + fprintf(stderr, "Font# %d, \"%s\"\n", i, nxagentRemoteFontList.list[i]->name); + } - fprintf(stderr, "nxagentListRemoteFonts: End of list\n"); + fprintf(stderr, "nxagentListRemoteFonts: End of list\n"); - #endif + #endif } void nxagentListRemoteAddName(const char *name, int status) { - int pos; + int pos; - if (nxagentFontFind(name, &pos)) - { - if (nxagentRemoteFontList.list[pos]->status < status) - { - nxagentRemoteFontList.list[pos]->status = status; - - #ifdef NXAGENT_FONTMATCH_DEBUG - fprintf(stderr, "Font: Font# %d, [%s] change status to %s\n", - pos, nxagentRemoteFontList.list[pos]->name,nxagentRemoteFontList.list[pos]->status?"OK":"deleted"); - #endif - } - return; - } + if (nxagentFontFind(name, &pos)) + { + if (nxagentRemoteFontList.list[pos]->status < status) + { + nxagentRemoteFontList.list[pos]->status = status; - if (nxagentRemoteFontList.length == nxagentRemoteFontList.listSize) - { - nxagentRemoteFontList.list = realloc(nxagentRemoteFontList.list, sizeof(nxagentFontRecPtr) - * (nxagentRemoteFontList.listSize + 1000)); + #ifdef NXAGENT_FONTMATCH_DEBUG + fprintf(stderr, "Font: Font# %d, [%s] change status to %s\n", + pos, nxagentRemoteFontList.list[pos]->name, + nxagentRemoteFontList.list[pos]->status ? "OK" : "deleted"); + #endif + } + return; + } - if (nxagentRemoteFontList.list == NULL) - { - FatalError("Font: remote list memory re-allocation failed!.\n"); - } + if (nxagentRemoteFontList.length == nxagentRemoteFontList.listSize) + { + /* FIXME: if realloc fails the pointer is lost! */ + nxagentRemoteFontList.list = realloc(nxagentRemoteFontList.list, sizeof(nxagentFontRecPtr) + * (nxagentRemoteFontList.listSize + 1000)); - nxagentRemoteFontList.listSize += 1000; - } + if (nxagentRemoteFontList.list == NULL) + { + FatalError("Font: remote list memory re-allocation failed!.\n"); + } - if (pos < nxagentRemoteFontList.length) - { - #ifdef NXAGENT_FONTMATCH_DEBUG - fprintf(stderr, "Font: Going to move list from %p to %p len = %d!.\n", - &nxagentRemoteFontList.list[pos], &nxagentRemoteFontList.list[pos+1], - (nxagentRemoteFontList.length - pos) * sizeof(nxagentFontRecPtr)); - #endif + nxagentRemoteFontList.listSize += 1000; + } - memmove(&nxagentRemoteFontList.list[pos+1], - &nxagentRemoteFontList.list[pos], - (nxagentRemoteFontList.length - pos) * sizeof(nxagentFontRecPtr)); - } + if (pos < nxagentRemoteFontList.length) + { + #ifdef NXAGENT_FONTMATCH_DEBUG + fprintf(stderr, "Font: Going to move list from %p to %p len = %d!.\n", + &nxagentRemoteFontList.list[pos], &nxagentRemoteFontList.list[pos+1], + (nxagentRemoteFontList.length - pos) * sizeof(nxagentFontRecPtr)); + #endif - if ((nxagentRemoteFontList.list[pos] = malloc(sizeof(nxagentFontRec)))) - { - nxagentRemoteFontList.list[pos]->name = strdup(name); - if (nxagentRemoteFontList.list[pos]->name == NULL) + memmove(&nxagentRemoteFontList.list[pos+1], + &nxagentRemoteFontList.list[pos], + (nxagentRemoteFontList.length - pos) * sizeof(nxagentFontRecPtr)); + } + + if ((nxagentRemoteFontList.list[pos] = malloc(sizeof(nxagentFontRec)))) { - fprintf(stderr, "Font: remote list name memory allocation failed!.\n"); - SAFE_free(nxagentRemoteFontList.list[pos]); - return; + nxagentRemoteFontList.list[pos]->name = strdup(name); + if (nxagentRemoteFontList.list[pos]->name == NULL) + { + fprintf(stderr, "Font: remote list name memory allocation failed!.\n"); + SAFE_free(nxagentRemoteFontList.list[pos]); + return; + } } - } - else - { - fprintf(stderr, "Font: remote list record memory allocation failed!.\n"); - return; - } - nxagentRemoteFontList.list[pos]->status = status; - nxagentRemoteFontList.length++; - - #ifdef NXAGENT_FONTMATCH_DEBUG - fprintf(stderr, "Font: remote font list added [%s] in position [%d] as %s !.\n", - name, pos, status ? "OK" : "deleted"); - fprintf(stderr, "Font: remote font list total len is [%d] Size is [%d] !.\n", - nxagentRemoteFontList.length, nxagentRemoteFontList.listSize); - #endif + else + { + fprintf(stderr, "Font: remote list record memory allocation failed!.\n"); + return; + } + nxagentRemoteFontList.list[pos]->status = status; + nxagentRemoteFontList.length++; + + #ifdef NXAGENT_FONTMATCH_DEBUG + fprintf(stderr, "Font: remote font list added [%s] in position [%d] as %s !.\n", + name, pos, status ? "OK" : "deleted"); + fprintf(stderr, "Font: remote font list total len is [%d] Size is [%d] !.\n", + nxagentRemoteFontList.length, nxagentRemoteFontList.listSize); + #endif } static void nxagentFreeRemoteFontList(nxagentFontList *listRec) { - for (int l = 0; l < listRec -> length; l++) - { - if (listRec -> list[l]) + for (int l = 0; l < listRec -> length; l++) { - SAFE_free(listRec -> list[l] -> name); - SAFE_free(listRec -> list[l]); + if (listRec -> list[l]) + { + SAFE_free(listRec -> list[l] -> name); + SAFE_free(listRec -> list[l]); + } } - } - listRec -> length = listRec -> listSize = 0; + listRec -> length = listRec -> listSize = 0; - SAFE_free(listRec -> list); + SAFE_free(listRec -> list); - return; + return; } Bool nxagentFontFind(const char *name, int *pos) { - if (!nxagentRemoteFontList.length) - { - *pos=0; - return False; - } - int low = 0; - int high = nxagentRemoteFontList.length - 1; - int iter = 0; - int res = 1; - int lpos = nxagentRemoteFontList.length; - while (low <= high) - { - *pos = (high + low)/2; - iter ++; - res = strcasecmp(nxagentRemoteFontList.list[*pos]->name,name); - if (res > 0) - { - high = *pos - 1; - lpos = *pos; - continue; - } - else if (res < 0) - { - low = *pos + 1; - lpos = low; - continue; - } - break; - } - *pos = (res == 0)?*pos:lpos; - - #ifdef NXAGENT_FONTMATCH_DEBUG - if (res == 0) - fprintf(stderr, "Font: font found in %d iterations in pos = %d\n", iter, *pos); - else - fprintf(stderr, "Font: not font found in %d iterations insertion pos is = %d\n", iter, *pos); - #endif - - return (res == 0); + if (!nxagentRemoteFontList.length) + { + *pos=0; + return False; + } + int low = 0; + int high = nxagentRemoteFontList.length - 1; + int iter = 0; + int res = 1; + int lpos = nxagentRemoteFontList.length; + while (low <= high) + { + *pos = (high + low)/2; + iter ++; + res = strcasecmp(nxagentRemoteFontList.list[*pos]->name,name); + if (res > 0) + { + high = *pos - 1; + lpos = *pos; + continue; + } + else if (res < 0) + { + low = *pos + 1; + lpos = low; + continue; + } + break; + } + *pos = (res == 0) ? *pos : lpos; + + #ifdef NXAGENT_FONTMATCH_DEBUG + if (res == 0) + fprintf(stderr, "Font: font found in %d iterations in pos = %d\n", iter, *pos); + else + fprintf(stderr, "Font: not font found in %d iterations insertion pos is = %d\n", iter, *pos); + #endif + + return (res == 0); } Bool nxagentFontLookUp(const char *name) { - int i; + int i; - if (name != NULL && strlen(name) == 0) - { - return 0; - } + if (name && strlen(name) == 0) + { + return 0; + } - int result = nxagentFontFind(name, &i); + int result = nxagentFontFind(name, &i); - char *scalable = NULL; + char *scalable = NULL; - /* - * Let's try with the scalable font description. - */ + /* + * Let's try with the scalable font description. + */ - if (result == 0) - { - if ((scalable = nxagentMakeScalableFontName(name, 0)) != NULL) + if (result == 0) { - result = nxagentFontFind(scalable, &i); + if ((scalable = nxagentMakeScalableFontName(name, 0)) != NULL) + { + result = nxagentFontFind(scalable, &i); - SAFE_free(scalable); + SAFE_free(scalable); + } } - } - /* - * Let's try again after replacing zero to xdpi and ydpi in the pattern. - */ + /* + * Let's try again after replacing zero to xdpi and ydpi in the pattern. + */ - if (result == 0) - { - if ((scalable = nxagentMakeScalableFontName(name, 1)) != NULL) + if (result == 0) { - result = nxagentFontFind(scalable, &i); + if ((scalable = nxagentMakeScalableFontName(name, 1)) != NULL) + { + result = nxagentFontFind(scalable, &i); - SAFE_free(scalable); + SAFE_free(scalable); + } } - } - if (result == 0) - { - return 0; - } - else - { - return (nxagentRemoteFontList.list[i]->status > 0); - } + if (result == 0) + { + return 0; + } + else + { + return (nxagentRemoteFontList.list[i]->status > 0); + } } Bool nxagentRealizeFont(ScreenPtr pScreen, FontPtr pFont) { - void * priv; - Atom name_atom, value_atom; - int nprops; - FontPropPtr props; - int i; - const char *name; - char *origName = (char*) pScreen; - #ifdef HAS_XFONT2 - xfont2_font_set_private(pFont, nxagentFontPrivateIndex, NULL); + xfont2_font_set_private(pFont, nxagentFontPrivateIndex, NULL); #else - FontSetPrivate(pFont, nxagentFontPrivateIndex, NULL); + FontSetPrivate(pFont, nxagentFontPrivateIndex, NULL); #endif /* HAS_XFONT2 */ - name_atom = MakeAtom("FONT", 4, True); - value_atom = 0L; + Atom name_atom = MakeAtom("FONT", 4, True); + Atom value_atom = 0L; - nprops = pFont->info.nprops; - props = pFont->info.props; + int nprops = pFont->info.nprops; + FontPropPtr props = pFont->info.props; - for (i = 0; i < nprops; i++) - if ((Atom)props[i].name == name_atom) { - value_atom = props[i].value; - break; + for (int i = 0; i < nprops; i++) + { + if ((Atom)props[i].name == name_atom) + { + value_atom = props[i].value; + break; + } } - if (!value_atom) return False; + if (!value_atom) + return False; - name = NameForAtom(value_atom); + const char *name = NameForAtom(value_atom); - #ifdef NXAGENT_FONTCACHE_DEBUG - fprintf(stderr, "Font: nxagentRealizeFont, realizing font: %s\n", validateString(name)); - fprintf(stderr, " atom: %ld\n", value_atom); - fprintf(stderr, "Font: Cache dump:\n"); - for (i = 0; i < CACHE_INDEX; i++) - { - fprintf(stderr, "nxagentFontCache.entry[%d]->name: %s font_struct at %p\n", - i, CACHE_NAME(i), CACHE_FSTRUCT(i)); - } - #endif + #ifdef NXAGENT_FONTCACHE_DEBUG + fprintf(stderr, "Font: nxagentRealizeFont, realizing font: %s\n", validateString(name)); + fprintf(stderr, " atom: %ld\n", value_atom); + fprintf(stderr, "Font: Cache dump:\n"); + for (int i = 0; i < CACHE_INDEX; i++) + { + fprintf(stderr, "nxagentFontCache.entry[%d]->name: %s font_struct at %p\n", + i, CACHE_NAME(i), CACHE_FSTRUCT(i)); + } + #endif - if (!name) return False; + if (!name) + return False; - if ((strcasecmp(origName, name) != 0) && !strchr(origName,'*')) - { - #ifdef NXAGENT_FONTMATCH_DEBUG - fprintf(stderr, "Font: Changing font name to realize from [%s] to [%s]\n", - validateString(name), origName); - #endif + char *origName = (char*) pScreen; + if ((strcasecmp(origName, name) != 0) && !strchr(origName,'*')) + { + #ifdef NXAGENT_FONTMATCH_DEBUG + fprintf(stderr, "Font: Changing font name to realize from [%s] to [%s]\n", + validateString(name), origName); + #endif - name = origName; - } + name = origName; + } - priv = (void *)malloc(sizeof(nxagentPrivFont)); + void *priv = (void *)malloc(sizeof(nxagentPrivFont)); #ifdef HAS_XFONT2 - xfont2_font_set_private(pFont, nxagentFontPrivateIndex, priv); + xfont2_font_set_private(pFont, nxagentFontPrivateIndex, priv); #else - FontSetPrivate(pFont, nxagentFontPrivateIndex, priv); + FontSetPrivate(pFont, nxagentFontPrivateIndex, priv); #endif /* HAS_XFONT2 */ - nxagentFontPriv(pFont) -> mirrorID = 0; + nxagentFontPriv(pFont) -> mirrorID = 0; - for (i = 0; i < nxagentFontCache.index; i++) - { -/* if (value_atom == CACHE_ATOM(i))*/ - if (strcasecmp(CACHE_NAME(i), name) == 0) - { + int fci; + for (fci = 0; fci < nxagentFontCache.index; fci++) + { + /* if (value_atom == CACHE_ATOM(i))*/ + if (strcasecmp(CACHE_NAME(fci), name) == 0) + { + #ifdef NXAGENT_FONTCACHE_DEBUG + fprintf(stderr, "Font: nxagentFontCache hit [%s] = [%s]!\n", CACHE_NAME(fci), validateString(name)); + #endif + + break; + } + } + + if (fci < CACHE_INDEX) + { + nxagentFontPriv(pFont)->font_struct = CACHE_FSTRUCT(fci); + strcpy(nxagentFontPriv(pFont)->fontName, name); + } + else + { #ifdef NXAGENT_FONTCACHE_DEBUG - fprintf(stderr, "Font: nxagentFontCache hit [%s] = [%s]!\n", CACHE_NAME(i), validateString(name)); + fprintf(stderr, "Font: nxagentFontCache fail.\n"); #endif - break; - } - } + if (CACHE_INDEX == CACHE_SIZE) + { + /* FIXME: if realloc fails the pointer is lost */ + CACHE_ENTRY_PTR = realloc(CACHE_ENTRY_PTR, sizeof(nxCacheFontEntryRecPtr) * (CACHE_SIZE + 100)); - if (i < CACHE_INDEX) - { - nxagentFontPriv(pFont)->font_struct = CACHE_FSTRUCT(i); - strcpy(nxagentFontPriv(pFont)->fontName, name); - } - else - { - #ifdef NXAGENT_FONTCACHE_DEBUG - fprintf(stderr, "Font: nxagentFontCache fail.\n"); - #endif + if (CACHE_ENTRY_PTR == NULL) + { + FatalError("Font: Cache list memory re-allocation failed.\n"); + } - if (CACHE_INDEX == CACHE_SIZE) - { - CACHE_ENTRY_PTR = realloc(CACHE_ENTRY_PTR, sizeof(nxCacheFontEntryRecPtr) * (CACHE_SIZE + 100)); + CACHE_SIZE += 100; + } + + CACHE_ENTRY(CACHE_INDEX) = malloc(sizeof(nxCacheFontEntryRec)); - if (CACHE_ENTRY_PTR == NULL) + if (CACHE_ENTRY(CACHE_INDEX) == NULL) { - FatalError("Font: Cache list memory re-allocation failed.\n"); + return False; } - CACHE_SIZE += 100; - } + CACHE_NAME(CACHE_INDEX) = malloc(strlen(name) + 1); - CACHE_ENTRY(CACHE_INDEX) = malloc(sizeof(nxCacheFontEntryRec)); + if (CACHE_NAME(CACHE_INDEX) == NULL) + { + return False; + } - if (CACHE_ENTRY(CACHE_INDEX) == NULL) - { - return False; - } + #ifdef NXAGENT_FONTMATCH_DEBUG + fprintf(stderr, "Font: Going to realize font [%s],[%s] on real X server.\n", validateString(name), origName); + #endif - CACHE_NAME(CACHE_INDEX) = malloc(strlen(name) + 1); + if (nxagentRemoteFontList.length == 0 && (NXDisplayError(nxagentDisplay) == 0)) + { + nxagentListRemoteFonts("*", nxagentMaxFontNames); + } - if (CACHE_NAME(CACHE_INDEX) == NULL) - { - return False; - } - - #ifdef NXAGENT_FONTMATCH_DEBUG - fprintf(stderr, "Font: Going to realize font [%s],[%s] on real X server.\n", validateString(name), origName); - #endif - - if (nxagentRemoteFontList.length == 0 && (NXDisplayError(nxagentDisplay) == 0)) - { - nxagentListRemoteFonts("*", nxagentMaxFontNames); - } - - nxagentFontPriv(pFont)->font_struct = nxagentLoadQueryFont(nxagentDisplay, (char *)name, pFont); - strcpy(nxagentFontPriv(pFont)->fontName, name); - if (nxagentFontPriv(pFont)->font_struct != NULL) - { - CACHE_ATOM(i) = value_atom; - strcpy(CACHE_NAME(i), name); - CACHE_FSTRUCT(i) = nxagentFontPriv(pFont)->font_struct; - CACHE_INDEX++; - - nxagentFontPriv(pFont) -> mirrorID = FakeClientID(serverClient -> index); - AddResource(nxagentFontPriv(pFont) -> mirrorID, RT_NX_FONT, pFont); - - #ifdef NXAGENT_FONTCACHE_DEBUG - fprintf(stderr, "Font: nxagentFontCache adds font [%s] in pos. [%d].\n", - validateString(name), CACHE_INDEX - 1); - #endif - } - } + nxagentFontPriv(pFont)->font_struct = nxagentLoadQueryFont(nxagentDisplay, (char *)name, pFont); + strcpy(nxagentFontPriv(pFont)->fontName, name); + if (nxagentFontPriv(pFont)->font_struct != NULL) + { + CACHE_ATOM(fci) = value_atom; + strcpy(CACHE_NAME(fci), name); + CACHE_FSTRUCT(fci) = nxagentFontPriv(pFont)->font_struct; + CACHE_INDEX++; + + nxagentFontPriv(pFont) -> mirrorID = FakeClientID(serverClient -> index); + AddResource(nxagentFontPriv(pFont) -> mirrorID, RT_NX_FONT, pFont); + + #ifdef NXAGENT_FONTCACHE_DEBUG + fprintf(stderr, "Font: nxagentFontCache adds font [%s] in pos. [%d].\n", + validateString(name), CACHE_INDEX - 1); + #endif + } + } - #ifdef NXAGENT_FONTMATCH_DEBUG + #ifdef NXAGENT_FONTMATCH_DEBUG - if (nxagentFontPriv(pFont)->font_struct == NULL) - { - if (nxagentFontLookUp(name) == False) + if (nxagentFontPriv(pFont)->font_struct == NULL) { - fprintf(stderr, "Font: nxagentRealizeFont failed with font Font=%s, not in our remote list\n", - validateString(name)); + if (nxagentFontLookUp(name) == False) + { + fprintf(stderr, "Font: nxagentRealizeFont failed with font Font=%s, not in our remote list\n", + validateString(name)); + } + else + { + fprintf(stderr, "Font: nxagentRealizeFont failed with font Font=%s but the font is in our remote list\n", + validateString(name)); + } } else { - fprintf(stderr, "Font: nxagentRealizeFont failed with font Font=%s but the font is in our remote list\n", - validateString(name)); + fprintf(stderr, "Font: nxagentRealizeFont OK realizing font Font=%s\n", + validateString(name)); } - } - else - fprintf(stderr, "Font: nxagentRealizeFont OK realizing font Font=%s\n", - validateString(name)); - #endif + #endif - return (nxagentFontPriv(pFont)->font_struct != NULL); + return (nxagentFontPriv(pFont)->font_struct != NULL); } Bool nxagentUnrealizeFont(ScreenPtr pScreen, FontPtr pFont) { - if (nxagentFontPriv(pFont)) - { - if (NXDisplayError(nxagentDisplay) == 0) + if (nxagentFontPriv(pFont)) { - if (nxagentFontStruct(pFont)) - { - int i; - - for (i = 0; i < CACHE_INDEX; i++) - { - if (CACHE_FSTRUCT(i) == nxagentFontStruct(pFont)) - { - #ifdef NXAGENT_FONTCACHE_DEBUG - fprintf(stderr, "nxagentUnrealizeFont: Not freeing the font in cache.\n"); - #endif - - break; - } - } - - if (i == CACHE_INDEX) - { - /* - * This font is not in the cache. - */ - - #ifdef NXAGENT_FONTCACHE_DEBUG - fprintf(stderr, "nxagentUnrealizeFont: Freeing font not found in cache '%d'\n", - CACHE_ATOM(i)); - #endif - - XFreeFont(nxagentDisplay, nxagentFontStruct(pFont)); - } - } - } + if (NXDisplayError(nxagentDisplay) == 0) + { + if (nxagentFontStruct(pFont)) + { + int fci; + + for (fci = 0; fci < CACHE_INDEX; fci++) + { + if (CACHE_FSTRUCT(fci) == nxagentFontStruct(pFont)) + { + #ifdef NXAGENT_FONTCACHE_DEBUG + fprintf(stderr, "nxagentUnrealizeFont: Not freeing the font in cache.\n"); + #endif + + break; + } + } + + if (fci == CACHE_INDEX) + { + /* + * This font is not in the cache. + */ + + #ifdef NXAGENT_FONTCACHE_DEBUG + fprintf(stderr, "nxagentUnrealizeFont: Freeing font not found in cache '%d'\n", + CACHE_ATOM(fci)); + #endif + + XFreeFont(nxagentDisplay, nxagentFontStruct(pFont)); + } + } + } - if (nxagentFontPriv(pFont) -> mirrorID) - FreeResource(nxagentFontPriv(pFont) -> mirrorID, RT_NONE); + if (nxagentFontPriv(pFont) -> mirrorID) + FreeResource(nxagentFontPriv(pFont) -> mirrorID, RT_NONE); - free(nxagentFontPriv(pFont)); + free(nxagentFontPriv(pFont)); #ifdef HAS_XFONT2 - xfont2_font_set_private(pFont, nxagentFontPrivateIndex, NULL); + xfont2_font_set_private(pFont, nxagentFontPrivateIndex, NULL); #else - FontSetPrivate(pFont, nxagentFontPrivateIndex, NULL); + FontSetPrivate(pFont, nxagentFontPrivateIndex, NULL); #endif /* HAS_XFONT2 */ - } + } - return True; + return True; } int nxagentDestroyNewFontResourceType(void * p, XID id) { - #ifdef TEST - fprintf(stderr, "%s: Destroying mirror id [%ld] for font at [%p].\n", __func__, - nxagentFontPriv((FontPtr) p) -> mirrorID, (void *) p); - #endif + #ifdef TEST + fprintf(stderr, "%s: Destroying mirror id [%ld] for font at [%p].\n", __func__, + nxagentFontPriv((FontPtr) p) -> mirrorID, (void *) p); + #endif /* FIXME: It happens that this resource had been already destroyed. We @@ -684,12 +686,12 @@ FIXME: It happens that this resource had been already destroyed. We client and another client. We had a crash when freeing server client resources. */ - if (nxagentFontPriv((FontPtr) p) != NULL) - { - nxagentFontPriv((FontPtr) p) -> mirrorID = None; - } + if (nxagentFontPriv((FontPtr) p) != NULL) + { + nxagentFontPriv((FontPtr) p) -> mirrorID = None; + } - return 1; + return 1; } static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontPtr pFont) @@ -722,7 +724,7 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP 5, /* Set-width */ 8, /* Point size */ 10 /* DPI_y */ - }; + }; #ifdef NXAGENT_RECONNECT_FONT_DEBUG fprintf(stderr, "nxagentLoadBestQueryFont: Searching font '%s' .\n", fontName); @@ -734,71 +736,69 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP if (numFontFields <= FIELDS) { - #ifdef WARNING - if (nxagentVerbose == 1) - { - fprintf(stderr, "nxagentLoadBestQueryFont: WARNING! Font name in non standard format. \n"); - } - #endif + #ifdef WARNING + if (nxagentVerbose == 1) + { + fprintf(stderr, "nxagentLoadBestQueryFont: WARNING! Font name in non standard format.\n"); + } + #endif } else { - for (int i = 1 ; i < nxagentRemoteFontList.length ; i++) - { - numSearchFields = nxagentSplitString(nxagentRemoteFontList.list[i]->name, searchFields, FIELDS+1, "-"); - - - /* The following code attempts to find an accurate approximation - * of the missing font. The current candidate and the missing font are - * compared on the 14 fields of the X Logical Font Description Convention. - * The selection is performed by the analysis of the matching fields, - * shifting left the value of the Weight variable on the right matches - * and shifting right the value of the Weight on the wrong ones; - * due a probability of overmuch right shifting, the starting weight is set - * to a high value. At the end of matching the selected font is the one - * with the bigger final Weight. The shift operation has been used instead - * of other operation for a performance issue. - * In some check the shift is performed by more than one position, because - * of the relevance of the field; for example a correct slant or a matching - * charset is more relevant than the size. - */ - - if (numSearchFields > FIELDS) + for (int i = 1 ; i < nxagentRemoteFontList.length ; i++) { - - tempWeight = 0; - - for (int j = 0; j < FIELDS; j++) - { - if (strcasecmp(searchFields[fieldOrder[j]], fontNameFields[fieldOrder[j]]) == 0 || - strcmp(searchFields[fieldOrder[j]], "") == 0 || - strcmp(fontNameFields[fieldOrder[j]], "") != 0 || - strcmp(searchFields[fieldOrder[j]], "*") == 0 || - strcmp(fontNameFields[fieldOrder[j]], "*") == 0) + numSearchFields = nxagentSplitString(nxagentRemoteFontList.list[i]->name, searchFields, FIELDS+1, "-"); + + + /* The following code attempts to find an accurate approximation + * of the missing font. The current candidate and the missing font are + * compared on the 14 fields of the X Logical Font Description Convention. + * The selection is performed by the analysis of the matching fields, + * shifting left the value of the Weight variable on the right matches + * and shifting right the value of the Weight on the wrong ones; + * due a probability of overmuch right shifting, the starting weight is set + * to a high value. At the end of matching the selected font is the one + * with the bigger final Weight. The shift operation has been used instead + * of other operation for a performance issue. + * In some check the shift is performed by more than one position, because + * of the relevance of the field; for example a correct slant or a matching + * charset is more relevant than the size. + */ + + if (numSearchFields > FIELDS) { - tempWeight ++; - } - - tempWeight <<= 1; - } - + tempWeight = 0; + + for (int j = 0; j < FIELDS; j++) + { + if (strcasecmp(searchFields[fieldOrder[j]], fontNameFields[fieldOrder[j]]) == 0 || + strcmp(searchFields[fieldOrder[j]], "") == 0 || + strcmp(fontNameFields[fieldOrder[j]], "") != 0 || + strcmp(searchFields[fieldOrder[j]], "*") == 0 || + strcmp(fontNameFields[fieldOrder[j]], "*") == 0) + { + tempWeight ++; + } + + tempWeight <<= 1; + } } if (tempWeight > weight) { - /* Found more accurate font */ + /* Found more accurate font */ - weight = tempWeight; - snprintf(substFontBuf, sizeof(substFontBuf), "%s", nxagentRemoteFontList.list[i]->name); + weight = tempWeight; + snprintf(substFontBuf, sizeof(substFontBuf), "%s", nxagentRemoteFontList.list[i]->name); - #ifdef NXAGENT_RECONNECT_FONT_DEBUG - fprintf(stderr, "nxagentLoadBestQueryFont: Weight '%d' of more accurate font '%s' .\n", weight, substFontBuf); - #endif + #ifdef NXAGENT_RECONNECT_FONT_DEBUG + fprintf(stderr, "nxagentLoadBestQueryFont: Weight '%d' of more accurate font '%s' .\n", weight, substFontBuf); + #endif } for (int j = 0; j < numSearchFields; j++) { - SAFE_free(searchFields[j]); + SAFE_free(searchFields[j]); } } } @@ -806,8 +806,8 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP #ifdef WARNING if (nxagentVerbose == 1) { - fprintf(stderr, "nxagentLoadBestQueryFont: WARNING! Failed to load font '%s'. Replacing with '%s'.\n", - fontName, substFontBuf); + fprintf(stderr, "nxagentLoadBestQueryFont: WARNING! Failed to load font '%s'. Replacing with '%s'.\n", + fontName, substFontBuf); } #endif @@ -815,7 +815,7 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP for (int j = 0; j < numFontFields; j++) { - SAFE_free(fontNameFields[j]); + SAFE_free(fontNameFields[j]); } return fontStruct; @@ -837,16 +837,16 @@ static void nxagentFontDisconnect(FontPtr pFont, XID param1, void * param2) for (int i = 0; i < CACHE_INDEX; i++) { - if (strcasecmp(CACHE_NAME(i), privFont -> fontName) == 0) - { - #ifdef NXAGENT_RECONNECT_FONT_DEBUG - fprintf(stderr, "nxagentFontDisconnect: font %s found in cache at position %d\n", - privFont -> fontName, i); - #endif + if (strcasecmp(CACHE_NAME(i), privFont -> fontName) == 0) + { + #ifdef NXAGENT_RECONNECT_FONT_DEBUG + fprintf(stderr, "nxagentFontDisconnect: font %s found in cache at position %d\n", + privFont -> fontName, i); + #endif - privFont -> font_struct = NULL; - return; - } + privFont -> font_struct = NULL; + return; + } } #ifdef NXAGENT_RECONNECT_FONT_DEBUG @@ -856,888 +856,883 @@ static void nxagentFontDisconnect(FontPtr pFont, XID param1, void * param2) if (privFont -> font_struct) { - XFreeFont(nxagentDisplay, privFont -> font_struct); - privFont -> font_struct = NULL; + XFreeFont(nxagentDisplay, privFont -> font_struct); + privFont -> font_struct = NULL; } } static void nxagentCollectFailedFont(FontPtr fpt, XID id) { - if (nxagentFailedToReconnectFonts.font == NULL) - { - nxagentFailedToReconnectFonts.size = 8; + if (nxagentFailedToReconnectFonts.font == NULL) + { + nxagentFailedToReconnectFonts.size = 8; - nxagentFailedToReconnectFonts.font = malloc(nxagentFailedToReconnectFonts.size * - sizeof(FontPtr)); + nxagentFailedToReconnectFonts.font = malloc(nxagentFailedToReconnectFonts.size * + sizeof(FontPtr)); - nxagentFailedToReconnectFonts.id = malloc(nxagentFailedToReconnectFonts.size * sizeof(XID)); + nxagentFailedToReconnectFonts.id = malloc(nxagentFailedToReconnectFonts.size * + sizeof(XID)); - if (nxagentFailedToReconnectFonts.font == NULL || nxagentFailedToReconnectFonts.id == NULL) - { - SAFE_free(nxagentFailedToReconnectFonts.font); - SAFE_free(nxagentFailedToReconnectFonts.id); + if (nxagentFailedToReconnectFonts.font == NULL || nxagentFailedToReconnectFonts.id == NULL) + { + SAFE_free(nxagentFailedToReconnectFonts.font); + SAFE_free(nxagentFailedToReconnectFonts.id); - FatalError("Font: font not reconnected memory allocation failed!.\n"); + FatalError("Font: font not reconnected memory allocation failed!.\n"); + } + + #ifdef NXAGENT_RECONNECT_FONT_DEBUG + fprintf(stderr, "nxagentCollectFailedFont: allocated [%d] bytes.\n", + 8 * (sizeof(FontPtr)+ sizeof(XID))); + #endif } + else if (nxagentFailedToReconnectFonts.index == nxagentFailedToReconnectFonts.size - 1) + { + nxagentFailedToReconnectFonts.size *= 2; - #ifdef NXAGENT_RECONNECT_FONT_DEBUG - fprintf(stderr, "nxagentCollectFailedFont: allocated [%d] bytes.\n", - 8 * (sizeof(FontPtr)+ sizeof(XID))); - #endif - } - else if (nxagentFailedToReconnectFonts.index == nxagentFailedToReconnectFonts.size - 1) - { - nxagentFailedToReconnectFonts.size *= 2; + /* FIXME: if realloc fails the pointer is lost */ + nxagentFailedToReconnectFonts.font = realloc(nxagentFailedToReconnectFonts.font, + nxagentFailedToReconnectFonts.size * + sizeof(FontPtr)); - nxagentFailedToReconnectFonts.font = realloc(nxagentFailedToReconnectFonts.font, - nxagentFailedToReconnectFonts.size * - sizeof(FontPtr)); + nxagentFailedToReconnectFonts.id = realloc(nxagentFailedToReconnectFonts.id, + nxagentFailedToReconnectFonts.size * + sizeof(XID)); - nxagentFailedToReconnectFonts.id = realloc(nxagentFailedToReconnectFonts.id, - nxagentFailedToReconnectFonts.size * - sizeof(XID)); + if (nxagentFailedToReconnectFonts.font == NULL || nxagentFailedToReconnectFonts.id == NULL) + { + FatalError("Font: font not reconnected memory re-allocation failed!.\n"); + } - if (nxagentFailedToReconnectFonts.font == NULL || nxagentFailedToReconnectFonts.id == NULL) - { - FatalError("Font: font not reconnected memory re-allocation failed!.\n"); + #ifdef NXAGENT_RECONNECT_FONT_DEBUG + fprintf(stderr,"nxagentCollectFailedFont: reallocated memory.\n "); + #endif } - #ifdef NXAGENT_RECONNECT_FONT_DEBUG - fprintf(stderr,"nxagentCollectFailedFont: reallocated memory.\n "); - #endif - } - - nxagentFailedToReconnectFonts.font[nxagentFailedToReconnectFonts.index] = fpt; + nxagentFailedToReconnectFonts.font[nxagentFailedToReconnectFonts.index] = fpt; - nxagentFailedToReconnectFonts.id[nxagentFailedToReconnectFonts.index] = id; + nxagentFailedToReconnectFonts.id[nxagentFailedToReconnectFonts.index] = id; - #ifdef NXAGENT_RECONNECT_FONT_DEBUG - fprintf(stderr, "nxagentCollectFailedFont: font not reconnected at [%p], " - "put in nxagentFailedToReconnectFonts.font[%d] = [%p], with XID = [%lu].\n", - (void*) fpt, nxagentFailedToReconnectFonts.index, - (void *)nxagentFailedToReconnectFonts.font[nxagentFailedToReconnectFonts.index], - nxagentFailedToReconnectFonts.id[nxagentFailedToReconnectFonts.index]); - #endif + #ifdef NXAGENT_RECONNECT_FONT_DEBUG + fprintf(stderr, "nxagentCollectFailedFont: font not reconnected at [%p], " + "put in nxagentFailedToReconnectFonts.font[%d] = [%p], with XID = [%lu].\n", + (void*) fpt, nxagentFailedToReconnectFonts.index, + (void *)nxagentFailedToReconnectFonts.font[nxagentFailedToReconnectFonts.index], + nxagentFailedToReconnectFonts.id[nxagentFailedToReconnectFonts.index]); + #endif - nxagentFailedToReconnectFonts.index++; + nxagentFailedToReconnectFonts.index++; } static void nxagentFontReconnect(FontPtr pFont, XID param1, void * param2) { - int i; - Bool *pBool = (Bool*)param2; + int i; + Bool *pBool = (Bool*)param2; - if (pFont == NULL) - return; + if (pFont == NULL) + return; - nxagentPrivFont *privFont = nxagentFontPriv(pFont); + nxagentPrivFont *privFont = nxagentFontPriv(pFont); - #ifdef NXAGENT_RECONNECT_FONT_DEBUG - fprintf(stderr, "nxagentFontReconnect: pFont %p - XID %lx - name %s\n", - (void*) pFont, (privFont -> font_struct) ? nxagentFont(pFont) : 0, - privFont -> fontName); - #endif + #ifdef NXAGENT_RECONNECT_FONT_DEBUG + fprintf(stderr, "nxagentFontReconnect: pFont %p - XID %lx - name %s\n", + (void*) pFont, (privFont -> font_struct) ? nxagentFont(pFont) : 0, + privFont -> fontName); + #endif - for (i = 0; i < CACHE_INDEX; i++) - { - if (strcasecmp(CACHE_NAME(i), privFont -> fontName) == 0) + for (i = 0; i < CACHE_INDEX; i++) { - #ifdef NXAGENT_RECONNECT_FONT_DEBUG - fprintf(stderr, "\tfound in cache"); - #endif + if (strcasecmp(CACHE_NAME(i), privFont -> fontName) == 0) + { + #ifdef NXAGENT_RECONNECT_FONT_DEBUG + fprintf(stderr, "\tfound in cache"); + #endif - if (!CACHE_FSTRUCT(i)) - { - #ifdef NXAGENT_RECONNECT_FONT_DEBUG - fprintf(stderr, " --- font struct not valid\n"); - #endif + if (!CACHE_FSTRUCT(i)) + { + #ifdef NXAGENT_RECONNECT_FONT_DEBUG + fprintf(stderr, " --- font struct not valid\n"); + #endif - break; - } + break; + } - nxagentFontStruct(pFont) = CACHE_FSTRUCT(i); + nxagentFontStruct(pFont) = CACHE_FSTRUCT(i); - return; + return; + } } - } - if (i == CACHE_INDEX) - { - FatalError("nxagentFontReconnect: font not found in cache."); - } + if (i == CACHE_INDEX) + { + FatalError("nxagentFontReconnect: font not found in cache."); + } - privFont -> font_struct = nxagentLoadQueryFont(nxagentDisplay, privFont -> fontName, pFont); + privFont -> font_struct = nxagentLoadQueryFont(nxagentDisplay, privFont -> fontName, pFont); - if ((privFont -> font_struct == NULL) && reconnectFlexibility) - { - privFont -> font_struct = nxagentLoadBestQueryFont(nxagentDisplay, privFont -> fontName, pFont); - } + if ((privFont -> font_struct == NULL) && reconnectFlexibility) + { + privFont -> font_struct = nxagentLoadBestQueryFont(nxagentDisplay, privFont -> fontName, pFont); + } - if (privFont->font_struct != NULL) - { - #ifdef NXAGENT_RECONNECT_FONT_DEBUG - fprintf(stderr, "\tXID %lx\n", privFont -> font_struct -> fid); - #endif + if (privFont->font_struct != NULL) + { + #ifdef NXAGENT_RECONNECT_FONT_DEBUG + fprintf(stderr, "\tXID %lx\n", privFont -> font_struct -> fid); + #endif - CACHE_FSTRUCT(i) = privFont -> font_struct; - } - else - { - #ifdef NXAGENT_RECONNECT_FONT_DEBUG - fprintf(stderr, "nxagentFontReconnect: failed\n"); - #endif + CACHE_FSTRUCT(i) = privFont -> font_struct; + } + else + { + #ifdef NXAGENT_RECONNECT_FONT_DEBUG + fprintf(stderr, "nxagentFontReconnect: failed\n"); + #endif - nxagentCollectFailedFont(pFont, param1); + nxagentCollectFailedFont(pFont, param1); - #ifdef NXAGENT_RECONNECT_FONT_DEBUG - fprintf(stderr, "nxagentFontReconnect: reconnection of font [%s] failed.\n", - privFont -> fontName); - #endif + #ifdef NXAGENT_RECONNECT_FONT_DEBUG + fprintf(stderr, "nxagentFontReconnect: reconnection of font [%s] failed.\n", + privFont -> fontName); + #endif - nxagentSetReconnectError(FAILED_RESUME_FONTS_ALERT, - "Couldn't restore the font '%s'", privFont -> fontName); + nxagentSetReconnectError(FAILED_RESUME_FONTS_ALERT, + "Couldn't restore the font '%s'", privFont -> fontName); - *pBool = False; - } + *pBool = False; + } - return; + return; } static void nxagentFreeCacheBeforeReconnect(void) { - #ifdef NXAGENT_RECONNECT_FONT_DEBUG - printFontCacheDump("nxagentFreeCacheBeforeReconnect"); - #endif + #ifdef NXAGENT_RECONNECT_FONT_DEBUG + printFontCacheDump("nxagentFreeCacheBeforeReconnect"); + #endif - for (int i = 0; i < CACHE_INDEX; i++) - { - if (CACHE_FSTRUCT(i)) + for (int i = 0; i < CACHE_INDEX; i++) { - nxagentFreeFont(CACHE_FSTRUCT(i)); - CACHE_FSTRUCT(i) = NULL; + if (CACHE_FSTRUCT(i)) + { + nxagentFreeFont(CACHE_FSTRUCT(i)); + CACHE_FSTRUCT(i) = NULL; + } } - } } static void nxagentCleanCacheAfterReconnect(void) { - int real_size = CACHE_INDEX; + int real_size = CACHE_INDEX; - #ifdef NXAGENT_RECONNECT_FONT_DEBUG - printFontCacheDump("nxagentCleanCacheAfterReconnect"); - #endif + #ifdef NXAGENT_RECONNECT_FONT_DEBUG + printFontCacheDump("nxagentCleanCacheAfterReconnect"); + #endif - for (int i = 0; i < CACHE_INDEX; i++) - { - if(CACHE_FSTRUCT(i) == NULL) + for (int i = 0; i < CACHE_INDEX; i++) { - SAFE_XFree(CACHE_NAME(i)); - real_size--; + if (CACHE_FSTRUCT(i) == NULL) + { + SAFE_XFree(CACHE_NAME(i)); + real_size--; + } } - } - for (int i = 0; i < real_size; i++) - { - int j; - nxCacheFontEntryRecPtr swapEntryPtr; + for (int i = 0; i < real_size; i++) + { + int j; + nxCacheFontEntryRecPtr swapEntryPtr; - /* Find - first bad occurrence if exist. */ - while ((i < real_size) && CACHE_FSTRUCT(i)) i++; + /* Find - first bad occurrence if exist. */ + while ((i < real_size) && CACHE_FSTRUCT(i)) + i++; - /* Really nothing more to do. */ - if (i == real_size) - break; + /* Really nothing more to do. */ + if (i == real_size) + break; - /* - * Find - first good occurrence (moving backward from right end) entry in - * order to replace the bad one. - */ - for (j = CACHE_INDEX - 1; CACHE_FSTRUCT(j) == NULL; j--); - - /* - * Now we can swap the two entry and reduce the Cache index - */ - swapEntryPtr = CACHE_ENTRY(i); - CACHE_ENTRY(i) = CACHE_ENTRY(j); - CACHE_ENTRY(j) = swapEntryPtr; - } + /* + * Find - first good occurrence (moving backward from right end) entry in + * order to replace the bad one. + */ + for (j = CACHE_INDEX - 1; CACHE_FSTRUCT(j) == NULL; j--); - CACHE_INDEX = real_size; + /* + * Now we can swap the two entry and reduce the Cache index + */ + swapEntryPtr = CACHE_ENTRY(i); + CACHE_ENTRY(i) = CACHE_ENTRY(j); + CACHE_ENTRY(j) = swapEntryPtr; + } + + CACHE_INDEX = real_size; } #ifdef NXAGENT_RECONNECT_FONT_DEBUG static void printFontCacheDump(char* msg) { - fprintf(stderr, "%s - begin -\n", msg); + fprintf(stderr, "%s - begin -\n", msg); - for (int i = 0; i < CACHE_INDEX; i++) - { - if (CACHE_FSTRUCT(i)) - { - fprintf(stderr, "\tXID %lx - %s\n", CACHE_FSTRUCT(i) -> fid, CACHE_NAME(i)); - } - else + for (int i = 0; i < CACHE_INDEX; i++) { - fprintf(stderr, "\tdestroyed - %s\n", CACHE_NAME(i)); + if (CACHE_FSTRUCT(i)) + { + fprintf(stderr, "\tXID %lx - %s\n", CACHE_FSTRUCT(i) -> fid, CACHE_NAME(i)); + } + else + { + fprintf(stderr, "\tdestroyed - %s\n", CACHE_NAME(i)); + } } - } - fprintf(stderr, "%s - end -\n", msg); + fprintf(stderr, "%s - end -\n", msg); } #endif Bool nxagentReconnectAllFonts(void *p0) { - Bool fontSuccess = True; + Bool fontSuccess = True; - reconnectFlexibility = *((int *) p0); + reconnectFlexibility = *((int *) p0); - #if defined(NXAGENT_RECONNECT_DEBUG) || defined(NXAGENT_RECONNECT_FONT_DEBUG) - fprintf(stderr, "nxagentReconnectAllFonts\n"); - #endif + #if defined(NXAGENT_RECONNECT_DEBUG) || defined(NXAGENT_RECONNECT_FONT_DEBUG) + fprintf(stderr, "nxagentReconnectAllFonts\n"); + #endif - /* - * The resource type RT_NX_FONT is created on the server client - * only, so we can avoid to loop through all the clients. - */ + /* + * The resource type RT_NX_FONT is created on the server client + * only, so we can avoid to loop through all the clients. + */ - FindClientResourcesByType(clients[serverClient -> index], RT_NX_FONT, - (FindResType) nxagentFontReconnect, &fontSuccess); + FindClientResourcesByType(clients[serverClient -> index], RT_NX_FONT, + (FindResType) nxagentFontReconnect, &fontSuccess); - for (int cid = 0; cid < MAXCLIENTS; cid++) - { - if (clients[cid]) + for (int cid = 0; cid < MAXCLIENTS; cid++) { - FindClientResourcesByType(clients[cid], RT_FONT, - (FindResType) nxagentFontReconnect, &fontSuccess); + if (clients[cid]) + { + FindClientResourcesByType(clients[cid], RT_FONT, + (FindResType) nxagentFontReconnect, &fontSuccess); + } } - } - if (fontSuccess) - { - nxagentCleanCacheAfterReconnect(); - } + if (fontSuccess) + { + nxagentCleanCacheAfterReconnect(); + } - return fontSuccess; + return fontSuccess; } static void nxagentFailedFontReconnect(FontPtr pFont, XID param1, void * param2) { - int i; - nxagentPrivFont *privFont; - Bool *pBool = (Bool*)param2; + int i; + Bool *pBool = (Bool*)param2; - if (pFont == NULL) - return; + if (pFont == NULL) + return; - privFont = nxagentFontPriv(pFont); + nxagentPrivFont *privFont = nxagentFontPriv(pFont); - #ifdef NXAGENT_RECONNECT_FONT_DEBUG - fprintf(stderr, "nxagentFailedFontReconnect: pFont %p - XID %lx - name %s\n", - (void*) pFont, (privFont -> font_struct) ? nxagentFont(pFont) : 0, - privFont -> fontName); - #endif + #ifdef NXAGENT_RECONNECT_FONT_DEBUG + fprintf(stderr, "nxagentFailedFontReconnect: pFont %p - XID %lx - name %s\n", + (void*) pFont, (privFont -> font_struct) ? nxagentFont(pFont) : 0, + privFont -> fontName); + #endif - for (i = 0; i < CACHE_INDEX; i++) - { - if (strcasecmp(CACHE_NAME(i), privFont -> fontName) == 0) + for (i = 0; i < CACHE_INDEX; i++) { - #ifdef NXAGENT_RECONNECT_FONT_DEBUG - fprintf(stderr, "\tfound in cache"); - #endif + if (strcasecmp(CACHE_NAME(i), privFont -> fontName) == 0) + { + #ifdef NXAGENT_RECONNECT_FONT_DEBUG + fprintf(stderr, "\tfound in cache"); + #endif - if (!CACHE_FSTRUCT(i)) - { - #ifdef NXAGENT_RECONNECT_FONT_DEBUG - fprintf(stderr, " --- font struct not valid\n"); - #endif + if (!CACHE_FSTRUCT(i)) + { + #ifdef NXAGENT_RECONNECT_FONT_DEBUG + fprintf(stderr, " --- font struct not valid\n"); + #endif - break; - } + break; + } - nxagentFontStruct(pFont) = CACHE_FSTRUCT(i); + nxagentFontStruct(pFont) = CACHE_FSTRUCT(i); - return; + return; + } } - } - if (i == CACHE_INDEX) - { - FatalError("nxagentFailedFontReconnect: font not found in cache."); - } + if (i == CACHE_INDEX) + { + FatalError("nxagentFailedFontReconnect: font not found in cache."); + } - privFont -> font_struct = nxagentLoadQueryFont(nxagentDisplay, privFont -> fontName, pFont); + privFont -> font_struct = nxagentLoadQueryFont(nxagentDisplay, privFont -> fontName, pFont); - if (privFont -> font_struct == NULL) - { - privFont -> font_struct = nxagentLoadBestQueryFont(nxagentDisplay, privFont -> fontName, pFont); - } + if (privFont -> font_struct == NULL) + { + privFont -> font_struct = nxagentLoadBestQueryFont(nxagentDisplay, privFont -> fontName, pFont); + } - if (privFont->font_struct != NULL) - { - #ifdef NXAGENT_RECONNECT_FONT_DEBUG - fprintf(stderr, "\tXID %lx\n", privFont -> font_struct -> fid); - #endif + if (privFont->font_struct != NULL) + { + #ifdef NXAGENT_RECONNECT_FONT_DEBUG + fprintf(stderr, "\tXID %lx\n", privFont -> font_struct -> fid); + #endif - CACHE_FSTRUCT(i) = privFont -> font_struct; - } - else - { - #ifdef NXAGENT_RECONNECT_FONT_DEBUG - fprintf(stderr, "nxagentFailedFontReconnect: failed\n"); - #endif + CACHE_FSTRUCT(i) = privFont -> font_struct; + } + else + { + #ifdef NXAGENT_RECONNECT_FONT_DEBUG + fprintf(stderr, "nxagentFailedFontReconnect: failed\n"); + #endif - #ifdef NXAGENT_RECONNECT_FONT_DEBUG - fprintf(stderr, "nxagentFailedFontReconnect: reconnection of font [%s] failed.\n", - privFont -> fontName); - #endif + #ifdef NXAGENT_RECONNECT_FONT_DEBUG + fprintf(stderr, "nxagentFailedFontReconnect: reconnection of font [%s] failed.\n", + privFont -> fontName); + #endif - nxagentSetReconnectError(FAILED_RESUME_FONTS_ALERT, - "Couldn't restore the font '%s'", privFont -> fontName); + nxagentSetReconnectError(FAILED_RESUME_FONTS_ALERT, + "Couldn't restore the font '%s'", privFont -> fontName); - *pBool = False; - } + *pBool = False; + } - return; + return; } static void nxagentFreeFailedToReconnectFonts(void) { - SAFE_free(nxagentFailedToReconnectFonts.font); - SAFE_free(nxagentFailedToReconnectFonts.id); + SAFE_free(nxagentFailedToReconnectFonts.font); + SAFE_free(nxagentFailedToReconnectFonts.id); - nxagentFailedToReconnectFonts.size = 0; - nxagentFailedToReconnectFonts.index = 0; + nxagentFailedToReconnectFonts.size = 0; + nxagentFailedToReconnectFonts.index = 0; } Bool nxagentReconnectFailedFonts(void *p0) { - int attempt = 1; - const int maxAttempt = 5; - - char **fontPaths, **localFontPaths, **newFontPaths; - char fontServerPath[256] = ""; - int nPaths = 0; - - Bool repeat = True; - Bool fontSuccess = True; - - reconnectFlexibility = *((int *) p0); + char fontServerPath[256] = ""; - #ifdef NXAGENT_RECONNECT_FONT_DEBUG - fprintf(stderr, "nxagentReconnectFailedFonts: \n"); - #endif + reconnectFlexibility = *((int *) p0); - if (nxagentGetFontServerPath(fontServerPath, sizeof(fontServerPath)) == False) - { - #ifdef WARNING - fprintf(stderr, "nxagentReconnectFailedFonts: WARNING! " - "Font server tunneling not retrieved.\n"); + #ifdef NXAGENT_RECONNECT_FONT_DEBUG + fprintf(stderr, "nxagentReconnectFailedFonts: \n"); #endif - } - #ifdef NXAGENT_RECONNECT_FONT_DEBUG - fprintf(stderr, "nxagentReconnectFailedFonts: font server path [%s]\n", fontServerPath); - #endif - - fontPaths = XGetFontPath(nxagentDisplay, &nPaths); - - if ((newFontPaths = malloc((nPaths + 1) * sizeof(char *))) == NULL) - { - FatalError("nxagentReconnectFailedFonts: malloc failed."); - } - - memcpy(newFontPaths, fontPaths, nPaths * sizeof(char*)); - - localFontPaths = newFontPaths; - localFontPaths += nPaths; - *localFontPaths = fontServerPath; + if (nxagentGetFontServerPath(fontServerPath, sizeof(fontServerPath)) == False) + { + #ifdef WARNING + fprintf(stderr, "nxagentReconnectFailedFonts: WARNING! " + "Font server tunneling not retrieved.\n"); + #endif + } - while(repeat) - { #ifdef NXAGENT_RECONNECT_FONT_DEBUG - fprintf(stderr, "nxagentReconnectFailedFonts: attempt [%d].\n", attempt); + fprintf(stderr, "nxagentReconnectFailedFonts: font server path [%s]\n", fontServerPath); #endif - repeat = False; + int nPaths = 0; + char **fontPaths = XGetFontPath(nxagentDisplay, &nPaths); + char **newFontPaths = malloc((nPaths + 1) * sizeof(char *)); - XSetFontPath(nxagentDisplay, newFontPaths, nPaths + 1); - nxagentFreeRemoteFontList(&nxagentRemoteFontList); - nxagentListRemoteFonts("*", nxagentMaxFontNames); + if (newFontPaths == NULL) + { + FatalError("nxagentReconnectFailedFonts: malloc failed."); + } + + memcpy(newFontPaths, fontPaths, nPaths * sizeof(char*)); + + char **localFontPaths = newFontPaths; + localFontPaths += nPaths; + *localFontPaths = fontServerPath; - for(int i = 0; i < nxagentFailedToReconnectFonts.index; i++) + int attempt = 1; + const int maxAttempt = 5; + Bool repeat = True; + while (repeat) { - fontSuccess = True; + #ifdef NXAGENT_RECONNECT_FONT_DEBUG + fprintf(stderr, "nxagentReconnectFailedFonts: attempt [%d].\n", attempt); + #endif - if(nxagentFailedToReconnectFonts.font[i]) - { - nxagentFailedFontReconnect(nxagentFailedToReconnectFonts.font[i], - nxagentFailedToReconnectFonts.id[i], - &fontSuccess); + repeat = False; - if (fontSuccess) - { - nxagentFailedToReconnectFonts.font[i] = NULL; - } - else + XSetFontPath(nxagentDisplay, newFontPaths, nPaths + 1); + nxagentFreeRemoteFontList(&nxagentRemoteFontList); + nxagentListRemoteFonts("*", nxagentMaxFontNames); + + for (int i = 0; i < nxagentFailedToReconnectFonts.index; i++) { - repeat = True; + Bool fontSuccess = True; + + if (nxagentFailedToReconnectFonts.font[i]) + { + nxagentFailedFontReconnect(nxagentFailedToReconnectFonts.font[i], + nxagentFailedToReconnectFonts.id[i], + &fontSuccess); + + if (fontSuccess) + { + nxagentFailedToReconnectFonts.font[i] = NULL; + } + else + { + repeat = True; + } + } } - } - } - - attempt++; + attempt++; - if (attempt > maxAttempt) - { - nxagentFreeFailedToReconnectFonts(); + if (attempt > maxAttempt) + { + nxagentFreeFailedToReconnectFonts(); - XSetFontPath(nxagentDisplay, fontPaths, nPaths); - nxagentFreeRemoteFontList(&nxagentRemoteFontList); - nxagentListRemoteFonts("*", nxagentMaxFontNames); + XSetFontPath(nxagentDisplay, fontPaths, nPaths); + nxagentFreeRemoteFontList(&nxagentRemoteFontList); + nxagentListRemoteFonts("*", nxagentMaxFontNames); - XFreeFontPath(fontPaths); - SAFE_free(newFontPaths); + XFreeFontPath(fontPaths); + SAFE_free(newFontPaths); - return False; + return False; + } } - } - nxagentFreeFailedToReconnectFonts(); + nxagentFreeFailedToReconnectFonts(); - XSetFontPath(nxagentDisplay, fontPaths, nPaths); + XSetFontPath(nxagentDisplay, fontPaths, nPaths); - XFreeFontPath(fontPaths); - SAFE_free(newFontPaths); + XFreeFontPath(fontPaths); + SAFE_free(newFontPaths); - nxagentCleanCacheAfterReconnect(); + nxagentCleanCacheAfterReconnect(); - return True; + return True; } Bool nxagentDisconnectAllFonts(void) { - Bool fontSuccess = True; + Bool fontSuccess = True; - #if defined(NXAGENT_RECONNECT_DEBUG) || defined(NXAGENT_RECONNECT_FONT_DEBUG) - fprintf(stderr, "nxagentDisconnectAllFonts\n"); - #endif + #if defined(NXAGENT_RECONNECT_DEBUG) || defined(NXAGENT_RECONNECT_FONT_DEBUG) + fprintf(stderr, "nxagentDisconnectAllFonts\n"); + #endif - nxagentFreeRemoteFontList(&nxagentRemoteFontList); - nxagentFreeCacheBeforeReconnect(); + nxagentFreeRemoteFontList(&nxagentRemoteFontList); + nxagentFreeCacheBeforeReconnect(); - /* - * The resource type RT_NX_FONT is created on the server client - * only, so we can avoid to loop through all the clients. - */ + /* + * The resource type RT_NX_FONT is created on the server client + * only, so we can avoid to loop through all the clients. + */ - FindClientResourcesByType(clients[serverClient -> index], RT_NX_FONT, - (FindResType) nxagentFontDisconnect, &fontSuccess); + FindClientResourcesByType(clients[serverClient -> index], RT_NX_FONT, + (FindResType) nxagentFontDisconnect, &fontSuccess); - for(int cid = 0; cid < MAXCLIENTS; cid++) - { - if( clients[cid] && fontSuccess ) + for (int cid = 0; cid < MAXCLIENTS; cid++) { - FindClientResourcesByType(clients[cid], RT_FONT, - (FindResType) nxagentFontDisconnect, &fontSuccess); + if (clients[cid] && fontSuccess) + { + FindClientResourcesByType(clients[cid], RT_FONT, + (FindResType) nxagentFontDisconnect, &fontSuccess); + } } - } - return True; + return True; } static Bool nxagentGetFontServerPath(char * fontServerPath, int size) { - char path[256] = {0}; - - if (NXGetFontParameters(nxagentDisplay, sizeof(path), path) == True) - { - /* the length is stored in the first byte and is therefore limited to 255 */ - unsigned int len = *path; + char path[256] = {0}; - if (len) + if (NXGetFontParameters(nxagentDisplay, sizeof(path), path) == True) { - snprintf(fontServerPath, min(size, len + 1), "%s", path + 1); + /* the length is stored in the first byte and is therefore limited to 255 */ + unsigned int len = *path; - #ifdef TEST - fprintf(stderr, "%s: Got path [%s].\n", __func__, - fontServerPath); - #endif + if (len) + { + snprintf(fontServerPath, min(size, len + 1), "%s", path + 1); + + #ifdef TEST + fprintf(stderr, "%s: Got path [%s].\n", __func__, + fontServerPath); + #endif + } + else + { + #ifdef TEST + fprintf(stderr, "%s: WARNING! Font server tunneling not enabled.\n", __func__); + #endif + + return False; + } } else { - #ifdef TEST - fprintf(stderr, "%s: WARNING! Font server tunneling not enabled.\n", __func__); - #endif + #ifdef TEST + fprintf(stderr, "%s: WARNING! Failed to get path for font server tunneling.\n", __func__); + #endif - return False; + return False; } - } - else - { - #ifdef TEST - fprintf(stderr, "%s: WARNING! Failed to get path for font server tunneling.\n", __func__); - #endif - - return False; - } - return True; + return True; } void nxagentVerifySingleFontPath(char **dest, const char *fontDir) { - if (!dest || !*dest) - return; + if (!dest || !*dest) + return; - #ifdef TEST - fprintf(stderr, "%s: Assuming fonts in directory [%s].\n", __func__, - validateString(fontDir)); - #endif + #ifdef TEST + fprintf(stderr, "%s: Assuming fonts in directory [%s].\n", __func__, + validateString(fontDir)); + #endif - for (int i = 0; ; i++) - { - char *tmppath = NULL; - int rc; + for (int i = 0; ; i++) + { + char *tmppath = NULL; + int rc; - const char *subdir = nxagentFontSubdirs[i]; + const char *subdir = nxagentFontSubdirs[i]; - if (subdir == NULL) - return; + if (subdir == NULL) + return; - if (**dest != '\0') - { - rc = asprintf(&tmppath, "%s,%s/%s", *dest, fontDir, subdir); - } - else - { - rc = asprintf(&tmppath, "%s/%s", fontDir, subdir); - } + if (**dest != '\0') + { + rc = asprintf(&tmppath, "%s,%s/%s", *dest, fontDir, subdir); + } + else + { + rc = asprintf(&tmppath, "%s/%s", fontDir, subdir); + } - if (rc == -1) - return; + if (rc == -1) + return; - SAFE_free(*dest); - *dest = tmppath; - tmppath = NULL; - } + SAFE_free(*dest); + *dest = tmppath; + tmppath = NULL; + } } void nxagentVerifyDefaultFontPath(void) { - static char *fontPath; + static char *fontPath; - #ifdef TEST - fprintf(stderr, "%s: Going to search for one or more valid font paths.\n", __func__); - #endif - - /* - * Set the default font path as the first choice. - */ - - if ((fontPath = strdup(defaultFontPath)) == NULL) - { - #ifdef WARNING - fprintf(stderr, "%s: WARNING! Unable to allocate memory for a new font path. " - "Using the default font path [%s].\n", __func__, - validateString(defaultFontPath)); + #ifdef TEST + fprintf(stderr, "%s: Going to search for one or more valid font paths.\n", __func__); #endif - return; - } - - for (int i = 0; ; i++) - { - int j; - const char *dir = nxagentFontDirs[i]; + /* + * Set the default font path as the first choice. + */ - if (dir == NULL) + if ((fontPath = strdup(defaultFontPath)) == NULL) { - break; + #ifdef WARNING + fprintf(stderr, "%s: WARNING! Unable to allocate memory for a new font path. " + "Using the default font path [%s].\n", __func__, + validateString(defaultFontPath)); + #endif + + return; } - else + + for (int i = 0; ; i++) { - for (j = 0; j <= i; j++) - { - //if (strcmp(nxagentFontDirs[j], dir) == 0) - if (nxagentFontDirs[j] == dir) + int j; + const char *dir = nxagentFontDirs[i]; + + if (dir == NULL) { - break; + break; } - } - - if (j == i) - { - nxagentVerifySingleFontPath(&fontPath, dir); - } + else + { + for (j = 0; j <= i; j++) + { + //if (strcmp(nxagentFontDirs[j], dir) == 0) + if (nxagentFontDirs[j] == dir) + { + break; + } + } + + if (j == i) + { + nxagentVerifySingleFontPath(&fontPath, dir); + } #ifdef TEST - else - { - fprintf(stderr, "%s: Skipping duplicate font dir [%s].\n", __func__, - validateString(dir)); - } + else + { + fprintf(stderr, "%s: Skipping duplicate font dir [%s].\n", __func__, + validateString(dir)); + } #endif + } } - } - if (*fontPath == '\0') - { - #ifdef WARNING - fprintf(stderr, "%s: WARNING! Can't find a valid font directory.\n", __func__); - fprintf(stderr, "%s: WARNING! Using font path [%s].\n", __func__, - validateString(defaultFontPath)); - #endif - } - else - { - /* do _not_ free defaultFontPath here - it's either set at compile time or - part of argv */ - defaultFontPath = fontPath; + if (*fontPath == '\0') + { + #ifdef WARNING + fprintf(stderr, "%s: WARNING! Can't find a valid font directory.\n", __func__); + fprintf(stderr, "%s: WARNING! Using font path [%s].\n", __func__, + validateString(defaultFontPath)); + #endif + } + else + { + /* do _not_ free defaultFontPath here - it's either set at compile time or + part of argv */ + defaultFontPath = fontPath; - #ifdef TEST - fprintf(stderr, "%s: Using font path [%s].\n", __func__, - validateString(defaultFontPath)); - #endif - } + #ifdef TEST + fprintf(stderr, "%s: Using font path [%s].\n", __func__, + validateString(defaultFontPath)); + #endif + } - return; + return; } XFontStruct* nxagentLoadQueryFont(register Display *dpy, char *name, FontPtr pFont) { - XFontStruct* fs; - xCharInfo *xcip; + XFontStruct* fs = (XFontStruct *) malloc (sizeof (XFontStruct)); - fs = (XFontStruct *) malloc (sizeof (XFontStruct)); - - if (fs == NULL) - { - #ifdef WARNING - fprintf(stderr, "nxagentLoadQueryFont: WARNING! Failed allocation of XFontStruct.\n"); - #endif + if (fs == NULL) + { + #ifdef WARNING + fprintf(stderr, "nxagentLoadQueryFont: WARNING! Failed allocation of XFontStruct.\n"); + #endif - return (XFontStruct *)NULL; - } + return (XFontStruct *)NULL; + } #ifdef NXAGENT_RECONNECT_FONT_DEBUG fprintf(stderr, "nxagentLoadQueryFont: Looking for font '%s'.\n", name); #endif - if (nxagentFontLookUp(name) == 0) - { - #ifdef DEBUG - fprintf(stderr, "nxagentLoadQueryFont: WARNING! Font not found '%s'.\n", name); - #endif - - SAFE_free(fs); + if (nxagentFontLookUp(name) == 0) + { + #ifdef DEBUG + fprintf(stderr, "nxagentLoadQueryFont: WARNING! Font not found '%s'.\n", name); + #endif - return (XFontStruct *) NULL; - } + SAFE_free(fs); - fs -> ext_data = NULL; /* Hook for extension to hang data.*/ - fs -> fid = XLoadFont(dpy, name); /* Font id for this font. */ - fs -> direction = pFont->info.drawDirection; /* Hint about the direction font is painted. */ - fs -> min_char_or_byte2 = pFont->info.firstCol; /* First character. */ - fs -> max_char_or_byte2 = pFont->info.lastCol; /* Last character. */ - fs -> min_byte1 = pFont->info.firstRow; /* First row that exists. */ - fs -> max_byte1 = pFont->info.lastRow; /* Last row that exists. */ - fs -> all_chars_exist = pFont->info.allExist; /* Flag if all characters have nonzero size. */ - fs -> default_char = pFont->info.defaultCh; /* Char to print for undefined character. */ - fs -> n_properties = pFont->info.nprops; /* How many properties there are. */ - - /* - * If no properties defined for the font, then it is bad - * font, but shouldn't try to read nothing. - */ + return (XFontStruct *) NULL; + } - if (fs -> n_properties > 0) - { - register long nbytes; + fs -> ext_data = NULL; /* Hook for extension to hang data.*/ + fs -> fid = XLoadFont(dpy, name); /* Font id for this font. */ + fs -> direction = pFont->info.drawDirection; /* Hint about the direction font is painted. */ + fs -> min_char_or_byte2 = pFont->info.firstCol; /* First character. */ + fs -> max_char_or_byte2 = pFont->info.lastCol; /* Last character. */ + fs -> min_byte1 = pFont->info.firstRow; /* First row that exists. */ + fs -> max_byte1 = pFont->info.lastRow; /* Last row that exists. */ + fs -> all_chars_exist = pFont->info.allExist; /* Flag if all characters have nonzero size. */ + fs -> default_char = pFont->info.defaultCh; /* Char to print for undefined character. */ + fs -> n_properties = pFont->info.nprops; /* How many properties there are. */ - nbytes = pFont -> info.nprops * sizeof(XFontProp); - fs -> properties = (XFontProp *) malloc((unsigned) nbytes); + /* + * If no properties defined for the font, then it is bad + * font, but shouldn't try to read nothing. + */ - if (fs -> properties == NULL) + if (fs -> n_properties > 0) { - #ifdef WARNING - fprintf(stderr, "nxagentLoadQueryFont: WARNING! Failed allocation of XFontProp."); - #endif + long nbytes; - SAFE_free(fs); - return (XFontStruct *) NULL; - } + nbytes = pFont -> info.nprops * sizeof(XFontProp); + fs -> properties = (XFontProp *) malloc((unsigned) nbytes); - memmove(fs -> properties, pFont -> info.props, nbytes); - } + if (fs -> properties == NULL) + { + #ifdef WARNING + fprintf(stderr, "nxagentLoadQueryFont: WARNING! Failed allocation of XFontProp."); + #endif + + SAFE_free(fs); + return (XFontStruct *) NULL; + } + + memmove(fs -> properties, pFont -> info.props, nbytes); + } - xcip = (xCharInfo *) &pFont -> info.ink_minbounds; + xCharInfo *xcip = (xCharInfo *) &pFont -> info.ink_minbounds; - fs -> min_bounds.lbearing = cvtINT16toShort(xcip -> leftSideBearing); - fs -> min_bounds.rbearing = cvtINT16toShort(xcip -> rightSideBearing); - fs -> min_bounds.width = cvtINT16toShort(xcip -> characterWidth); - fs -> min_bounds.ascent = cvtINT16toShort(xcip -> ascent); - fs -> min_bounds.descent = cvtINT16toShort(xcip -> descent); - fs -> min_bounds.attributes = xcip -> attributes; + fs -> min_bounds.lbearing = cvtINT16toShort(xcip -> leftSideBearing); + fs -> min_bounds.rbearing = cvtINT16toShort(xcip -> rightSideBearing); + fs -> min_bounds.width = cvtINT16toShort(xcip -> characterWidth); + fs -> min_bounds.ascent = cvtINT16toShort(xcip -> ascent); + fs -> min_bounds.descent = cvtINT16toShort(xcip -> descent); + fs -> min_bounds.attributes = xcip -> attributes; - xcip = (xCharInfo *) &pFont -> info.ink_maxbounds; + xcip = (xCharInfo *) &pFont -> info.ink_maxbounds; - fs -> max_bounds.lbearing = cvtINT16toShort(xcip -> leftSideBearing); - fs -> max_bounds.rbearing = cvtINT16toShort(xcip -> rightSideBearing); - fs -> max_bounds.width = cvtINT16toShort(xcip -> characterWidth); - fs -> max_bounds.ascent = cvtINT16toShort(xcip -> ascent); - fs -> max_bounds.descent = cvtINT16toShort(xcip -> descent); - fs -> max_bounds.attributes = xcip -> attributes; + fs -> max_bounds.lbearing = cvtINT16toShort(xcip -> leftSideBearing); + fs -> max_bounds.rbearing = cvtINT16toShort(xcip -> rightSideBearing); + fs -> max_bounds.width = cvtINT16toShort(xcip -> characterWidth); + fs -> max_bounds.ascent = cvtINT16toShort(xcip -> ascent); + fs -> max_bounds.descent = cvtINT16toShort(xcip -> descent); + fs -> max_bounds.attributes = xcip -> attributes; - fs -> per_char = NULL; /* First_char to last_char information. */ - fs -> ascent = pFont->info.fontAscent; /* Logical extent above baseline for spacing. */ - fs -> descent = pFont->info.fontDescent; /* Logical decent below baseline for spacing. */ + fs -> per_char = NULL; /* First_char to last_char information. */ + fs -> ascent = pFont->info.fontAscent; /* Logical extent above baseline for spacing. */ + fs -> descent = pFont->info.fontDescent; /* Logical decent below baseline for spacing. */ - return fs; + return fs; } int nxagentFreeFont(XFontStruct *fs) { - if (fs->per_char) - { - #ifdef USE_XF86BIGFONT - _XF86BigfontFreeFontMetrics(fs); - #else - SAFE_free(fs->per_char); - #endif - } + if (fs->per_char) + { + #ifdef USE_XF86BIGFONT + _XF86BigfontFreeFontMetrics(fs); + #else + SAFE_free(fs->per_char); + #endif + } - SAFE_free(fs->properties); - SAFE_XFree(fs); + SAFE_free(fs->properties); + SAFE_XFree(fs); - return 1; + return 1; } int nxagentSplitString(char *string, char *fields[], int nfields, char *sep) { - int seplen = strlen(sep); - int len = strlen(string); - - char *current = string; + int seplen = strlen(sep); + int len = strlen(string); - int i = 0; - int last = 0; + char *current = string; - for (;;) - { - char *next = NULL; + int i = 0; + int last = 0; - if (current < string + len) + for (;;) { - next = strstr(current, sep); - } + char *next = NULL; - if (next == NULL) - { - next = string + len; - last = 1; - } + if (current < string + len) + { + next = strstr(current, sep); + } - int fieldlen = next - current; + if (next == NULL) + { + next = string + len; + last = 1; + } - if (i < nfields) - { - fields[i] = strndup(current, fieldlen); - } - else - { - fields[i] = NULL; - } + int fieldlen = next - current; - current = next + seplen; + if (i < nfields) + { + fields[i] = strndup(current, fieldlen); + } + else + { + fields[i] = NULL; + } - i++; + current = next + seplen; - if (last == 1) - { - break; + i++; + + if (last == 1) + { + break; + } } - } - return i; + return i; } char *nxagentMakeScalableFontName(const char *fontName, int scalableResolution) { - char *scalableFontName; + char *scalableFontName; - /* FIXME: use str(n)dup()? */ - if ((scalableFontName = malloc(strlen(fontName) + 1)) == NULL) - { - #ifdef PANIC - fprintf(stderr, "nxagentMakeScalableFontName: PANIC! malloc() failed.\n"); - #endif - - return NULL; - } + /* FIXME: use str(n)dup()? */ + if ((scalableFontName = malloc(strlen(fontName) + 1)) == NULL) + { + #ifdef PANIC + fprintf(stderr, "nxagentMakeScalableFontName: PANIC! malloc() failed.\n"); + #endif - scalableFontName[0] = '\0'; + return NULL; + } - if (*fontName != '-') - { - goto MakeScalableFontNameError; - } + scalableFontName[0] = '\0'; - const char *s = fontName; + if (*fontName != '-') + { + goto MakeScalableFontNameError; + } - int field = 0; + const char *s = fontName; - while (s != NULL) - { - s = strchr(s + 1, '-'); + int field = 0; - if (s != NULL) + while (s != NULL) { - if (field == 6 || field == 7 || field == 11) - { - /* - * PIXEL_SIZE || POINT_SIZE || AVERAGE_WIDTH - */ - - strcat(scalableFontName, "-0"); - } - else if (scalableResolution == 1 && (field == 8 || field == 9)) - { - /* - * RESOLUTION_X || RESOLUTION_Y - */ + s = strchr(s + 1, '-'); - strcat(scalableFontName, "-0"); - } - else - { - strncat(scalableFontName, fontName, s - fontName); - } + if (s != NULL) + { + if (field == 6 || field == 7 || field == 11) + { + /* + * PIXEL_SIZE || POINT_SIZE || AVERAGE_WIDTH + */ + + strcat(scalableFontName, "-0"); + } + else if (scalableResolution == 1 && (field == 8 || field == 9)) + { + /* + * RESOLUTION_X || RESOLUTION_Y + */ + + strcat(scalableFontName, "-0"); + } + else + { + strncat(scalableFontName, fontName, s - fontName); + } + + fontName = s; + } + else + { + strcat(scalableFontName, fontName); + } - fontName = s; + field++; } - else + + if (field != 14) { - strcat(scalableFontName, fontName); + goto MakeScalableFontNameError; } - field++; - } - - if (field != 14) - { - goto MakeScalableFontNameError; - } - - return scalableFontName; + return scalableFontName; MakeScalableFontNameError: - SAFE_free(scalableFontName); + SAFE_free(scalableFontName); - #ifdef DEBUG - fprintf(stderr, "nxagentMakeScalableFontName: Invalid font name.\n"); - #endif + #ifdef DEBUG + fprintf(stderr, "nxagentMakeScalableFontName: Invalid font name.\n"); + #endif - return NULL; + return NULL; } |