- // Convert UTF-8 string to unicode string
- const std::size_t length = fribidi_charset_to_unicode( FRIBIDI_CHAR_SET_UTF8, textToBeConverted.c_str(), stringSize, logicalStr );
-
- if( 0u == length )
- {
- DALI_ASSERT_DEBUG( !"TextProcessor::ConvertBidirectionalText. Error when calling at fribidi_charset_to_unicode" );
-
- return;
- }
-
- logicalToVisualMap.resize( length );
- visualToLogicalMap.resize( length );
-
- // Convert and reorder the string as specified by the Unicode Bidirectional Algorithm
- FriBidiCharType baseDirection = FRIBIDI_TYPE_ON;
- fribidi_boolean log2vis = fribidi_log2vis( logicalStr, length, &baseDirection, visualStr, &logicalToVisualMap[0u], &visualToLogicalMap[0u], NULL );
-
- if(log2vis)
- {
- // Convert the unicode string back to the UTF-8 string
- std::vector<char> bidiTextConverted;
-
- bidiTextConverted.resize( length * 4u + 1u ); // Maximum bytes to represent one UTF-8 character is 6.
- // Currently Dali doesn't support this UTF-8 extension. Dali only supports 'regular' UTF-8 which has a maximum of 4 bytes per character.
-
- fribidi_unicode_to_charset( FRIBIDI_CHAR_SET_UTF8, visualStr, length, &bidiTextConverted[0u] );
-
- textToBeConverted = &bidiTextConverted[0u];
-
- // After reorder the text, rebuild the text with the original styles is needed.
- // To assign the original style is needed to use the characterLogicalToVisualMap table.
- Text text( &bidiTextConverted[0u] );
-
- // Split the line in words.
- // Add the correct styles for the characters after they are reordered.
-
- for( size_t i = 0u; i < length; ++i )
- {
- const Character character( text[i] );
-
- MarkupProcessor::StyledText styledText;
- styledText.mText.Append( character );
- styledText.mStyle = line[visualToLogicalMap[i]].mStyle;
-
- convertedText.push_back( styledText );
- }
- }