void SpriteComponent::init() { const char *comma = strchr(_name.c_str(), ','); Common::String name(_name.c_str(), comma); if (_sprite) { if (_parent) { MeshComponent *mc = static_cast<MeshComponent *>(_parent); mc->getNode()->removeSprite(_sprite); } delete _sprite; _sprite = NULL; } if (comma) { int width, height, x, y, z; sscanf(comma, ",%d,%d,%d,%d,%d", &width, &height, &x, &y, &z); _sprite = new Sprite; _sprite->_material = g_resourceloader->loadMaterial(name, getCMap()); _sprite->_width = (float)width / 100.0f; _sprite->_height = (float)height / 100.0f; _sprite->_pos.set((float)x / 100.0f, (float)y / 100.0f, (float)z / 100.0f); _sprite->_visible = false; _sprite->_next = NULL; if (_parent) { if (_parent->isComponentType('M','E','S','H')) { MeshComponent *mc = static_cast<MeshComponent *>(_parent); mc->getNode()->addSprite(_sprite); } else Debug::warning(Debug::Costumes, "Parent of sprite %s wasn't a mesh", _name.c_str()); } } }
void ModelComponent::resetColormap() { CMap *cm; cm = getCMap(); if (_obj && cm) _obj->reload(cm); }
/* * Function to initialize global config struct */ static Config initConfig(CMap cmap) { char * val; int i = 0; Config c = mallocConfig(); FILE * file = fopen(DEFAULT_OPTIONS_FILENAME, "r"); if (file == NULL) { die("Default config file not found.", 2); } defCMap = getCMap(file); /* Load default config map from file */ for (i = 0; i < ARYLEN; ++i) { /* Load default values into config ary 1st */ config[i].value = getCValue(defCMap, config[i].keyword); } for (i = 0; i < ARYLEN; ++i) { val = getCValue(cmap, config[i].keyword); /* get user config value */ if (val != NULL) { if (!setConfigValue(c, i, val)) /* check & set configuration */ printErr("Invalid parameter value: ", "initConfig()", 1); /* ... or log an error */ } else if (!setConfigValue(c, i, config[i].value)) printErr("Error in default config file: ", "initConfig()", 1); } fclose(file); return c; }
void Component::setColormap(CMap *c) { if (c) _cmap = c; if (getCMap()) { resetHierCMap(); } }
/* Configure global config struct and return error if any */ Config configSPQR(FILE * file) { CMap cmap = getCMap(file); Config c = initConfig(cmap); c->errors = configError; freeCMap(defCMap); freeCMap(cmap); return c; }
bool QFontEngineMac::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const { if (flags & QTextEngine::GlyphIndicesOnly) { if (!cmap) { cmapTable = getSfntTable(MAKE_TAG('c', 'm', 'a', 'p')); int size = 0; cmap = getCMap(reinterpret_cast<const uchar *>(cmapTable.constData()), cmapTable.size(), &symbolCMap, &size); if (!cmap) return false; } if (symbolCMap) { for (int i = 0; i < len; ++i) { unsigned int uc = getChar(str, i, len); glyphs->glyph = getTrueTypeGlyphIndex(cmap, uc); if(!glyphs->glyph && uc < 0x100) glyphs->glyph = getTrueTypeGlyphIndex(cmap, uc + 0xf000); glyphs++; } } else { for (int i = 0; i < len; ++i) { unsigned int uc = getChar(str, i, len); glyphs->glyph = getTrueTypeGlyphIndex(cmap, uc); glyphs++; } } *nglyphs = len; return true; } if (!multiEngine) return false; const bool kashidaRequest = (len == 1 && *str == QChar(0x640)); if (kashidaRequest && kashidaGlyph.glyph != 0) { *glyphs = kashidaGlyph; *nglyphs = 1; return true; } bool result = multiEngine->stringToCMap(str, len, glyphs, nglyphs, flags); if (result && kashidaRequest) { kashidaGlyph = *glyphs; } return result; }
void ModelComponent::init() { if (_prevComp && _prevComp->isComponentType('M','M','D','L')) { _previousCmap = _prevComp->getCMap(); } // Skip loading if it was initialized // by the sharing MainModelComponent // constructor before if (!_obj) { CMapPtr cm = getCMap(); // Get the default colormap if we haven't found // a valid colormap if (!cm && g_grim->getCurrSet()) cm = g_grim->getCurrSet()->getCMap(); if (!cm) { Debug::warning(Debug::Costumes, "No colormap specified for %s, using %s", _name.c_str(), DEFAULT_COLORMAP); cm = g_resourceloader->getColormap(DEFAULT_COLORMAP); } // If we're the child of a mesh component, put our nodes in the // parent object's tree. if (_parent) { MeshComponent *mc = static_cast<MeshComponent *>(_parent); _obj = g_resourceloader->loadModel(_name, cm, mc->getModel()); _hier = _obj->getHierarchy(); mc->getNode()->addChild(_hier); } else { _obj = g_resourceloader->loadModel(_name, cm); _hier = _obj->getHierarchy(); Debug::warning(Debug::Costumes, "Parent of model %s wasn't a mesh", _name.c_str()); } // Use parent availablity to decide whether to default the // component to being visible if (_parent) setKey(0); else setKey(1); } if (!_animation) { _animation = new AnimManager(); } }
QWindowsFontEngine::QWindowsFontEngine(const QString &name, LOGFONT lf, const QSharedPointer<QWindowsFontEngineData> &fontEngineData) : QFontEngine(Win), m_fontEngineData(fontEngineData), _name(name), m_logfont(lf), ttf(0), hasOutline(0) { qCDebug(lcQpaFonts) << __FUNCTION__ << name << lf.lfHeight; hfont = CreateFontIndirect(&m_logfont); if (!hfont) { qErrnoWarning("%s: CreateFontIndirect failed for family '%s'", __FUNCTION__, qPrintable(name)); hfont = QWindowsFontDatabase::systemFont(); } HDC hdc = m_fontEngineData->hdc; SelectObject(hdc, hfont); const BOOL res = GetTextMetrics(hdc, &tm); if (!res) { qErrnoWarning("%s: GetTextMetrics failed", __FUNCTION__); ZeroMemory(&tm, sizeof(TEXTMETRIC)); } fontDef.pixelSize = -lf.lfHeight; fontDef.fixedPitch = !(tm.tmPitchAndFamily & TMPF_FIXED_PITCH); cache_cost = tm.tmHeight * tm.tmAveCharWidth * 2000; getCMap(); if (!resolvedGetCharWidthI) resolveGetCharWidthI(); // ### Properties accessed by QWin32PrintEngine (QtPrintSupport) QVariantMap userData; userData.insert(QStringLiteral("logFont"), QVariant::fromValue(m_logfont)); userData.insert(QStringLiteral("hFont"), QVariant::fromValue(hfont)); userData.insert(QStringLiteral("trueType"), QVariant(bool(ttf))); setUserData(userData); hasUnreliableOutline = (tm.tmPitchAndFamily & (TMPF_TRUETYPE | TMPF_VECTOR)) == 0; }
QFontEngineWin::QFontEngineWin(const QString &name, HFONT _hfont, bool stockFont, LOGFONT lf) { //qDebug("regular windows font engine created: font='%s', size=%d", name, lf.lfHeight); _name = name; cmap = 0; hfont = _hfont; logfont = lf; HDC hdc = shared_dc(); SelectObject(hdc, hfont); this->stockFont = stockFont; fontDef.pixelSize = -lf.lfHeight; lbearing = SHRT_MIN; rbearing = SHRT_MIN; synthesized_flags = -1; lineWidth = -1; x_height = -1; BOOL res = GetTextMetrics(hdc, &tm); fontDef.fixedPitch = !(tm.tmPitchAndFamily & TMPF_FIXED_PITCH); if (!res) { qErrnoWarning("QFontEngineWin: GetTextMetrics failed"); ZeroMemory(&tm, sizeof(TEXTMETRIC)); } cache_cost = tm.tmHeight * tm.tmAveCharWidth * 2000; getCMap(); widthCache = 0; widthCacheSize = 0; designAdvances = 0; designAdvancesSize = 0; if (!resolvedGetCharWidthI) resolveGetCharWidthI(); }
QFontEngineQPA::QFontEngineQPA(const QFontDef &def, const QByteArray &data) : fontData(reinterpret_cast<const uchar *>(data.constData())), dataSize(data.size()) { fontDef = def; cache_cost = 100; externalCMap = 0; cmapOffset = 0; cmapSize = 0; glyphMapOffset = 0; glyphMapEntries = 0; glyphDataOffset = 0; glyphDataSize = 0; kerning_pairs_loaded = false; readOnly = true; #if defined(DEBUG_FONTENGINE) qDebug() << "QFontEngineQPA::QFontEngineQPA( fd =" << fd << ", renderingFontEngine =" << renderingFontEngine << ')'; #endif if (!verifyHeader(fontData, dataSize)) { #if defined(DEBUG_FONTENGINE) qDebug() << "verifyHeader failed!"; #endif return; } const Header *header = reinterpret_cast<const Header *>(fontData); readOnly = (header->lock == 0xffffffff); const uchar *imgData = fontData + sizeof(Header) + qFromBigEndian<quint16>(header->dataSize); const uchar *endPtr = fontData + dataSize; while (imgData <= endPtr - 8) { quint16 blockTag = readValue<quint16>(imgData); imgData += 2; // skip padding quint32 blockSize = readValue<quint32>(imgData); if (blockTag == CMapBlock) { cmapOffset = imgData - fontData; cmapSize = blockSize; } else if (blockTag == GMapBlock) { glyphMapOffset = imgData - fontData; glyphMapEntries = blockSize / 4; } else if (blockTag == GlyphBlock) { glyphDataOffset = imgData - fontData; glyphDataSize = blockSize; } imgData += blockSize; } face_id.filename = QFile::encodeName(extractHeaderField(fontData, Tag_FileName).toString()); face_id.index = extractHeaderField(fontData, Tag_FileIndex).toInt(); // get the real cmap if (cmapOffset) { int tableSize = cmapSize; const uchar *cmapPtr = getCMap(fontData + cmapOffset, tableSize, &symbol, &cmapSize); if (cmapPtr) cmapOffset = cmapPtr - fontData; else cmapOffset = 0; } else if (externalCMap) { int tableSize = cmapSize; externalCMap = getCMap(externalCMap, tableSize, &symbol, &cmapSize); } // verify all the positions in the glyphMap if (glyphMapOffset) { const quint32 *gmapPtr = reinterpret_cast<const quint32 *>(fontData + glyphMapOffset); for (uint i = 0; i < glyphMapEntries; ++i) { quint32 glyphDataPos = qFromBigEndian<quint32>(gmapPtr[i]); if (glyphDataPos == 0xffffffff) continue; if (glyphDataPos >= glyphDataSize) { // error glyphMapOffset = 0; glyphMapEntries = 0; break; } } } #if defined(DEBUG_FONTENGINE) if (!isValid()) qDebug() << "fontData" << fontData << "dataSize" << dataSize << "externalCMap" << externalCMap << "cmapOffset" << cmapOffset << "glyphMapOffset" << glyphMapOffset << "glyphDataOffset" << glyphDataOffset << "fd" << fd << "glyphDataSize" << glyphDataSize; #endif }
int QFontEngineWin::getGlyphIndexes(const QChar *str, int numChars, QGlyphLayout *glyphs, bool mirrored) const { int i = 0; int glyph_pos = 0; if (mirrored) { #if defined(Q_WS_WINCE) { #else if (symbol) { for (; i < numChars; ++i, ++glyph_pos) { unsigned int uc = getChar(str, i, numChars); glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, uc); if (!glyphs->glyphs[glyph_pos] && uc < 0x100) glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, uc + 0xf000); } } else if (ttf) { for (; i < numChars; ++i, ++glyph_pos) { unsigned int uc = getChar(str, i, numChars); glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, QChar::mirroredChar(uc)); } } else { #endif wchar_t first = tm.tmFirstChar; wchar_t last = tm.tmLastChar; for (; i < numChars; ++i, ++glyph_pos) { uint ucs = QChar::mirroredChar(getChar(str, i, numChars)); if ( #ifdef Q_WS_WINCE tm.tmFirstChar > 60000 || // see line 375 #endif ucs >= first && ucs <= last) glyphs->glyphs[glyph_pos] = ucs; else glyphs->glyphs[glyph_pos] = 0; } } } else { #if defined(Q_WS_WINCE) { #else if (symbol) { for (; i < numChars; ++i, ++glyph_pos) { unsigned int uc = getChar(str, i, numChars); glyphs->glyphs[i] = getTrueTypeGlyphIndex(cmap, uc); if(!glyphs->glyphs[glyph_pos] && uc < 0x100) glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, uc + 0xf000); } } else if (ttf) { for (; i < numChars; ++i, ++glyph_pos) { unsigned int uc = getChar(str, i, numChars); glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, uc); } } else { #endif wchar_t first = tm.tmFirstChar; wchar_t last = tm.tmLastChar; for (; i < numChars; ++i, ++glyph_pos) { uint uc = getChar(str, i, numChars); if ( #ifdef Q_WS_WINCE tm.tmFirstChar > 60000 || // see comment in QFontEngineWin #endif uc >= first && uc <= last) glyphs->glyphs[glyph_pos] = uc; else glyphs->glyphs[glyph_pos] = 0; } } } glyphs->numGlyphs = glyph_pos; return glyph_pos; } QFontEngineWin::QFontEngineWin(const QString &name, HFONT _hfont, bool stockFont, LOGFONT lf) { //qDebug("regular windows font engine created: font='%s', size=%d", name, lf.lfHeight); _name = name; cmap = 0; hfont = _hfont; logfont = lf; HDC hdc = shared_dc(); SelectObject(hdc, hfont); this->stockFont = stockFont; fontDef.pixelSize = -lf.lfHeight; lbearing = SHRT_MIN; rbearing = SHRT_MIN; synthesized_flags = -1; lineWidth = -1; x_height = -1; BOOL res = GetTextMetrics(hdc, &tm); fontDef.fixedPitch = !(tm.tmPitchAndFamily & TMPF_FIXED_PITCH); if (!res) { qErrnoWarning("QFontEngineWin: GetTextMetrics failed"); ZeroMemory(&tm, sizeof(TEXTMETRIC)); } cache_cost = tm.tmHeight * tm.tmAveCharWidth * 2000; getCMap(); widthCache = 0; widthCacheSize = 0; designAdvances = 0; designAdvancesSize = 0; #ifndef Q_WS_WINCE if (!resolvedGetCharWidthI) resolveGetCharWidthI(); #endif }
QFontEngineQPF::QFontEngineQPF(const QFontDef &def, int fileDescriptor, QFontEngine *fontEngine) : fd(fileDescriptor), renderingFontEngine(fontEngine) { fontData = 0; dataSize = 0; fontDef = def; cache_cost = 100; freetype = 0; externalCMap = 0; cmapOffset = 0; cmapSize = 0; glyphMapOffset = 0; glyphMapEntries = 0; glyphDataOffset = 0; glyphDataSize = 0; kerning_pairs_loaded = false; readOnly = true; #if defined(DEBUG_FONTENGINE) qDebug() << "QFontEngineQPF::QFontEngineQPF( fd =" << fd << ", renderingFontEngine =" << renderingFontEngine << ")"; #endif if (fd < 0) { if (!renderingFontEngine) return; fileName = fontDef.family.toLower() + QLatin1String("_") + QString::number(fontDef.pixelSize) + QLatin1String("_") + QString::number(fontDef.weight) + (fontDef.style != QFont::StyleNormal ? QLatin1String("_italic") : QLatin1String("")) + QLatin1String(".qsf"); fileName.replace(QLatin1Char(' '), QLatin1Char('_')); fileName.prepend(qws_fontCacheDir()); const QByteArray encodedName = QFile::encodeName(fileName); if (::access(encodedName, F_OK) == 0) { #if defined(DEBUG_FONTENGINE) qDebug() << "found existing qpf:" << fileName; #endif if (::access(encodedName, W_OK | R_OK) == 0) fd = ::open(encodedName, O_RDWR); else if (::access(encodedName, R_OK) == 0) fd = ::open(encodedName, O_RDONLY); } else { #if defined(DEBUG_FONTENGINE) qDebug() << "creating qpf on the fly:" << fileName; #endif if (::access(QFile::encodeName(qws_fontCacheDir()), W_OK) == 0) { fd = ::open(encodedName, O_RDWR | O_EXCL | O_CREAT, 0644); QBuffer buffer; buffer.open(QIODevice::ReadWrite); QPFGenerator generator(&buffer, renderingFontEngine); generator.generate(); buffer.close(); const QByteArray &data = buffer.data(); ::write(fd, data.constData(), data.size()); } } } QT_STATBUF st; if (QT_FSTAT(fd, &st)) { #if defined(DEBUG_FONTENGINE) qDebug() << "stat failed!"; #endif return; } dataSize = st.st_size; fontData = (const uchar *)::mmap(0, st.st_size, PROT_READ | (renderingFontEngine ? PROT_WRITE : 0), MAP_SHARED, fd, 0); if (!fontData || fontData == (const uchar *)MAP_FAILED) { #if defined(DEBUG_FONTENGINE) perror("mmap failed"); #endif fontData = 0; return; } if (!verifyHeader(fontData, st.st_size)) { #if defined(DEBUG_FONTENGINE) qDebug() << "verifyHeader failed!"; #endif return; } const Header *header = reinterpret_cast<const Header *>(fontData); readOnly = (header->lock == 0xffffffff); const uchar *data = fontData + sizeof(Header) + qFromBigEndian<quint16>(header->dataSize); const uchar *endPtr = fontData + dataSize; while (data <= endPtr - 8) { quint16 blockTag = readValue<quint16>(data); data += 2; // skip padding quint32 blockSize = readValue<quint32>(data); if (blockTag == CMapBlock) { cmapOffset = data - fontData; cmapSize = blockSize; } else if (blockTag == GMapBlock) { glyphMapOffset = data - fontData; glyphMapEntries = blockSize / 4; } else if (blockTag == GlyphBlock) { glyphDataOffset = data - fontData; glyphDataSize = blockSize; } data += blockSize; } face_id.filename = QFile::encodeName(extractHeaderField(fontData, Tag_FileName).toString()); face_id.index = extractHeaderField(fontData, Tag_FileIndex).toInt(); #if !defined(QT_NO_FREETYPE) freetype = QFreetypeFace::getFace(face_id); if (!freetype) { QString newPath = #ifndef QT_NO_SETTINGS QLibraryInfo::location(QLibraryInfo::LibrariesPath) + #endif QLatin1String("/fonts/") + QFileInfo(QFile::decodeName(face_id.filename)).fileName(); face_id.filename = QFile::encodeName(newPath); freetype = QFreetypeFace::getFace(face_id); } if (freetype) { const quint32 qpfTtfRevision = extractHeaderField(fontData, Tag_FontRevision).toUInt(); uchar data[4]; uint length = 4; bool ok = freetype->getSfntTable(MAKE_TAG('h', 'e', 'a', 'd'), data, &length); if (!ok || length != 4 || qFromBigEndian<quint32>(data) != qpfTtfRevision) { freetype->release(face_id); freetype = 0; } } if (!cmapOffset && freetype) { freetypeCMapTable = getSfntTable(MAKE_TAG('c', 'm', 'a', 'p')); externalCMap = reinterpret_cast<const uchar *>(freetypeCMapTable.constData()); cmapSize = freetypeCMapTable.size(); } #endif // get the real cmap if (cmapOffset) { int tableSize = cmapSize; const uchar *cmapPtr = getCMap(fontData + cmapOffset, tableSize, &symbol, &cmapSize); if (cmapPtr) cmapOffset = cmapPtr - fontData; else cmapOffset = 0; } else if (externalCMap) { int tableSize = cmapSize; externalCMap = getCMap(externalCMap, tableSize, &symbol, &cmapSize); } // verify all the positions in the glyphMap if (glyphMapOffset) { const quint32 *gmapPtr = reinterpret_cast<const quint32 *>(fontData + glyphMapOffset); for (uint i = 0; i < glyphMapEntries; ++i) { quint32 glyphDataPos = qFromBigEndian<quint32>(gmapPtr[i]); if (glyphDataPos == 0xffffffff) continue; if (glyphDataPos >= glyphDataSize) { // error glyphMapOffset = 0; glyphMapEntries = 0; break; } } } #if defined(DEBUG_FONTENGINE) if (!isValid()) qDebug() << "fontData" << fontData << "dataSize" << dataSize << "externalCMap" << externalCMap << "cmapOffset" << cmapOffset << "glyphMapOffset" << glyphMapOffset << "glyphDataOffset" << glyphDataOffset << "fd" << fd << "glyphDataSize" << glyphDataSize; #endif #if defined(Q_WS_QWS) if (isValid() && renderingFontEngine) qt_fbdpy->sendFontCommand(QWSFontCommand::StartedUsingFont, QFile::encodeName(fileName)); #endif }