summaryrefslogtreecommitdiff
path: root/scene/resources
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2020-05-07 21:18:41 +0200
committerGitHub <noreply@github.com>2020-05-07 21:18:41 +0200
commitd7b85fbaa1fc438effe406c9d7f973749eb4e527 (patch)
treed76ca3eeb5681426ec48aed248df9ed0180f364d /scene/resources
parentae33cf5f458a57fbf8aa3ec0a65c94e86cd4d6f4 (diff)
parent9f1de2cfddf2f5f8f4a9d1f861a3141c052517a2 (diff)
Merge pull request #31086 from volzhs/underline
Use underline position and thickness value in font file
Diffstat (limited to 'scene/resources')
-rw-r--r--scene/resources/dynamic_font.cpp28
-rw-r--r--scene/resources/dynamic_font.h6
-rw-r--r--scene/resources/font.cpp10
-rw-r--r--scene/resources/font.h4
4 files changed, 48 insertions, 0 deletions
diff --git a/scene/resources/dynamic_font.cpp b/scene/resources/dynamic_font.cpp
index eea4d12d0e..442151de36 100644
--- a/scene/resources/dynamic_font.cpp
+++ b/scene/resources/dynamic_font.cpp
@@ -221,6 +221,8 @@ Error DynamicFontAtSize::_load() {
ascent = (face->size->metrics.ascender / 64.0) / oversampling * scale_color_font;
descent = (-face->size->metrics.descender / 64.0) / oversampling * scale_color_font;
+ underline_position = -face->underline_position / 64.0 / oversampling * scale_color_font;
+ underline_thickness = face->underline_thickness / 64.0 / oversampling * scale_color_font;
linegap = 0;
valid = true;
@@ -243,6 +245,16 @@ float DynamicFontAtSize::get_descent() const {
return descent;
}
+float DynamicFontAtSize::get_underline_position() const {
+
+ return underline_position;
+}
+
+float DynamicFontAtSize::get_underline_thickness() const {
+
+ return underline_thickness;
+}
+
const Pair<const DynamicFontAtSize::Character *, DynamicFontAtSize *> DynamicFontAtSize::_find_char_with_font(CharType p_char, const Vector<Ref<DynamicFontAtSize>> &p_fallbacks) const {
const Character *chr = char_map.getptr(p_char);
ERR_FAIL_COND_V(!chr, (Pair<const Character *, DynamicFontAtSize *>(nullptr, nullptr)));
@@ -821,6 +833,22 @@ float DynamicFont::get_descent() const {
return data_at_size->get_descent() + spacing_bottom;
}
+float DynamicFont::get_underline_position() const {
+
+ if (!data_at_size.is_valid())
+ return 2;
+
+ return data_at_size->get_underline_position();
+}
+
+float DynamicFont::get_underline_thickness() const {
+
+ if (!data_at_size.is_valid())
+ return 1;
+
+ return data_at_size->get_underline_thickness();
+}
+
Size2 DynamicFont::get_char_size(CharType p_char, CharType p_next) const {
if (!data_at_size.is_valid())
diff --git a/scene/resources/dynamic_font.h b/scene/resources/dynamic_font.h
index ef4b9dd9d0..2fa1951d27 100644
--- a/scene/resources/dynamic_font.h
+++ b/scene/resources/dynamic_font.h
@@ -124,6 +124,8 @@ class DynamicFontAtSize : public Reference {
float rect_margin;
float oversampling;
float scale_color_font;
+ float underline_position;
+ float underline_thickness;
bool valid;
@@ -187,6 +189,8 @@ public:
float get_ascent() const;
float get_descent() const;
+ float get_underline_position() const;
+ float get_underline_thickness() const;
Size2 get_char_size(CharType p_char, CharType p_next, const Vector<Ref<DynamicFontAtSize>> &p_fallbacks) const;
@@ -274,6 +278,8 @@ public:
virtual float get_ascent() const;
virtual float get_descent() const;
+ virtual float get_underline_position() const;
+ virtual float get_underline_thickness() const;
virtual Size2 get_char_size(CharType p_char, CharType p_next = 0) const;
diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp
index 267816f267..51c2ff389a 100644
--- a/scene/resources/font.cpp
+++ b/scene/resources/font.cpp
@@ -356,6 +356,16 @@ float BitmapFont::get_descent() const {
return height - ascent;
}
+float BitmapFont::get_underline_position() const {
+
+ return 2;
+}
+
+float BitmapFont::get_underline_thickness() const {
+
+ return 1;
+}
+
void BitmapFont::add_texture(const Ref<Texture2D> &p_texture) {
ERR_FAIL_COND_MSG(p_texture.is_null(), "It's not a reference to a valid Texture object.");
diff --git a/scene/resources/font.h b/scene/resources/font.h
index c233344529..54b1eaa1b9 100644
--- a/scene/resources/font.h
+++ b/scene/resources/font.h
@@ -47,6 +47,8 @@ public:
virtual float get_ascent() const = 0;
virtual float get_descent() const = 0;
+ virtual float get_underline_position() const = 0;
+ virtual float get_underline_thickness() const = 0;
virtual Size2 get_char_size(CharType p_char, CharType p_next = 0) const = 0;
Size2 get_string_size(const String &p_string) const;
@@ -167,6 +169,8 @@ public:
void set_ascent(float p_ascent);
float get_ascent() const;
float get_descent() const;
+ float get_underline_position() const;
+ float get_underline_thickness() const;
void add_texture(const Ref<Texture2D> &p_texture);
void add_char(CharType p_char, int p_texture_idx, const Rect2 &p_rect, const Size2 &p_align, float p_advance = -1);