Пример #1
0
void FontContext::fontstashError(void* _uptr, int _error, int _val) {
    FontContext* fontContext = static_cast<FontContext*>(_uptr);

    switch(_error) {
    case FONS_ATLAS_FULL: {
        // callback during rasterize ()
        fontContext->m_handleAtlasFull = true;
        const auto& tex = fontContext->m_atlas;
        unsigned int nw = tex->getWidth() * 2;
        unsigned int nh = tex->getHeight() * 2;

        if (nw > TANGRAM_MAX_TEXTURE_WIDTH || nh > TANGRAM_MAX_TEXTURE_HEIGHT) {
            LOGE("Full font texture atlas size reached!");
        } else {
            std::lock_guard<std::mutex> lock(fontContext->m_atlasMutex);

            if (fonsExpandAtlas(fontContext->m_fsContext, nw, nh, 1)) {
                tex->resize(nw, nh);
                LOGW("Texture Atlas resized to %d %d", nw, nh);
            } else {
                LOGE("Unexpected error while expanding the font atlas");
            }
        }
        fontContext->m_handleAtlasFull = false;
        break;
    }
    case FONS_SCRATCH_FULL:
    case FONS_STATES_OVERFLOW:
    case FONS_STATES_UNDERFLOW:
    default:
        LOGE("Unexpected error in Fontstash %d:%d!", _error, _val);
        break;
    }
}
Пример #2
0
static void expandAtlas(struct FONScontext* stash)
{
	int w = 0, h = 0;
	fonsGetAtlasSize(stash, &w, &h);
	if (w < h)
		w *= 2;
	else
		h *= 2;
	fonsExpandAtlas(stash, w, h);
	printf("expanded atlas to %d x %d\n", w, h);
}