void CGUIFontTTFBase::Clear() { if (m_texture) delete(m_texture); m_texture = NULL; if (m_char) delete[] m_char; memset(m_charquick, 0, sizeof(m_charquick)); m_char = NULL; m_maxChars = 0; m_numChars = 0; m_posX = 0; m_posY = 0; #ifdef HAS_HARFBUZZ_NG if (hb_font) { hb_font_destroy (hb_font); hb_font = NULL; } #endif if (m_face) { g_freeTypeLibrary.ReleaseFont(); m_face = NULL; } m_faceLoadTime = 0; }
void CGUIFontTTFBase::Clear() { delete(m_texture); m_texture = NULL; delete[] m_char; memset(m_charquick, 0, sizeof(m_charquick)); m_char = NULL; m_maxChars = 0; m_numChars = 0; m_posX = 0; m_posY = 0; m_nestedBeginCount = 0; if (m_face) g_freeTypeLibrary.ReleaseFont(m_face); m_face = NULL; if (m_stroker) g_freeTypeLibrary.ReleaseStroker(m_stroker); m_stroker = NULL; free(m_vertex); m_vertex = NULL; m_vertex_count = 0; }
void CGUIFontTTF::Clear() { if (m_texture) #ifndef HAS_SDL m_texture->Release(); #else SDL_FreeSurface(m_texture); #endif m_texture = NULL; if (m_char) delete[] m_char; memset(m_charquick, 0, sizeof(m_charquick)); m_char = NULL; m_maxChars = 0; m_numChars = 0; m_posX = 0; m_posY = 0; m_dwNestedBeginCount = 0; if (m_face) g_freeTypeLibrary.ReleaseFont(m_face); m_face = NULL; }
void CGUIFontTTFBase::ReloadFace() { bool reloaded; m_face = g_freeTypeLibrary.GetFont(m_strFilename, m_height, m_aspect, reloaded); if (!m_face) return; if (m_faceLoadTime == 0) m_faceLoadTime = time(NULL); #ifdef HAS_HARFBUZZ_NG if (reloaded) { if (hb_font) { hb_font_destroy (hb_font); hb_font = NULL; } hb_font = hb_ft_font_create (m_face, NULL); } #endif }
bool CGUIFontTTFBase::Load(const CStdString& strFilename, float height, float aspect, float lineSpacing, bool border) { // we now know that this object is unique - only the GUIFont objects are non-unique, so no need // for reference tracking these fonts m_face = g_freeTypeLibrary.GetFont(strFilename, height, aspect); if (!m_face) return false; // grab the maximum cell height and width unsigned int m_cellWidth = m_face->bbox.xMax - m_face->bbox.xMin; m_cellHeight = std::max<unsigned int>(m_face->bbox.yMax - m_face->bbox.yMin, m_face->ascender - m_face->descender); m_cellBaseLine = std::max<unsigned int>(m_face->bbox.yMax, m_face->ascender); if (border) { m_stroker = g_freeTypeLibrary.GetStroker(); FT_Pos strength = FT_MulFix( m_face->units_per_EM, m_face->size->metrics.y_scale) / 12; if (strength < 128) strength = 128; m_cellHeight += 2*strength; if (m_stroker) FT_Stroker_Set(m_stroker, strength, FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0); } unsigned int ydpi = g_freeTypeLibrary.GetDPI(); unsigned int xdpi = (unsigned int)MathUtils::round_int(ydpi * aspect); m_cellWidth *= (unsigned int)(height * xdpi); m_cellWidth /= (72 * m_face->units_per_EM); m_cellHeight *= (unsigned int)(height * ydpi); m_cellHeight /= (72 * m_face->units_per_EM); m_cellBaseLine *= (unsigned int)(height * ydpi); m_cellBaseLine /= (72 * m_face->units_per_EM); // increment for good measure to give space in our texture m_cellWidth++; m_cellHeight+=2; m_cellBaseLine++; // CLog::Log(LOGDEBUG, "%s Scaled size of font %s (%f): width = %i, height = %i, lineheight = %li", // __FUNCTION__, strFilename.c_str(), height, m_cellWidth, m_cellHeight, m_face->size->metrics.height / 64); m_height = height; delete(m_texture); m_texture = NULL; delete[] m_char; m_char = NULL; m_maxChars = 0; m_numChars = 0; m_strFilename = strFilename; m_textureHeight = 0; m_textureWidth = ((m_cellHeight * CHARS_PER_TEXTURE_LINE) & ~63) + 64; m_textureWidth = CBaseTexture::PadPow2(m_textureWidth); if (m_textureWidth > g_Windowing.GetMaxTextureSize()) m_textureWidth = g_Windowing.GetMaxTextureSize(); // set the posX and posY so that our texture will be created on first character write. m_posX = m_textureWidth; m_posY = -(int)m_cellHeight; // cache the ellipses width Character *ellipse = GetCharacter(L'.'); if (ellipse) m_ellipsesWidth = ellipse->advance; return true; }
bool CGUIFontTTF::Load(const CStdString& strFile, float height, float aspect, float lineSpacing) { CStdString strFilename = strFile; #ifdef __APPLE__ // Hardwire to the unicode version that's built into every system. if (strFilename.Right(9) == "Arial.ttf") strFilename = "/Library/Fonts/Arial Unicode.ttf"; #endif #ifndef HAS_SDL // create our character texture + font shader m_pD3DDevice = g_graphicsContext.Get3DDevice(); #endif // we now know that this object is unique - only the GUIFont objects are non-unique, so no need // for reference tracking these fonts m_face = g_freeTypeLibrary.GetFont(strFilename, height, aspect); if (!m_face) return false; // grab the maximum cell height and width unsigned int m_cellWidth = m_face->bbox.xMax - m_face->bbox.xMin; m_cellHeight = m_face->bbox.yMax - m_face->bbox.yMin; m_cellBaseLine = m_face->bbox.yMax; unsigned int ydpi = g_freeTypeLibrary.GetDPI(); unsigned int xdpi = (unsigned int)ROUND(ydpi * aspect); m_cellWidth *= (unsigned int)(height * xdpi); m_cellWidth /= (72 * m_face->units_per_EM); m_cellHeight *= (unsigned int)(height * ydpi); m_cellHeight /= (72 * m_face->units_per_EM); m_cellBaseLine *= (unsigned int)(height * ydpi); m_cellBaseLine /= (72 * m_face->units_per_EM); // increment for good measure to give space in our texture m_cellWidth++; m_cellHeight+=2; m_cellBaseLine++; CLog::Log(LOGDEBUG, "%s Scaled size of font %s (%f): width = %i, height = %i, lineheight = %li", __FUNCTION__, strFilename.c_str(), height, m_cellWidth, m_cellHeight, m_face->size->metrics.height / 64); m_height = height; if (m_texture) #ifndef HAS_SDL m_texture->Release(); #else SDL_FreeSurface(m_texture); #endif m_texture = NULL; if (m_char) delete[] m_char; m_char = NULL; m_maxChars = 0; m_numChars = 0; m_strFilename = strFilename; m_textureHeight = 0; m_textureWidth = ((m_cellHeight * CHARS_PER_TEXTURE_LINE) & ~63) + 64; #ifdef HAS_SDL_OPENGL m_textureWidth = PadPow2(m_textureWidth); GLint maxTextureSize; glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize); #else int maxTextureSize = 2048; #endif // Use a maximum texture width of 2048, which should work on all Macs. Ideally we should query the maximum texture width. if (m_textureWidth > maxTextureSize) m_textureWidth = maxTextureSize; // set the posX and posY so that our texture will be created on first character write. m_posX = m_textureWidth; m_posY = -(int)m_cellHeight; // cache the ellipses width Character *ellipse = GetCharacter(L'.'); if (ellipse) m_ellipsesWidth = ellipse->advance; return true; }
bool CGUIFontTTFBase::Load(const CStdString& strFilename, float height, float aspect, float lineSpacing) { m_strFilename = strFilename; m_height = height; m_aspect = aspect; ReloadFace(); if (!m_face) return false; // grab the maximum cell height and width unsigned int m_cellWidth = m_face->bbox.xMax - m_face->bbox.xMin; m_cellHeight = m_face->bbox.yMax - m_face->bbox.yMin; m_cellBaseLine = m_face->bbox.yMax; unsigned int ydpi = g_freeTypeLibrary.GetDPI(); unsigned int xdpi = (unsigned int)MathUtils::round_int(ydpi * aspect); m_cellWidth *= (unsigned int)(height * xdpi); m_cellWidth /= (72 * m_face->units_per_EM); m_cellHeight *= (unsigned int)(height * ydpi); m_cellHeight /= (72 * m_face->units_per_EM); m_cellBaseLine *= (unsigned int)(height * ydpi); m_cellBaseLine /= (72 * m_face->units_per_EM); // increment for good measure to give space in our texture m_cellWidth++; m_cellHeight+=2; m_cellBaseLine++; // CLog::Log(LOGDEBUG, "%s Scaled size of font %s (%f): width = %i, height = %i, lineheight = %li", // __FUNCTION__, strFilename.c_str(), height, m_cellWidth, m_cellHeight, m_face->size->metrics.height / 64); if (m_texture) delete(m_texture); m_texture = NULL; if (m_char) delete[] m_char; m_char = NULL; m_maxChars = 0; m_numChars = 0; m_textureHeight = 0; m_textureWidth = ((m_cellHeight * CHARS_PER_TEXTURE_LINE) & ~63) + 64; m_textureWidth = CBaseTexture::PadPow2(m_textureWidth); if (m_textureWidth > g_Windowing.GetMaxTextureSize()) m_textureWidth = g_Windowing.GetMaxTextureSize(); // set the posX and posY so that our texture will be created on first character write. m_posX = m_textureWidth; m_posY = -(int)m_cellHeight; // cache the ellipses width Character *ellipse = GetCharacter(L'.'); if (ellipse) m_ellipsesWidth = ellipse->advance; return true; }