2018-01-29 16:25:32 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-02-24 18:45:25 +08:00
|
|
|
https://adxeproject.github.io/
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2011-07-29 15:57:27 +08:00
|
|
|
#include "FontTest.h"
|
|
|
|
#include "../testResource.h"
|
2016-11-18 09:23:44 +08:00
|
|
|
#include "2d/CCFontAtlasCache.h"
|
|
|
|
#include "2d/CCFontFreeType.h"
|
2011-07-29 15:57:27 +08:00
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
USING_NS_CC;
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
enum
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
kTagLabel1,
|
|
|
|
kTagLabel2,
|
|
|
|
kTagLabel3,
|
|
|
|
kTagLabel4,
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2013-04-24 14:49:52 +08:00
|
|
|
kTagColor1,
|
|
|
|
kTagColor2,
|
|
|
|
kTagColor3,
|
2011-07-29 15:57:27 +08:00
|
|
|
};
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
// you don't need any ifdef anymore
|
|
|
|
static std::string fontList[] = {
|
|
|
|
"fonts/A Damn Mess.ttf", "fonts/Abberancy.ttf", "fonts/Abduction.ttf",
|
|
|
|
"fonts/Paint Boy.ttf", "fonts/Schwarzwald.ttf", "fonts/Scissor Cuts.ttf",
|
2011-07-29 15:57:27 +08:00
|
|
|
};
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
static int vAlignIdx = 0;
|
|
|
|
static TextVAlignment verticalAlignment[] = {
|
2013-07-27 07:04:21 +08:00
|
|
|
TextVAlignment::TOP,
|
|
|
|
TextVAlignment::CENTER,
|
|
|
|
TextVAlignment::BOTTOM,
|
2012-06-15 15:10:40 +08:00
|
|
|
};
|
2011-07-29 15:57:27 +08:00
|
|
|
|
2015-04-22 10:20:21 +08:00
|
|
|
FontTests::FontTests()
|
|
|
|
{
|
|
|
|
for (auto& fontFile : fontList)
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
addTestCase("FontTests", [&]() {
|
|
|
|
vAlignIdx = 0;
|
|
|
|
return FontTest::create(fontFile);
|
|
|
|
});
|
2015-04-22 10:20:21 +08:00
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2015-04-22 10:20:21 +08:00
|
|
|
for (auto& fontFile : fontList)
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
addTestCase("FontTests", [&]() {
|
|
|
|
vAlignIdx = 1;
|
|
|
|
return FontTest::create(fontFile);
|
|
|
|
});
|
2015-04-22 10:20:21 +08:00
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2015-04-22 10:20:21 +08:00
|
|
|
for (auto& fontFile : fontList)
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
addTestCase("FontTests", [&]() {
|
|
|
|
vAlignIdx = 2;
|
|
|
|
return FontTest::create(fontFile);
|
|
|
|
});
|
2015-04-22 10:20:21 +08:00
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
ADD_TEST_CASE(FontNoReplacementTest);
|
2015-04-22 10:20:21 +08:00
|
|
|
}
|
|
|
|
|
2021-12-28 15:58:56 +08:00
|
|
|
void FontTest::showFont(std::string_view fontFile)
|
2011-07-29 15:57:27 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
auto blockSize = Size(s.width / 3, 200);
|
2012-08-01 15:30:12 +08:00
|
|
|
float fontSize = 26;
|
2012-06-12 11:16:31 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
removeChildByTag(kTagLabel1, true);
|
|
|
|
removeChildByTag(kTagLabel2, true);
|
|
|
|
removeChildByTag(kTagLabel3, true);
|
|
|
|
removeChildByTag(kTagLabel4, true);
|
2013-04-24 14:49:52 +08:00
|
|
|
removeChildByTag(kTagColor1, true);
|
|
|
|
removeChildByTag(kTagColor2, true);
|
|
|
|
removeChildByTag(kTagColor3, true);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
auto top = Label::createWithSystemFont(fontFile, fontFile, 24);
|
|
|
|
auto left = Label::createWithSystemFont("alignment left", fontFile, fontSize, blockSize, TextHAlignment::LEFT,
|
|
|
|
verticalAlignment[vAlignIdx]);
|
|
|
|
auto center = Label::createWithSystemFont("alignment center", fontFile, fontSize, blockSize, TextHAlignment::CENTER,
|
|
|
|
verticalAlignment[vAlignIdx]);
|
|
|
|
auto right = Label::createWithSystemFont("alignment right", fontFile, fontSize, blockSize, TextHAlignment::RIGHT,
|
|
|
|
verticalAlignment[vAlignIdx]);
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
auto leftColor = LayerColor::create(Color4B(100, 100, 100, 255), blockSize.width, blockSize.height);
|
2013-08-16 16:05:27 +08:00
|
|
|
auto centerColor = LayerColor::create(Color4B(200, 100, 100, 255), blockSize.width, blockSize.height);
|
2021-12-28 16:06:23 +08:00
|
|
|
auto rightColor = LayerColor::create(Color4B(100, 100, 200, 255), blockSize.width, blockSize.height);
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2016-04-25 19:43:42 +08:00
|
|
|
leftColor->setIgnoreAnchorPointForPosition(false);
|
|
|
|
centerColor->setIgnoreAnchorPointForPosition(false);
|
|
|
|
rightColor->setIgnoreAnchorPointForPosition(false);
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
top->setAnchorPoint(Vec2(0.5, 1));
|
2021-12-28 16:06:23 +08:00
|
|
|
left->setAnchorPoint(Vec2(0, 0.5));
|
|
|
|
leftColor->setAnchorPoint(Vec2(0, 0.5));
|
|
|
|
center->setAnchorPoint(Vec2(0, 0.5));
|
|
|
|
centerColor->setAnchorPoint(Vec2(0, 0.5));
|
|
|
|
right->setAnchorPoint(Vec2(0, 0.5));
|
|
|
|
rightColor->setAnchorPoint(Vec2(0, 0.5));
|
|
|
|
|
|
|
|
top->setPosition(s.width / 2, s.height - 20);
|
|
|
|
left->setPosition(0, s.height / 2);
|
2012-06-15 15:10:40 +08:00
|
|
|
leftColor->setPosition(left->getPosition());
|
2021-12-28 16:06:23 +08:00
|
|
|
center->setPosition(blockSize.width, s.height / 2);
|
2012-06-15 15:10:40 +08:00
|
|
|
centerColor->setPosition(center->getPosition());
|
2021-12-28 16:06:23 +08:00
|
|
|
right->setPosition(blockSize.width * 2, s.height / 2);
|
2012-06-15 15:10:40 +08:00
|
|
|
rightColor->setPosition(right->getPosition());
|
|
|
|
|
2013-04-24 14:49:52 +08:00
|
|
|
this->addChild(leftColor, -1, kTagColor1);
|
2012-06-15 15:10:40 +08:00
|
|
|
this->addChild(left, 0, kTagLabel1);
|
2013-04-24 14:49:52 +08:00
|
|
|
this->addChild(rightColor, -1, kTagColor2);
|
2012-06-15 15:10:40 +08:00
|
|
|
this->addChild(right, 0, kTagLabel2);
|
2013-04-24 14:49:52 +08:00
|
|
|
this->addChild(centerColor, -1, kTagColor3);
|
2012-06-15 15:10:40 +08:00
|
|
|
this->addChild(center, 0, kTagLabel3);
|
2012-06-12 11:16:31 +08:00
|
|
|
this->addChild(top, 0, kTagLabel4);
|
2011-07-29 15:57:27 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string FontTest::title() const
|
2011-07-29 15:57:27 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Font test";
|
2011-07-29 15:57:27 +08:00
|
|
|
}
|
2016-11-18 09:23:44 +08:00
|
|
|
|
|
|
|
FontNoReplacementTest* FontNoReplacementTest::create()
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
auto ret = new FontNoReplacementTest;
|
|
|
|
if (ret->init())
|
|
|
|
{
|
|
|
|
ret->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete ret;
|
|
|
|
ret = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2016-11-18 09:23:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
FontNoReplacementTest::FontNoReplacementTest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
FontNoReplacementTest::~FontNoReplacementTest()
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
// need to clear the caches since we change the lookup dictionary after the application init.
|
|
|
|
FontAtlasCache::unloadFontAtlasTTF("fonts/A Damn Mess.ttf");
|
|
|
|
FontFreeType::releaseFont("fonts/A Damn Mess.ttf");
|
|
|
|
FontAtlasCache::unloadFontAtlasTTF("fonts/Abberancy.ttf");
|
|
|
|
FontFreeType::releaseFont("fonts/Abberancy.ttf");
|
|
|
|
FontAtlasCache::unloadFontAtlasTTF("fonts/Abduction.ttf");
|
|
|
|
FontFreeType::releaseFont("fonts/Abduction.ttf");
|
|
|
|
FontAtlasCache::unloadFontAtlasTTF("fonts/Schwarzwald.ttf");
|
|
|
|
FontFreeType::releaseFont("fonts/Schwarzwald.ttf");
|
2016-11-18 09:23:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void FontNoReplacementTest::onEnter()
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
TestCase::onEnter();
|
|
|
|
|
|
|
|
std::string suffix;
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
auto blockSize = Size(s.width / 3, 200);
|
|
|
|
float fontSize = 26;
|
|
|
|
|
|
|
|
removeChildByTag(kTagLabel1, true);
|
|
|
|
removeChildByTag(kTagLabel2, true);
|
|
|
|
removeChildByTag(kTagLabel3, true);
|
|
|
|
removeChildByTag(kTagLabel4, true);
|
|
|
|
removeChildByTag(kTagColor1, true);
|
|
|
|
removeChildByTag(kTagColor2, true);
|
|
|
|
removeChildByTag(kTagColor3, true);
|
|
|
|
|
|
|
|
auto top = Label::createWithTTF("fonts/A Damn Mess.ttf" + suffix, "fonts/A Damn Mess.ttf", 24);
|
|
|
|
auto left = Label::createWithTTF("fonts/Abberancy.ttf" + suffix, "fonts/Abberancy.ttf", fontSize, blockSize,
|
|
|
|
TextHAlignment::LEFT, verticalAlignment[0]);
|
|
|
|
auto center = Label::createWithTTF("fonts/Abduction.ttf" + suffix, "fonts/Abduction.ttf", fontSize, blockSize,
|
|
|
|
TextHAlignment::CENTER, verticalAlignment[0]);
|
|
|
|
auto right = Label::createWithTTF("fonts/Schwarzwald.ttf" + suffix, "fonts/Schwarzwald.ttf", fontSize, blockSize,
|
|
|
|
TextHAlignment::RIGHT, verticalAlignment[0]);
|
|
|
|
|
|
|
|
auto leftColor = LayerColor::create(Color4B(100, 100, 100, 255), blockSize.width, blockSize.height);
|
|
|
|
auto centerColor = LayerColor::create(Color4B(200, 100, 100, 255), blockSize.width, blockSize.height);
|
|
|
|
auto rightColor = LayerColor::create(Color4B(100, 100, 200, 255), blockSize.width, blockSize.height);
|
|
|
|
|
|
|
|
leftColor->setIgnoreAnchorPointForPosition(false);
|
|
|
|
centerColor->setIgnoreAnchorPointForPosition(false);
|
|
|
|
rightColor->setIgnoreAnchorPointForPosition(false);
|
|
|
|
|
|
|
|
top->setAnchorPoint(Vec2(0.5, 1));
|
|
|
|
left->setAnchorPoint(Vec2(0, 0.5));
|
|
|
|
leftColor->setAnchorPoint(Vec2(0, 0.5));
|
|
|
|
center->setAnchorPoint(Vec2(0, 0.5));
|
|
|
|
centerColor->setAnchorPoint(Vec2(0, 0.5));
|
|
|
|
right->setAnchorPoint(Vec2(0, 0.5));
|
|
|
|
rightColor->setAnchorPoint(Vec2(0, 0.5));
|
|
|
|
|
|
|
|
top->setPosition(s.width / 2, s.height - 20);
|
|
|
|
left->setPosition(0, s.height / 2);
|
|
|
|
leftColor->setPosition(left->getPosition());
|
|
|
|
center->setPosition(blockSize.width, s.height / 2);
|
|
|
|
centerColor->setPosition(center->getPosition());
|
|
|
|
right->setPosition(blockSize.width * 2, s.height / 2);
|
|
|
|
rightColor->setPosition(right->getPosition());
|
|
|
|
|
|
|
|
this->addChild(leftColor, -1, kTagColor1);
|
|
|
|
this->addChild(left, 0, kTagLabel1);
|
|
|
|
this->addChild(rightColor, -1, kTagColor2);
|
|
|
|
this->addChild(right, 0, kTagLabel2);
|
|
|
|
this->addChild(centerColor, -1, kTagColor3);
|
|
|
|
this->addChild(center, 0, kTagLabel3);
|
|
|
|
this->addChild(top, 0, kTagLabel4);
|
2016-11-18 09:23:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string FontNoReplacementTest::title() const
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
return "Font no replacement test";
|
2016-11-18 09:23:44 +08:00
|
|
|
}
|