Exemplo n.º 1
0
bool TBBFRenderer::Load(const char *filename, int size)
{
	m_size = size;
	if (!m_node.ReadFile(filename))
		return false;

	// Check for size nodes and get the one closest to the size we want.
	TBNode *size_node = nullptr;
	for (TBNode *n = m_node.GetFirstChild(); n; n = n->GetNext())
	{
		if (strcmp(n->GetName(), "size") == 0)
		{
			if (!size_node || ABS(m_size - n->GetValue().GetInt()) < ABS(m_size - size_node->GetValue().GetInt()))
				size_node = n;
		}
	}
	if (!size_node)
		return false;

	// Metrics
	m_metrics.ascent = size_node->GetValueInt("ascent", 0);
	m_metrics.descent = size_node->GetValueInt("descent", 0);
	m_metrics.height = m_metrics.ascent + m_metrics.descent;

	// Other data
	m_advance_delta = size_node->GetValueInt("advance_delta", 0);
	m_space_advance = size_node->GetValueInt("space_advance", 0);
	m_x_ofs = size_node->GetValueInt("x_ofs", 0);

	// Info
	m_rgb = m_node.GetValueInt("info>rgb", 0);

	// Get the path for the bitmap file.
	TBTempBuffer bitmap_filename;
	if (!bitmap_filename.AppendPath(filename))
		return false;

	// Append the bitmap filename for the given size.
	bitmap_filename.AppendString(size_node->GetValueString("bitmap", ""));

	m_img = TBImageLoader::CreateFromFile(bitmap_filename.GetData());

	return FindGlyphs();
}
Exemplo n.º 2
0
bool TBLanguage::Load(const char *filename)
{
	// Read the file into a node tree (even though it's only a flat list)
	TBNode node;
	if (!node.ReadFile(filename))
		return false;

	// Go through all nodes and add to the strings hash table
	TBNode *n = node.GetFirstChild();
	while (n)
	{
		const char *str = n->GetValue().GetString();
		TBStr *new_str = new TBStr(str);
		if (!new_str || !strings.Add(TBID(n->GetName()), new_str))
		{
			delete new_str;
			return false;
		}
		n = n->GetNext();
	}
	return true;
}
Exemplo n.º 3
0
	void IncludeFile(int line_nr, const char *filename)
	{
		// Read the included file into a new TBNode and then
		// move all the children to m_target_node.
		TBTempBuffer include_filename;
		include_filename.AppendPath(m_filename);
		include_filename.AppendString(filename);
		TBNode content;
		if (content.ReadFile(include_filename.GetData()))
		{
			while (TBNode *content_n = content.GetFirstChild())
			{
				content.Remove(content_n);
				m_target_node->Add(content_n);
			}
		}
		else
		{
			TBStr err;
			err.SetFormatted("Referenced file \"%s\" was not found!", include_filename.GetData());
			OnError(line_nr, err);
		}
	}