OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::WxFontUtils Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/Utils/WxFontUtils.hpp>

Public Member Functions

 WxFontUtils ()=delete

Static Public Member Functions

static bool can_load (const wxFont &font)
static std::unique_ptr< Slic3r::Emboss::FontFile > create_font_file (const wxFont &font)
static EmbossStyle::Type get_current_type ()
static EmbossStyle create_emboss_style (const wxFont &font, const std::string &name="")
static std::string get_human_readable_name (const wxFont &font)
static std::string store_wxFont (const wxFont &font)
static wxFont load_wxFont (const std::string &font_descriptor)
static wxFont create_wxFont (const EmbossStyle &style)
static void update_property (FontProp &font_prop, const wxFont &font)
static bool is_italic (const wxFont &font)
static bool is_bold (const wxFont &font)
static void get_suitable_font_size (int max_height, wxDC &dc)
static std::unique_ptr< Slic3r::Emboss::FontFile > set_italic (wxFont &font, const Slic3r::Emboss::FontFile &prev_font_file)
 Set italic into wx font When italic font is same as original return nullptr. To not load font file twice on success is font_file returned.
static std::unique_ptr< Slic3r::Emboss::FontFile > set_bold (wxFont &font, const Slic3r::Emboss::FontFile &font_file)
 Set boldness into wx font When bolded font is same as original return nullptr. To not load font file twice on success is font_file returned.

Static Public Attributes

static const boost::bimap< wxFontFamily, std::string_view > type_to_family
static const boost::bimap< wxFontStyle, std::string_view > type_to_style
static const boost::bimap< wxFontWeight, std::string_view > type_to_weight

Detailed Description

Constructor & Destructor Documentation

◆ WxFontUtils()

Slic3r::GUI::WxFontUtils::WxFontUtils ( )
delete

References style.

Member Function Documentation

◆ can_load()

bool WxFontUtils::can_load ( const wxFont & font)
static
76{
77
78 if (!font.IsOk()) return false;
79#ifdef _WIN32
80 return Emboss::can_load(font.GetHFONT()) != nullptr;
81#elif defined(__APPLE__)
82 return true;
83 //return is_valid_ttf(get_file_path(font));
84#elif defined(__linux__)
85 return true;
86 // font config check file path take about 4000ms for chech them all
87 //std::string font_path = Slic3r::GUI::get_font_path(font);
88 //return !font_path.empty();
89#endif
90 return false;
91}

Referenced by anonymous_namespace{GLGizmoEmboss.cpp}::init_face_names(), and Slic3r::GUI::DesignTextDialog::load_font().

Here is the caller graph for this function:

◆ create_emboss_style()

EmbossStyle WxFontUtils::create_emboss_style ( const wxFont & font,
const std::string & name = "" )
static
134{
135 std::string name_item = name.empty()? get_human_readable_name(font) : name;
136 std::string fontDesc = store_wxFont(font);
138
139 // synchronize font property with actual font
140 FontProp font_prop;
141
142 // The point size is defined as 1/72 of the Anglo-Saxon inch (25.4 mm): it
143 // is approximately 0.0139 inch or 352.8 um. But it is too small, so I
144 // decide use point size as mm for emboss
145 font_prop.size_in_mm = font.GetPointSize(); // *0.3528f;
146
147 WxFontUtils::update_property(font_prop, font);
148 return { name_item, fontDesc, type, font_prop };
149}
static std::string get_human_readable_name(const wxFont &font)
Definition WxFontUtils.cpp:162
static std::string store_wxFont(const wxFont &font)
Definition WxFontUtils.cpp:176
static EmbossStyle::Type get_current_type()
Definition WxFontUtils.cpp:120
static void update_property(FontProp &font_prop, const wxFont &font)
Definition WxFontUtils.cpp:273
Type
Definition TextConfiguration.hpp:137
float size_in_mm
Definition TextConfiguration.hpp:63

References get_current_type(), get_human_readable_name(), Slic3r::FontProp::size_in_mm, store_wxFont(), and update_property().

Referenced by anonymous_namespace{GLGizmoEmboss.cpp}::add_style_for_default_text(), and Slic3r::GUI::GLGizmoEmboss::create_default_styles().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_font_file()

std::unique_ptr< Emboss::FontFile > WxFontUtils::create_font_file ( const wxFont & font)
static
94{
95#ifdef _WIN32
96 return Emboss::create_font_file(font.GetHFONT());
97#elif defined(__APPLE__)
98 std::string file_path = get_file_path(font);
99 if (!is_valid_ttf(file_path)) {
100 BOOST_LOG_TRIVIAL(error) << "Can not process font('" << get_human_readable_name(font) << "'), "
101 << "file in path('" << file_path << "') is not valid TTF.";
102 return nullptr;
103 }
104 return Emboss::create_font_file(file_path.c_str());
105#elif defined(__linux__)
106 std::string font_path = Slic3r::GUI::get_font_path(font);
107 if (font_path.empty()){
108 BOOST_LOG_TRIVIAL(error) << "Can not read font('" << get_human_readable_name(font) << "'), "
109 << "file path is empty.";
110 return nullptr;
111 }
112 return Emboss::create_font_file(font_path.c_str());
113#else
114 // HERE is place to add implementation for another platform
115 // to convert wxFont to font data as windows or font file path as linux
116 return nullptr;
117#endif
118}
std::unique_ptr< FontFile > create_font_file(const char *file_path)
Load font file into buffer.
Definition Emboss.cpp:1164

References Slic3r::Emboss::create_font_file(), and get_human_readable_name().

Referenced by Slic3r::GUI::GLGizmoEmboss::create_default_styles(), create_wxFont(), anonymous_namespace{GLGizmoEmboss.cpp}::get_installed_face_name(), Slic3r::GUI::Emboss::StyleManager::init_style_images(), Slic3r::GUI::DesignTextDialog::load_font(), Slic3r::GUI::CreateFontImageJob::process(), set_bold(), set_italic(), and Slic3r::GUI::Emboss::StyleManager::set_wx_font().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_wxFont()

wxFont WxFontUtils::create_wxFont ( const EmbossStyle & style)
static
233{
234 const FontProp &fp = style.prop;
235 double point_size = static_cast<double>(fp.size_in_mm);
236 wxFontInfo info(point_size);
237 if (fp.family.has_value()) {
238 auto it = type_to_family.right.find(*fp.family);
239 if (it != type_to_family.right.end()) info.Family(it->second);
240 }
241 // Face names are not portable, so prefer to use Family() in portable code.
242 /* if (fp.face_name.has_value()) {
243 wxString face_name(*fp.face_name);
244 info.FaceName(face_name);
245 }*/
246 if (fp.style.has_value()) {
247 auto it = type_to_style.right.find(*fp.style);
248 if (it != type_to_style.right.end()) info.Style(it->second);
249 }
250 if (fp.weight.has_value()) {
251 auto it = type_to_weight.right.find(*fp.weight);
252 if (it != type_to_weight.right.end()) info.Weight(it->second);
253 }
254
255 // Improve: load descriptor instead of store to font property to 3mf
256 // switch (es.type) {
257 // case EmbossStyle::Type::wx_lin_font_descr:
258 // case EmbossStyle::Type::wx_win_font_descr:
259 // case EmbossStyle::Type::wx_mac_font_descr:
260 // case EmbossStyle::Type::file_path:
261 // case EmbossStyle::Type::undefined:
262 // default:
263 //}
264
265 wxFont wx_font(info);
266 // Check if exist font file
267 std::unique_ptr<Emboss::FontFile> ff = create_font_file(wx_font);
268 if (ff == nullptr) return {};
269
270 return wx_font;
271}
#define style
Definition WipeTowerDialog.cpp:101
static const boost::bimap< wxFontWeight, std::string_view > type_to_weight
Definition WxFontUtils.hpp:74
static const boost::bimap< wxFontStyle, std::string_view > type_to_style
Definition WxFontUtils.hpp:73
static std::unique_ptr< Slic3r::Emboss::FontFile > create_font_file(const wxFont &font)
Definition WxFontUtils.cpp:93
static const boost::bimap< wxFontFamily, std::string_view > type_to_family
Definition WxFontUtils.hpp:72
std::optional< std::string > style
Definition TextConfiguration.hpp:69
std::optional< std::string > weight
Definition TextConfiguration.hpp:70
std::optional< std::string > family
Definition TextConfiguration.hpp:67

References create_font_file(), Slic3r::FontProp::family, Slic3r::FontProp::size_in_mm, Slic3r::FontProp::style, style, type_to_family, type_to_style, type_to_weight, and Slic3r::FontProp::weight.

Referenced by Slic3r::GUI::GLGizmoEmboss::set_volume_by_selection().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_current_type()

EmbossStyle::Type WxFontUtils::get_current_type ( )
static
121{
122#ifdef _WIN32
124#elif defined(__APPLE__)
126#elif defined(__linux__)
128#else
130#endif
131}
@ wx_mac_font_descr
Definition TextConfiguration.hpp:144
@ wx_lin_font_descr
Definition TextConfiguration.hpp:143
@ undefined
Definition TextConfiguration.hpp:138
@ wx_win_font_descr
Definition TextConfiguration.hpp:142

References Slic3r::EmbossStyle::undefined, Slic3r::EmbossStyle::wx_lin_font_descr, Slic3r::EmbossStyle::wx_mac_font_descr, and Slic3r::EmbossStyle::wx_win_font_descr.

Referenced by create_emboss_style(), Slic3r::GUI::GLGizmoEmboss::draw_style_add_button(), anonymous_namespace{EmbossStyleManager.cpp}::load_style(), Slic3r::GUI::Emboss::StyleManager::load_style(), Slic3r::GUI::GLGizmoEmboss::set_volume_by_selection(), Slic3r::GUI::Emboss::StyleManager::set_wx_font(), and anonymous_namespace{EmbossStyleManager.cpp}::store_styles().

Here is the caller graph for this function:

◆ get_human_readable_name()

std::string WxFontUtils::get_human_readable_name ( const wxFont & font)
static
163{
164 if (!font.IsOk()) return "Font is NOT ok.";
165 // Face name is optional in wxFont
166 if (!font.GetFaceName().empty()) {
167 return std::string(font.GetFaceName().c_str());
168 } else {
169 return std::string((font.GetFamilyString() + " " +
170 font.GetStyleString() + " " +
171 font.GetWeightString())
172 .c_str());
173 }
174}

Referenced by create_emboss_style(), create_font_file(), and load_wxFont().

Here is the caller graph for this function:

◆ get_suitable_font_size()

void Slic3r::GUI::WxFontUtils::get_suitable_font_size ( int max_height,
wxDC & dc )
static
310{
311 wxFont font = dc.GetFont();
312 if (!font.IsOk()) return;
313
314 int font_size = font.GetPointSize();
315 int height = dc.GetFontMetrics().height;
316 if (height < max_height) /*go smaller*/
317 {
318 while (height < max_height) {
319 font_size++;
320 font.SetPointSize(font_size);
321 dc.SetFont(font);
322 height = dc.GetFontMetrics().height;
323 }
324
325 if (height > max_height)
326 {
327 font_size--;
328 font.SetPointSize(font_size);
329 dc.SetFont(font);
330 }
331 }
332 else if (height > max_height) /*go bigger*/
333 {
334 while (height > max_height && font_size > 1) {
335 font_size--;
336 font.SetPointSize(font_size);
337 dc.SetFont(font);
338 height = dc.GetFontMetrics().height;
339 }
340 }
341}
coord_t height(const BoundingBox &box)
Definition Arrange.cpp:1185

Referenced by Slic3r::GUI::AMSExtText::doRender(), Slic3r::GUI::AMSHumidity::doRender(), Slic3r::GUI::MaterialItem::doRender(), Slic3r::GUI::PinCodePanel::doRender(), SwitchBoard::doRender(), get_extruder_color_icon(), and get_extruder_color_icon().

Here is the caller graph for this function:

◆ is_bold()

bool WxFontUtils::is_bold ( const wxFont & font)
static
304 {
305 wxFontWeight wx_weight = font.GetWeight();
306 return wx_weight != wxFONTWEIGHT_NORMAL;
307}

Referenced by Slic3r::GUI::DesignTextDialog::DesignTextDialog(), Slic3r::GUI::GLGizmoEmboss::draw_bold_button(), and Slic3r::GUI::Emboss::StyleManager::is_font_changed().

Here is the caller graph for this function:

◆ is_italic()

bool WxFontUtils::is_italic ( const wxFont & font)
static
298 {
299 wxFontStyle wx_style = font.GetStyle();
300 return wx_style == wxFONTSTYLE_ITALIC ||
301 wx_style == wxFONTSTYLE_SLANT;
302}

Referenced by Slic3r::GUI::DesignTextDialog::DesignTextDialog(), Slic3r::GUI::GLGizmoEmboss::draw_italic_button(), and Slic3r::GUI::Emboss::StyleManager::is_font_changed().

Here is the caller graph for this function:

◆ load_wxFont()

wxFont WxFontUtils::load_wxFont ( const std::string & font_descriptor)
static
191{
192 BOOST_LOG_TRIVIAL(trace) << "'" << font_descriptor << "'font descriptor string param of load_wxFont()";
193 wxString font_descriptor_wx = wxString::FromUTF8(font_descriptor);
194 BOOST_LOG_TRIVIAL(trace) << "'" << font_descriptor_wx.c_str() << "' wx string descriptor";
195 wxFont wx_font(font_descriptor_wx);
196 BOOST_LOG_TRIVIAL(trace) << "loaded font is '" << get_human_readable_name(wx_font) << "'.";
197 return wx_font;
198}
void trace(unsigned int level, const char *message)
Definition utils.cpp:247

References get_human_readable_name(), and Slic3r::trace().

Referenced by Slic3r::GUI::DesignTextDialog::DesignTextDialog(), Slic3r::GUI::GLGizmoEmboss::draw_font_list_line(), Slic3r::GUI::Emboss::StyleManager::init_style_images(), Slic3r::GUI::Emboss::StyleManager::load_style(), and Slic3r::GUI::GLGizmoEmboss::set_volume_by_selection().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_bold()

std::unique_ptr< Emboss::FontFile > WxFontUtils::set_bold ( wxFont & font,
const Slic3r::Emboss::FontFile & font_file )
static

Set boldness into wx font When bolded font is same as original return nullptr. To not load font file twice on success is font_file returned.

Parameters
fontwx descriptor of font
font_filefile described in wx font
Returns
New created font fileon success otherwise nullptr
369{
370 static std::vector<wxFontWeight> bold_weight = {
371 wxFontWeight::wxFONTWEIGHT_BOLD,
372 wxFontWeight::wxFONTWEIGHT_HEAVY,
373 wxFontWeight::wxFONTWEIGHT_EXTRABOLD,
374 wxFontWeight::wxFONTWEIGHT_EXTRAHEAVY
375 };
376 wxFontWeight orig_weight = font.GetWeight();
377 for (wxFontWeight weight : bold_weight) {
378 font.SetWeight(weight);
379 std::unique_ptr<Emboss::FontFile> new_font_file =
381
382 // can create bold font file?
383 if (new_font_file == nullptr) continue;
384
385 // is still same font file pointer?
386 if (font_file == *new_font_file) continue;
387
388 return new_font_file;
389 }
390 // There is NO bold font by wx
391 font.SetWeight(orig_weight);
392 return nullptr;
393}

References create_font_file().

Referenced by Slic3r::GUI::GLGizmoEmboss::draw_bold_button().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_italic()

std::unique_ptr< Emboss::FontFile > WxFontUtils::set_italic ( wxFont & font,
const Slic3r::Emboss::FontFile & prev_font_file )
static

Set italic into wx font When italic font is same as original return nullptr. To not load font file twice on success is font_file returned.

Parameters
fontwx descriptor of font
font_filefile described in wx font
Returns
New created font fileon success otherwise nullptr
344{
345 static std::vector<wxFontStyle> italic_styles = {
346 wxFontStyle::wxFONTSTYLE_ITALIC,
347 wxFontStyle::wxFONTSTYLE_SLANT
348 };
349 wxFontStyle orig_style = font.GetStyle();
350 for (wxFontStyle style : italic_styles) {
351 font.SetStyle(style);
352 std::unique_ptr<Emboss::FontFile> new_font_file =
354
355 // can create italic font?
356 if (new_font_file == nullptr) continue;
357
358 // is still same font file pointer?
359 if (font_file == *new_font_file) continue;
360
361 return new_font_file;
362 }
363 // There is NO italic font by wx
364 font.SetStyle(orig_style);
365 return nullptr;
366}

References create_font_file(), and style.

Referenced by Slic3r::GUI::GLGizmoEmboss::draw_italic_button().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ store_wxFont()

std::string WxFontUtils::store_wxFont ( const wxFont & font)
static
177{
178 // wxString os = wxPlatformInfo::Get().GetOperatingSystemIdName();
179 wxString font_descriptor = font.GetNativeFontInfoDesc();
180 BOOST_LOG_TRIVIAL(trace) << "'" << font_descriptor << "' wx string get from GetNativeFontInfoDesc. wxFont " <<
181 "IsOk(" << font.IsOk() << "), " <<
182 "isNull(" << font.IsNull() << ")" <<
183 // "IsFree(" << font.IsFree() << "), " << // on MacOs is no function is free
184 "IsFixedWidth(" << font.IsFixedWidth() << "), " <<
185 "IsUsingSizeInPixels(" << font.IsUsingSizeInPixels() << "), " <<
186 "Encoding(" << (int)font.GetEncoding() << "), " ;
187 return std::string(font_descriptor.ToUTF8().data());
188}

References Slic3r::trace().

Referenced by Slic3r::GUI::DesignTextDialog::accept(), anonymous_namespace{GLGizmoEmboss.cpp}::create_emboss_data_base(), create_emboss_style(), Slic3r::GUI::Emboss::StyleManager::set_wx_font(), and Slic3r::GUI::DesignTextDialog::spec().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_property()

void WxFontUtils::update_property ( FontProp & font_prop,
const wxFont & font )
static
274{
275 wxString wx_face_name = font.GetFaceName();
276 std::string face_name((const char *) wx_face_name.ToUTF8());
277 if (!face_name.empty()) font_prop.face_name = face_name;
278
279 wxFontFamily wx_family = font.GetFamily();
280 if (wx_family != wxFONTFAMILY_DEFAULT) {
281 auto it = type_to_family.left.find(wx_family);
282 if (it != type_to_family.left.end()) font_prop.family = it->second;
283 }
284
285 wxFontStyle wx_style = font.GetStyle();
286 if (wx_style != wxFONTSTYLE_NORMAL) {
287 auto it = type_to_style.left.find(wx_style);
288 if (it != type_to_style.left.end()) font_prop.style = it->second;
289 }
290
291 wxFontWeight wx_weight = font.GetWeight();
292 if (wx_weight != wxFONTWEIGHT_NORMAL) {
293 auto it = type_to_weight.left.find(wx_weight);
294 if (it != type_to_weight.left.end()) font_prop.weight = it->second;
295 }
296}
std::optional< std::string > face_name
Definition TextConfiguration.hpp:68

References Slic3r::FontProp::face_name, Slic3r::FontProp::family, Slic3r::FontProp::style, type_to_family, type_to_style, type_to_weight, and Slic3r::FontProp::weight.

Referenced by create_emboss_style(), and Slic3r::GUI::Emboss::StyleManager::set_wx_font().

Here is the caller graph for this function:

Member Data Documentation

◆ type_to_family

const TypeToFamily WxFontUtils::type_to_family
static
Initial value:
=
boost::assign::list_of<TypeToFamily::relation>
(wxFONTFAMILY_DEFAULT, "default")
(wxFONTFAMILY_DECORATIVE, "decorative")
(wxFONTFAMILY_ROMAN, "roman")
(wxFONTFAMILY_SCRIPT, "script")
(wxFONTFAMILY_SWISS, "swiss")
(wxFONTFAMILY_MODERN, "modern")
(wxFONTFAMILY_TELETYPE, "teletype")

Referenced by create_wxFont(), and update_property().

◆ type_to_style

const TypeToStyle WxFontUtils::type_to_style
static
Initial value:
=
boost::assign::list_of<TypeToStyle::relation>
(wxFONTSTYLE_ITALIC, "italic")
(wxFONTSTYLE_SLANT, "slant")
(wxFONTSTYLE_NORMAL, "normal")

Referenced by create_wxFont(), and update_property().

◆ type_to_weight

const TypeToWeight WxFontUtils::type_to_weight
static
Initial value:
=
boost::assign::list_of<TypeToWeight::relation>
(wxFONTWEIGHT_THIN, "thin")
(wxFONTWEIGHT_EXTRALIGHT, "extraLight")
(wxFONTWEIGHT_LIGHT, "light")
(wxFONTWEIGHT_NORMAL, "normal")
(wxFONTWEIGHT_MEDIUM, "medium")
(wxFONTWEIGHT_SEMIBOLD, "semibold")
(wxFONTWEIGHT_BOLD, "bold")
(wxFONTWEIGHT_EXTRABOLD, "extraBold")
(wxFONTWEIGHT_HEAVY, "heavy")
(wxFONTWEIGHT_EXTRAHEAVY, "extraHeavy")

Referenced by create_wxFont(), and update_property().


The documentation for this class was generated from the following files: