refactor font loading

This commit is contained in:
2019-12-01 18:24:59 +01:00
parent 0905827b8d
commit c8bce21b95
30 changed files with 180 additions and 84 deletions

View File

@@ -14,12 +14,13 @@ void NodeText::clone_copy(Node* dest) const
NodeText* n = static_cast<NodeText*>(dest);
n->m_text_mesh.max_width = m_text_mesh.max_width;
n->m_text_mesh.create();
n->m_text_mesh.update(font_id, m_text);
n->m_text_mesh.update(m_text, m_font_name, m_font_size, m_font_weight, m_font_italic);
n->m_text = m_text;
n->m_font = m_font;
n->m_color = m_color;
n->m_font_name = m_font_name;
n->m_font_size = m_font_size;
n->font_id = font_id;
n->m_font_weight = m_font_weight;
n->m_font_italic = m_font_italic;
n->m_color = m_color;
n->m_multiline = m_multiline;
n->m_off = m_off;
n->m_text_align_v = m_text_align_v;
@@ -29,20 +30,30 @@ void NodeText::clone_copy(Node* dest) const
void NodeText::create()
{
Node::create();
if (!m_font.empty())
if (!m_font_name.empty())
{
font_id = fmt::format("{}-{}", m_font, m_font_size);
m_text_mesh.create();
m_text_mesh.update(font_id, m_text);
m_text_mesh.update(m_text, m_font_name, m_font_size, m_font_weight, m_font_italic);
update_layout();
}
}
void NodeText::set_font(const std::string& fontID)
void NodeText::set_font(const std::string& name, int size, const std::string& weight, bool italic)
{
font_id = fontID;
m_font_name = name;
m_font_size = size;
m_font_weight = weight;
m_font_italic = italic;
m_text_mesh.create();
m_text_mesh.update(font_id, m_text);
m_text_mesh.update(m_text, m_font_name, m_font_size, m_font_weight, m_font_italic);
update_layout();
}
void NodeText::set_font_size(int size)
{
m_font_size = size;
m_text_mesh.create();
m_text_mesh.update(m_text, m_font_name, m_font_size, m_font_weight, m_font_italic);
update_layout();
}
@@ -77,7 +88,7 @@ void NodeText::parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* att
m_text = unescape(attr->Value());
break;
case kAttribute::FontFace:
m_font = attr->Value();
m_font_name = attr->Value();
break;
case kAttribute::FontSize:
m_font_size = attr->IntValue();
@@ -100,7 +111,7 @@ void NodeText::parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* att
void NodeText::set_text(const std::string& s)
{
m_text = s;
m_text_mesh.update(font_id, s);
m_text_mesh.update(m_text, m_font_name, m_font_size, m_font_weight, m_font_italic);
update_layout();
}
@@ -112,7 +123,7 @@ void NodeText::set_text_format(const char* fmt, ...)
vsnprintf(buffer, sizeof(buffer), fmt, args);
va_end(args);
m_text = buffer;
m_text_mesh.update(font_id, buffer);
m_text_mesh.update(m_text, m_font_name, m_font_size, m_font_weight, m_font_italic);
update_layout();
}
@@ -164,6 +175,6 @@ void NodeText::handle_resize(glm::vec2 old_size, glm::vec2 new_size, float zoom)
{
auto pad = GetPadding();
m_text_mesh.max_width = m_multiline ? new_size.x - (pad[1] + pad[3]) : 0;
m_text_mesh.update(font_id, m_text);
m_text_mesh.update(m_text, m_font_name, m_font_size, m_font_weight, m_font_italic);
update_layout();
}