Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions framework/draw/fontmetrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ double FontMetrics::descent() const
return fontProvider()->descent(m_font);
}

double FontMetrics::underlinePos() const
{
return fontProvider()->underlinePos(m_font);
}

double FontMetrics::lineWidth() const
{
return fontProvider()->lineWidth(m_font);
}

double FontMetrics::strikeOutPos() const
{
return fontProvider()->strikeOutPos(m_font);
}

double FontMetrics::width(const String& string) const
{
return horizontalAdvance(string);
Expand Down
4 changes: 4 additions & 0 deletions framework/draw/fontmetrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class FontMetrics
double ascent() const;
double descent() const;

double underlinePos() const;
double lineWidth() const;
double strikeOutPos() const;

double width(const String& string) const;
double width(const Char& ch) const;

Expand Down
4 changes: 4 additions & 0 deletions framework/draw/ifontprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class IFontProvider : MODULE_GLOBAL_INTERFACE
virtual double ascent(const Font& f) const = 0;
virtual double descent(const Font& f) const = 0;

virtual double underlinePos(const Font& f) const = 0;
virtual double lineWidth(const Font& f) const = 0;
virtual double strikeOutPos(const Font& f) const = 0;

virtual bool inFont(const Font& f, char32_t ucs4) const = 0;

// Text
Expand Down
10 changes: 10 additions & 0 deletions framework/draw/internal/fontfacedu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ f26dot6_t FontFaceDU::capHeight() const
return m_origin->capHeight();
}

f26dot6_t FontFaceDU::underlinePos() const
{
return m_origin->underlinePos();
}

f26dot6_t FontFaceDU::lineWidth() const
{
return m_origin->lineWidth();
}

std::vector<GlyphPos> FontFaceDU::glyphs(const char32_t* text, int text_length) const
{
std::vector<GlyphPos> glyphs = m_origin->glyphs(text, text_length);
Expand Down
3 changes: 3 additions & 0 deletions framework/draw/internal/fontfacedu.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class FontFaceDU : public IFontFace
f26dot6_t xHeight() const override;
f26dot6_t capHeight() const override;

f26dot6_t underlinePos() const override;
f26dot6_t lineWidth() const override;

std::vector<GlyphPos> glyphs(const char32_t* text, int text_length) const override;
glyph_idx_t glyphIndex(char32_t ucs4) const override;
glyph_idx_t glyphIndex(const std::string& glyphName) const override;
Expand Down
12 changes: 12 additions & 0 deletions framework/draw/internal/fontfaceft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,18 @@ f26dot6_t FontFaceFT::capHeight() const
return gm->bbox.height();
}

f26dot6_t FontFaceFT::underlinePos() const
{
f26dot6_t thickness = FT_MulFix(m_data->face->underline_thickness, m_data->face->size->metrics.y_scale);
f26dot6_t centerPos = -FT_MulFix(m_data->face->underline_position, m_data->face->size->metrics.y_scale);
return centerPos - thickness / 2;
}

f26dot6_t FontFaceFT::lineWidth() const
{
return FT_MulFix(m_data->face->underline_thickness, m_data->face->size->metrics.y_scale);
}

GlyphMetrics* FontFaceFT::glyphMetrics(glyph_idx_t idx) const
{
if (m_data->glyphsMetrics.find(idx) != m_data->glyphsMetrics.end()) {
Expand Down
3 changes: 3 additions & 0 deletions framework/draw/internal/fontfaceft.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class FontFaceFT : public IFontFace
f26dot6_t xHeight() const override;
f26dot6_t capHeight() const override;

f26dot6_t underlinePos() const override;
f26dot6_t lineWidth() const override;

std::vector<GlyphPos> glyphs(const char32_t* text, int text_length) const override;
glyph_idx_t glyphIndex(char32_t ucs4) const override;
glyph_idx_t glyphIndex(const std::string& glyphName) const override;
Expand Down
14 changes: 14 additions & 0 deletions framework/draw/internal/fontfacext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ bool FontFaceXT::load(const FaceKey& key, const FontData& fontData, bool isSymbo
m_xHeight = std::stol(valStr);
} else if (name == "capHeight") {
m_capHeight = std::stol(valStr);
} else if (name == "underlinePos") {
m_underlinePos = std::stol(valStr);
} else if (name == "lineWidth") {
m_lineWidth = std::stol(valStr);
} else {
LOGW() << "unknown param: " << name;
}
Expand Down Expand Up @@ -277,6 +281,16 @@ f26dot6_t FontFaceXT::capHeight() const
return m_capHeight;
}

f26dot6_t FontFaceXT::underlinePos() const
{
return m_underlinePos;
}

f26dot6_t FontFaceXT::lineWidth() const
{
return m_lineWidth;
}

void FontFaceXT::applyLigatures(std::vector<glyph_idx_t>& glyphs, const Ligatures& ls)
{
for (const Ligature& l : ls) {
Expand Down
5 changes: 5 additions & 0 deletions framework/draw/internal/fontfacext.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ class FontFaceXT : public IFontFace
f26dot6_t xHeight() const override;
f26dot6_t capHeight() const override;

f26dot6_t underlinePos() const override;
f26dot6_t lineWidth() const override;

std::vector<GlyphPos> glyphs(const char32_t* text, int text_length) const override;
glyph_idx_t glyphIndex(char32_t ucs4) const override;
glyph_idx_t glyphIndex(const std::string& glyphName) const override;
Expand Down Expand Up @@ -121,6 +124,8 @@ class FontFaceXT : public IFontFace
f26dot6_t m_descent = -1;
f26dot6_t m_xHeight = -1;
f26dot6_t m_capHeight = -1;
f26dot6_t m_underlinePos = -1;
f26dot6_t m_lineWidth = -1;

Ligatures m_ligatures;
Kernings m_kernings;
Expand Down
15 changes: 15 additions & 0 deletions framework/draw/internal/fontprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ double FontProvider::descent(const muse::draw::Font& f) const
return fontsEngine()->descent(f);
}

double FontProvider::underlinePos(const muse::draw::Font& f) const
{
return fontsEngine()->underlinePos(f);
}

double FontProvider::lineWidth(const muse::draw::Font& f) const
{
return fontsEngine()->lineWidth(f);
}

double FontProvider::strikeOutPos(const muse::draw::Font& f) const
{
return fontsEngine()->strikeOutPos(f);
}

bool FontProvider::inFont(const muse::draw::Font& f, char32_t ucs4) const
{
return fontsEngine()->inFont(f, ucs4);
Expand Down
4 changes: 4 additions & 0 deletions framework/draw/internal/fontprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class FontProvider : public IFontProvider, public Contextable
double ascent(const Font& f) const override;
double descent(const Font& f) const override;

double underlinePos(const Font& f) const override;
double lineWidth(const Font& f) const override;
double strikeOutPos(const Font& f) const override;

bool inFont(const Font& f, char32_t ucs4) const override;

// Text
Expand Down
23 changes: 23 additions & 0 deletions framework/draw/internal/fontsengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,29 @@ double FontsEngine::descent(const Font& f) const
return from_f26d6(rf->face->descent()) * rf->pixelScale();
}

double FontsEngine::underlinePos(const Font& f) const
{
RequireFace* rf = fontFace(f);
IF_ASSERT_FAILED(rf && rf->face) {
return 0.0;
}
return from_f26d6(rf->face->underlinePos()) * rf->pixelScale();
}

double FontsEngine::lineWidth(const Font& f) const
{
RequireFace* rf = fontFace(f);
IF_ASSERT_FAILED(rf && rf->face) {
return 1.0;
}
return from_f26d6(rf->face->lineWidth()) * rf->pixelScale();
}
Comment thread
alexpavlov96 marked this conversation as resolved.

double FontsEngine::strikeOutPos(const Font& f) const
{
return ascent(f) / 3.0;
}

bool FontsEngine::inFont(const Font& f, char32_t ucs4) const
{
RequireFace* rf = fontFace(f);
Expand Down
4 changes: 4 additions & 0 deletions framework/draw/internal/fontsengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class FontsEngine : public IFontsEngine, public Contextable
double ascent(const Font& f) const override;
double descent(const Font& f) const override;

double underlinePos(const Font& f) const override;
double lineWidth(const Font& f) const override;
double strikeOutPos(const Font& f) const override;

bool inFont(const Font& f, char32_t ucs4) const override;

double horizontalAdvance(const Font& f, const char32_t& ch) const override;
Expand Down
3 changes: 3 additions & 0 deletions framework/draw/internal/ifontface.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class IFontFace
virtual f26dot6_t xHeight() const = 0;
virtual f26dot6_t capHeight() const = 0;

virtual f26dot6_t underlinePos() const = 0;
virtual f26dot6_t lineWidth() const = 0;

virtual std::vector<GlyphPos> glyphs(const char32_t* text, int text_length) const = 0;
virtual glyph_idx_t glyphIndex(char32_t ucs4) const = 0;
virtual glyph_idx_t glyphIndex(const std::string& glyphName) const = 0;
Expand Down
4 changes: 4 additions & 0 deletions framework/draw/internal/ifontsengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class IFontsEngine : MODULE_GLOBAL_INTERFACE
virtual double ascent(const Font& f) const = 0;
virtual double descent(const Font& f) const = 0;

virtual double underlinePos(const Font& f) const = 0;
virtual double lineWidth(const Font& f) const = 0;
virtual double strikeOutPos(const Font& f) const = 0;

virtual bool inFont(const Font& f, char32_t ucs4) const = 0;

virtual double horizontalAdvance(const Font& f, const char32_t& ch) const = 0;
Expand Down
15 changes: 15 additions & 0 deletions framework/draw/internal/qfontprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ double QFontProvider::descent(const Font& f) const
return QFontMetricsF(f.toQFont(), &device).descent();
}

double QFontProvider::underlinePos(const Font& f) const
{
return QFontMetricsF(f.toQFont(), &device).underlinePos();
}

double QFontProvider::lineWidth(const Font& f) const
{
return QFontMetricsF(f.toQFont(), &device).lineWidth();
}

double QFontProvider::strikeOutPos(const Font& f) const
{
return QFontMetricsF(f.toQFont(), &device).strikeOutPos();
}

bool QFontProvider::inFont(const Font& f, char32_t ucs4) const
{
// NOTE: QFontMetricsF::inFontUcs4 is unreliable for our use case because it uses Qt's fallback
Expand Down
4 changes: 4 additions & 0 deletions framework/draw/internal/qfontprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class QFontProvider : public IFontProvider
double ascent(const Font& f) const override;
double descent(const Font& f) const override;

double underlinePos(const Font& f) const override;
double lineWidth(const Font& f) const override;
double strikeOutPos(const Font& f) const override;

bool inFont(const Font& f, char32_t ucs4) const override;

// Text
Expand Down
2 changes: 2 additions & 0 deletions framework/draw/tests/fontfacext_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ TEST_F(Draw_FontFaceXTTests, TextMetrics)
if (faces->xt.capHeight() >= 0) {
EXPECT_TRUE(valueIsNear(faces->ft.capHeight(), faces->xt.capHeight(), ONE_PIXEL));
}
EXPECT_TRUE(valueIsNear(faces->ft.underlinePos(), faces->xt.underlinePos(), ONE_PIXEL));
EXPECT_TRUE(valueIsNear(faces->ft.lineWidth(), faces->xt.lineWidth(), ONE_PIXEL));
}

TEST_F(Draw_FontFaceXTTests, GlyphMetrics)
Expand Down
Binary file modified framework/draw/tests/fonts/edwin/Edwin-Roman.ftx
Binary file not shown.
45 changes: 45 additions & 0 deletions framework/draw/tests/fontsprovider_qt_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,51 @@ TEST_F(Draw_FontsProviderQtTests, descent)
}
}

TEST_F(Draw_FontsProviderQtTests, underlinePos)
{
Env env;
Font f(u"Edwin", Font::Type::Text);

for (double pointSize : TEST_POINTSIZES) {
f.setPointSizeF(pointSize);

double qVal = env.qProvider.underlinePos(f);
double xVal = env.xProvider.underlinePos(f);

EXPECT_TRUE(ValuesMatch(f.pointSizeF(), qVal, xVal, 0.0));
}
}

TEST_F(Draw_FontsProviderQtTests, lineWidth)
{
Env env;
Font f(u"Edwin", Font::Type::Text);

for (double pointSize : TEST_POINTSIZES) {
f.setPointSizeF(pointSize);

double qVal = env.qProvider.lineWidth(f);
double xVal = env.xProvider.lineWidth(f);

EXPECT_TRUE(ValuesMatch(f.pointSizeF(), qVal, xVal, 0.0));
}
}

TEST_F(Draw_FontsProviderQtTests, strikeOutPos)
{
Env env;
Font f(u"Edwin", Font::Type::Text);

for (double pointSize : TEST_POINTSIZES) {
f.setPointSizeF(pointSize);

double qVal = env.qProvider.strikeOutPos(f);
double xVal = env.xProvider.strikeOutPos(f);

EXPECT_TRUE(ValuesMatch(f.pointSizeF(), qVal, xVal, 0.0));
}
}

TEST_F(Draw_FontsProviderQtTests, horizontalAdvance_Char)
{
Env env;
Expand Down
2 changes: 2 additions & 0 deletions framework/draw/types/fontstypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ struct FontParams {
bool bold = false;
bool italic = false;
float pointSize = 0.0f;
bool underline = false;
bool strike = false;
Comment thread
handrok marked this conversation as resolved.
};
}

Expand Down