X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Fbidirectional-support.cpp;h=c09c03c529fdcbe6f1aad4a80b1b45d3c3b72741;hb=c284103e2575f3276ef70eee3953bea531484e29;hp=14fb1a754544e4cba684d4499a4ecc6dc2bfb583;hpb=2c7cfdb64f1a8281c8cbbe9531ec0b2ed779f915;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/text/bidirectional-support.cpp b/dali-toolkit/internal/text/bidirectional-support.cpp index 14fb1a7..c09c03c 100644 --- a/dali-toolkit/internal/text/bidirectional-support.cpp +++ b/dali-toolkit/internal/text/bidirectional-support.cpp @@ -19,7 +19,8 @@ #include // EXTERNAL INCLUDES -#include +#include +#include namespace Dali { @@ -113,8 +114,8 @@ void SetBidirectionalInfo( const Vector& text, const ScriptRun& scriptRun = *it; const CharacterIndex lastScriptRunIndex = scriptRun.characterRun.characterIndex + scriptRun.characterRun.numberOfCharacters; - if( TextAbstraction::IsRightToLeftScript( scriptRun.script ) && // The script is right to left. - ( lastScriptRunIndex > paragraphCharacterIndex ) ) // It isn't part of a previous paragraph. + if( ( lastScriptRunIndex > paragraphCharacterIndex ) && // It isn't part of a previous paragraph. + TextAbstraction::IsRightToLeftScript( scriptRun.script ) ) // The script is right to left. { // Find the paragraphs which contains this script run. // Consider: @@ -161,15 +162,8 @@ void SetBidirectionalInfo( const Vector& text, } } -void ReplaceBidirectionalInfo( LogicalModel& model, - CharacterIndex characterIndex, - Length numberOfCharactersToRemove, - Length numberOfCharactersToInsert ) -{ -} - void ReorderLines( const Vector& bidirectionalInfo, - const Vector& lineRuns, + Vector& lineRuns, Vector& lineInfoRuns ) { // Handle to the bidirectional info module in text-abstraction. @@ -185,6 +179,7 @@ void ReorderLines( const Vector& bidirectionalInf ++it ) { const BidirectionalParagraphInfoRun& paragraphInfo = *it; + const CharacterDirection direction = bidirectionalSupport.GetParagraphDirection( paragraphInfo.bidirectionalInfoIndex ); // Get the lines for this paragraph. unsigned int firstLine = 0u; @@ -200,27 +195,34 @@ void ReorderLines( const Vector& bidirectionalInf lineIndex = firstLine + numberOfLines; // Traverse the lines and reorder them - for( Vector::ConstIterator lineIt = lineRuns.Begin() + firstLine, + for( Vector::Iterator lineIt = lineRuns.Begin() + firstLine, endLineIt = lineRuns.Begin() + firstLine + numberOfLines; lineIt != endLineIt; ++lineIt ) { - const LineRun& line = *lineIt; + LineRun& line = *lineIt; + + // Sets the paragraph's direction. + line.direction = direction; // Creates a bidirectional info for the line run. BidirectionalLineInfoRun lineInfoRun; lineInfoRun.characterRun.characterIndex = line.characterRun.characterIndex; lineInfoRun.characterRun.numberOfCharacters = line.characterRun.numberOfCharacters; + lineInfoRun.direction = direction; // Allocate space for the conversion maps. // The memory is freed after the visual to logical to visual conversion tables are built in the logical model. lineInfoRun.visualToLogicalMap = reinterpret_cast( malloc( line.characterRun.numberOfCharacters * sizeof( CharacterIndex ) ) ); - // Reorders the line. - bidirectionalSupport.Reorder( paragraphInfo.bidirectionalInfoIndex, - line.characterRun.characterIndex, - line.characterRun.numberOfCharacters, - lineInfoRun.visualToLogicalMap ); + if( NULL != lineInfoRun.visualToLogicalMap ) + { + // Reorders the line. + bidirectionalSupport.Reorder( paragraphInfo.bidirectionalInfoIndex, + line.characterRun.characterIndex - paragraphInfo.characterRun.characterIndex, + line.characterRun.numberOfCharacters, + lineInfoRun.visualToLogicalMap ); + } // Push the run into the vector. lineInfoRuns.PushBack( lineInfoRun ); @@ -228,12 +230,65 @@ void ReorderLines( const Vector& bidirectionalInf } } -void ReorderLines( LogicalModel& logicalModel, - const VisualModel& visualModel, - CharacterIndex characterIndex, - Length numberOfCharactersToRemove, - Length numberOfCharactersToInsert ) +bool GetMirroredText( const Vector& text, + const Vector& directions, + const Vector& bidirectionalInfo, + Vector& mirroredText ) +{ + bool hasTextMirrored = false; + + // Handle to the bidirectional info module in text-abstraction. + TextAbstraction::BidirectionalSupport bidirectionalSupport = TextAbstraction::BidirectionalSupport::Get(); + + mirroredText = text; + + Character* mirroredTextBuffer = mirroredText.Begin(); + CharacterDirection* directionsBuffer = directions.Begin(); + + // Traverse the paragraphs and mirror the right to left ones. + for( Vector::ConstIterator it = bidirectionalInfo.Begin(), + endIt = bidirectionalInfo.End(); + it != endIt; + ++it ) + { + const BidirectionalParagraphInfoRun& paragraph = *it; + + const bool tmpMirrored = bidirectionalSupport.GetMirroredText( mirroredTextBuffer + paragraph.characterRun.characterIndex, + directionsBuffer + paragraph.characterRun.characterIndex, + paragraph.characterRun.numberOfCharacters ); + + hasTextMirrored = hasTextMirrored || tmpMirrored; + } + + return hasTextMirrored; +} + +void GetCharactersDirection( const Vector& bidirectionalInfo, + Vector& directions ) { + // Handle to the bidirectional info module in text-abstraction. + TextAbstraction::BidirectionalSupport bidirectionalSupport = TextAbstraction::BidirectionalSupport::Get(); + + CharacterIndex index = 0u; + CharacterDirection* directionsBuffer = directions.Begin(); + for( Vector::ConstIterator it = bidirectionalInfo.Begin(), + endIt = bidirectionalInfo.End(); + it != endIt; + ++it ) + { + const BidirectionalParagraphInfoRun& paragraph = *it; + + // Fills with left to right those paragraphs without right to left characters. + memset( directionsBuffer + index, false, ( paragraph.characterRun.characterIndex - index ) * sizeof( bool ) ); + index += paragraph.characterRun.numberOfCharacters; + + bidirectionalSupport.GetCharactersDirection( paragraph.bidirectionalInfoIndex, + directionsBuffer + paragraph.characterRun.characterIndex, + paragraph.characterRun.numberOfCharacters ); + } + + // Fills with left to right those paragraphs without right to left characters. + memset( directionsBuffer + index, false, ( directions.Count() - index ) * sizeof( bool ) ); } } // namespace Text