FontItem improvmement: Use default constructors to let the compiler

generate move constructor and move assignement.
Also used some move operators to reduce unnecessary memory allocations.
This commit is contained in:
Vojtech Bubnik 2022-03-01 16:41:52 +01:00
parent 5a1cbbc4ba
commit 120a85d4c4
6 changed files with 10 additions and 21 deletions

View File

@ -188,9 +188,9 @@ std::optional<Emboss::Glyph> Private::get_glyph(
} }
FontItem Private::create_font_item(std::wstring name, std::wstring path) { FontItem Private::create_font_item(std::wstring name, std::wstring path) {
return FontItem(boost::nowide::narrow(name.c_str()), return { boost::nowide::narrow(name.c_str()),
boost::nowide::narrow(path.c_str()), boost::nowide::narrow(path.c_str()),
FontItem::Type::file_path, FontProp()); FontItem::Type::file_path, FontProp() };
} }
ExPolygons Private::dilate_to_unique_points(ExPolygons &expolygons) ExPolygons Private::dilate_to_unique_points(ExPolygons &expolygons)

View File

@ -3374,14 +3374,14 @@ std::optional<TextConfiguration> TextConfigurationSerialization::read(const char
std::string weight = get_attribute_value_string(attributes, num_attributes, FONT_WEIGHT_ATTR); std::string weight = get_attribute_value_string(attributes, num_attributes, FONT_WEIGHT_ATTR);
if (!weight.empty()) fp.weight = weight; if (!weight.empty()) fp.weight = weight;
std::string font_name = ""; std::string font_name {};
std::string font_descriptor = get_attribute_value_string(attributes, num_attributes, FONT_DESCRIPTOR_ATTR); std::string font_descriptor = get_attribute_value_string(attributes, num_attributes, FONT_DESCRIPTOR_ATTR);
std::string type_str = get_attribute_value_string(attributes, num_attributes, FONT_DESCRIPTOR_TYPE_ATTR); std::string type_str = get_attribute_value_string(attributes, num_attributes, FONT_DESCRIPTOR_TYPE_ATTR);
FontItem::Type type = TextConfigurationSerialization::get_type(type_str); FontItem::Type type = TextConfigurationSerialization::get_type(type_str);
FontItem fi(font_name, font_descriptor, type, fp); FontItem fi{ font_name, std::move(font_descriptor), type, std::move(fp) };
std::string text = get_attribute_value_string(attributes, num_attributes, TEXT_DATA_ATTR); std::string text = get_attribute_value_string(attributes, num_attributes, TEXT_DATA_ATTR);
return TextConfiguration(fi, text); return TextConfiguration(std::move(fi), std::move(text));
} }

View File

@ -118,22 +118,11 @@ struct FontItem
enum class Type; enum class Type;
// Define what is stored in path // Define what is stored in path
Type type; Type type { Type::undefined };
// User modification of font style // User modification of font style
FontProp prop; FontProp prop;
FontItem() : type(Type::undefined){} // set undefined type
// when name is empty than Font item was loaded from .3mf file
// and potentionaly it is not reproducable
FontItem(const std::string &name,
const std::string &path,
Type type,
const FontProp & prop)
: name(name), path(path), type(type), prop(prop) // copy values
{}
// define data stored in path // define data stored in path
// when wx change way of storing add new descriptor Type // when wx change way of storing add new descriptor Type
enum class Type { enum class Type {

View File

@ -1824,7 +1824,7 @@ bool GLGizmoEmboss::choose_true_type_file()
std::string name = get_file_name(path); std::string name = get_file_name(path);
//make_unique_name(name, m_font_list); //make_unique_name(name, m_font_list);
const FontProp& prop = m_font_manager.get_font_prop(); const FontProp& prop = m_font_manager.get_font_prop();
FontItem fi(name, path, FontItem::Type::file_path, prop); FontItem fi{ name, path, FontItem::Type::file_path, prop };
m_font_manager.add_font(fi); m_font_manager.add_font(fi);
// set first valid added font as active // set first valid added font as active
if (m_font_manager.load_font(index)) return true; if (m_font_manager.load_font(index)) return true;

View File

@ -87,7 +87,7 @@ std::optional<FontItem> FontListSerializable::load_font_item(
read(app_cfg_section, APP_CONFIG_FONT_LINE_GAP, fp.line_gap); read(app_cfg_section, APP_CONFIG_FONT_LINE_GAP, fp.line_gap);
FontItem::Type type = WxFontUtils::get_actual_type(); FontItem::Type type = WxFontUtils::get_actual_type();
return FontItem(name, path, type, fp); return FontItem{ name, path, type, fp };
} }
void FontListSerializable::store_font_item(AppConfig & cfg, void FontListSerializable::store_font_item(AppConfig & cfg,

View File

@ -96,7 +96,7 @@ FontItem WxFontUtils::get_font_item(const wxFont &font, const std::string& name)
// synchronize font property with actual font // synchronize font property with actual font
FontProp font_prop; FontProp font_prop;
WxFontUtils::update_property(font_prop, font); WxFontUtils::update_property(font_prop, font);
return FontItem(name_item, fontDesc, type, font_prop); return { name_item, fontDesc, type, font_prop };
} }
FontItem WxFontUtils::get_os_font() FontItem WxFontUtils::get_os_font()