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 Renderer2D::drawText( const attributes_2d& attributes,Font2D font, const char* text, const float32_t& fontSize, const color_argb& color, const float32_t& blur, const float32_t& spacing, const float32_t& lineHeight, const TextAlignment& alignment ) { Context2D* context = _context2D; nvgSave( context ); nvgBeginPath( context ); nvgRotate( context, attributes.rotation ); nvgFontSize( context, fontSize * attributes.scale ); nvgFontBlur( context, blur ); nvgTextLetterSpacing(context, spacing); nvgTextLineHeight(context, lineHeight); nvgTextAlign(context, alignment.value ); nvgFontFaceId(context, font); nvgFillColor( context, nvgRGBA( color.r, color.g, color.b, color.a) ); nvgFill(context); nvgText(context, attributes.position[0], attributes.position[1], text, NULL); nvgRestore( context ); }
void TextNode::setupContext(NVGcontext& nanoVgContext) const { nvgFontFaceId(&nanoVgContext, mFontHandle); nvgFontSize(&nanoVgContext, mFontSize); nvgFontBlur(&nanoVgContext, mFontBlur); nvgTextLetterSpacing(&nanoVgContext, mFontLetterSpacing); nvgTextLineHeight(&nanoVgContext, mFontLineHeight); int alignment = static_cast<int>(mHorizontalAlignment) | static_cast<int>(mVerticalAlignment); nvgTextAlign(&nanoVgContext, alignment); }
void NVGRenderer::textLetterSpacing(float spacing) { nvgTextLetterSpacing(m_context, spacing); }
void drawClock(NVGcontext* vg, int screenWidth, int screenHeight) { int clockRadius = (fmin(screenWidth, screenHeight) - 10) / 2; NVGcolor baseColor = nvgRGB(145, 100, 0); NVGcolor lighterColor = nvgRGB(200, 140, 0); NVGcolor dblLighterColor = nvgRGB(255, 177, 0); NVGcolor lightestColor = nvgRGB(255, 195, 60); int widthLight = fmax(clockRadius * 0.0075, 1); int widthMedium = fmax(clockRadius * 0.013, 1); int widthHeavy = fmax(clockRadius * 0.025, 1); time_t t = time(NULL); struct tm localTime = *localtime(&t); nvgTranslate(vg, screenWidth / 2, screenHeight / 2); nvgStrokeColor(vg, baseColor); // Frame nvgSave(vg); nvgBeginPath(vg); nvgCircle(vg, 0, 0, clockRadius); nvgStrokeWidth(vg, widthMedium); nvgStroke(vg); nvgBeginPath(vg); nvgStrokeColor(vg, lighterColor); for (int i = 0; i < 12; i++) { nvgMoveTo(vg, 0, -clockRadius * 0.98); nvgLineTo(vg, 0, -clockRadius * 0.90); for (int j = 0; j < 5; j++) { nvgRotate(vg, 2 * M_PI / 12 / 5); nvgMoveTo(vg, 0, -clockRadius * 0.98); nvgLineTo(vg, 0, -clockRadius * 0.95); } } nvgStroke(vg); nvgBeginPath(vg); nvgFontFace(vg, "bold"); int digitsRadius = clockRadius * 0.79; int digitLargeSize = clockRadius * 0.29; int digitSmallSize = clockRadius * 0.2; int clockTitleSize = clockRadius * 0.06; nvgFillColor(vg, dblLighterColor); char* nineTitle = "9"; nvgFontSize(vg, digitLargeSize); nvgTranslate(vg, -digitsRadius, 0); nvgRotate(vg, - 3 * 2 * M_PI / 12); //nvgTranslate(vg, 0, -digitsRadius); drawTextCenter(vg, nineTitle, 0, 0); nvgFill(vg); nvgFillColor(vg, lighterColor); char* tenTitle = "10"; nvgFontSize(vg, digitSmallSize); nvgTranslate(vg, 0, digitsRadius); nvgRotate(vg, 2 * M_PI / 12); nvgTranslate(vg, 0, -digitsRadius); drawTextCenter(vg, tenTitle, 0, 0); nvgFill(vg); char* elevenTitle = "11"; nvgTranslate(vg, 0, digitsRadius); nvgRotate(vg, 2 * M_PI / 12); nvgTranslate(vg, 0, -digitsRadius); drawTextCenter(vg, elevenTitle, 0, 0); nvgFill(vg); nvgFillColor(vg, dblLighterColor); char* twelveTitle = "12"; nvgFontSize(vg, digitLargeSize); nvgTranslate(vg, 0, digitsRadius); nvgRotate(vg, 2 * M_PI / 12); nvgTranslate(vg, 0, -digitsRadius); drawTextCenter(vg, twelveTitle, 0, 0); nvgFill(vg); nvgFillColor(vg, lighterColor); char* oneTitle = "1"; nvgFontSize(vg, digitSmallSize); nvgTranslate(vg, 0, digitsRadius); nvgRotate(vg, 2 * M_PI / 12); nvgTranslate(vg, 0, -digitsRadius); drawTextCenter(vg, oneTitle, 0, 0); nvgFill(vg); char* twoTitle = "2"; nvgTranslate(vg, 0, digitsRadius); nvgRotate(vg, 2 * M_PI / 12); nvgTranslate(vg, 0, -digitsRadius); drawTextCenter(vg, twoTitle, 0, 0); nvgFill(vg); nvgFillColor(vg, dblLighterColor); char* threeTitle = "3"; nvgFontSize(vg, digitLargeSize); nvgTranslate(vg, 0, digitsRadius); nvgRotate(vg, 2 * M_PI / 12); nvgTranslate(vg, 0, -digitsRadius); drawTextCenter(vg, threeTitle, 0, 0); nvgFill(vg); nvgFillColor(vg, lighterColor); char* fourTitle = "4"; nvgFontSize(vg, digitSmallSize); nvgTranslate(vg, 0, digitsRadius); nvgRotate(vg, 2 * M_PI / 12 - M_PI); nvgTranslate(vg, 0, digitsRadius); drawTextCenter(vg, fourTitle, 0, 0); nvgFill(vg); char* fiveTitle = "5"; nvgTranslate(vg, 0, -digitsRadius); nvgRotate(vg, 2 * M_PI / 12); nvgTranslate(vg, 0, digitsRadius); drawTextCenter(vg, fiveTitle, 0, 0); nvgFill(vg); nvgFillColor(vg, dblLighterColor); char* sixTitle = "6"; nvgFontSize(vg, digitLargeSize); nvgTranslate(vg, 0, -digitsRadius); nvgRotate(vg, 2 * M_PI / 12); nvgTranslate(vg, 0, digitsRadius); drawTextCenter(vg, sixTitle, 0, 0); nvgFill(vg); nvgFillColor(vg, lighterColor); char* sevenTitle = "7"; nvgFontSize(vg, digitSmallSize); nvgTranslate(vg, 0, -digitsRadius); nvgRotate(vg, 2 * M_PI / 12); nvgTranslate(vg, 0, digitsRadius); drawTextCenter(vg, sevenTitle, 0, 0); nvgFill(vg); char* eightTitle = "8"; nvgTranslate(vg, 0, -digitsRadius); nvgRotate(vg, 2 * M_PI / 12); nvgTranslate(vg, 0, digitsRadius); drawTextCenter(vg, eightTitle, 0, 0); nvgFill(vg); nvgRestore(vg); nvgSave(vg); nvgFontFace(vg, "black"); char* clockTitle = "ALPHA"; nvgFontSize(vg, clockTitleSize); nvgFillColor(vg, baseColor); nvgTranslate(vg, 0, clockTitleSize); nvgTextLetterSpacing(vg, clockTitleSize); drawTextCenter(vg, clockTitle, 0, -2 * clockTitleSize); nvgFill(vg); nvgRestore(vg); double secAngle = 2 * M_PI / 60 * localTime.tm_sec; double minAngle = 2 * M_PI / 60 * localTime.tm_min + secAngle / 60; double hrAngle = 2 * M_PI / 12 * localTime.tm_hour + minAngle / 60; // Hour hand nvgStrokeColor(vg, lighterColor); nvgSave(vg); nvgRotate(vg, hrAngle); nvgBeginPath(vg); nvgMoveTo(vg, 0, clockRadius * 0.02); nvgLineTo(vg, 0, -clockRadius * 0.5); nvgStrokeWidth(vg, widthHeavy); nvgStroke(vg); nvgRestore(vg); // Minute hand nvgStrokeColor(vg, lighterColor); nvgSave(vg); nvgRotate(vg, minAngle); nvgBeginPath(vg); nvgMoveTo(vg, 0, clockRadius * 0.04); nvgLineTo(vg, 0, -clockRadius * 0.8); nvgStrokeWidth(vg, widthMedium); nvgStroke(vg); nvgRestore(vg); // Second hand nvgStrokeColor(vg, lightestColor); nvgSave(vg); nvgRotate(vg, secAngle); nvgBeginPath(vg); nvgMoveTo(vg, 0, clockRadius * 0.05); nvgLineTo(vg, 0, -clockRadius * 0.9); nvgStrokeWidth(vg, widthLight); nvgStroke(vg); nvgRestore(vg); }
JNIEXPORT void JNICALL Java_firststep_internal_NVG_textLetterSpacing (JNIEnv *e, jclass c, jlong ctx, jfloat spacing) { nvgTextLetterSpacing((NVGcontext*)ctx, spacing); }