Skip to content

Commit a39779f

Browse files
author
devsh
committed
Merge branch 'master' of github.com:Devsh-Graphics-Programming/Nabla
2 parents 9b7901e + fcd6348 commit a39779f

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

include/nbl/ext/TextRendering/TextRendering.h

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#include "nabla.h"
99

10-
#include "nbl/video/utilities/CPropertyPool.h"
1110
#include <msdfgen/msdfgen.h>
1211
#include <ft2build.h>
1312
#include <nbl/builtin/hlsl/cpp_compat.hlsl>
@@ -43,6 +42,12 @@ class TextRenderer : public nbl::core::IReferenceCounted
4342
auto error = FT_Init_FreeType(&m_ftLibrary);
4443
assert(!error);
4544
}
45+
46+
~TextRenderer()
47+
{
48+
auto error = FT_Done_FreeType(m_ftLibrary);
49+
assert(!error);
50+
}
4651

4752
// TODO: Remove these here, it's only used for customized tests such as building shapes for hatches
4853
const FT_Library& getFreetypeLibrary() const { return m_ftLibrary; }
@@ -56,11 +61,23 @@ class TextRenderer : public nbl::core::IReferenceCounted
5661
class FontFace : public nbl::core::IReferenceCounted
5762
{
5863
public:
64+
65+
// Face Global Metrics/Settings
66+
struct Metrics
67+
{
68+
// This value is the vertical distance between two consecutive baselines, expressed in font units. It is always positive.
69+
float64_t height;
70+
// The distance from the baseline to the highest or upper grid coordinate used to place an outline point. It is a positive value.
71+
float64_t ascent;
72+
// The distance from the baseline to the lowest grid coordinate used to place an outline point. this is almost always a negative value.
73+
float64_t descent;
74+
};
75+
5976
struct GlyphMetrics
6077
{
6178
// Offset that should be applied to the current baseline after this glyph is placed
6279
float64_t2 advance;
63-
// Offset that the image of the glyph should be placed from the current baseline start, horizontal refers to horizonral LTR or RTL Languages
80+
// Offset of the glyph's top left from the current baseline start, horizontal refers to horizonral LTR or RTL Languages
6481
float64_t2 horizontalBearing;
6582
// Size of the glyph in the text line
6683
float64_t2 size;
@@ -76,6 +93,12 @@ class FontFace : public nbl::core::IReferenceCounted
7693
m_hash = std::hash<std::string>{}(path);
7794
}
7895

96+
~FontFace()
97+
{
98+
auto error = FT_Done_Face(m_ftFace);
99+
assert(!error);
100+
}
101+
79102
static constexpr uint32_t InvalidGlyphIndex = ~0u;
80103

81104
uint32_t getGlyphIndex(wchar_t unicode)
@@ -88,7 +111,9 @@ class FontFace : public nbl::core::IReferenceCounted
88111
return FT_Get_Char_Index(m_ftFace, unicode);
89112
}
90113

91-
GlyphMetrics getGlyphMetricss(uint32_t glyphId);
114+
Metrics getMetrics() const;
115+
116+
GlyphMetrics getGlyphMetrics(uint32_t glyphId);
92117

93118
// returns the cpu buffer for the generated MSDF texture with "TextRenderer::MSDFTextureFormat" format
94119
// it will place the glyph in the center of msdfExtents considering the margin of msdfPixelRange

src/nbl/ext/TextRendering/TextRendering.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
using namespace nbl;
32
using namespace nbl::core;
43
using namespace nbl::asset;
@@ -56,7 +55,16 @@ core::smart_refctd_ptr<ICPUBuffer> TextRenderer::generateShapeMSDF(msdfgen::Shap
5655

5756
constexpr double FreeTypeFontScaling = 1.0 / 64.0;
5857

59-
FontFace::GlyphMetrics FontFace::getGlyphMetricss(uint32_t glyphId)
58+
FontFace::Metrics FontFace::getMetrics() const
59+
{
60+
Metrics ret = {};
61+
ret.height = float64_t(m_ftFace->height) * FreeTypeFontScaling;
62+
ret.ascent = float64_t(m_ftFace->ascender) * FreeTypeFontScaling;
63+
ret.descent = float64_t(m_ftFace->descender) * FreeTypeFontScaling;
64+
return ret;
65+
}
66+
67+
FontFace::GlyphMetrics FontFace::getGlyphMetrics(uint32_t glyphId)
6068
{
6169
auto slot = getGlyphSlot(glyphId);
6270

@@ -164,4 +172,4 @@ msdfgen::Shape FontFace::generateGlyphShape(uint32_t glyphId)
164172

165173
}
166174
}
167-
}
175+
}

0 commit comments

Comments
 (0)