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

Add SDF HintingMode #1966

Merged
merged 11 commits into from
Jun 23, 2024
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Documentation
-------------

We use our [wiki][wiki] for documentation.
If you need further help, feel free to ask on our [forums][forums], our [Discord server][discord], or our IRC channel [#love on OFTC][irc].
If you need further help, feel free to ask on our [forums][forums], our [Discord server][discord], or our [subreddit][subreddit].

Repository
----------
Expand Down Expand Up @@ -97,7 +97,7 @@ Dependencies
[wiki]: https://love2d.org/wiki
[forums]: https://love2d.org/forums
[discord]: https://discord.gg/rhUets9
[irc]: irc://irc.oftc.net/love
[subreddit]: https://www.reddit.com/r/love2d
[dependencies-apple]: https://github.com/love2d/love-apple-dependencies
[dependencies-ios]: https://github.com/love2d/love/releases
[megasource]: https://github.com/love2d/megasource
Expand Down
1 change: 1 addition & 0 deletions src/modules/font/TrueTypeRasterizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ StringMap<TrueTypeRasterizer::Hinting, TrueTypeRasterizer::HINTING_MAX_ENUM>::En
{"light", HINTING_LIGHT},
{"mono", HINTING_MONO},
{"none", HINTING_NONE},
{"sdf", HINTING_SDF},
};

StringMap<TrueTypeRasterizer::Hinting, TrueTypeRasterizer::HINTING_MAX_ENUM> TrueTypeRasterizer::hintings(TrueTypeRasterizer::hintingEntries, sizeof(TrueTypeRasterizer::hintingEntries));
Expand Down
1 change: 1 addition & 0 deletions src/modules/font/TrueTypeRasterizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class TrueTypeRasterizer : public Rasterizer
HINTING_LIGHT,
HINTING_MONO,
HINTING_NONE,
HINTING_SDF,
HINTING_MAX_ENUM
};

Expand Down
18 changes: 15 additions & 3 deletions src/modules/font/freetype/TrueTypeRasterizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,23 @@ GlyphData *TrueTypeRasterizer::getGlyphDataForIndex(int index) const
FT_Render_Mode rendermode = FT_RENDER_MODE_NORMAL;
if (hinting == HINTING_MONO)
rendermode = FT_RENDER_MODE_MONO;
else if (hinting == HINTING_SDF)
rendermode = FT_RENDER_MODE_SDF;

err = FT_Glyph_To_Bitmap(&ftglyph, rendermode, 0, 1);

if (err != FT_Err_Ok)
throw love::Exception("TrueType Font glyph error: FT_Glyph_To_Bitmap failed (0x%x)", err);

{
if (rendermode == FT_RENDER_MODE_SDF)
{
err = FT_Glyph_To_Bitmap(&ftglyph, FT_RENDER_MODE_NORMAL, 0, 1);
if (err != FT_Err_Ok)
throw love::Exception("TrueType Font glyph error: FT_Glyph_To_Bitmap failed (0x%x)", err);
}
else
{
throw love::Exception("TrueType Font glyph error: FT_Glyph_To_Bitmap failed (0x%x)", err);
}
}
FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph) ftglyph;
const FT_Bitmap &bitmap = bitmap_glyph->bitmap; //just to make things easier

Expand Down Expand Up @@ -236,6 +247,7 @@ FT_UInt TrueTypeRasterizer::hintingToLoadOption(Hinting hint)
return FT_LOAD_TARGET_LIGHT;
case HINTING_MONO:
return FT_LOAD_TARGET_MONO;
case HINTING_SDF:
Labrium marked this conversation as resolved.
Show resolved Hide resolved
case HINTING_NONE:
return FT_LOAD_NO_HINTING;
}
Expand Down
Loading