/** * Initializes the font list by creating empty RS_Font * objects, one for each font that could be found. */ void RS_FontList::init() { RS_DEBUG->print("RS_FontList::initFonts"); QStringList list = RS_SYSTEM->getNewFontList(); #if QT_VERSION < 0x040500 emu_qt45_QList_append(list, RS_SYSTEM->getFontList()); #else list.append(RS_SYSTEM->getFontList()); #endif QHash<QString, int> added; //used to remember added fonts (avoid duplication) RS_Font* font; for (int i = 0; i < list.size(); ++i) { RS_DEBUG->print("font: %s:", list.at(i).toLatin1().data()); QFileInfo fi( list.at(i) ); if ( !added.contains(fi.baseName()) ) { font = new RS_Font(fi.baseName()); fonts.append(font); added.insert(fi.baseName(), 1); } RS_DEBUG->print("base: %s", fi.baseName().toLatin1().data()); } }
/** * Loads the font into memory. * * @retval true font was already loaded or is loaded now. * @retval false font could not be loaded. */ bool RS_Font::loadFont() { RS_DEBUG->print("RS_Font::loadFont"); if (loaded) { return true; } QString path; // Search for the appropriate font if we have only the name of the font: if (!fileName.toLower().contains(".cxf") && !fileName.toLower().contains(".lff")) { QStringList fonts = RS_SYSTEM->getNewFontList(); #if QT_VERSION < 0x040500 emu_qt45_QList_append(fonts, RS_SYSTEM->getFontList()); #else fonts.append(RS_SYSTEM->getFontList()); #endif QFileInfo file; for (QStringList::Iterator it = fonts.begin(); it!=fonts.end(); it++) { if (QFileInfo(*it).baseName().toLower()==fileName.toLower()) { path = *it; break; } } } // We have the full path of the font: else { path = fileName; } // No font paths found: if (path.isEmpty()) { RS_DEBUG->print(RS_Debug::D_WARNING, "RS_Font::loadFont: No fonts available."); return false; } // Open cxf file: QFile f(path); if (!f.open(QIODevice::ReadOnly)) { RS_DEBUG->print(RS_Debug::D_WARNING, "RS_Font::loadFont: Cannot open font file: %s", path.toLatin1().data()); return false; } else { RS_DEBUG->print("RS_Font::loadFont: " "Successfully opened font file: %s", path.toLatin1().data()); } f.close(); if (path.contains(".cxf")) readCXF(path); if (path.contains(".lff")) readLFF(path); RS_Block* bk = letterList.find(QChar(0xfffd)); if (!bk) { // create new letter: RS_FontChar* letter = new RS_FontChar(nullptr, QChar(0xfffd), RS_Vector(0.0, 0.0)); RS_Polyline* pline = new RS_Polyline(letter, RS_PolylineData()); pline->setPen(RS_Pen(RS2::FlagInvalid)); pline->setLayer(nullptr); pline->addVertex(RS_Vector(1, 0), 0); pline->addVertex(RS_Vector(0, 2), 0); pline->addVertex(RS_Vector(1, 4), 0); pline->addVertex(RS_Vector(2, 2), 0); pline->addVertex(RS_Vector(1, 0), 0); letter->addEntity(pline); letter->calculateBorders(); letterList.add(letter); } loaded = true; RS_DEBUG->print("RS_Font::loadFont OK"); return true; }