2014-02-10 09:10:30 +08:00
|
|
|
/*************************************************************************/
|
|
|
|
/* editor_fonts.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 20:16:55 +08:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 09:10:30 +08:00
|
|
|
/*************************************************************************/
|
2019-01-01 19:53:14 +08:00
|
|
|
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 09:10:30 +08:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 07:50:27 +08:00
|
|
|
|
2015-04-19 01:38:54 +08:00
|
|
|
#include "editor_fonts.h"
|
2017-01-16 15:04:19 +08:00
|
|
|
|
2017-06-23 23:03:41 +08:00
|
|
|
#include "builtin_fonts.gen.h"
|
2018-07-03 21:37:07 +08:00
|
|
|
#include "core/os/dir_access.h"
|
2016-05-30 11:28:29 +08:00
|
|
|
#include "editor_scale.h"
|
2017-03-05 23:44:50 +08:00
|
|
|
#include "editor_settings.h"
|
2016-05-30 11:28:29 +08:00
|
|
|
#include "scene/resources/default_theme/default_theme.h"
|
2017-03-05 23:44:50 +08:00
|
|
|
#include "scene/resources/dynamic_font.h"
|
2015-04-19 01:38:54 +08:00
|
|
|
|
2017-08-31 20:49:48 +08:00
|
|
|
#define MAKE_FALLBACKS(m_name) \
|
|
|
|
m_name->add_fallback(FontArabic); \
|
|
|
|
m_name->add_fallback(FontHebrew); \
|
|
|
|
m_name->add_fallback(FontThai); \
|
2018-08-30 04:11:09 +08:00
|
|
|
m_name->add_fallback(FontHindi); \
|
2017-08-31 20:49:48 +08:00
|
|
|
m_name->add_fallback(FontJapanese); \
|
|
|
|
m_name->add_fallback(FontFallback);
|
|
|
|
|
2017-09-03 14:49:31 +08:00
|
|
|
// the custom spacings might only work with Noto Sans
|
2017-09-14 08:56:02 +08:00
|
|
|
#define MAKE_DEFAULT_FONT(m_name, m_size) \
|
|
|
|
Ref<DynamicFont> m_name; \
|
|
|
|
m_name.instance(); \
|
|
|
|
m_name->set_size(m_size); \
|
2017-12-27 02:14:48 +08:00
|
|
|
if (CustomFont.is_valid()) { \
|
|
|
|
m_name->set_font_data(CustomFont); \
|
|
|
|
m_name->add_fallback(DefaultFont); \
|
|
|
|
} else { \
|
|
|
|
m_name->set_font_data(DefaultFont); \
|
|
|
|
} \
|
2017-09-14 08:56:02 +08:00
|
|
|
m_name->set_spacing(DynamicFont::SPACING_TOP, -EDSCALE); \
|
|
|
|
m_name->set_spacing(DynamicFont::SPACING_BOTTOM, -EDSCALE); \
|
2016-05-31 14:06:40 +08:00
|
|
|
MAKE_FALLBACKS(m_name);
|
2016-05-31 06:41:32 +08:00
|
|
|
|
2018-04-10 23:26:26 +08:00
|
|
|
#define MAKE_BOLD_FONT(m_name, m_size) \
|
|
|
|
Ref<DynamicFont> m_name; \
|
|
|
|
m_name.instance(); \
|
|
|
|
m_name->set_size(m_size); \
|
|
|
|
if (CustomFont.is_valid()) { \
|
|
|
|
m_name->set_font_data(CustomFontBold); \
|
|
|
|
m_name->add_fallback(DefaultFontBold); \
|
|
|
|
} else { \
|
|
|
|
m_name->set_font_data(DefaultFontBold); \
|
|
|
|
} \
|
|
|
|
m_name->set_spacing(DynamicFont::SPACING_TOP, -EDSCALE); \
|
|
|
|
m_name->set_spacing(DynamicFont::SPACING_BOTTOM, -EDSCALE); \
|
|
|
|
MAKE_FALLBACKS(m_name);
|
|
|
|
|
2018-01-08 03:07:47 +08:00
|
|
|
#define MAKE_SOURCE_FONT(m_name, m_size) \
|
|
|
|
Ref<DynamicFont> m_name; \
|
|
|
|
m_name.instance(); \
|
|
|
|
m_name->set_size(m_size); \
|
|
|
|
if (CustomFontSource.is_valid()) { \
|
|
|
|
m_name->set_font_data(CustomFontSource); \
|
|
|
|
m_name->add_fallback(dfmono); \
|
|
|
|
} else { \
|
|
|
|
m_name->set_font_data(dfmono); \
|
|
|
|
} \
|
|
|
|
m_name->set_spacing(DynamicFont::SPACING_TOP, -EDSCALE); \
|
|
|
|
m_name->set_spacing(DynamicFont::SPACING_BOTTOM, -EDSCALE); \
|
|
|
|
MAKE_FALLBACKS(m_name);
|
|
|
|
|
2015-04-19 01:38:54 +08:00
|
|
|
void editor_register_fonts(Ref<Theme> p_theme) {
|
2018-07-03 21:37:07 +08:00
|
|
|
DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
|
|
|
|
2017-12-27 02:14:48 +08:00
|
|
|
/* Custom font */
|
|
|
|
|
2018-11-11 05:07:32 +08:00
|
|
|
bool font_antialiased = (bool)EditorSettings::get_singleton()->get("interface/editor/main_font_antialiased");
|
2018-02-27 22:04:08 +08:00
|
|
|
DynamicFontData::Hinting font_hinting = (DynamicFontData::Hinting)(int)EditorSettings::get_singleton()->get("interface/editor/main_font_hinting");
|
2018-04-10 23:26:26 +08:00
|
|
|
|
|
|
|
String custom_font_path = EditorSettings::get_singleton()->get("interface/editor/main_font");
|
2017-12-27 02:14:48 +08:00
|
|
|
Ref<DynamicFontData> CustomFont;
|
2018-07-03 21:37:07 +08:00
|
|
|
if (custom_font_path.length() > 0 && dir->file_exists(custom_font_path)) {
|
2017-12-27 02:14:48 +08:00
|
|
|
CustomFont.instance();
|
2018-11-11 05:07:32 +08:00
|
|
|
CustomFont->set_antialiased(font_antialiased);
|
2018-02-27 22:04:08 +08:00
|
|
|
CustomFont->set_hinting(font_hinting);
|
2018-04-10 23:26:26 +08:00
|
|
|
CustomFont->set_font_path(custom_font_path);
|
2017-12-27 02:14:48 +08:00
|
|
|
CustomFont->set_force_autohinter(true); //just looks better..i think?
|
2018-07-03 21:37:07 +08:00
|
|
|
} else {
|
|
|
|
EditorSettings::get_singleton()->set_manually("interface/editor/main_font", "");
|
2017-12-27 02:14:48 +08:00
|
|
|
}
|
|
|
|
|
2018-04-10 23:26:26 +08:00
|
|
|
/* Custom Bold font */
|
|
|
|
|
|
|
|
String custom_font_path_bold = EditorSettings::get_singleton()->get("interface/editor/main_font_bold");
|
|
|
|
Ref<DynamicFontData> CustomFontBold;
|
2018-07-03 21:37:07 +08:00
|
|
|
if (custom_font_path_bold.length() > 0 && dir->file_exists(custom_font_path_bold)) {
|
2018-04-10 23:26:26 +08:00
|
|
|
CustomFontBold.instance();
|
2018-11-11 05:07:32 +08:00
|
|
|
CustomFontBold->set_antialiased(font_antialiased);
|
2018-04-10 23:26:26 +08:00
|
|
|
CustomFontBold->set_hinting(font_hinting);
|
|
|
|
CustomFontBold->set_font_path(custom_font_path_bold);
|
|
|
|
CustomFontBold->set_force_autohinter(true); //just looks better..i think?
|
2018-07-03 21:37:07 +08:00
|
|
|
} else {
|
|
|
|
EditorSettings::get_singleton()->set_manually("interface/editor/main_font_bold", "");
|
2018-04-10 23:26:26 +08:00
|
|
|
}
|
|
|
|
|
2018-01-08 03:07:47 +08:00
|
|
|
/* Custom source code font */
|
|
|
|
|
2018-04-10 23:26:26 +08:00
|
|
|
String custom_font_path_source = EditorSettings::get_singleton()->get("interface/editor/code_font");
|
2018-11-11 05:07:32 +08:00
|
|
|
bool font_source_antialiased = (bool)EditorSettings::get_singleton()->get("interface/editor/code_font_antialiased");
|
2018-02-27 22:04:08 +08:00
|
|
|
DynamicFontData::Hinting font_source_hinting = (DynamicFontData::Hinting)(int)EditorSettings::get_singleton()->get("interface/editor/code_font_hinting");
|
2018-01-08 03:07:47 +08:00
|
|
|
Ref<DynamicFontData> CustomFontSource;
|
2018-07-03 21:37:07 +08:00
|
|
|
if (custom_font_path_source.length() > 0 && dir->file_exists(custom_font_path_source)) {
|
2018-01-08 03:07:47 +08:00
|
|
|
CustomFontSource.instance();
|
2018-11-11 05:07:32 +08:00
|
|
|
CustomFontSource->set_antialiased(font_source_antialiased);
|
2018-02-27 22:04:08 +08:00
|
|
|
CustomFontSource->set_hinting(font_source_hinting);
|
2018-04-10 23:26:26 +08:00
|
|
|
CustomFontSource->set_font_path(custom_font_path_source);
|
2018-07-03 21:37:07 +08:00
|
|
|
} else {
|
|
|
|
EditorSettings::get_singleton()->set_manually("interface/editor/code_font", "");
|
2018-01-08 03:07:47 +08:00
|
|
|
}
|
|
|
|
|
2018-07-03 21:37:07 +08:00
|
|
|
memdelete(dir);
|
|
|
|
|
2016-05-31 06:41:32 +08:00
|
|
|
/* Droid Sans */
|
|
|
|
|
2017-08-31 20:49:48 +08:00
|
|
|
Ref<DynamicFontData> DefaultFont;
|
|
|
|
DefaultFont.instance();
|
2018-11-11 05:07:32 +08:00
|
|
|
DefaultFont->set_antialiased(font_antialiased);
|
2018-02-27 22:04:08 +08:00
|
|
|
DefaultFont->set_hinting(font_hinting);
|
2017-08-31 20:49:48 +08:00
|
|
|
DefaultFont->set_font_ptr(_font_NotoSansUI_Regular, _font_NotoSansUI_Regular_size);
|
|
|
|
DefaultFont->set_force_autohinter(true); //just looks better..i think?
|
2016-05-31 06:41:32 +08:00
|
|
|
|
2018-04-10 23:26:26 +08:00
|
|
|
Ref<DynamicFontData> DefaultFontBold;
|
|
|
|
DefaultFontBold.instance();
|
2018-11-11 05:07:32 +08:00
|
|
|
DefaultFontBold->set_antialiased(font_antialiased);
|
|
|
|
DefaultFontBold->set_hinting(font_hinting);
|
2018-04-10 23:26:26 +08:00
|
|
|
DefaultFontBold->set_font_ptr(_font_NotoSansUI_Bold, _font_NotoSansUI_Bold_size);
|
|
|
|
DefaultFontBold->set_force_autohinter(true); // just looks better..i think?
|
|
|
|
|
2017-08-31 20:49:48 +08:00
|
|
|
Ref<DynamicFontData> FontFallback;
|
|
|
|
FontFallback.instance();
|
2018-11-11 05:07:32 +08:00
|
|
|
FontFallback->set_antialiased(font_antialiased);
|
2018-02-27 22:04:08 +08:00
|
|
|
FontFallback->set_hinting(font_hinting);
|
2017-08-31 20:49:48 +08:00
|
|
|
FontFallback->set_font_ptr(_font_DroidSansFallback, _font_DroidSansFallback_size);
|
|
|
|
FontFallback->set_force_autohinter(true); //just looks better..i think?
|
2016-05-31 06:41:32 +08:00
|
|
|
|
2017-08-31 20:49:48 +08:00
|
|
|
Ref<DynamicFontData> FontJapanese;
|
|
|
|
FontJapanese.instance();
|
2018-11-11 05:07:32 +08:00
|
|
|
FontJapanese->set_antialiased(font_antialiased);
|
2018-02-27 22:04:08 +08:00
|
|
|
FontJapanese->set_hinting(font_hinting);
|
2017-08-31 20:49:48 +08:00
|
|
|
FontJapanese->set_font_ptr(_font_DroidSansJapanese, _font_DroidSansJapanese_size);
|
|
|
|
FontJapanese->set_force_autohinter(true); //just looks better..i think?
|
2016-05-31 06:41:32 +08:00
|
|
|
|
2017-08-31 20:49:48 +08:00
|
|
|
Ref<DynamicFontData> FontArabic;
|
|
|
|
FontArabic.instance();
|
2018-11-11 05:07:32 +08:00
|
|
|
FontArabic->set_antialiased(font_antialiased);
|
2018-02-27 22:04:08 +08:00
|
|
|
FontArabic->set_hinting(font_hinting);
|
2017-08-31 20:49:48 +08:00
|
|
|
FontArabic->set_font_ptr(_font_NotoNaskhArabicUI_Regular, _font_NotoNaskhArabicUI_Regular_size);
|
|
|
|
FontArabic->set_force_autohinter(true); //just looks better..i think?
|
2016-05-31 06:41:32 +08:00
|
|
|
|
2017-08-31 20:49:48 +08:00
|
|
|
Ref<DynamicFontData> FontHebrew;
|
|
|
|
FontHebrew.instance();
|
2018-11-11 05:07:32 +08:00
|
|
|
FontHebrew->set_antialiased(font_antialiased);
|
2018-02-27 22:04:08 +08:00
|
|
|
FontHebrew->set_hinting(font_hinting);
|
2017-08-31 20:49:48 +08:00
|
|
|
FontHebrew->set_font_ptr(_font_NotoSansHebrew_Regular, _font_NotoSansHebrew_Regular_size);
|
|
|
|
FontHebrew->set_force_autohinter(true); //just looks better..i think?
|
2016-05-31 06:41:32 +08:00
|
|
|
|
2017-08-31 20:49:48 +08:00
|
|
|
Ref<DynamicFontData> FontThai;
|
|
|
|
FontThai.instance();
|
2018-11-11 05:07:32 +08:00
|
|
|
FontThai->set_antialiased(font_antialiased);
|
2018-02-27 22:04:08 +08:00
|
|
|
FontThai->set_hinting(font_hinting);
|
2017-08-31 20:49:48 +08:00
|
|
|
FontThai->set_font_ptr(_font_NotoSansThaiUI_Regular, _font_NotoSansThaiUI_Regular_size);
|
|
|
|
FontThai->set_force_autohinter(true); //just looks better..i think?
|
2016-05-31 06:41:32 +08:00
|
|
|
|
2018-08-30 04:11:09 +08:00
|
|
|
Ref<DynamicFontData> FontHindi;
|
|
|
|
FontHindi.instance();
|
2018-11-11 05:07:32 +08:00
|
|
|
FontHindi->set_antialiased(font_antialiased);
|
2018-08-30 04:11:09 +08:00
|
|
|
FontHindi->set_hinting(font_hinting);
|
|
|
|
FontHindi->set_font_ptr(_font_NotoSansDevanagariUI_Regular, _font_NotoSansDevanagariUI_Regular_size);
|
|
|
|
FontHindi->set_force_autohinter(true); //just looks better..i think?
|
|
|
|
|
2018-02-27 22:04:08 +08:00
|
|
|
/* Hack */
|
2015-04-19 01:38:54 +08:00
|
|
|
|
2016-05-29 22:37:26 +08:00
|
|
|
Ref<DynamicFontData> dfmono;
|
|
|
|
dfmono.instance();
|
2018-11-11 05:07:32 +08:00
|
|
|
dfmono->set_antialiased(font_source_antialiased);
|
2018-02-27 22:04:08 +08:00
|
|
|
dfmono->set_hinting(font_source_hinting);
|
2017-09-16 08:46:00 +08:00
|
|
|
dfmono->set_font_ptr(_font_Hack_Regular, _font_Hack_Regular_size);
|
2016-05-29 22:37:26 +08:00
|
|
|
//dfd->set_force_autohinter(true); //just looks better..i think?
|
|
|
|
|
2018-01-08 03:07:47 +08:00
|
|
|
int default_font_size = int(EditorSettings::get_singleton()->get("interface/editor/main_font_size")) * EDSCALE;
|
2016-05-29 22:37:26 +08:00
|
|
|
|
2018-04-10 23:26:26 +08:00
|
|
|
// Default font
|
|
|
|
MAKE_DEFAULT_FONT(df, default_font_size);
|
2016-05-29 22:37:26 +08:00
|
|
|
p_theme->set_default_theme_font(df);
|
|
|
|
|
2018-04-10 23:26:26 +08:00
|
|
|
// Bold font
|
|
|
|
MAKE_BOLD_FONT(df_bold, default_font_size);
|
|
|
|
p_theme->set_font("bold", "EditorFonts", df_bold);
|
|
|
|
|
|
|
|
// Title font
|
|
|
|
MAKE_BOLD_FONT(df_title, default_font_size + 2 * EDSCALE);
|
2017-11-10 09:36:19 +08:00
|
|
|
p_theme->set_font("title", "EditorFonts", df_title);
|
|
|
|
|
2018-04-10 23:26:26 +08:00
|
|
|
// Doc font
|
|
|
|
MAKE_BOLD_FONT(df_doc_title, int(EDITOR_DEF("text_editor/help/help_title_font_size", 23)) * EDSCALE);
|
2016-05-29 22:37:26 +08:00
|
|
|
|
2017-11-24 06:13:02 +08:00
|
|
|
MAKE_DEFAULT_FONT(df_doc, int(EDITOR_DEF("text_editor/help/help_font_size", 15)) * EDSCALE);
|
2016-05-29 22:37:26 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
p_theme->set_font("doc", "EditorFonts", df_doc);
|
2017-11-10 09:36:19 +08:00
|
|
|
p_theme->set_font("doc_title", "EditorFonts", df_doc_title);
|
2016-05-29 22:37:26 +08:00
|
|
|
|
2018-04-10 23:26:26 +08:00
|
|
|
MAKE_SOURCE_FONT(df_doc_code, int(EDITOR_DEF("text_editor/help/help_source_font_size", 14)) * EDSCALE);
|
|
|
|
p_theme->set_font("doc_source", "EditorFonts", df_doc_code);
|
|
|
|
|
|
|
|
// Ruler font
|
2017-11-24 23:11:03 +08:00
|
|
|
MAKE_DEFAULT_FONT(df_rulers, 8 * EDSCALE);
|
2017-08-30 03:50:18 +08:00
|
|
|
p_theme->set_font("rulers", "EditorFonts", df_rulers);
|
|
|
|
|
2018-04-10 23:26:26 +08:00
|
|
|
// Code font
|
2018-01-08 03:07:47 +08:00
|
|
|
MAKE_SOURCE_FONT(df_code, int(EditorSettings::get_singleton()->get("interface/editor/code_font_size")) * EDSCALE);
|
2017-03-05 23:44:50 +08:00
|
|
|
p_theme->set_font("source", "EditorFonts", df_code);
|
2016-05-29 22:37:26 +08:00
|
|
|
|
2018-01-08 03:07:47 +08:00
|
|
|
MAKE_SOURCE_FONT(df_output_code, int(EDITOR_DEF("run/output/font_size", 13)) * EDSCALE);
|
2017-09-25 22:12:17 +08:00
|
|
|
p_theme->set_font("output_source", "EditorFonts", df_output_code);
|
|
|
|
|
2019-01-19 02:20:35 +08:00
|
|
|
MAKE_SOURCE_FONT(df_text_editor_status_code, default_font_size);
|
2017-12-27 05:09:28 +08:00
|
|
|
p_theme->set_font("status_source", "EditorFonts", df_text_editor_status_code);
|
2015-04-19 01:38:54 +08:00
|
|
|
}
|