void CL_FontProvider_Freetype::load_font(const CL_StringRef &resource_id, CL_ResourceManager *resources)
{
	CL_Resource resource = resources->get_resource(resource_id);
	if (resource.get_type() != "font")
		throw CL_Exception(cl_format("Resource '%1' is not of type 'font'", resource.get_name()));

	CL_DomElement freetype_element = resource.get_element().named_item("freetype").to_element();
	if (freetype_element.is_null())
		throw CL_Exception(cl_format("Font resource '%1' has no 'freetype' child element", resource.get_name()));

	CL_FontDescription desc;

	if (freetype_element.has_attribute("file"))
		desc.set_typeface_name(freetype_element.get_attribute("file"));
	else
		throw CL_Exception(cl_format("Font resource '%1' has no 'file' attribute", resource.get_name()));

	if (freetype_element.has_attribute("height"))
		desc.set_height(freetype_element.get_attribute_int("height", 0));
	else
		throw CL_Exception(cl_format("Font resource '%1' has no 'height' attribute", resource.get_name()));

	if (freetype_element.has_attribute("average_width"))
		desc.set_average_width(freetype_element.get_attribute_int("average_width", 0));

	if (freetype_element.has_attribute("anti_alias"))
		desc.set_anti_alias(freetype_element.get_attribute_bool("anti_alias", true));

	if (freetype_element.has_attribute("subpixel"))
		desc.set_subpixel(freetype_element.get_attribute_bool("subpixel", true));

	load_font(desc, resources->get_directory(resource));
}
CL_Font_System::CL_Font_System(
	CL_GraphicContext &context, const CL_StringRef &typeface_name, int height) : CL_Font( new CL_FontProvider_System())
{
	CL_FontDescription desc;
	desc.set_typeface_name(typeface_name);
	desc.set_height(height);
	load_font(context, desc);
}
Exemple #3
0
CL_Font::CL_Font( CL_GraphicContext &context, const CL_StringRef &typeface_name, int height)
: impl(new CL_Font_Impl)
{
	CL_FontDescription desc;
	desc.set_typeface_name(typeface_name);
	desc.set_height(height);

	CL_Font_System new_font(context, typeface_name, height);
	*this = new_font;
}
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;
}
Exemple #5
0
GSLobby::GSLobby(CL_GraphicContext& gc, CL_ResourceManager& resources)
: m_gsgame(new GSGame(gc, resources)){
	CL_FontDescription desc;
	desc.set_typeface_name("tahoma");
	desc.set_height(32);
	m_font.reset(new CL_Font_System(gc, desc));
	m_xpos = gc.get_width()/2-100;
	m_ypos = gc.get_height()/4;
	m_playbtn.initialize(gc, resources, "game_lobby/play_btn",
						 CL_Vec2<float>(m_xpos, m_ypos+100));
	m_backbtn.initialize(gc, resources, "game_lobby/back_btn",
						 CL_Vec2<float>(m_xpos, m_ypos+200));
}
Exemple #6
0
void
CLLoader::addFont(string const &path, int size, Resources *resources, string const &alias) {
  int realSize = (4 * size) / 3;
  CL_FontDescription desc;
  desc.set_typeface_name(path);
  desc.set_height(realSize);
  desc.set_anti_alias(true);
  desc.set_subpixel(false);
  CL_Font_Freetype *font;
  try {
    font = new CL_Font_Freetype(desc);
  } catch (CL_Exception e) {
    cerr << "Error building CL_Font: " << e.what() << endl;
    return;
  }
    
  resources->setFont(path, new CLResFont(font));
  if (alias.length() > 0) {
    resources->setFont(alias, new CLResFont(font));
  }
}
Exemple #7
0
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);
}