CL_Font CL_GUIThemePart::get_font() const { CL_GUIFontCache &font_cache = impl->component->get_gui_manager().impl->font_cache; CL_Font font = font_cache.get_font(get_element_name(), impl->states); if (!font.is_null()) return font; CL_StringRef font_weight = get_property(impl->prop_font_weight); int weight = 0; if (font_weight == "normal") weight = 400; else if (font_weight == "bold" || font_weight == "bolder") weight = 700; else if (font_weight == "light" || font_weight == "lighter") weight = 300; else weight = CL_StringHelp::text_to_int(font_weight); int font_size = get_property_int(impl->prop_font_size); bool italic = (get_property(impl->prop_font_style) == "italic"); bool underline = (get_property(impl->prop_text_decoration) == "underline"); bool strikeout = false; CL_GUIComponent *component = impl->component; impl->font_loaded = true; const CL_String typeface_name = get_property(impl->prop_font_family); // Build the font details CL_FontDescription desc; desc.set_height(font_size); desc.set_weight(weight); desc.set_italic(italic); desc.set_underline(underline); desc.set_strikeout(strikeout); desc.set_typeface_name(typeface_name); font = font_cache.get_font(desc); // Check to see if matching font description in the font cache if (!font.is_null()) return font; CL_GUIManager manager = impl->component->get_gui_manager(); font = manager.get_registered_font(desc); if (font.is_null()) { CL_GraphicContext &gc = component->get_gc(); font = CL_Font(gc, desc); } font_cache.set_font(font, desc, get_element_name(), impl->states); return font; }
void LabelImpl::load(CL_GraphicContext &p_gc) { CL_FontDescription desc; desc.set_height(m_size); if (m_font == Label::F_REGULAR || m_font == Label::F_BOLD) { desc.set_typeface_name("tahoma"); if (m_font == Label::F_BOLD) { desc.set_weight(100000); } m_clFont = new CL_Font_System(p_gc, desc); } else { desc.set_typeface_name("resources/pixel.ttf"); m_clFont = new CL_Font_Freetype(p_gc, desc); } // remember metrics m_fontMetrics = m_clFont->get_font_metrics(p_gc); }