X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=text%2Fdali%2Finternal%2Ftext-abstraction%2Fshaping-impl.cpp;h=4d5fd6e63c4a7c1947b1c1315ccd7ec9dab58050;hb=ef68353604bc2f4b1eab022c1fdd2626eaff5eb1;hp=ae87d9448a1f2153b85ae921f28beaa0315d6439;hpb=12e0713584c2475eabbc49843029e193a819ac42;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git diff --git a/text/dali/internal/text-abstraction/shaping-impl.cpp b/text/dali/internal/text-abstraction/shaping-impl.cpp index ae87d94..4d5fd6e 100644 --- a/text/dali/internal/text-abstraction/shaping-impl.cpp +++ b/text/dali/internal/text-abstraction/shaping-impl.cpp @@ -29,6 +29,97 @@ #include #include +#include + +namespace +{ + +const static uint8_t U2 = 2u; +const static uint8_t U3 = 3u; +const static uint8_t U4 = 4u; + +uint32_t GetNumberOfUtf8Bytes( const uint32_t* const utf32, uint32_t numberOfCharacters ) +{ + uint32_t numberOfBytes = 0u; + + const uint32_t* begin = utf32; + const uint32_t* end = utf32 + numberOfCharacters; + + for( ; begin < end; ++begin ) + { + const uint32_t code = *begin; + + if( code < 0x80u ) + { + ++numberOfBytes; + } + else if( code < 0x800u ) + { + numberOfBytes += U2; + } + else if( code < 0x10000u ) + { + numberOfBytes += U3; + } + else if( code < 0x200000u ) + { + numberOfBytes += U4; + } + } + + return numberOfBytes; +} + +uint32_t Utf32ToUtf8( const uint32_t* const utf32, uint32_t numberOfCharacters, uint8_t* utf8 ) +{ + const uint32_t* begin = utf32; + const uint32_t* end = utf32 + numberOfCharacters; + + uint8_t* utf8Begin = utf8; + + for( ; begin < end; ++begin ) + { + const uint32_t code = *begin; + + if( code < 0x80u ) + { + *utf8++ = code; + } + else if( code < 0x800u ) + { + *utf8++ = static_cast( code >> 6u ) | 0xc0u; // lead byte for 2 byte sequence + *utf8++ = static_cast( code & 0x3f ) | 0x80u; // continuation byte + } + else if( code < 0x10000u ) + { + *utf8++ = static_cast( code >> 12u ) | 0xe0u; // lead byte for 2 byte sequence + *utf8++ = static_cast( ( code >> 6u ) & 0x3f ) | 0x80u; // continuation byte + *utf8++ = static_cast( code & 0x3f ) | 0x80u; // continuation byte + } + else if( code < 0x200000u ) + { + *utf8++ = static_cast( code >> 18u ) | 0xf0u; // lead byte for 2 byte sequence + *utf8++ = static_cast( ( code >> 12u ) & 0x3f ) | 0x80u; // continuation byte + *utf8++ = static_cast( ( code >> 6u ) & 0x3f ) | 0x80u; // continuation byte + *utf8++ = static_cast( code & 0x3f ) | 0x80u; // continuation byte + } + } + + return utf8 - utf8Begin; +} + +void Utf32ToUtf8( const uint32_t* const utf32, uint32_t numberOfCharacters, std::string& utf8 ) +{ + utf8.clear(); + + uint32_t numberOfBytes = GetNumberOfUtf8Bytes( &utf32[0], numberOfCharacters ); + utf8.resize( numberOfBytes ); + + // This is a bit horrible but std::string returns a (signed) char* + Utf32ToUtf8( utf32, numberOfCharacters, reinterpret_cast(&utf8[0]) ); +} + +} namespace Dali { @@ -94,6 +185,13 @@ const hb_script_t SCRIPT_TO_HARFBUZZ[] = HB_SCRIPT_LAO, HB_SCRIPT_THAI, HB_SCRIPT_KHMER, + HB_SCRIPT_JAVANESE, + HB_SCRIPT_SUNDANESE, + + HB_SCRIPT_ETHIOPIC, + HB_SCRIPT_OL_CHIKI, + HB_SCRIPT_TAGALOG, + HB_SCRIPT_MEETEI_MAYEK, HB_SCRIPT_UNKNOWN, // EMOJI HB_SCRIPT_UNKNOWN, // SYMBOLS1 @@ -187,15 +285,24 @@ struct Shaping::Plugin hb_buffer_set_script( harfBuzzBuffer, SCRIPT_TO_HARFBUZZ[ script ] ); /* see hb-unicode.h */ - hb_buffer_set_language( harfBuzzBuffer, - hb_language_from_string( DEFAULT_LANGUAGE, - DEFAULT_LANGUAGE_LENGTH ) ); + + char* currentLocale = setlocale(LC_MESSAGES,NULL); + + std::istringstream stringStream( currentLocale ); + std::string localeString; + std::getline(stringStream, localeString, '_'); + hb_buffer_set_language( harfBuzzBuffer, hb_language_from_string( localeString.c_str(), localeString.size() ) ); /* Layout the text */ hb_buffer_add_utf32( harfBuzzBuffer, text, numberOfCharacters, 0u, numberOfCharacters ); hb_shape( harfBuzzFont, harfBuzzBuffer, NULL, 0u ); + std::string currentText; + Utf32ToUtf8( text, numberOfCharacters, currentText ); + + DALI_LOG_RELEASE_INFO( "Shape: currentText: %s, font: %s, pointSize: %d\n", currentText.c_str(), fontDescription.path.c_str(), static_cast( fontClient.GetPointSize( fontId ) * FROM_266 ) ); + /* Get glyph data */ unsigned int glyphCount; hb_glyph_info_t* glyphInfo = hb_buffer_get_glyph_infos( harfBuzzBuffer, &glyphCount ); @@ -254,6 +361,8 @@ struct Shaping::Plugin mOffset.PushBack( floor( glyphPositions[i].x_offset * FROM_266 ) ); mOffset.PushBack( floor( glyphPositions[i].y_offset * FROM_266 ) ); + DALI_LOG_RELEASE_INFO( "glyphIndex: %u, glyph.advance: %f, glyph.xBearing: %f\n", glyphInfo[i].codepoint, floor( glyphPositions[i].x_advance * FROM_266 ), floor( glyphPositions[i].x_offset * FROM_266 ) ); + ++i; } }