#include <dali-test-suite-utils.h>
#include <dali/dali.h>
+#include <dali/devel-api/text-abstraction/bitmap-font.h>
#include <dali/devel-api/text-abstraction/font-client.h>
#include <dali/internal/text/text-abstraction/plugin/font-client-utils.h>
#include <stdint.h>
// Block's width or height are less than 512
tet_infoline("UtcDaliFontClientAtlasLimitationEnabled PointSize=200");
- uint32_t pointSize200 = 200 * TextAbstraction::FontClient::NUMBER_OF_POINTS_PER_ONE_UNIT_OF_POINT_SIZE;
- TextAbstraction::FontId fontId200 = fontClient.GetFontId(fontDescription, pointSize200);
- TextAbstraction::FontClient::GlyphBufferData glyphBufferData200;
+ uint32_t pointSize200 = 200 * TextAbstraction::FontClient::NUMBER_OF_POINTS_PER_ONE_UNIT_OF_POINT_SIZE;
+ TextAbstraction::FontId fontId200 = fontClient.GetFontId(fontDescription, pointSize200);
+ TextAbstraction::GlyphBufferData glyphBufferData200;
glyphBufferData200.width = 0;
glyphBufferData200.height = 0;
fontClient.CreateBitmap(fontId200, 68, false, false, glyphBufferData200, 0);
// Block's width or height are greater than 512 and less than 1024
uint32_t pointSize1000 = 1000 * TextAbstraction::FontClient::NUMBER_OF_POINTS_PER_ONE_UNIT_OF_POINT_SIZE;
tet_infoline("UtcDaliFontClientAtlasLimitationEnabled PointSize=1000");
- TextAbstraction::FontId fontId1000 = fontClient.GetFontId(fontDescription, pointSize1000);
- TextAbstraction::FontClient::GlyphBufferData glyphBufferData1000;
+ TextAbstraction::FontId fontId1000 = fontClient.GetFontId(fontDescription, pointSize1000);
+ TextAbstraction::GlyphBufferData glyphBufferData1000;
glyphBufferData1000.width = 0;
glyphBufferData1000.height = 0;
fontClient.CreateBitmap(fontId1000, 68, false, false, glyphBufferData1000, 0);
// Block's width or height are greater than 1024 and less than 2048
uint32_t pointSize2000 = 2000 * TextAbstraction::FontClient::NUMBER_OF_POINTS_PER_ONE_UNIT_OF_POINT_SIZE;
tet_infoline("UtcDaliFontClientAtlasLimitationEnabled PointSize=2000");
- TextAbstraction::FontId fontId2000 = fontClient.GetFontId(fontDescription, pointSize2000);
- TextAbstraction::FontClient::GlyphBufferData glyphBufferData2000;
+ TextAbstraction::FontId fontId2000 = fontClient.GetFontId(fontDescription, pointSize2000);
+ TextAbstraction::GlyphBufferData glyphBufferData2000;
glyphBufferData2000.width = 0;
glyphBufferData2000.height = 0;
fontClient.CreateBitmap(fontId2000, 68, false, false, glyphBufferData2000, 0);
// Block's width or height are less than 512
tet_infoline("UtcDaliFontClientAtlasLimitationDisabled PointSize=200");
- uint32_t pointSize200 = 200 * TextAbstraction::FontClient::NUMBER_OF_POINTS_PER_ONE_UNIT_OF_POINT_SIZE;
- TextAbstraction::FontId fontId200 = fontClient.GetFontId(fontDescription, pointSize200);
- TextAbstraction::FontClient::GlyphBufferData glyphBufferData200;
+ uint32_t pointSize200 = 200 * TextAbstraction::FontClient::NUMBER_OF_POINTS_PER_ONE_UNIT_OF_POINT_SIZE;
+ TextAbstraction::FontId fontId200 = fontClient.GetFontId(fontDescription, pointSize200);
+ TextAbstraction::GlyphBufferData glyphBufferData200;
glyphBufferData200.width = 0;
glyphBufferData200.height = 0;
fontClient.CreateBitmap(fontId200, 68, false, false, glyphBufferData200, 0);
// Block's width or height are greater than 512 and less than 1024
tet_infoline("UtcDaliFontClientAtlasLimitationDisabled PointSize=1000");
- uint32_t pointSize1000 = 1000 * TextAbstraction::FontClient::NUMBER_OF_POINTS_PER_ONE_UNIT_OF_POINT_SIZE;
- TextAbstraction::FontId fontId1000 = fontClient.GetFontId(fontDescription, pointSize1000);
- TextAbstraction::FontClient::GlyphBufferData glyphBufferData1000;
+ uint32_t pointSize1000 = 1000 * TextAbstraction::FontClient::NUMBER_OF_POINTS_PER_ONE_UNIT_OF_POINT_SIZE;
+ TextAbstraction::FontId fontId1000 = fontClient.GetFontId(fontDescription, pointSize1000);
+ TextAbstraction::GlyphBufferData glyphBufferData1000;
glyphBufferData1000.width = 0;
glyphBufferData1000.height = 0;
fontClient.CreateBitmap(fontId1000, 68, false, false, glyphBufferData1000, 0);
// Block's width or height are greater than 1024 and less than 2048
tet_infoline("UtcDaliFontClientAtlasLimitationDisabled PointSize=2000");
- uint32_t pointSize2000 = 2000 * TextAbstraction::FontClient::NUMBER_OF_POINTS_PER_ONE_UNIT_OF_POINT_SIZE;
- TextAbstraction::FontId fontId2000 = fontClient.GetFontId(fontDescription, pointSize2000);
- TextAbstraction::FontClient::GlyphBufferData glyphBufferData2000;
+ uint32_t pointSize2000 = 2000 * TextAbstraction::FontClient::NUMBER_OF_POINTS_PER_ONE_UNIT_OF_POINT_SIZE;
+ TextAbstraction::FontId fontId2000 = fontClient.GetFontId(fontDescription, pointSize2000);
+ TextAbstraction::GlyphBufferData glyphBufferData2000;
glyphBufferData2000.width = 0;
glyphBufferData2000.height = 0;
fontClient.CreateBitmap(fontId2000, 68, false, false, glyphBufferData2000, 0);
DALI_TEST_GREATER(1024u, glyphBufferData2000.width, TEST_LOCATION); //924u
DALI_TEST_GREATER(glyphBufferData2000.height, 1024u, TEST_LOCATION); //1148u
+ // Test GlyphBufferData move
+ TextAbstraction::GlyphBufferData movedGlyphBufferData2000 = std::move(glyphBufferData2000);
+
+ for(int i = 0; i < 50; ++i)
+ {
+ TextAbstraction::GlyphBufferData dummy = std::move(movedGlyphBufferData2000);
+ movedGlyphBufferData2000 = std::move(dummy);
+
+ // Test moved GlyphBufferData destruct well
+ }
+
+ DALI_TEST_GREATER(1024u, movedGlyphBufferData2000.width, TEST_LOCATION); //924u
+ DALI_TEST_GREATER(movedGlyphBufferData2000.height, 1024u, TEST_LOCATION); //1148u
+
END_TEST;
}
Size maximumTextAtlasSize = fontClient.GetMaximumTextAtlasSize();
Size currentMaximumBlockSizeFitInAtlas = fontClient.GetCurrentMaximumBlockSizeFitInAtlas();
- tet_infoline("CurrentMaximumBlockSizeFitInAtlas start with default ");
- DALI_TEST_EQUALS(currentMaximumBlockSizeFitInAtlas, defaultTextAtlasSize, TEST_LOCATION);
+ // TODO : This UTC pass only if we don't create fontClient plugin. Currently we always create plugin at Get API, due to performance
+ //tet_infoline("CurrentMaximumBlockSizeFitInAtlas start with default ");
+ //DALI_TEST_EQUALS(currentMaximumBlockSizeFitInAtlas, defaultTextAtlasSize, TEST_LOCATION);
+
+ currentMaximumBlockSizeFitInAtlas = defaultTextAtlasSize;
tet_infoline("SetCurrentMaximumBlockSizeFitInAtlas is changed with current ");
isChanged = fontClient.SetCurrentMaximumBlockSizeFitInAtlas(currentMaximumBlockSizeFitInAtlas);
return o;
}
-int UtcDaliFontClientFindFallbackFont(void)
+int UtcDaliFontClientGetDefaultPlatformFontDescription(void)
{
TestApplication application;
- tet_infoline(" UtcDaliFontClientFindFallbackFont ");
+ tet_infoline(" UtcDaliFontClientGetDefaultPlatformFontDescription");
FontClient fontClient;
fontClient = FontClient::Get();
- FontList fontList;
- fontClient.GetSystemFonts(fontList);
- DALI_TEST_CHECK(fontList.size() > 0);
-
- const std::string emptyString;
- FontDescription fontDescription;
- fontDescription.width = FontWidth::NORMAL;
- fontDescription.weight = FontWeight::NORMAL;
- fontDescription.slant = FontSlant::NORMAL;
- fontDescription.type = FontDescription::BITMAP_FONT;
+ FontDescription fontDescription;
+ fontClient.GetDefaultPlatformFontDescription(fontDescription);
std::ostringstream oss;
oss << fontDescription;
- tet_printf("Looking for: %s", oss.str().c_str());
+ tet_printf("%s", oss.str().c_str());
+
+ DALI_TEST_CHECK(fontDescription.path.empty() == false);
FontId fontId = fontClient.FindFallbackFont('A',
fontDescription,
FontClient::DEFAULT_POINT_SIZE,
true);
- DALI_TEST_CHECK(fontId != 0);
-
- fontClient.GetDescription(fontId, fontDescription);
- oss.clear();
- oss << fontDescription;
- tet_printf("Found: %d: %s", fontId, oss.str().c_str());
- bool color = fontClient.IsColorGlyph(fontId, fontClient.GetGlyphIndex(fontId, 'A'));
- DALI_TEST_CHECK(color || 1);
+ bool supported = fontClient.IsCharacterSupportedByFont(fontId, 'A');
+ DALI_TEST_EQUALS(supported, true, TEST_LOCATION);
END_TEST;
}
-int UtcDaliFontClientGetDefaultPlatformFontDescription(void)
+namespace
+{
+constexpr uint8_t U1 = 1u;
+constexpr uint8_t U2 = 2u;
+constexpr uint8_t U3 = 3u;
+constexpr uint8_t U4 = 4u;
+constexpr uint8_t U5 = 5u;
+constexpr uint8_t U6 = 6u;
+constexpr uint8_t U0 = 0u;
+constexpr uint8_t UTF8_LENGTH[256] = {
+ U1, U1, U1, U1, U1, U1, U1, U1, U1, U1, //
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1, //
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1, //
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1, //
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1, //
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1, //
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1, //
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1, //
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1, // lead byte = 0xxx xxxx (U+0000 - U+007F + some extended ascii characters)
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1, //
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1, //
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1, //
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1, //
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1, //
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1, //
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1, //
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1, //
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1, //
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1,
+ U1, //
+ U1,
+ U1, //
+
+ U2,
+ U2,
+ U2,
+ U2,
+ U2,
+ U2,
+ U2,
+ U2,
+ U2,
+ U2, //
+ U2,
+ U2,
+ U2,
+ U2,
+ U2,
+ U2,
+ U2,
+ U2,
+ U2,
+ U2, // lead byte = 110x xxxx (U+0080 - U+07FF)
+ U2,
+ U2,
+ U2,
+ U2,
+ U2,
+ U2,
+ U2,
+ U2,
+ U2,
+ U2, //
+ U2,
+ U2, //
+
+ U3,
+ U3,
+ U3,
+ U3,
+ U3,
+ U3,
+ U3,
+ U3,
+ U3,
+ U3, // lead byte = 1110 xxxx (U+0800 - U+FFFF)
+ U3,
+ U3,
+ U3,
+ U3,
+ U3,
+ U3, //
+
+ U4,
+ U4,
+ U4,
+ U4,
+ U4,
+ U4,
+ U4,
+ U4, // lead byte = 1111 0xxx (U+10000 - U+1FFFFF)
+
+ U5,
+ U5,
+ U5,
+ U5, // lead byte = 1111 10xx (U+200000 - U+3FFFFFF)
+
+ U6,
+ U6, // lead byte = 1111 110x (U+4000000 - U+7FFFFFFF)
+
+ U0,
+ U0, // Non valid.
+};
+
+constexpr uint8_t CR = 0xd;
+constexpr uint8_t LF = 0xa;
+
+uint8_t GetUtf8Length(uint8_t utf8LeadByte)
+{
+ return UTF8_LENGTH[utf8LeadByte];
+}
+
+uint32_t Utf8ToUtf32(const uint8_t* const utf8, uint32_t length, uint32_t* utf32)
+{
+ uint32_t numberOfCharacters = 0u;
+
+ const uint8_t* begin = utf8;
+ const uint8_t* end = utf8 + length;
+
+ for(; begin < end; ++numberOfCharacters)
+ {
+ const uint8_t leadByte = *begin;
+
+ switch(UTF8_LENGTH[leadByte])
+ {
+ case U1:
+ {
+ if(CR == leadByte)
+ {
+ // Replace CR+LF or CR by LF
+ *utf32++ = LF;
+
+ // Look ahead if the next one is a LF.
+ ++begin;
+ if(begin < end)
+ {
+ if(LF == *begin)
+ {
+ ++begin;
+ }
+ }
+ }
+ else
+ {
+ *utf32++ = leadByte;
+ begin++;
+ }
+ break;
+ }
+
+ case U2:
+ {
+ uint32_t& code = *utf32++;
+ code = leadByte & 0x1fu;
+ begin++;
+ code <<= 6u;
+ code |= *begin++ & 0x3fu;
+ break;
+ }
+
+ case U3:
+ {
+ uint32_t& code = *utf32++;
+ code = leadByte & 0x0fu;
+ begin++;
+ code <<= 6u;
+ code |= *begin++ & 0x3fu;
+ code <<= 6u;
+ code |= *begin++ & 0x3fu;
+ break;
+ }
+
+ case U4:
+ {
+ uint32_t& code = *utf32++;
+ code = leadByte & 0x07u;
+ begin++;
+ code <<= 6u;
+ code |= *begin++ & 0x3fu;
+ code <<= 6u;
+ code |= *begin++ & 0x3fu;
+ code <<= 6u;
+ code |= *begin++ & 0x3fu;
+ break;
+ }
+
+ case U5:
+ {
+ uint32_t& code = *utf32++;
+ code = leadByte & 0x03u;
+ begin++;
+ code <<= 6u;
+ code |= *begin++ & 0x3fu;
+ code <<= 6u;
+ code |= *begin++ & 0x3fu;
+ code <<= 6u;
+ code |= *begin++ & 0x3fu;
+ code <<= 6u;
+ code |= *begin++ & 0x3fu;
+ break;
+ }
+
+ case U6:
+ {
+ uint32_t& code = *utf32++;
+ code = leadByte & 0x01u;
+ begin++;
+ code <<= 6u;
+ code |= *begin++ & 0x3fu;
+ code <<= 6u;
+ code |= *begin++ & 0x3fu;
+ code <<= 6u;
+ code |= *begin++ & 0x3fu;
+ code <<= 6u;
+ code |= *begin++ & 0x3fu;
+ code <<= 6u;
+ code |= *begin++ & 0x3fu;
+ break;
+ }
+
+ case U0: // Invalid case
+ {
+ begin++;
+ *utf32++ = 0x20; // Use white space
+ break;
+ }
+ }
+ }
+
+ return numberOfCharacters;
+}
+
+TextAbstraction::FontId SetupBitmapFont()
+{
+ struct GlyphDesc
+ {
+ GlyphDesc()
+ {
+ }
+ GlyphDesc(const std::string& url, const std::string& utf8)
+ {
+ this->url = url;
+ std::copy(utf8.begin(), utf8.end(), this->utf8);
+ }
+ std::string url;
+ uint8_t utf8[4];
+ };
+ std::vector<GlyphDesc> glyphs;
+
+ glyphs.push_back({TEST_RESOURCE_DIR "/fonts/bitmap/u0030.png", ":"});
+ glyphs.push_back({TEST_RESOURCE_DIR "/fonts/bitmap/u0031.png", "0"});
+ glyphs.push_back({TEST_RESOURCE_DIR "/fonts/bitmap/u0032.png", "1"});
+ glyphs.push_back({TEST_RESOURCE_DIR "/fonts/bitmap/u0033.png", "2"});
+ glyphs.push_back({TEST_RESOURCE_DIR "/fonts/bitmap/u0034.png", "3"});
+ glyphs.push_back({TEST_RESOURCE_DIR "/fonts/bitmap/u0035.png", "4"});
+ glyphs.push_back({TEST_RESOURCE_DIR "/fonts/bitmap/u0036.png", "5"});
+ glyphs.push_back({TEST_RESOURCE_DIR "/fonts/bitmap/u0037.png", "6"});
+ glyphs.push_back({TEST_RESOURCE_DIR "/fonts/bitmap/u0038.png", "7"});
+ glyphs.push_back({TEST_RESOURCE_DIR "/fonts/bitmap/u0039.png", "8"});
+ glyphs.push_back({TEST_RESOURCE_DIR "/fonts/bitmap/u003a.png", "9"});
+
+ TextAbstraction::BitmapFont bitmapFont;
+ bitmapFont.glyphs.reserve(glyphs.size());
+ bitmapFont.name = "Digits";
+ bitmapFont.underlinePosition = 0.f;
+ bitmapFont.underlineThickness = 0.f;
+ bitmapFont.isColorFont = true;
+
+ for(const auto& glyph : glyphs)
+ {
+ uint32_t c = 0u;
+ Utf8ToUtf32(glyph.utf8, GetUtf8Length(glyph.utf8[0u]), &c);
+ TextAbstraction::BitmapGlyph bitmapGlyph(glyph.url, c, 34.f, 0.f);
+ bitmapFont.glyphs.push_back(std::move(bitmapGlyph));
+ }
+
+ TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
+ return fontClient.GetFontId(bitmapFont);
+}
+
+} // namespace
+
+int UtcDaliFontClientTestBitmapFont(void)
{
TestApplication application;
- tet_infoline(" UtcDaliFontClientGetDefaultPlatformFontDescription");
+ tet_infoline(" UtcDaliFontClientTestBitmapFont");
FontClient fontClient;
fontClient = FontClient::Get();
- FontDescription fontDescription;
- fontClient.GetDefaultPlatformFontDescription(fontDescription);
+ auto bitmapFontId = SetupBitmapFont();
+ FontDescription fontDescription;
+ fontClient.GetDescription(bitmapFontId, fontDescription);
std::ostringstream oss;
oss << fontDescription;
- tet_printf("%s", oss.str().c_str());
+ tet_printf("Found: %d: %s", bitmapFontId, oss.str().c_str());
- DALI_TEST_CHECK(fontDescription.path.empty() == false);
+ bool color = fontClient.IsColorGlyph(bitmapFontId, fontClient.GetGlyphIndex(bitmapFontId, '2'));
+ DALI_TEST_EQUALS(color, true, TEST_LOCATION);
- FontId fontId = fontClient.FindFallbackFont('A',
- fontDescription,
- FontClient::DEFAULT_POINT_SIZE,
- true);
+ DALI_TEST_EQUALS(fontClient.GetPointSize(bitmapFontId), FontClient::DEFAULT_POINT_SIZE, TEST_LOCATION);
+
+ DALI_TEST_EQUALS(fontClient.IsCharacterSupportedByFont(bitmapFontId, '3'), true, TEST_LOCATION);
+ DALI_TEST_EQUALS(fontClient.IsCharacterSupportedByFont(bitmapFontId, 'a'), false, TEST_LOCATION);
- bool supported = fontClient.IsCharacterSupportedByFont(fontId, 'A');
- DALI_TEST_EQUALS(supported, true, TEST_LOCATION);
END_TEST;
}