Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed crash when glyph cannot be loaded (#15) #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 11 additions & 5 deletions src/freeType/FtFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,7 @@ class Font
GlyphMetrics renderGlyph(std::uint32_t* buffer, std::uint32_t surfaceW, std::uint32_t surfaceH, int x, int y,
std::uint32_t ch, std::uint32_t color) const
{
FT_Int32 loadFlags = FT_LOAD_RENDER | FT_LOAD_FORCE_AUTOHINT;
if (monochrome_)
loadFlags |= FT_LOAD_MONOCHROME;

const auto loadFlags = getLoadFlags();
const auto error = FT_Load_Char(face, ch, loadFlags);
if (error)
throw std::runtime_error("Load glyph error");
Expand Down Expand Up @@ -177,7 +174,7 @@ class Font

int isGlyphProvided(FT_ULong ch) const
{
return FT_Get_Char_Index(face, ch);
return FT_Get_Char_Index(face, ch) && !FT_Load_Char(face, ch, getLoadFlags());
}

int getKerning(const std::uint32_t left, const std::uint32_t right) const
Expand Down Expand Up @@ -299,6 +296,15 @@ class Font
/* Extra width in glyph bounds for text styles */
int glyph_overhang;
float glyph_italics;

private:
FT_Int32 getLoadFlags() const
{
FT_Int32 loadFlags = FT_LOAD_RENDER | FT_LOAD_FORCE_AUTOHINT;
if (monochrome_)
loadFlags |= FT_LOAD_MONOCHROME;
return loadFlags;
}
};

}