X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Fbidirectional-support.cpp;h=165ae0d4b4872a98d731bc673c3a4a20397b2b61;hp=9f9bddce6d57cbac24630ed49193da0aa8e4393c;hb=528aa3699cd51dab5115bca1aaebb65d4bc67c15;hpb=7c17cd67c31718258dc619565b07e8864f8eaea7 diff --git a/dali-toolkit/internal/text/bidirectional-support.cpp b/dali-toolkit/internal/text/bidirectional-support.cpp index 9f9bddc..165ae0d 100755 --- a/dali-toolkit/internal/text/bidirectional-support.cpp +++ b/dali-toolkit/internal/text/bidirectional-support.cpp @@ -31,58 +31,6 @@ namespace Toolkit namespace Text { -namespace -{ - -/** - * @brief Get the lines of a paragraph. - * - * @param[in] paragraphInfo The paragraph. - * @param[in] lines The lines. - * @param[in] lineIndex Index pointing the first line to be checked. - * @param[out] firstLine Index to the first line of the paragraph. - * @param[out] numberOfLines The number of lines. - */ -void GetLines( const BidirectionalParagraphInfoRun& paragraphInfo, - const Vector& lines, - unsigned int lineIndex, - unsigned int& firstLine, - unsigned int& numberOfLines ) -{ - firstLine = lineIndex; - numberOfLines = 0u; - - const CharacterIndex lastCharacterIndex = paragraphInfo.characterRun.characterIndex + paragraphInfo.characterRun.numberOfCharacters; - bool firstLineFound = false; - - for( Vector::ConstIterator it = lines.Begin() + lineIndex, - endIt = lines.End(); - it != endIt; - ++it ) - { - const LineRun& line = *it; - - if( ( line.characterRun.characterIndex + line.characterRun.numberOfCharacters > paragraphInfo.characterRun.characterIndex ) && - ( lastCharacterIndex > line.characterRun.characterIndex ) ) - { - firstLineFound = true; - ++numberOfLines; - } - else if( lastCharacterIndex <= line.characterRun.characterIndex ) - { - // nothing else to do. - break; - } - - if( !firstLineFound ) - { - ++firstLine; - } - } -} - -} // namespace - void SetBidirectionalInfo( const Vector& text, const Vector& scripts, const Vector& lineBreakInfo, @@ -148,7 +96,7 @@ void SetBidirectionalInfo( const Vector& text, break; } - if( !hasRightToLeftScript && TextAbstraction::IsRightToLeftScript( scriptRun.script ) ) + if( !hasRightToLeftScript && scriptRun.isRightToLeft ) { // The script is right to left. hasRightToLeftScript = true; @@ -171,6 +119,8 @@ void SetBidirectionalInfo( const Vector& text, matchSystemLanguageDirection, layoutDirection ); + bidirectionalRun.direction = bidirectionalSupport.GetParagraphDirection( bidirectionalRun.bidirectionalInfoIndex ); + bidirectionalInfo.Insert( bidirectionalInfo.Begin() + bidiInfoIndex, bidirectionalRun ); ++bidiInfoIndex; } @@ -195,118 +145,49 @@ void SetBidirectionalInfo( const Vector& text, } } -void ReorderLines( const Vector& bidirectionalInfo, - CharacterIndex startIndex, - Length numberOfCharacters, - Vector& lineRuns, - Vector& lineInfoRuns ) +void ReorderLine( const BidirectionalParagraphInfoRun& bidirectionalParagraphInfo, + Vector& lineInfoRuns, + BidirectionalLineRunIndex bidiLineIndex, + CharacterIndex startIndex, + Length numberOfCharacters, + CharacterDirection direction ) { - // Find where to insert the new paragraphs. - BidirectionalLineRunIndex bidiLineInfoIndex = 0u; - for( Vector::ConstIterator it = lineInfoRuns.Begin(), - endIt = lineInfoRuns.End(); - it != endIt; - ++it ) - { - const BidirectionalLineInfoRun& run = *it; - - if( startIndex < run.characterRun.characterIndex + run.characterRun.numberOfCharacters ) - { - // Found where to insert the bidi line info. - break; - } - ++bidiLineInfoIndex; - } - // Handle to the bidirectional info module in text-abstraction. TextAbstraction::BidirectionalSupport bidirectionalSupport = TextAbstraction::BidirectionalSupport::Get(); - const CharacterIndex lastCharacter = startIndex + numberOfCharacters; + // Creates a bidirectional info for the line run. + BidirectionalLineInfoRun lineInfoRun; + lineInfoRun.characterRun.characterIndex = startIndex; + lineInfoRun.characterRun.numberOfCharacters = numberOfCharacters; + lineInfoRun.direction = direction; + lineInfoRun.isIdentity = true; - // Keep an index to the first line to be checked if it's contained inside the paragraph. - // Avoids check the lines from the beginning for each paragraph. - unsigned int lineIndex = 0u; + // 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( numberOfCharacters * sizeof( CharacterIndex ) ) ); - for( Vector::ConstIterator it = bidirectionalInfo.Begin(), - endIt = bidirectionalInfo.End(); - it != endIt; - ++it ) + if( nullptr != lineInfoRun.visualToLogicalMap ) { - const BidirectionalParagraphInfoRun& paragraphInfo = *it; - - if( paragraphInfo.characterRun.characterIndex < startIndex ) - { - // Do not process, the paragraph has already been processed. - continue; - } - - if( lastCharacter <= paragraphInfo.characterRun.characterIndex ) - { - // Do not process paragraphs beyond startIndex + numberOfCharacters. - break; - } - - const CharacterDirection direction = bidirectionalSupport.GetParagraphDirection( paragraphInfo.bidirectionalInfoIndex ); - - // Get the lines for this paragraph. - unsigned int firstLine = 0u; - unsigned int numberOfLines = 0u; - - // Get an index to the first line and the number of lines of the current paragraph. - GetLines( paragraphInfo, - lineRuns, - lineIndex, - firstLine, - numberOfLines ); - - lineIndex = firstLine + numberOfLines; - - // Traverse the lines and reorder them - for( Vector::Iterator lineIt = lineRuns.Begin() + firstLine, - endLineIt = lineRuns.Begin() + firstLine + numberOfLines; - lineIt != endLineIt; - ++lineIt ) + // Reorders the line. + bidirectionalSupport.Reorder( bidirectionalParagraphInfo.bidirectionalInfoIndex, + lineInfoRun.characterRun.characterIndex - bidirectionalParagraphInfo.characterRun.characterIndex, + lineInfoRun.characterRun.numberOfCharacters, + lineInfoRun.visualToLogicalMap ); + + // For those LTR lines inside a bidirectional paragraph. + // It will save to relayout the line after reordering. + for( unsigned int i=0; i( malloc( line.characterRun.numberOfCharacters * sizeof( CharacterIndex ) ) ); - - if( NULL != lineInfoRun.visualToLogicalMap ) + if( i != *( lineInfoRun.visualToLogicalMap + i ) ) { - // Reorders the line. - bidirectionalSupport.Reorder( paragraphInfo.bidirectionalInfoIndex, - line.characterRun.characterIndex - paragraphInfo.characterRun.characterIndex, - line.characterRun.numberOfCharacters, - lineInfoRun.visualToLogicalMap ); + lineInfoRun.isIdentity = false; + break; } - - // Push the run into the vector. - lineInfoRuns.Insert( lineInfoRuns.Begin() + bidiLineInfoIndex, lineInfoRun ); - ++bidiLineInfoIndex; } } - // Update indices of the bidi runs. - for( Vector::Iterator it = lineInfoRuns.Begin() + bidiLineInfoIndex, - endIt = lineInfoRuns.End(); - it != endIt; - ++it ) - { - BidirectionalLineInfoRun& run = *it; - - run.characterRun.characterIndex += numberOfCharacters; - } + // Push the run into the vector. + lineInfoRuns.Insert( lineInfoRuns.Begin() + bidiLineIndex, lineInfoRun ); } bool GetMirroredText( const Vector& text,