- // Clean vectors first. This function doesn't use any previous value.
- logicalToVisualMap.clear();
- visualToLogicalMap.clear();
- convertedText.clear();
-
- if( line.empty() )
- {
- // nothing to do if the line is empty.
- return;
- }
-
- // Get the plain text from the line to be reordered by the BiDirectional algorithm.
- std::string textToBeConverted;
- GetPlainString( line, textToBeConverted );
-
- const std::size_t stringSize = textToBeConverted.size();
-
- std::vector<FriBidiChar> logicalStrBuffer;
- std::vector<FriBidiChar> visualStrBuffer;
- // unicode length <= UTF-8 length in bytes (reserve one extra for terminator)
- // pad these buffers with 0's, as it's unclear what fribidi_log2vis does w.r.t.
- // the length of it's output content (appears the same as input content, and does
- // not seem to generate bidi marks i.e. FRIBIDI_CHAR_LRM/FRIBIDI_CHAR_RLM)
- logicalStrBuffer.resize( stringSize+1, 0 );
- visualStrBuffer.resize( stringSize+1, 0 );
- FriBidiChar *logicalStr( &logicalStrBuffer[0] );
- FriBidiChar *visualStr( &visualStrBuffer[0] );
-
- // 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( 0 == 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[0], &visualToLogicalMap[0], NULL );
-
- if(log2vis)
- {
- // Convert the unicode string back to the UTF-8 string
- std::vector<char> bidiTextConverted;
-
- bidiTextConverted.resize( length * 4 + 1 ); // 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[0] );
-
- textToBeConverted = &bidiTextConverted[0];
-
- // 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[0] );
-
- // Split the line in groups of words.
- // Words are grouped if they can be displayed left to right or right to left.
- // Add the correct styles for the characters after they are reordered.
-
- MarkupProcessor::StyledTextArray groupOfWords;