Const improve

This commit is contained in:
Filip Sykala 2022-03-21 12:50:46 +01:00
parent 350d062495
commit 2621d66cb0
6 changed files with 16 additions and 13 deletions

View File

@ -49,7 +49,10 @@ struct SurfaceCut : public indexed_triangle_set
// list of circulated open surface // list of circulated open surface
CutType cut; CutType cut;
// conversion map from vertex index to contour point // Conversion map from vertex index to contour point
// Could be used for filtration of surface cuts
// Still I don't have an idea how to filtrate it.
// What is wanted result on wave?
// std::map<Index, ExPolygonsPoint> vertex2contour; // std::map<Index, ExPolygonsPoint> vertex2contour;
}; };
using SurfaceCuts = std::vector<SurfaceCut>; using SurfaceCuts = std::vector<SurfaceCut>;

View File

@ -22,7 +22,7 @@ class Private
public: public:
Private() = delete; Private() = delete;
static std::optional<stbtt_fontinfo> load_font_info(const unsigned char *data, unsigned int index = 0); static std::optional<stbtt_fontinfo> load_font_info(const unsigned char *data, unsigned int index = 0);
static std::optional<Emboss::Glyph> get_glyph(stbtt_fontinfo &font_info, int unicode_letter, float flatness); static std::optional<Emboss::Glyph> get_glyph(const stbtt_fontinfo &font_info, int unicode_letter, float flatness);
static std::optional<Emboss::Glyph> get_glyph(int unicode, const Emboss::FontFile &font, const FontProp &font_prop, static std::optional<Emboss::Glyph> get_glyph(int unicode, const Emboss::FontFile &font, const FontProp &font_prop,
Emboss::Glyphs &cache, std::optional<stbtt_fontinfo> &font_info_opt); Emboss::Glyphs &cache, std::optional<stbtt_fontinfo> &font_info_opt);
@ -56,7 +56,7 @@ std::optional<stbtt_fontinfo> Private::load_font_info(
return font_info; return font_info;
} }
std::optional<Emboss::Glyph> Private::get_glyph(stbtt_fontinfo &font_info, int unicode_letter, float flatness) std::optional<Emboss::Glyph> Private::get_glyph(const stbtt_fontinfo &font_info, int unicode_letter, float flatness)
{ {
int glyph_index = stbtt_FindGlyphIndex(&font_info, unicode_letter); int glyph_index = stbtt_FindGlyphIndex(&font_info, unicode_letter);
if (glyph_index == 0) { if (glyph_index == 0) {
@ -636,7 +636,7 @@ ExPolygons Emboss::text2shapes(FontFileWithCache &font_with_cache,
} }
void Emboss::apply_transformation(const FontProp &font_prop, void Emboss::apply_transformation(const FontProp &font_prop,
Transform3d &transformation) Transform3d &transformation)
{ {
if (font_prop.angle.has_value()) { if (font_prop.angle.has_value()) {
double angle_z = *font_prop.angle; double angle_z = *font_prop.angle;
@ -648,7 +648,7 @@ void Emboss::apply_transformation(const FontProp &font_prop,
} }
} }
bool Emboss::is_italic(FontFile &font, unsigned int font_index) bool Emboss::is_italic(const FontFile &font, unsigned int font_index)
{ {
if (font_index >= font.count) return false; if (font_index >= font.count) return false;
std::optional<stbtt_fontinfo> font_info_opt = Private::load_font_info(font.data->data(), font_index); std::optional<stbtt_fontinfo> font_info_opt = Private::load_font_info(font.data->data(), font_index);

View File

@ -105,7 +105,7 @@ public:
/// </summary> /// </summary>
struct FontFileWithCache struct FontFileWithCache
{ {
std::shared_ptr<FontFile> font_file; std::shared_ptr<const FontFile> font_file;
// cache for glyph shape // cache for glyph shape
std::shared_ptr<Emboss::Glyphs> cache; std::shared_ptr<Emboss::Glyphs> cache;
@ -157,7 +157,7 @@ public:
/// </summary> /// </summary>
/// <param name="font_prop">Z-move as surface distance(FontProp::distance) /// <param name="font_prop">Z-move as surface distance(FontProp::distance)
/// Z-rotation as angle to Y axis(FontProp::angle)</param> /// Z-rotation as angle to Y axis(FontProp::angle)</param>
/// <param name="transformation"></param> /// <param name="transformation">In / Out transformation to modify by property</param>
static void apply_transformation(const FontProp &font_prop, static void apply_transformation(const FontProp &font_prop,
Transform3d &transformation); Transform3d &transformation);
@ -168,7 +168,7 @@ public:
/// <param name="font">Selector of font</param> /// <param name="font">Selector of font</param>
/// <param name="font_index">Index of font in collection</param> /// <param name="font_index">Index of font in collection</param>
/// <returns>True when the font description contains italic/obligue otherwise False</returns> /// <returns>True when the font description contains italic/obligue otherwise False</returns>
static bool is_italic(FontFile &font, unsigned int font_index); static bool is_italic(const FontFile &font, unsigned int font_index);
/// <summary> /// <summary>
/// Project 2d point into space /// Project 2d point into space

View File

@ -1301,7 +1301,7 @@ void GLGizmoEmboss::draw_style_list() {
bool GLGizmoEmboss::italic_button() bool GLGizmoEmboss::italic_button()
{ {
std::optional<wxFont> &wx_font = m_font_manager.get_wx_font(); std::optional<wxFont> &wx_font = m_font_manager.get_wx_font();
std::shared_ptr<Emboss::FontFile> &font_file = m_font_manager.get_font_file(); const std::shared_ptr<const Emboss::FontFile> &font_file = m_font_manager.get_font_file();
if (!wx_font.has_value() || font_file == nullptr) { if (!wx_font.has_value() || font_file == nullptr) {
draw_icon(IconType::italic, IconState::disabled); draw_icon(IconType::italic, IconState::disabled);
return false; return false;
@ -1343,7 +1343,7 @@ bool GLGizmoEmboss::italic_button()
bool GLGizmoEmboss::bold_button() { bool GLGizmoEmboss::bold_button() {
std::optional<wxFont> &wx_font = m_font_manager.get_wx_font(); std::optional<wxFont> &wx_font = m_font_manager.get_wx_font();
std::shared_ptr<Emboss::FontFile> &font_file = m_font_manager.get_font_file(); const std::shared_ptr<const Emboss::FontFile> &font_file = m_font_manager.get_font_file();
if (!wx_font.has_value() || font_file==nullptr) { if (!wx_font.has_value() || font_file==nullptr) {
draw_icon(IconType::bold, IconState::disabled); draw_icon(IconType::bold, IconState::disabled);
return false; return false;
@ -1652,7 +1652,7 @@ void GLGizmoEmboss::do_rotate(float relative_z_angle)
void GLGizmoEmboss::draw_advanced() void GLGizmoEmboss::draw_advanced()
{ {
std::shared_ptr<Emboss::FontFile>& font_file = m_font_manager.get_font_file(); const std::shared_ptr<const Emboss::FontFile>& font_file = m_font_manager.get_font_file();
if (font_file == nullptr) { if (font_file == nullptr) {
ImGui::Text("%s", _u8L("Advanced font options could be change only for corect font.\nStart with select correct font.").c_str()); ImGui::Text("%s", _u8L("Advanced font options could be change only for corect font.\nStart with select correct font.").c_str());
return; return;

View File

@ -145,7 +145,7 @@ void FontManager::add_fonts(FontList font_list)
add_font(fi); add_font(fi);
} }
std::shared_ptr<Emboss::FontFile> &FontManager::get_font_file() std::shared_ptr<const Emboss::FontFile> &FontManager::get_font_file()
{ {
// TODO: fix not selected font // TODO: fix not selected font
//if (!is_activ_font()) return nullptr; //if (!is_activ_font()) return nullptr;

View File

@ -75,7 +75,7 @@ public:
void add_fonts(FontList font_list); void add_fonts(FontList font_list);
// getter on active font file for access to glyphs // getter on active font file for access to glyphs
std::shared_ptr<Emboss::FontFile> &get_font_file(); std::shared_ptr<const Emboss::FontFile> &get_font_file();
// getter on active font item for access to font property // getter on active font item for access to font property
const FontItem &get_font_item() const; const FontItem &get_font_item() const;