remove reference initialization in header

This commit is contained in:
Filip Sykala 2021-09-10 13:09:45 +02:00
parent 77209abbcd
commit 999aef0440
3 changed files with 10 additions and 7 deletions

View File

@ -485,8 +485,11 @@ std::optional<Emboss::Glyph> Emboss::letter2glyph(const Font &font,
Polygons Emboss::text2polygons(const Font & font,
const char * text,
const FontProp &font_prop,
Glyphs & cache)
Glyphs * cache)
{
Glyphs tmp;
if (cache == nullptr) cache = &tmp;
std::optional<stbtt_fontinfo> font_info_opt;
Point cursor(0, 0);
@ -501,8 +504,8 @@ Polygons Emboss::text2polygons(const Font & font,
}
int unicode = static_cast<int>(wc);
std::optional<Glyph> glyph_opt;
auto glyph_item = cache.find(unicode);
if (glyph_item != cache.end()) glyph_opt = glyph_item->second;
auto glyph_item = cache->find(unicode);
if (glyph_item != cache->end()) glyph_opt = glyph_item->second;
else {
if (!font_info_opt.has_value()) {
font_info_opt = Privat::load_font_info(font);
@ -513,7 +516,7 @@ Polygons Emboss::text2polygons(const Font & font,
font_prop.flatness);
// has definition inside of font?
if (!glyph_opt.has_value()) continue;
cache[unicode] = *glyph_opt;
cache->operator[](unicode) = *glyph_opt;
}
// move glyph to cursor position

View File

@ -117,7 +117,7 @@ public:
static Polygons text2polygons(const Font & font,
const char * text,
const FontProp &font_prop,
Glyphs & cache = Glyphs());
Glyphs * cache = nullptr);
/// <summary>
/// Project 2d point into space

View File

@ -275,8 +275,8 @@ bool GLGizmoEmboss::gizmo_event(SLAGizmoEventType action,
void GLGizmoEmboss::process() {
if (!m_font.has_value()) return;
Polygons polygons = Emboss::text2polygons(*m_font, m_text.get(), m_font_prop, m_font_glyph_cache);
if (polygons.empty()) return;
Polygons polygons = Emboss::text2polygons(*m_font, m_text.get(), m_font_prop, &m_font_glyph_cache);
if (polygons.empty()) return;
auto project = std::make_unique<Emboss::ProjectScale>(
std::make_unique<Emboss::ProjectZ>(m_emboss/m_scale), m_scale);