Example #1
0
int XSetFontPath(Display* display, char** directories, int ndirs) {
    SET_X_SERVER_REQUEST(display, X_SetFontPath);
    char* path;
    size_t i;
    while (fontSearchPaths->length > 0) {
        // Clear the array and free the data
        free(removeArray(fontSearchPaths, 0, False));
    }
    if (directories == NULL || ndirs == 0) {
        // Reset the search path to the default for the compiled platform
        ndirs = ARRAY_LENGTH(DEFAULT_FONT_SEARCH_PATHS);
        directories = (char **) DEFAULT_FONT_SEARCH_PATHS;
    }
    for (i = 0; i < ndirs; i++) {
        if (checkFontPath(directories[i])) {
            path = strdup(directories[i]);
            if (path == NULL) {
                handleOutOfMemory(0, display, 0, 0);
            } else {
                insertArray(fontSearchPaths, path);
            }
        }
    }
    return updateFontCache() ? 1 : 0;
}
Example #2
0
void GraphicsLayer::updateArray(VertexArray& array, const QVector<Vertex>& data)
{
	int length = data.count();
	if (array.length() != length) {
		removeArray(array);
		array.start = -1;
		for (int i = 0; i < m_free_regions.count(); ++i) {
			VertexArray& free_region = m_free_regions[i];
			if (free_region.length() == length) {
				array.start = free_region.start;
				array.end = array.start + length;
				m_free_regions.removeAt(i);
				break;
			} else if (free_region.length() > length) {
				array.start = free_region.start;
				array.end = array.start + length;
				free_region.start += length;
				break;
			}
		}
	}

	if (array.start != -1) {
		qCopy(data.begin(), data.end(), m_data.begin() + array.start);
		if (!m_changed) {
			m_changed_regions.append(array);
		}
	} else {
		array.start = m_data.count();
		array.end = array.start + length;
		m_data += data;
		m_changed = true;
		m_changed_regions.clear();
	}
}
Example #3
0
// first index=0
void Settings::removeArrayEntry( const QString & key , int index)
{
    QList< QVariantMap > array;
    array = getArray(key);
    array.removeAt(index);

    removeArray(key);

    foreach (QVariantMap entry, array)
        appendToArray(key, entry);
    bool b;
    b=true;
}
Example #4
0
void freeFontStorage() {
    if (fontSearchPaths != NULL) {
        // Clear the array and free the data
        while (fontSearchPaths->length > 0) {
            free(removeArray(fontSearchPaths, 0, False));
        }
        freeArray(fontSearchPaths);
        free(fontSearchPaths);
        fontSearchPaths = NULL;
    }
    if (fontCache != NULL) {
        // Clear the array and free the data
        while (fontCache->length > 0) {
            FontCacheEntry* entry = removeArray(fontSearchPaths, 0, False);
            free(entry->filePath);
            free(entry->XLFName);
            free(entry);
        }
        freeArray(fontCache);
        free(fontCache);
        fontSearchPaths = NULL;
    }
}
Example #5
0
void BPlusIndexP::removeElements(IndexPage* source, int startIndex, int endIndex) {
	removeArray((void**)source, startIndex, endIndex);
	source->size -= (endIndex - startIndex);
}
Example #6
0
Bool updateFontCache() {
    size_t i, entryNameLen;
    size_t fontCacheIndex = 0;
    DIR* fontDirectory;
    struct dirent* entry;
    char pathBuffer[512];
    for (i = 0; i < fontSearchPaths->length; i++) {
        char* fontDirPath = fontSearchPaths->array[i];
        fontDirectory = opendir(fontDirPath);
        if (fontDirectory == NULL) {
            free(removeArray(fontSearchPaths, i, False));
            i--;
            continue;
        }
        while ((entry = readdir(fontDirectory)) != NULL) {
            // We add all missing fonts to the cache, swapping their position to the front.
            // We can be sure, that the fonts with an index lower than fontCacheIndex are valid.
            entryNameLen = strlen(entry->d_name);
            if (entryNameLen > 4 && strncmp(&entry->d_name[entryNameLen - 4], ".ttf", 4) == 0) {
                ssize_t index = findInArrayNCmp(fontCache, entry->d_name,
                                                fontCacheIndex, &fontCacheEntryFileNameCmp);
                
                if (index == -1) {
                    snprintf(pathBuffer, 512, "%s/%s", fontDirPath, entry->d_name);
                    TTF_Font* font = TTF_OpenFont(pathBuffer, FONT_SIZE);
                    if (font == NULL) continue;
                    FontCacheEntry* fontCacheEntry = malloc(sizeof(FontCacheEntry));
                    if (fontCacheEntry == NULL) {
                        TTF_CloseFont(font);
                        closedir(fontDirectory);
                        return False;
                    }
                    fontCacheEntry->filePath = strdup(pathBuffer);
                    fontCacheEntry->XLFName = getFontXLFDName(font);
                    if (fontCacheEntry->filePath == NULL ||  fontCacheEntry->XLFName == NULL) {
                        if (fontCacheEntry->filePath != NULL) free(fontCacheEntry->filePath);
                        if (fontCacheEntry->XLFName != NULL) free(fontCacheEntry->XLFName);
                        free(fontCacheEntry);
                        TTF_CloseFont(font);
                        closedir(fontDirectory);
                        return False;
                    }
                    if (!insertArray(fontCache, fontCacheEntry)) {
                        free(fontCacheEntry->filePath);
                        free(fontCacheEntry->XLFName);
                        free(fontCacheEntry);
                        TTF_CloseFont(font);
                        closedir(fontDirectory);
                        return False;
                    }
                    index = fontCache->length - 1;
                }
                if (index != fontCacheIndex) {
                    swapArray(fontCache, (size_t) index, fontCacheIndex);
                }
                fontCacheIndex++;
            }
        }
        closedir(fontDirectory);
    }
    while (fontCache->length > fontCacheIndex) {
        // Remove all invalid cache entries
        FontCacheEntry* cacheEntry = removeArray(fontCache, fontCache->length - 1, True);
        free(cacheEntry->filePath);
        free(cacheEntry->XLFName);
        free(cacheEntry);
    }
    return True;
}