Skip to content

Commit

Permalink
ENH: load more fonts
Browse files Browse the repository at this point in the history
this feature is according to Prusa by Filip Sykala<[email protected]>, thanks to Filip Sykala
jira: none
Change-Id: I55e92f184f750c0b93b679d4382aaa5b164ec5c3
(cherry picked from commit d05522c4cc5d7ee4cac42de398b88d347a55f74b)
  • Loading branch information
zhimin-zeng-bambulab authored and SoftFever committed Apr 27, 2024
1 parent 690a444 commit 32b6fd1
Show file tree
Hide file tree
Showing 6 changed files with 358 additions and 68 deletions.
8 changes: 4 additions & 4 deletions src/imgui/imstb_truetype.h
Original file line number Diff line number Diff line change
Expand Up @@ -500,11 +500,11 @@ int main(int arg, char **argv)
#ifndef __STB_INCLUDE_STB_TRUETYPE_H__
#define __STB_INCLUDE_STB_TRUETYPE_H__

#ifdef STBTT_STATIC
#define STBTT_DEF static
#else
//#ifdef STBTT_STATIC
//#define STBTT_DEF static
//#else
#define STBTT_DEF extern
#endif
//#endif

#ifdef __cplusplus
extern "C" {
Expand Down
4 changes: 4 additions & 0 deletions src/slic3r/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,10 @@ set(SLIC3R_GUI_SOURCES
GUI/Jobs/OAuthJob.hpp
Utils/SimplyPrint.cpp
Utils/SimplyPrint.hpp
Utils/FontConfigHelp.cpp
Utils/FontConfigHelp.hpp
Utils/FontUtils.cpp
Utils/FontUtils.hpp
)

if (WIN32)
Expand Down
4 changes: 4 additions & 0 deletions src/slic3r/GUI/GLTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "GUI_App.hpp"
#include <boost/log/trivial.hpp>
#include <wx/dcgraph.h>
#include "FontUtils.hpp"
namespace Slic3r {
namespace GUI {

Expand Down Expand Up @@ -553,6 +554,9 @@ bool GLTexture::generate_from_text(const std::string &text_str, wxFont &font, wx

bool GLTexture::generate_texture_from_text(const std::string& text_str, wxFont& font, int& ww, int& hh, int& hl, wxColor background, wxColor foreground)
{
if(!can_generate_text_shape(text_str))
return false;

if (text_str.empty())
{
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":no text string, should not happen\n";
Expand Down
65 changes: 1 addition & 64 deletions src/slic3r/GUI/Gizmos/GLGizmoText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "libslic3r/SVG.hpp"
#include <codecvt>
#include "wx/fontenum.h"
#include "FontUtils.hpp"

namespace Slic3r {
namespace GUI {
Expand All @@ -35,68 +36,8 @@ static const wxColour FONT_TEXTURE_FG = *wxWHITE;
static const int FONT_SIZE = 12;
static const float SELECTABLE_INNER_OFFSET = 8.0f;

static std::vector<std::string> font_black_list = {
#ifdef _WIN32
"MT Extra",
"Marlett",
"Symbol",
"Webdings",
"Wingdings",
"Wingdings 2",
"Wingdings 3",
#endif
};

static const wxFontEncoding font_encoding = wxFontEncoding::wxFONTENCODING_SYSTEM;

#ifdef _WIN32
static bool load_hfont(void *hfont, DWORD &dwTable, DWORD &dwOffset, size_t &size, HDC hdc = nullptr)
{
bool del_hdc = false;
if (hdc == nullptr) {
del_hdc = true;
hdc = ::CreateCompatibleDC(NULL);
if (hdc == NULL) return false;
}

// To retrieve the data from the beginning of the file for TrueType
// Collection files specify 'ttcf' (0x66637474).
dwTable = 0x66637474;
dwOffset = 0;

::SelectObject(hdc, hfont);
size = ::GetFontData(hdc, dwTable, dwOffset, NULL, 0);
if (size == GDI_ERROR) {
// HFONT is NOT TTC(collection)
dwTable = 0;
size = ::GetFontData(hdc, dwTable, dwOffset, NULL, 0);
}

if (size == 0 || size == GDI_ERROR) {
if (del_hdc) ::DeleteDC(hdc);
return false;
}
return true;
}
#endif // _WIN32

bool can_load(const wxFont &font)
{
#ifdef _WIN32
DWORD dwTable = 0, dwOffset = 0;
size_t size = 0;
void* hfont = font.GetHFONT();
if (!load_hfont(hfont, dwTable, dwOffset, size))
return false;
return hfont != nullptr;
#elif defined(__APPLE__)
return true;
#elif defined(__linux__)
return true;
#endif
return false;
}

std::vector<std::string> init_face_names()
{
std::vector<std::string> valid_font_names;
Expand Down Expand Up @@ -141,10 +82,6 @@ std::vector<std::string> init_face_names()
}
assert(std::is_sorted(bad_fonts.begin(), bad_fonts.end()));

for (auto iter = font_black_list.begin(); iter != font_black_list.end(); ++iter) {
valid_font_names.erase(std::remove(valid_font_names.begin(), valid_font_names.end(), *iter), valid_font_names.end());
}

return valid_font_names;
}

Expand Down
Loading

0 comments on commit 32b6fd1

Please sign in to comment.