int QNanoFont::getID(NVGcontext* nvg) { if (m_fontPropertiesChanged) { nvgFontSize(nvg, m_size); nvgFontBlur(nvg, m_blur); nvgTextLetterSpacing(nvg, m_spacing); nvgTextLineHeight(nvg, m_lineHeight); } if (m_filename.isEmpty()) { // No font file set, so loading the default font setFontId(QNanoFont::DEFAULT_FONT_NORMAL); } m_id = nvgFindFont(nvg,m_filename.toUtf8().constData()); if (m_id == -1) { // Font is not yet in cache, so load and add it QFile file(m_filename); if (!file.open(QFile::ReadOnly)) { qWarning() << "Could not open font file: " << m_filename; } else { qint64 length = file.bytesAvailable(); char * data = static_cast<char*>(malloc(length)); file.read(data,length); m_id = nvgCreateFontMem(nvg, m_filename.toUtf8().constData(), reinterpret_cast<unsigned char*>(data), length, 1); file.close(); } } return m_id; }
void VectorTextFormat::ensureFontId() { if (fontId == VectorTextFormat::FONT_UNDEFINED) { int id = nvgFindFont(nvg, font.c_str()); fontId = id >= 0 ? id : VectorTextFormat::FONT_NOTFOUND; } if (fontId == VectorTextFormat::FONT_NOTFOUND) { if (defaultFontId == VectorTextFormat::FONT_UNDEFINED) loadDefaultFontFace(); fontId = defaultFontId; } if (fontId < 0) { if (defaultFontId != VectorTextFormat::FONT_REPORTEDERROR) { const char *msg; switch (defaultFontId) { case VectorTextFormat::FONT_DEFAULTMISSING: msg = "Missing default system font face (load error or unsupported platform)"; break; case VectorTextFormat::FONT_DEFAULTMEMORY: msg = "Unable to create default font face memory"; break; default: msg = "Unknown error"; break; } lmLogError(gGFXVectorRendererLogGroup, "TextFormat font error: %s", msg); defaultFontId = VectorTextFormat::FONT_REPORTEDERROR; } return; } }
JNIEXPORT jint JNICALL Java_firststep_internal_NVG_findFont (JNIEnv *e, jclass c, jlong ctx, jstring jname) { checkJO(jname,"\nfindFont was passed a NULL name string\n"); const char *name = (*e)->GetStringUTFChars(e, jname, 0); int r = nvgFindFont((NVGcontext*)ctx, name); (*e)->ReleaseStringUTFChars(e, jname, name); return r; }