Skip to content

Commit ee1e635

Browse files
Use ascender value as common/base value
1 parent d9e5e7e commit ee1e635

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/App.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ App::Glyphs App::collectGlyphInfo(const ft::Font& font, const std::set<std::uint
3636
glyphInfo.height = glyphMetrics.height;
3737
glyphInfo.xAdvance = glyphMetrics.horiAdvance;
3838
glyphInfo.xOffset = glyphMetrics.horiBearingX;
39-
glyphInfo.yOffset = font.yMax - glyphMetrics.horiBearingY;
39+
glyphInfo.yOffset = font.ascent - glyphMetrics.horiBearingY;
4040
result[id] = glyphInfo;
4141
}
4242
else
@@ -246,7 +246,7 @@ void App::writeFontInfoFile(const Glyphs& glyphs, const Config& config, const ft
246246
f.info.spacing.vertical = static_cast<std::uint8_t>(config.spacing.ver);
247247

248248
f.common.lineHeight = static_cast<std::uint16_t>(font.height);
249-
f.common.base = static_cast<std::uint16_t>(font.yMax);
249+
f.common.base = static_cast<std::uint16_t>(font.ascent);
250250
if (!pagesHaveDifferentSize && !pages.empty())
251251
{
252252
f.common.scaleW = static_cast<std::uint16_t>(pages.front().w);

src/freeType/FtFont.h

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ class Font
7272
const auto scale = face->size->metrics.y_scale;
7373
yMin = FT_FLOOR(FT_MulFix(face->bbox.yMin, scale));
7474
yMax = FT_CEIL(FT_MulFix(face->bbox.yMax, scale));
75-
height = FT_CEIL(FT_MulFix(face->height, scale));
75+
// height = FT_CEIL(FT_MulFix(face->height, scale));
76+
height = std::lround(static_cast<float>(face->size->metrics.height) / static_cast<float>(1 << 6));
77+
//height = std::lround(FT_MulFix(face->height, scale) / static_cast<float>(1 << 6));
78+
ascent = FT_CEIL(FT_MulFix(face->ascender, scale));
79+
//ascent = std::lround(FT_MulFix(face->ascender, scale) / static_cast<float>(1 << 6));
80+
descent = FT_FLOOR(FT_MulFix(face->descender, scale));
7681
}
7782
else
7883
{
@@ -96,6 +101,10 @@ class Font
96101
yMin = 0;
97102
yMax = face->available_sizes[ptsize].height;
98103
height = face->available_sizes[ptsize].height;
104+
105+
//TODO: correct values
106+
ascent = 0;
107+
descent = 0;
99108
}
100109

101110
/* Initialize the font face style */
@@ -116,6 +125,8 @@ class Font
116125
glyph_italics *= height;
117126

118127
totalHeight = yMax - yMin;
128+
129+
119130
}
120131

121132
~Font()
@@ -233,7 +244,14 @@ class Font
233244
std::cout << "face->bbox.yMin " << FT_FLOOR(FT_MulFix(face->bbox.yMin, scale)) << "\n";
234245
std::cout << "face->ascender " << FT_CEIL(FT_MulFix(face->ascender, scale)) << "\n";
235246
std::cout << "face->descender " << FT_FLOOR(FT_MulFix(face->descender, scale)) << "\n";
236-
std::cout << "face->height " << FT_CEIL(FT_MulFix(face->height, scale)) << "\n";
247+
std::cout << "face->height " << FT_CEIL(FT_MulFix(face->height, scale)) << "\n"; // distance between lines
248+
std::cout << "face->height f " << static_cast<float>(FT_MulFix(face->height, scale)) / static_cast<float>(1 << 6) << "\n";
249+
std::cout << "face->size->metrics.height " << FT_CEIL(face->size->metrics.height) << "\n";
250+
251+
std::cout << "metrics.height " << static_cast<float>(face->size->metrics.height) / static_cast<float>(1 << 6) << "\n"; // as in SFML getLineSpacing
252+
std::cout << "metrics.ascender " << static_cast<float>(face->size->metrics.ascender) / static_cast<float>(1 << 6) << "\n";
253+
std::cout << "metrics.descender " << static_cast<float>(face->size->metrics.descender) / static_cast<float>(1 << 6) << "\n";
254+
std::cout << "a " << static_cast<float>(FT_MulFix(face->ascender, scale)) / static_cast<float>(1 << 6) << "\n";
237255

238256
FT_UInt gindex;
239257
FT_ULong charcode = FT_Get_First_Char(face, &gindex);
@@ -285,6 +303,8 @@ class Font
285303
int height;
286304
int yMax;
287305
int yMin;
306+
int ascent;
307+
int descent;
288308
int totalHeight = 0;
289309

290310
/* For non-scalable formats, we must remember which font index size */

0 commit comments

Comments
 (0)