示例#1
0
/**
 * @return Pointer to the font with the given name or
 * \p NULL if no such font was found. The font will be loaded into
 * memory if it's not already.
 */
RS_Font* RS_FontList::requestFont(const QString& name) {
    RS_DEBUG->print("RS_FontList::requestFont %s",  name.toLatin1().data());

    QString name2 = name.toLower();
    RS_Font* foundFont = NULL;

    // QCAD 1 compatibility:
    if (name2.contains('#') && name2.contains('_')) {
        name2 = name2.left(name2.indexOf('_'));
    } else if (name2.contains('#')) {
        name2 = name2.left(name2.indexOf('#'));
    }

    RS_DEBUG->print("name2: %s", name2.toLatin1().data());

    // Search our list of available fonts:
    for (int i = 0; i < fonts.size(); ++i) {
        RS_Font* f = fonts.at(i);

        if (f->getFileName()==name2) {
            // Make sure this font is loaded into memory:
            f->loadFont();
            foundFont = f;
            break;
        }
    }

    if (foundFont==NULL && name!="standard") {
        foundFont = requestFont("standard");
    }

    return foundFont;
}
示例#2
0
/**
 * @return Pointer to the font with the given name or
 * \p NULL if no such font was found. The font will be loaded into
 * memory if it's not already.
 */
RS_Font* RS_FontList::requestFont(const RS_String& name) {
    RS_DEBUG->print("RS_FontList::requestFont %s",  name.latin1());

    RS_String name2 = name.lower();
    RS_Font* foundFont = NULL;

    // QCad 1 compatibility:
    if (name2.contains('#') && name2.contains('_')) {
        name2 = name2.left(name2.find('_'));
    } else if (name2.contains('#')) {
        name2 = name2.left(name2.find('#'));
    }

    RS_DEBUG->print("name2: %s", name2.latin1());

    // Search our list of available fonts:
    for (RS_Font* f=fonts.first();
            f!=NULL;
            f=fonts.next()) {

        if (f->getFileName()==name2) {
            // Make sure this font is loaded into memory:
            f->loadFont();
            foundFont = f;
            break;
        }
    }

    if (foundFont==NULL && name!="standard") {
        foundFont = requestFont("standard");
    }

    return foundFont;
}
示例#3
0
void FontMan::loadFontCB(const std::string& assetName, bool error,
                         size_t bytesRead, uint8_t* buffer,
                         int32_t numRetries, CPM_ES_NS::ESCoreBase& core)
{
  if (!error)
  {
    // Generate a new ID for this font.
    ++mLastFontID;
    uint64_t fontID = mLastFontID;

    // No error. We have loaded the font file and are ready to load it up.
    // Remember, we are toying with the idea that the texture will not be
    // applied onto the object itself, but onto a ficticious font entity which
    // will be responsible for holding onto the texture until it is garbage
    // collected.
    mIDToFont.insert(std::make_pair(fontID, FontInfo(fontID, assetName)));

    auto it = mIDToFont.find(fontID);
    if (it != mIDToFont.end())
    {
      BMFont& font = it->second.fontInfo;
      font.loadFromBuffer(buffer, bytesRead);
    }
    else
    {
      std::cerr << "FontMan: Failed promise for " << assetName 
                << ". Unable to find newly inserted value!" << std::endl;
    }
  }
  else
  {
    if (numRetries > 0)
    {
      // Reattempt the request
      --numRetries;
      requestFont(core, assetName, numRetries);
    }
    else
    {
      std::cerr << "FontMan: Failed promise for " << assetName << std::endl;
    }
  }
}