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
2 changes: 1 addition & 1 deletion core/2d/FontFreeType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ FT_Library FontFreeType::_FTlibrary;
bool FontFreeType::_FTInitialized = false;
bool FontFreeType::_streamParsingEnabled = true;
bool FontFreeType::_doNativeBytecodeHinting = true;
bool FontFreeType::_shareDistanceFieldEnabled = false;
bool FontFreeType::_globalSDFEnabled = false;
const int FontFreeType::DistanceMapSpread = 6;

// By default, will render square when character glyph missing in current font
Expand Down
11 changes: 7 additions & 4 deletions core/2d/FontFreeType.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,15 @@ class AX_DLL FontFreeType : public Font
static void setMissingGlyphCharacter(char32_t charCode) { _mssingGlyphCharacter = charCode; };

/**
* @brief Whether enable SDF font rendering globally, by default: disabled, since axmol-2.1.0
* @brief Whether enable SDF text rendering globally, by default: disabled, since axmol-2.1.0
*
* @param enabled
*/
static void setShareDistanceFieldEnabled(bool enabled) { _shareDistanceFieldEnabled = enabled; }
static bool isShareDistanceFieldEnabled() { return _shareDistanceFieldEnabled; }
static void setGlobalSDFEnabled(bool enabled) { _globalSDFEnabled = enabled; }
static bool isGlobalSDFEnabled() { return _globalSDFEnabled; }

AX_DEPRECATED(2.9.2) static void setShareDistanceFieldEnabled(bool enabled) { setGlobalSDFEnabled(enabled); }
AX_DEPRECATED(2.9.2) static bool isShareDistanceFieldEnabled() { return isGlobalSDFEnabled(); }

/**
* @brief TrueType fonts with native bytecode hinting * *
Expand Down Expand Up @@ -149,7 +152,7 @@ class AX_DLL FontFreeType : public Font
static bool _FTInitialized;
static bool _streamParsingEnabled;
static bool _doNativeBytecodeHinting;
static bool _shareDistanceFieldEnabled;
static bool _globalSDFEnabled;
static char32_t _mssingGlyphCharacter;

static bool initFreeType();
Expand Down
2 changes: 1 addition & 1 deletion core/2d/Label.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ typedef struct _ttfConfig
float size = AX_DEFAULT_FONT_LABEL_SIZE,
const GlyphCollection& glyphCollection = GlyphCollection::DYNAMIC,
const char* customGlyphCollection = nullptr, /* nullable */
bool useDistanceField = FontFreeType::isShareDistanceFieldEnabled(),
bool useDistanceField = FontFreeType::isGlobalSDFEnabled(),
int outline = 0,
bool useItalics = false,
bool useBold = false,
Expand Down
2 changes: 1 addition & 1 deletion tests/cpp-tests/Source/AppDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ bool AppDelegate::applicationDidFinishLaunching()
ax::setLogFmtFlag(ax::LogFmtFlag::Full);

// whether enable global SDF font render support, since axmol-2.0.1
FontFreeType::setShareDistanceFieldEnabled(true);
FontFreeType::setGlobalSDFEnabled(true);

// As an example, load config file
// FIXME:: This should be loaded before the Director is initialized,
Expand Down
12 changes: 6 additions & 6 deletions tests/cpp-tests/Source/LabelTest/LabelTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1336,23 +1336,23 @@ LabelTitleButtonTTFDistanceField::LabelTitleButtonTTFDistanceField()
{
auto size = Director::getInstance()->getWinSize();

FontFreeType::setShareDistanceFieldEnabled(false);
FontFreeType::setGlobalSDFEnabled(false);
auto button = ax::ui::Button::create();
button->setTitleText("Should be the same size");
button->setTitleFontName("fonts/Marker Felt.ttf");
button->setTitleFontSize(20);
this->addChild(button);
button->setPosition(Vec2(size.width / 2, size.height * 0.7f));

FontFreeType::setShareDistanceFieldEnabled(true);
FontFreeType::setGlobalSDFEnabled(true);
button = ax::ui::Button::create();
button->setTitleText("Should be the same size");
button->setTitleFontName("fonts/Marker Felt.ttf");
button->setTitleFontSize(20);
this->addChild(button);
button->setPosition(Vec2(size.width / 2, size.height * 0.55f));

FontFreeType::setShareDistanceFieldEnabled(false);
FontFreeType::setGlobalSDFEnabled(false);
button = ax::ui::Button::create();
button->setTitleText("Should be the same size");
button->setTitleColor(Color3B::RED);
Expand All @@ -1361,7 +1361,7 @@ LabelTitleButtonTTFDistanceField::LabelTitleButtonTTFDistanceField()
this->addChild(button);
button->setPosition(Vec2(size.width / 2, size.height * 0.4f));

FontFreeType::setShareDistanceFieldEnabled(true);
FontFreeType::setGlobalSDFEnabled(true);
button = ax::ui::Button::create();
button->setTitleText("Should be the same size");
button->setTitleColor(Color3B::RED);
Expand All @@ -1384,15 +1384,15 @@ LabelTTFSDF::LabelTTFSDF()
{
auto size = Director::getInstance()->getWinSize();

FontFreeType::setShareDistanceFieldEnabled(false);
FontFreeType::setGlobalSDFEnabled(false);
Label* title = Label::createWithTTF("Normal", "fonts/Marker Felt.ttf", 20);
this->addChild(title);
title->setPosition(Vec2(size.width * 3 / 4, size.height * 0.75));
_labelNormal = Label::createWithTTF("Should be the same", "fonts/Marker Felt.ttf", 20);
this->addChild(_labelNormal);
_labelNormal->setPosition(Vec2(size.width * 3 / 4, size.height * 0.65));

FontFreeType::setShareDistanceFieldEnabled(true);
FontFreeType::setGlobalSDFEnabled(true);
title = Label::createWithTTF("SDF", "fonts/Marker Felt.ttf", 20);
this->addChild(title);
title->setPosition(Vec2(size.width / 4, size.height * 0.75));
Expand Down
2 changes: 1 addition & 1 deletion tests/unit-tests/Source/AppDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ bool AppDelegate::applicationDidFinishLaunching()
ax::setLogFmtFlag(ax::LogFmtFlag::Full);

// whether enable global SDF font render support, since axmol-2.0.1
FontFreeType::setShareDistanceFieldEnabled(true);
FontFreeType::setGlobalSDFEnabled(true);

// initialize director
auto director = Director::getInstance();
Expand Down
Loading