QString QFont::lastResortFont() const { static QString last; // already found if (! last.isNull()) return last; int i = 0; const char* f; while ((f = tryFonts[i])) { last = QString::fromLatin1(f); if (fontExists(last)) return last; i++; } #if defined(CHECK_NULL) qFatal("QFontPrivate::lastResortFont: Cannot find any reasonable font"); #endif return last; }
string Fonts_Logic::getFontPath (string font) { // Case of no font. if (font == "") return ""; // Case when the font exists within Bibledit. if (fontExists (font)) { return filter_url_create_path ("", "fonts", font); } // Case when the font is avaiable from the browser independent of Bibledit. if (filter_url_basename (font) == font) { return font; } // Font is on external location. return font; }
int createFont(FT_Face fontFace, FT_UInt size) { initFreeTypeLibrary(); VGfloat glyphOrigin[2]; VGfloat escapement[2]; FT_Stroker fontStroker; int error = FT_Stroker_New(freeTypeLibrary, &fontStroker); if (error) { logInfo(LOG_FREETYPE, "Error FT_Stroker_New.(error=%d)\n", error); return -1; } FT_Stroker_Set(fontStroker, 2*64.0f, // Need to get the right value based on size. FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0); VGFont tmpFont; struct fontListItem *tmpFontListItem = fontExists(fontFace, size); if (tmpFontListItem == NULL) { tmpFont = vgCreateFont(fontFace->num_glyphs); if (tmpFont == VG_INVALID_HANDLE) { logInfo(LOG_FREETYPE, "Error could not create vgCreateFont.\n"); return -1; } tmpFontListItem = malloc(sizeof(struct fontListItem)); tmpFontListItem->fontFace = fontFace; tmpFontListItem->size = size; tmpFontListItem->font = tmpFont; addToFontList(tmpFontListItem); } else { return 0; } error = FT_Set_Char_Size( fontFace, /* handle to face object */ 0, /* char_width in 1/64th of points */ size*64, /* char_height in 1/64th of points */ 72, /* horizontal device resolution */ 72 ); /* vertical device resolution */ if (error) { logInfo(LOG_FREETYPE, "Error FT_Set_Char_Size.(error=%d)\n", error); return -1; } int index; int counter = 0; FT_UInt charIndex; VGImage image = VG_INVALID_HANDLE; VGImage softenedImage; VGfloat blustStdDev; int padding; int image_width; int image_height; VGErrorCode vg_error; FT_Glyph glyph; logInfo(LOG_FREETYPE, "This font contains %ld glyphs.\n", fontFace->num_glyphs); for (index = 32; (index < 256) && (counter < fontFace->num_glyphs); index++) { counter++; charIndex = FT_Get_Char_Index(fontFace, index); logInfo(LOG_FREETYPE, "index=0x%x, charIndex=0x%x\n", index, charIndex); escapement[0] = 0; escapement[1] = 0; if (charIndex == 0) { vgSetGlyphToImage(tmpFont, index, VG_INVALID_HANDLE, escapement, escapement); logInfo(LOG_FREETYPE, "charindex== 0\n"); continue; } error = FT_Load_Glyph(fontFace, charIndex, FT_LOAD_NO_HINTING); if (error) { vgSetGlyphToImage(tmpFont, index, VG_INVALID_HANDLE, escapement, escapement); logInfo(LOG_FREETYPE, "Error FT_Load_Glyph (error:%d)\n", error); continue; } error = FT_Get_Glyph(fontFace->glyph, &glyph); if (error) { vgSetGlyphToImage(tmpFont, index, VG_INVALID_HANDLE, escapement, escapement); logInfo(LOG_FREETYPE, "Error FT_Get_Glyph (error:%d)\n", error); continue; } /* error = FT_Glyph_StrokeBorder(&glyph, fontStroker, 0, 1); if (error) { FT_Done_Glyph(glyph); vgSetGlyphToImage(tmpFont, index, VG_INVALID_HANDLE, escapement, escapement); logInfo(LOG_FREETYPE, "Error FT_Glyph_StrokeBorder (error:%d)\n", error); continue; } */ error = FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, NULL, 1); if (error) { FT_Done_Glyph(glyph); vgSetGlyphToImage(tmpFont, index, VG_INVALID_HANDLE, escapement, escapement); logInfo(LOG_FREETYPE, "Error FT_Glyph_To_Bitmap (error:%d)\n", error); continue; } FT_BitmapGlyph bitGlyph = (FT_BitmapGlyph)glyph; FT_Bitmap bitmap = bitGlyph->bitmap; if (bitmap.width > 0 && bitmap.rows > 0) { blustStdDev = 0.6; padding = (3*blustStdDev + 0.5); image_width = bitmap.width + padding*2; image_height = bitmap.rows + padding*2; image = vgCreateImage(VG_A_8, image_width, image_height, VG_IMAGE_QUALITY_NONANTIALIASED); if (image == VG_INVALID_HANDLE) { FT_Done_Glyph(glyph); vgSetGlyphToImage(tmpFont, index, VG_INVALID_HANDLE, escapement, escapement); logInfo(LOG_FREETYPE, "vgCreateImage (error:%d)\n", vgGetError()); continue; } if (bitmap.pitch > 0) { vgImageSubData(image, bitmap.buffer + bitmap.pitch*(bitmap.rows-1), -bitmap.pitch, VG_A_8, padding, padding, bitmap.width, bitmap.rows); } else { vgImageSubData(image, bitmap.buffer, bitmap.pitch, VG_A_8, padding, padding, bitmap.width, bitmap.rows); } vg_error = vgGetError(); if (vg_error) { vgDestroyImage(image); FT_Done_Glyph(glyph); vgSetGlyphToImage(tmpFont, index, VG_INVALID_HANDLE, escapement, escapement); showVGErrorStr(vg_error, "vgImageSubData"); continue; } softenedImage = vgCreateImage(VG_A_8, image_width, image_height, VG_IMAGE_QUALITY_NONANTIALIASED); if (softenedImage == VG_INVALID_HANDLE) { vgDestroyImage(image); FT_Done_Glyph(glyph); vgSetGlyphToImage(tmpFont, index, VG_INVALID_HANDLE, escapement, escapement); logInfo(LOG_FREETYPE, "vgCreateImage (error:%d)\n", vgGetError()); continue; } // Even out hard and soft edges vgGaussianBlur(softenedImage, image, blustStdDev, blustStdDev, VG_TILE_FILL); vg_error = vgGetError(); if (vg_error) { vgDestroyImage(softenedImage); vgDestroyImage(image); FT_Done_Glyph(glyph); vgSetGlyphToImage(tmpFont, index, VG_INVALID_HANDLE, escapement, escapement); showVGErrorStr(vg_error, "vgGaussianBlur"); continue; } vgDestroyImage(image); image = softenedImage; glyphOrigin[0] = (VGfloat)(padding - bitGlyph->left); glyphOrigin[1] = (VGfloat)(padding + bitmap.rows - bitGlyph->top - 1); } else { logInfo(LOG_FREETYPE, "Error bitmap.width = %d, bitmap.rows = %d\n", bitmap.width, bitmap.rows); } escapement[0] = (VGfloat)((fontFace->glyph->advance.x + 32) / 64); escapement[1] = 0; vgSetGlyphToImage(tmpFont, index, image, glyphOrigin, escapement); vg_error = vgGetError(); if (vg_error) { vgDestroyImage(softenedImage); vgDestroyImage(image); FT_Done_Glyph(glyph); vgSetGlyphToImage(tmpFont, index, VG_INVALID_HANDLE, escapement, escapement); showVGErrorStr(vg_error, "vgSetGlyphToImage"); continue; } logInfo(LOG_FREETYPE, "Create glyph %d.\n", index); FT_Done_Glyph(glyph); if (image != VG_INVALID_HANDLE) { vgDestroyImage(image); } } return 0; }