Skip to content

Commit

Permalink
Use ascender value as common/base value
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirgamalyan committed Dec 24, 2021
1 parent d9e5e7e commit ee1e635
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ App::Glyphs App::collectGlyphInfo(const ft::Font& font, const std::set<std::uint
glyphInfo.height = glyphMetrics.height;
glyphInfo.xAdvance = glyphMetrics.horiAdvance;
glyphInfo.xOffset = glyphMetrics.horiBearingX;
glyphInfo.yOffset = font.yMax - glyphMetrics.horiBearingY;
glyphInfo.yOffset = font.ascent - glyphMetrics.horiBearingY;
result[id] = glyphInfo;
}
else
Expand Down Expand Up @@ -246,7 +246,7 @@ void App::writeFontInfoFile(const Glyphs& glyphs, const Config& config, const ft
f.info.spacing.vertical = static_cast<std::uint8_t>(config.spacing.ver);

f.common.lineHeight = static_cast<std::uint16_t>(font.height);
f.common.base = static_cast<std::uint16_t>(font.yMax);
f.common.base = static_cast<std::uint16_t>(font.ascent);
if (!pagesHaveDifferentSize && !pages.empty())
{
f.common.scaleW = static_cast<std::uint16_t>(pages.front().w);
Expand Down
24 changes: 22 additions & 2 deletions src/freeType/FtFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ class Font
const auto scale = face->size->metrics.y_scale;
yMin = FT_FLOOR(FT_MulFix(face->bbox.yMin, scale));
yMax = FT_CEIL(FT_MulFix(face->bbox.yMax, scale));
height = FT_CEIL(FT_MulFix(face->height, scale));
// height = FT_CEIL(FT_MulFix(face->height, scale));
height = std::lround(static_cast<float>(face->size->metrics.height) / static_cast<float>(1 << 6));
//height = std::lround(FT_MulFix(face->height, scale) / static_cast<float>(1 << 6));
ascent = FT_CEIL(FT_MulFix(face->ascender, scale));
//ascent = std::lround(FT_MulFix(face->ascender, scale) / static_cast<float>(1 << 6));
descent = FT_FLOOR(FT_MulFix(face->descender, scale));
}
else
{
Expand All @@ -96,6 +101,10 @@ class Font
yMin = 0;
yMax = face->available_sizes[ptsize].height;
height = face->available_sizes[ptsize].height;

//TODO: correct values
ascent = 0;
descent = 0;
}

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

totalHeight = yMax - yMin;


}

~Font()
Expand Down Expand Up @@ -233,7 +244,14 @@ class Font
std::cout << "face->bbox.yMin " << FT_FLOOR(FT_MulFix(face->bbox.yMin, scale)) << "\n";
std::cout << "face->ascender " << FT_CEIL(FT_MulFix(face->ascender, scale)) << "\n";
std::cout << "face->descender " << FT_FLOOR(FT_MulFix(face->descender, scale)) << "\n";
std::cout << "face->height " << FT_CEIL(FT_MulFix(face->height, scale)) << "\n";
std::cout << "face->height " << FT_CEIL(FT_MulFix(face->height, scale)) << "\n"; // distance between lines
std::cout << "face->height f " << static_cast<float>(FT_MulFix(face->height, scale)) / static_cast<float>(1 << 6) << "\n";
std::cout << "face->size->metrics.height " << FT_CEIL(face->size->metrics.height) << "\n";

std::cout << "metrics.height " << static_cast<float>(face->size->metrics.height) / static_cast<float>(1 << 6) << "\n"; // as in SFML getLineSpacing
std::cout << "metrics.ascender " << static_cast<float>(face->size->metrics.ascender) / static_cast<float>(1 << 6) << "\n";
std::cout << "metrics.descender " << static_cast<float>(face->size->metrics.descender) / static_cast<float>(1 << 6) << "\n";
std::cout << "a " << static_cast<float>(FT_MulFix(face->ascender, scale)) / static_cast<float>(1 << 6) << "\n";

FT_UInt gindex;
FT_ULong charcode = FT_Get_First_Char(face, &gindex);
Expand Down Expand Up @@ -285,6 +303,8 @@ class Font
int height;
int yMax;
int yMin;
int ascent;
int descent;
int totalHeight = 0;

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

0 comments on commit ee1e635

Please sign in to comment.