FIX:romove font style preview

Change-Id: I1e8f2ffd94db967f17fa561fd5c56a20f718631b
This commit is contained in:
liz.li 2022-12-08 11:22:22 +08:00 committed by Lane.Wei
parent 4ea3d16fcc
commit 1da9bfcc13
5 changed files with 76 additions and 75 deletions

View File

@ -84,11 +84,14 @@ std::vector<std::string> init_occt_fonts()
file_type.LowerCase();
if (file_type == "ttf" || file_type == "otf" || file_type == "ttc") {
g_occt_fonts_maps.insert(std::make_pair(afn->ToCString(), decode_path(font_path.ToCString())));
stdFontNames.push_back(afn->ToCString());
}
}
}
BOOST_LOG_TRIVIAL(info) << "init_occt_fonts end";
// in order
for (auto occt_font : g_occt_fonts_maps) {
stdFontNames.push_back(occt_font.first);
}
return stdFontNames;
}

View File

@ -32,7 +32,7 @@ GLGizmoText::GLGizmoText(GLCanvas3D& parent, const std::string& icon_filename, u
bool GLGizmoText::on_init()
{
init_occt_fonts();
m_avail_font_names = init_occt_fonts();
m_shortcut_key = WXK_CONTROL_T;
return true;
}
@ -138,8 +138,6 @@ void GLGizmoText::pop_combo_style()
// BBS
void GLGizmoText::on_render_input_window(float x, float y, float bottom_limit)
{
std::vector<std::string> m_avail_font_names = wxGetApp().imgui()->get_fonts_names();
const float win_h = ImGui::GetWindowHeight();
y = std::min(y, bottom_limit - win_h);
GizmoImguiSetNextWIndowPos(x, y, ImGuiCond_Always, 0.0f, 0.0f);

View File

@ -14,7 +14,7 @@ namespace GUI {
class GLGizmoText : public GLGizmoBase
{
private:
//std::vector<std::string> m_avail_font_names;
std::vector<std::string> m_avail_font_names;
char m_text[1024] = { 0 };
std::string m_font_name;
float m_font_size = 16.f;

View File

@ -1485,9 +1485,9 @@ bool GLGizmosManager::activate_gizmo(EType type)
GLGizmoBase* new_gizmo = type == Undefined ? nullptr : m_gizmos[type].get();
if (old_gizmo) {
if (m_current == Text) {
wxGetApp().imgui()->destroy_fonts_texture();
}
//if (m_current == Text) {
// wxGetApp().imgui()->destroy_fonts_texture();
//}
old_gizmo->set_state(GLGizmoBase::Off);
if (old_gizmo->get_state() != GLGizmoBase::Off)
return false; // gizmo refused to be turned off, do nothing.
@ -1508,9 +1508,9 @@ bool GLGizmosManager::activate_gizmo(EType type)
m_current = type;
if (new_gizmo) {
if (m_current == Text) {
wxGetApp().imgui()->load_fonts_texture();
}
//if (m_current == Text) {
// wxGetApp().imgui()->load_fonts_texture();
//}
new_gizmo->set_state(GLGizmoBase::On);
}
return true;

View File

@ -304,7 +304,7 @@ ImGuiWrapper::ImGuiWrapper()
ImGuiWrapper::~ImGuiWrapper()
{
destroy_fonts_texture();
//destroy_fonts_texture();
destroy_font();
ImGui::DestroyContext();
}
@ -382,7 +382,7 @@ void ImGuiWrapper::set_language(const std::string &language)
if (ranges != m_glyph_ranges) {
m_glyph_ranges = ranges;
destroy_fonts_texture();
//destroy_fonts_texture();
destroy_font();
}
@ -410,7 +410,7 @@ void ImGuiWrapper::set_scaling(float font_size, float scale_style, float scale_b
ImGui::GetStyle().ScaleAllSizes(scale_style / m_style_scaling);
m_style_scaling = scale_style;
destroy_fonts_texture();
//destroy_fonts_texture();
destroy_font();
}
@ -2009,62 +2009,62 @@ void ImGuiWrapper::init_font(bool compress)
void ImGuiWrapper::load_fonts_texture()
{
if (m_font_another_texture == 0) {
ImGuiIO& io = ImGui::GetIO();
io.Fonts->Flags |= ImFontAtlasFlags_NoPowerOfTwoHeight;
ImFontConfig cfg = ImFontConfig();
cfg.OversampleH = cfg.OversampleV = 1;
std::map<std::string, std::string> sys_fonts_map = get_occt_fonts_maps(); // map<font name, font path>
im_fonts_map.clear(); // map<font name, ImFont*>
BOOST_LOG_TRIVIAL(info) << "init_im_font start";
for (auto sys_font : sys_fonts_map) {
boost::filesystem::path font_path(sys_font.second);
if (!boost::filesystem::exists(font_path)) {
BOOST_LOG_TRIVIAL(trace) << "load font = " << sys_font.first << ", path = " << font_path << " is not exists";
continue;
}
ImFont* im_font = io.Fonts->AddFontFromFileTTF(sys_font.second.c_str(), m_font_size, &cfg, ImGui::GetIO().Fonts->GetGlyphRangesBasic());
if (im_font == nullptr) {
BOOST_LOG_TRIVIAL(trace) << "load font = " << sys_font.first << " failed, path = " << font_path << " is not exists";
continue;
}
im_fonts_map.insert({ sys_font.first, im_font });
}
BOOST_LOG_TRIVIAL(info) << "init_im_font end";
//if (m_font_another_texture == 0) {
// ImGuiIO& io = ImGui::GetIO();
// io.Fonts->Flags |= ImFontAtlasFlags_NoPowerOfTwoHeight;
// ImFontConfig cfg = ImFontConfig();
// cfg.OversampleH = cfg.OversampleV = 1;
// std::map<std::string, std::string> sys_fonts_map = get_occt_fonts_maps(); // map<font name, font path>
// im_fonts_map.clear(); // map<font name, ImFont*>
// BOOST_LOG_TRIVIAL(info) << "init_im_font start";
// for (auto sys_font : sys_fonts_map) {
// boost::filesystem::path font_path(sys_font.second);
// if (!boost::filesystem::exists(font_path)) {
// BOOST_LOG_TRIVIAL(trace) << "load font = " << sys_font.first << ", path = " << font_path << " is not exists";
// continue;
// }
// ImFont* im_font = io.Fonts->AddFontFromFileTTF(sys_font.second.c_str(), m_font_size, &cfg, ImGui::GetIO().Fonts->GetGlyphRangesBasic());
// if (im_font == nullptr) {
// BOOST_LOG_TRIVIAL(trace) << "load font = " << sys_font.first << " failed, path = " << font_path << " is not exists";
// continue;
// }
// im_fonts_map.insert({ sys_font.first, im_font });
// }
// BOOST_LOG_TRIVIAL(info) << "init_im_font end";
unsigned char* pixels;
int width, height;
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
BOOST_LOG_TRIVIAL(trace) << "Build system fonts texture done. width: " << width << ", height: " << height;
// unsigned char* pixels;
// int width, height;
// io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
// BOOST_LOG_TRIVIAL(trace) << "Build system fonts texture done. width: " << width << ", height: " << height;
if (m_fonts_names.size() == 0) {
std::vector<std::string> to_delete_fonts;
for (auto im_font : im_fonts_map) {
if (im_font.second->Glyphs.Size < 4) { to_delete_fonts.push_back(im_font.first); }
}
for (auto to_delete_font : to_delete_fonts) {
sys_fonts_map.erase(to_delete_font);
im_fonts_map.erase(to_delete_font);
}
for (auto im_font : im_fonts_map) m_fonts_names.push_back(im_font.first);
}
// if (m_fonts_names.size() == 0) {
// std::vector<std::string> to_delete_fonts;
// for (auto im_font : im_fonts_map) {
// if (im_font.second->Glyphs.Size < 4) { to_delete_fonts.push_back(im_font.first); }
// }
// for (auto to_delete_font : to_delete_fonts) {
// sys_fonts_map.erase(to_delete_font);
// im_fonts_map.erase(to_delete_font);
// }
// for (auto im_font : im_fonts_map) m_fonts_names.push_back(im_font.first);
// }
GLint last_texture;
glsafe(::glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture));
glsafe(::glGenTextures(1, &(m_font_another_texture)));
glsafe(::glBindTexture(GL_TEXTURE_2D, m_font_another_texture));
glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
glsafe(::glPixelStorei(GL_UNPACK_ROW_LENGTH, 0));
// GLint last_texture;
// glsafe(::glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture));
// glsafe(::glGenTextures(1, &(m_font_another_texture)));
// glsafe(::glBindTexture(GL_TEXTURE_2D, m_font_another_texture));
// glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
// glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
// glsafe(::glPixelStorei(GL_UNPACK_ROW_LENGTH, 0));
glsafe(::glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels));
// glsafe(::glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels));
// Store our identifier
io.Fonts->TexID = (ImTextureID)(intptr_t)m_font_another_texture;
// // Store our identifier
// io.Fonts->TexID = (ImTextureID)(intptr_t)m_font_another_texture;
// Restore state
glsafe(::glBindTexture(GL_TEXTURE_2D, last_texture));
}
// // Restore state
// glsafe(::glBindTexture(GL_TEXTURE_2D, last_texture));
//}
}
void ImGuiWrapper::init_input()
@ -2274,17 +2274,17 @@ void ImGuiWrapper::destroy_font()
}
void ImGuiWrapper::destroy_fonts_texture() {
if (m_font_another_texture != 0) {
if (m_new_frame_open) {
render();
}
init_font(true);
glsafe(::glDeleteTextures(1, &m_font_another_texture));
m_font_another_texture = 0;
if (!m_new_frame_open) {
new_frame();
}
}
//if (m_font_another_texture != 0) {
// if (m_new_frame_open) {
// render();
// }
// init_font(true);
// glsafe(::glDeleteTextures(1, &m_font_another_texture));
// m_font_another_texture = 0;
// if (!m_new_frame_open) {
// new_frame();
// }
//}
}
const char* ImGuiWrapper::clipboard_get(void* user_data)