X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Flogical-model-impl.cpp;h=239a2f8897a870950d77598da18a36205e0f60ae;hp=807f7fb65df7ee43c1452110275a0004790de39c;hb=0b2e209ecfb3cedba510f53a4af58d7d8a2b3876;hpb=10d2080e1d25b75347daa2f8c2dcee494fbcb175 diff --git a/dali-toolkit/internal/text/logical-model-impl.cpp b/dali-toolkit/internal/text/logical-model-impl.cpp index 807f7fb..239a2f8 100644 --- a/dali-toolkit/internal/text/logical-model-impl.cpp +++ b/dali-toolkit/internal/text/logical-model-impl.cpp @@ -18,8 +18,9 @@ // CLASS HEADER #include -// EXTERNAL INCLUDES -#include +// INTERNAL INCLUDES +#include +#include namespace Dali { @@ -30,115 +31,22 @@ namespace Toolkit namespace Text { -LogicalModelPtr LogicalModel::New() -{ - return LogicalModelPtr( new LogicalModel() ); -} - -void LogicalModel::SetText( const Character* const text, - Length numberOfCharacters ) -{ - if( 0u == numberOfCharacters ) - { - mText.Clear(); - } - else - { - mText.Resize( numberOfCharacters ); - memcpy( mText.Begin(), text, numberOfCharacters * sizeof( Character ) ); - } -} - -Length LogicalModel::GetNumberOfCharacters() const -{ - return mText.Count(); -} - -void LogicalModel::GetText( Character* text, - CharacterIndex characterIndex, - Length numberOfCharacters ) const -{ - memcpy( text, mText.Begin() + characterIndex, numberOfCharacters * sizeof( Character ) ); -} - -Character LogicalModel::GetCharacter( CharacterIndex characterIndex ) const +void FreeFontFamilyNames( Vector& fontDescriptionRuns ) { - return mText[characterIndex]; -} - -void LogicalModel::ReplaceText( CharacterIndex characterIndex, - Length numberOfCharactersToRemove, - const Character* const text, - Length numberOfCharactersToInsert ) -{ -} - -void LogicalModel::SetScripts( const ScriptRun* const scripts, - Length numberOfRuns ) -{ - if( 0u == numberOfRuns ) - { - mScriptRuns.Clear(); - } - else - { - mScriptRuns.Resize( numberOfRuns ); - memcpy( mScriptRuns.Begin(), scripts, numberOfRuns * sizeof( ScriptRun ) ); - } -} - -void LogicalModel::GetNumberOfScriptRuns( CharacterIndex characterIndex, - Length numberOfCharacters, - ScriptRunIndex& firstScriptRun, - Length& numberOfScriptRuns ) const -{ - // Initialize the number of scripts and the index to the first script. - firstScriptRun = 0u; - numberOfScriptRuns = 0; - bool firstScriptFound = false; - - const CharacterIndex lastCharacterIndex = characterIndex + numberOfCharacters; - - // Traverse the scripts and count those scripts within the range of characters. - for( Vector::ConstIterator it = mScriptRuns.Begin(), - endIt = mScriptRuns.End(); + for( Vector::Iterator it = fontDescriptionRuns.Begin(), + endIt = fontDescriptionRuns.End(); it != endIt; ++it ) { - const ScriptRun& script = *it; - - if( ( script.characterRun.characterIndex + script.characterRun.numberOfCharacters > characterIndex ) && - ( lastCharacterIndex > script.characterRun.characterIndex ) ) - { - firstScriptFound = true; - ++numberOfScriptRuns; - } - else if( lastCharacterIndex <= script.characterRun.characterIndex ) - { - // nothing else to do. - break; - } - - if( !firstScriptFound ) - { - ++firstScriptRun; - } + delete (*it).familyName; } + + fontDescriptionRuns.Clear(); } -void LogicalModel::GetScriptRuns( ScriptRun* scriptRuns, - CharacterIndex characterIndex, - Length numberOfCharacters ) const +LogicalModelPtr LogicalModel::New() { - ScriptRunIndex firstScriptRun = 0u; - Length numberOfScriptRuns = 0u; - - GetNumberOfScriptRuns( characterIndex, - numberOfCharacters, - firstScriptRun, - numberOfScriptRuns ); - - memcpy( scriptRuns, mScriptRuns.Begin() + firstScriptRun, numberOfScriptRuns * sizeof( ScriptRun ) ); + return LogicalModelPtr( new LogicalModel() ); } Script LogicalModel::GetScript( CharacterIndex characterIndex ) const @@ -159,350 +67,487 @@ Script LogicalModel::GetScript( CharacterIndex characterIndex ) const return TextAbstraction::UNKNOWN; } -void LogicalModel::ReplaceScripts( CharacterIndex characterIndex, - Length numberOfCharactersToRemove, - const ScriptRun* const scriptRuns, - Length numberOfCharactersToInsert ) -{ -} - -void LogicalModel::SetFonts( const FontRun* const fonts, - Length numberOfRuns ) +CharacterDirection LogicalModel::GetCharacterDirection( CharacterIndex characterIndex ) const { - if( 0u == numberOfRuns ) + if( characterIndex >= mCharacterDirections.Count() ) { - mFontRuns.Clear(); - } - else - { - mFontRuns.Resize( numberOfRuns ); - memcpy( mFontRuns.Begin(), fonts, numberOfRuns * sizeof( FontRun ) ); + // The model has no right to left characters, so the vector of directions is void. + return false; } + + return *( mCharacterDirections.Begin() + characterIndex ); } -void LogicalModel::GetNumberOfFontRuns( CharacterIndex characterIndex, - Length numberOfCharacters, - FontRunIndex& firstFontRun, - Length& numberOfFontRuns ) const +void LogicalModel::SetVisualToLogicalMap( const BidirectionalLineInfoRun* const bidirectionalInfo, + Length numberOfRuns, + CharacterIndex startIndex, + Length numberOfCharacters ) { - // Initialize the number of fonts and the index to the first font. - firstFontRun = 0u; - numberOfFontRuns = 0; - bool firstFontFound = false; + mVisualToLogicalMap.Resize( numberOfCharacters ); + mLogicalToVisualMap.Resize( numberOfCharacters ); - const CharacterIndex lastCharacterIndex = characterIndex + numberOfCharacters; + const Length numberOfCharactersPlus = numberOfCharacters + 1u; + mVisualToLogicalCursorMap.Resize( numberOfCharactersPlus ); - // Traverse the fonts and count those fonts within the range of characters. - for( Vector::ConstIterator it = mFontRuns.Begin(), - endIt = mFontRuns.End(); - it != endIt; - ++it ) + CharacterIndex* modelVisualToLogicalMapBuffer = mVisualToLogicalMap.Begin(); + CharacterIndex* modelLogicalToVisualMapBuffer = mLogicalToVisualMap.Begin(); + + CharacterIndex* modelVisualToLogicalCursorMap = mVisualToLogicalCursorMap.Begin(); + + CharacterIndex lastIndex = startIndex; + for( unsigned int bidiIndex = 0u; bidiIndex < numberOfRuns; ++bidiIndex ) { - const FontRun& font = *it; + const BidirectionalLineInfoRun& bidiLineInfo = *( bidirectionalInfo + bidiIndex ); - if( ( font.characterRun.characterIndex + font.characterRun.numberOfCharacters > characterIndex ) && - ( characterIndex + numberOfCharacters > font.characterRun.characterIndex ) ) + if( bidiLineInfo.characterRun.characterIndex + bidiLineInfo.characterRun.numberOfCharacters <= startIndex ) { - firstFontFound = true; - ++numberOfFontRuns; + // Skip this paragraph. It has been already processed. + continue; } - else if( lastCharacterIndex <= font.characterRun.characterIndex ) + + if( lastIndex < bidiLineInfo.characterRun.characterIndex ) { - // nothing else to do. - break; + // Fill with the identity. + for( ; lastIndex < bidiLineInfo.characterRun.characterIndex; ++lastIndex ) + { + *( modelVisualToLogicalMapBuffer + lastIndex ) = lastIndex; + } } - if( !firstFontFound ) + // Fill the conversion table of the run. + for( CharacterIndex index = 0u; + index < bidiLineInfo.characterRun.numberOfCharacters; + ++index, ++lastIndex ) { - ++firstFontRun; + *( modelVisualToLogicalMapBuffer + lastIndex ) = bidiLineInfo.characterRun.characterIndex + *( bidiLineInfo.visualToLogicalMap + index ); } } -} -void LogicalModel::GetFontRuns( FontRun* fontRuns, - CharacterIndex characterIndex, - Length numberOfCharacters ) const -{ - FontRunIndex firstFontRun = 0u; - Length numberOfFontRuns = 0u; + // Complete with the identity if there are some left to right characters after the last right to left. + for( ; lastIndex < numberOfCharacters; ++lastIndex ) + { + *( modelVisualToLogicalMapBuffer + lastIndex ) = lastIndex; + } - GetNumberOfFontRuns( characterIndex, - numberOfCharacters, - firstFontRun, - numberOfFontRuns ); + // Sets the logical to visual conversion map. + for( CharacterIndex index = startIndex; index < numberOfCharacters; ++index ) + { + *( modelLogicalToVisualMapBuffer + *( modelVisualToLogicalMapBuffer + index ) ) = index; + } - memcpy( fontRuns, mFontRuns.Begin() + firstFontRun, numberOfFontRuns * sizeof( FontRun ) ); -} + // Sets the visual to logical conversion map for cursor positions. -FontId LogicalModel::GetFont( CharacterIndex characterIndex ) const -{ - for( Length index = 0u, length = mFontRuns.Count(); index < length; ++index ) + const Length numberOfBidirectionalParagraphs = mBidirectionalParagraphInfo.Count(); + BidirectionalParagraphInfoRun* bidirectionalParagraphInfoBuffer = mBidirectionalParagraphInfo.Begin(); + BidirectionalParagraphInfoRun* bidirectionalParagraph = bidirectionalParagraphInfoBuffer; + + const CharacterDirection* const modelCharacterDirections = mCharacterDirections.Begin(); + + Length bidirectionalParagraphIndex = 0u; + bool isRightToLeftParagraph = false; + for( CharacterIndex index = startIndex; index < numberOfCharactersPlus; ++index ) { - const FontRun* const fontRun = mFontRuns.Begin() + index; + if( bidirectionalParagraph && + ( bidirectionalParagraph->characterRun.characterIndex == index ) ) + { + isRightToLeftParagraph = *( modelCharacterDirections + index ); + } - if( ( fontRun->characterRun.characterIndex <= characterIndex ) && - ( characterIndex < fontRun->characterRun.characterIndex + fontRun->characterRun.numberOfCharacters ) ) + if( 0u == index ) { - return fontRun->fontId; + if( isRightToLeftParagraph ) + { + *( modelVisualToLogicalCursorMap + index ) = numberOfCharacters; + } + else // else logical position is zero. + { + *( modelVisualToLogicalCursorMap + index ) = 0u; + } } - } + else if( numberOfCharacters == index ) + { + if( isRightToLeftParagraph ) + { + *( modelVisualToLogicalCursorMap + index ) = 0u; + } + else // else logical position is the number of characters. + { + *( modelVisualToLogicalCursorMap + index ) = numberOfCharacters; + } + } + else + { + // Get the character indexed by index - 1 and index + // and calculate the logical position according the directions of + // both characters and the direction of the paragraph. - return 0u; -} + const CharacterIndex previousIndex = index - 1u; + const CharacterIndex logicalPosition0 = *( modelVisualToLogicalMapBuffer + previousIndex ); + const CharacterIndex logicalPosition1 = *( modelVisualToLogicalMapBuffer + index ); -void LogicalModel::ReplaceFonts( CharacterIndex characterIndex, - Length numberOfCharactersToRemove, - const FontRun* const fontRuns, - Length numberOfCharactersToInsert ) -{ + const CharacterDirection direction0 = *( modelCharacterDirections + logicalPosition0 ); + const CharacterDirection direction1 = *( modelCharacterDirections + logicalPosition1 ); + + if( direction0 == direction1 ) + { + // Both glyphs have the same direction. + if( direction0 ) + { + *( modelVisualToLogicalCursorMap + index ) = logicalPosition0; + } + else + { + *( modelVisualToLogicalCursorMap + index ) = logicalPosition1; + } + } + else + { + if( isRightToLeftParagraph ) + { + if( direction1 ) + { + *( modelVisualToLogicalCursorMap + index ) = logicalPosition1 + 1u; + } + else + { + *( modelVisualToLogicalCursorMap + index ) = logicalPosition0; + } + } + else + { + if( direction0 ) + { + *( modelVisualToLogicalCursorMap + index ) = logicalPosition1; + } + else + { + *( modelVisualToLogicalCursorMap + index ) = logicalPosition0 + 1u; + } + } + } + } + + if( bidirectionalParagraph && + ( bidirectionalParagraph->characterRun.characterIndex + bidirectionalParagraph->characterRun.numberOfCharacters == index ) ) + { + isRightToLeftParagraph = false; + ++bidirectionalParagraphIndex; + if( bidirectionalParagraphIndex < numberOfBidirectionalParagraphs ) + { + bidirectionalParagraph = bidirectionalParagraphInfoBuffer + bidirectionalParagraphIndex; + } + else + { + bidirectionalParagraph = NULL; + } + } + } } -void LogicalModel::SetLineBreakInfo( const LineBreakInfo* const lineBreakInfo, - Length length ) +CharacterIndex LogicalModel::GetLogicalCharacterIndex( CharacterIndex visualCharacterIndex ) const { - if( 0u == length ) - { - mLineBreakInfo.Clear(); - } - else + if( 0u == mVisualToLogicalMap.Count() ) { - mLineBreakInfo.Resize( length ); - memcpy( mLineBreakInfo.Begin(), lineBreakInfo, length * sizeof( LineBreakInfo ) ); + // If there is no visual to logical info is because the whole text is left to right. + // Return the identity. + return visualCharacterIndex; } -} -void LogicalModel::GetLineBreakInfo( LineBreakInfo* lineBreakInfo, - CharacterIndex characterIndex, - Length numberOfItems ) const -{ - memcpy( lineBreakInfo, mLineBreakInfo.Begin() + characterIndex, numberOfItems * sizeof( LineBreakInfo ) ); + return *( mVisualToLogicalMap.Begin() + visualCharacterIndex ); } -LineBreakInfo LogicalModel::GetLineBreakInfo( CharacterIndex characterIndex ) const +void LogicalModel::UpdateTextStyleRuns( CharacterIndex index, int numberOfCharacters ) { - return *( mLineBreakInfo.Begin() + characterIndex ); -} + const Length totalNumberOfCharacters = mText.Count(); -void LogicalModel::ReplaceLineBreakInfo( CharacterIndex characterIndex, - Length numberOfItemsToRemove, - const LineBreakInfo* const lineBreakInfo, - Length numberOfItemsToInsert ) -{ + // Process the color runs. + Vector removedColorRuns; + UpdateCharacterRuns( index, + numberOfCharacters, + totalNumberOfCharacters, + mColorRuns, + removedColorRuns ); + + // Process the font description runs. + Vector removedFontDescriptionRuns; + UpdateCharacterRuns( index, + numberOfCharacters, + totalNumberOfCharacters, + mFontDescriptionRuns, + removedFontDescriptionRuns ); + + // Free memory allocated for the font family name. + FreeFontFamilyNames( removedFontDescriptionRuns ); } -void LogicalModel::SetWordBreakInfo( const WordBreakInfo* const wordBreakInfo, - Length length ) +void LogicalModel::RetrieveStyle( CharacterIndex index, InputStyle& style ) { - if( 0u == length ) + unsigned int runIndex = 0u; + + // Set the text color. + bool colorOverriden = false; + unsigned int colorIndex = 0u; + const ColorRun* const colorRunsBuffer = mColorRuns.Begin(); + for( Vector::ConstIterator it = colorRunsBuffer, + endIt = mColorRuns.End(); + it != endIt; + ++it, ++runIndex ) { - mWordBreakInfo.Clear(); + const ColorRun& colorRun = *it; + + if( ( colorRun.characterRun.characterIndex <= index ) && + ( index < colorRun.characterRun.characterIndex + colorRun.characterRun.numberOfCharacters ) ) + { + colorIndex = runIndex; + colorOverriden = true; + } } - else + + // Set the text's color if it's overriden. + if( colorOverriden ) { - mWordBreakInfo.Resize( length ); - memcpy( mWordBreakInfo.Begin(), wordBreakInfo, length * sizeof( WordBreakInfo ) ); + style.textColor = ( *( colorRunsBuffer + colorIndex ) ).color; } -} -void LogicalModel::GetWordBreakInfo( WordBreakInfo* wordBreakInfo, - CharacterIndex characterIndex, - Length numberOfItems ) const -{ - memcpy( wordBreakInfo, mWordBreakInfo.Begin() + characterIndex, numberOfItems * sizeof( WordBreakInfo ) ); -} + // Reset the run index. + runIndex = 0u; + + // Set the font's parameters. + bool nameOverriden = false; + bool weightOverriden = false; + bool widthOverriden = false; + bool slantOverriden = false; + bool sizeOverriden = false; + unsigned int nameIndex = 0u; + unsigned int weightIndex = 0u; + unsigned int widthIndex = 0u; + unsigned int slantIndex = 0u; + unsigned int sizeIndex = 0u; + const FontDescriptionRun* const fontDescriptionRunsBuffer = mFontDescriptionRuns.Begin(); + for( Vector::ConstIterator it = fontDescriptionRunsBuffer, + endIt = mFontDescriptionRuns.End(); + it != endIt; + ++it, ++runIndex ) + { + const FontDescriptionRun& fontDescriptionRun = *it; -WordBreakInfo LogicalModel::GetWordBreakInfo( CharacterIndex characterIndex ) const -{ - return *( mWordBreakInfo.Begin() + characterIndex ); -} + if( ( fontDescriptionRun.characterRun.characterIndex <= index ) && + ( index < fontDescriptionRun.characterRun.characterIndex + fontDescriptionRun.characterRun.numberOfCharacters ) ) + { + if( fontDescriptionRun.familyDefined ) + { + nameIndex = runIndex; + nameOverriden = true; + } -void LogicalModel::ReplaceWordBreakInfo( CharacterIndex characterIndex, - Length numberOfItemsToRemove, - const WordBreakInfo* const wordBreakInfo, - Length numberOfItemsToInsert ) -{ -} + if( fontDescriptionRun.weightDefined ) + { + weightIndex = runIndex; + weightOverriden = true; + } -void LogicalModel::SetBidirectionalInfo( const BidirectionalParagraphInfoRun* const bidirectionalInfo, - Length numberOfRuns ) -{ - if( 0u == numberOfRuns ) + if( fontDescriptionRun.widthDefined ) + { + widthIndex = runIndex; + widthOverriden = true; + } + + if( fontDescriptionRun.slantDefined ) + { + slantIndex = runIndex; + slantOverriden = true; + } + + if( fontDescriptionRun.sizeDefined ) + { + sizeIndex = runIndex; + sizeOverriden = true; + } + } + } + + // Set the font's family name if it's overriden. + if( nameOverriden ) { - mBidirectionalParagraphInfo.Clear(); + const FontDescriptionRun& fontDescriptionRun = *( fontDescriptionRunsBuffer + nameIndex ); + + style.familyName = std::string( fontDescriptionRun.familyName, fontDescriptionRun.familyLength ); + style.familyDefined = true; } - else + + // Set the font's weight if it's overriden. + if( weightOverriden ) { - mBidirectionalParagraphInfo.Resize( numberOfRuns ); - memcpy( mBidirectionalParagraphInfo.Begin(), bidirectionalInfo, numberOfRuns * sizeof( BidirectionalParagraphInfoRun ) ); + const FontDescriptionRun& fontDescriptionRun = *( fontDescriptionRunsBuffer + weightIndex ); + + style.weight = fontDescriptionRun.weight; + style.weightDefined = true; } -} -void LogicalModel::GetNumberOfBidirectionalInfoRuns( CharacterIndex characterIndex, - Length numberOfCharacters, - BidirectionalRunIndex& firstBidirectionalRun, - Length& numberOfFontRuns ) const -{ - // Initialize the number of bidi paragraphs and the index to the first paragraph. - firstBidirectionalRun = 0u; - numberOfFontRuns = 0; - bool firstParagraphFound = false; - - // Traverse the bidirectional paragraph info and count those bidi paragraphs within the range of characters. - for( Vector::ConstIterator it = mBidirectionalParagraphInfo.Begin(), - endIt = mBidirectionalParagraphInfo.End(); - it != endIt; - ++it ) + // Set the font's width if it's overriden. + if( widthOverriden ) { - const BidirectionalParagraphInfoRun& bidi = *it; + const FontDescriptionRun& fontDescriptionRun = *( fontDescriptionRunsBuffer + widthIndex ); - if( ( bidi.characterRun.characterIndex + bidi.characterRun.numberOfCharacters > characterIndex ) && - ( characterIndex + numberOfCharacters > bidi.characterRun.characterIndex ) ) - { - firstParagraphFound = true; - ++numberOfFontRuns; - } + style.width = fontDescriptionRun.width; + style.widthDefined = true; + } - if( !firstParagraphFound ) - { - ++firstBidirectionalRun; - } + // Set the font's slant if it's overriden. + if( slantOverriden ) + { + const FontDescriptionRun& fontDescriptionRun = *( fontDescriptionRunsBuffer + slantIndex ); + + style.slant = fontDescriptionRun.slant; + style.slantDefined = true; } -} -void LogicalModel::GetBidirectionalInfo( BidirectionalParagraphInfoRun* bidirectionalInfo, - CharacterIndex characterIndex, - Length numberOfCharacters ) const -{ - BidirectionalRunIndex firstBidirectionalRun = 0u; - Length numberOfFontRuns = 0u; + // Set the font's size if it's overriden. + if( sizeOverriden ) + { + const FontDescriptionRun& fontDescriptionRun = *( fontDescriptionRunsBuffer + sizeIndex ); - GetNumberOfBidirectionalInfoRuns( characterIndex, - numberOfCharacters, - firstBidirectionalRun, - numberOfFontRuns ); + style.size = static_cast( fontDescriptionRun.size ) / 64.f; + style.sizeDefined = true; + } - memcpy( bidirectionalInfo, mBidirectionalParagraphInfo.Begin() + firstBidirectionalRun, numberOfFontRuns * sizeof( BidirectionalParagraphInfoRun ) ); + // Reset the run index. + runIndex = 0u; } -void ReplaceBidirectionalInfo( CharacterIndex characterIndex, - Length numberOfCharactersToRemove, - const BidirectionalParagraphInfoRun* const bidirectionalInfo, - Length numberOfCharactersToInsert ) +void LogicalModel::ClearFontDescriptionRuns() { + FreeFontFamilyNames( mFontDescriptionRuns ); } -void LogicalModel::GetCharacterDirections( CharacterDirection* directions, - CharacterIndex characterIndex, - Length numberOfCharacters ) const +void LogicalModel::CreateParagraphInfo( CharacterIndex startIndex, + Length numberOfCharacters ) { -} + const Length totalNumberOfCharacters = mLineBreakInfo.Count(); -CharacterDirection LogicalModel::GetCharacterDirection( CharacterIndex characterIndex ) const -{ - return false; -} + // Count the number of LINE_MUST_BREAK to reserve some space for the vector of paragraph's info. + Vector paragraphs; + paragraphs.Reserve( numberOfCharacters ); + const TextAbstraction::LineBreakInfo* lineBreakInfoBuffer = mLineBreakInfo.Begin(); + const CharacterIndex lastCharacterIndexPlusOne = startIndex + numberOfCharacters; + for( Length index = startIndex; index < lastCharacterIndexPlusOne; ++index ) + { + if( TextAbstraction::LINE_MUST_BREAK == *( lineBreakInfoBuffer + index ) ) + { + paragraphs.PushBack( index ); + } + } -void LogicalModel::SetVisualToLogicalMap( const BidirectionalLineInfoRun* const bidirectionalInfo, - Length numberOfRuns ) -{ - if( 0u == numberOfRuns ) + // Whether the current paragraphs are updated or set from scratch. + const bool updateCurrentParagraphs = numberOfCharacters < totalNumberOfCharacters; + + // Reserve space for current paragraphs plus new ones. + const Length numberOfNewParagraphs = paragraphs.Count(); + const Length totalNumberOfParagraphs = mParagraphInfo.Count() + numberOfNewParagraphs; + mParagraphInfo.Resize( totalNumberOfParagraphs ); + + ParagraphRun* paragraphInfoBuffer = NULL; + Vector newParagraphs; + + if( updateCurrentParagraphs ) { - mVisualToLogicalMap.Clear(); - mLogicalToVisualMap.Clear(); + newParagraphs.Resize( numberOfNewParagraphs ); + paragraphInfoBuffer = newParagraphs.Begin(); } else { - const Length numberOfCharacters = mText.Count(); - mVisualToLogicalMap.Resize( numberOfCharacters ); - mLogicalToVisualMap.Resize( numberOfCharacters ); + paragraphInfoBuffer = mParagraphInfo.Begin(); + } - CharacterIndex* modelVisualToLogicalMapBuffer = mVisualToLogicalMap.Begin(); - CharacterIndex* modelLogicalToVisualMapBuffer = mLogicalToVisualMap.Begin(); + // Find where to insert the new paragraphs. + ParagraphRunIndex paragraphIndex = 0u; + CharacterIndex firstIndex = startIndex; - CharacterIndex lastIndex = 0u; - for( unsigned int bidiIndex = 0u; bidiIndex < numberOfRuns; ++bidiIndex ) + if( updateCurrentParagraphs ) + { + for( Vector::ConstIterator it = mParagraphInfo.Begin(), + endIt = mParagraphInfo.Begin() + totalNumberOfParagraphs - numberOfNewParagraphs; + it != endIt; + ++it ) { - const BidirectionalLineInfoRun& bidiLineInfo = *( bidirectionalInfo + bidiIndex ); + const ParagraphRun& paragraph( *it ); - if( lastIndex < bidiLineInfo.characterRun.characterIndex ) + if( startIndex < paragraph.characterRun.characterIndex + paragraph.characterRun.numberOfCharacters ) { - // Fill with the identity. - for( ; lastIndex < bidiLineInfo.characterRun.characterIndex; ++lastIndex ) - { - *( modelVisualToLogicalMapBuffer + lastIndex ) = lastIndex; - } + firstIndex = paragraph.characterRun.characterIndex; + break; } - // Fill the conversion table of the run. - for( CharacterIndex index = 0u; - index < bidiLineInfo.characterRun.numberOfCharacters; - ++index, ++lastIndex ) - { - *( modelVisualToLogicalMapBuffer + lastIndex ) = bidiLineInfo.characterRun.characterIndex + *( bidiLineInfo.visualToLogicalMap + index ); - } + ++paragraphIndex; } + } - // Complete with the identity if there are some left to right characters after the last right to left. - for( ; lastIndex < numberOfCharacters; ++lastIndex ) - { - *( modelVisualToLogicalMapBuffer + lastIndex ) = lastIndex; - } + // Create the paragraph info. + ParagraphRunIndex newParagraphIndex = 0u; + for( Vector::ConstIterator it = paragraphs.Begin(), + endIt = paragraphs.End(); + it != endIt; + ++it, ++newParagraphIndex ) + { + const CharacterIndex index = *it; - // Sets the logical to visual conversion map. - for( CharacterIndex index = 0u; index < numberOfCharacters; ++index ) - { - *( modelLogicalToVisualMapBuffer + *( modelVisualToLogicalMapBuffer + index ) ) = index; - } + ParagraphRun& paragraph = *( paragraphInfoBuffer + newParagraphIndex ); + paragraph.characterRun.characterIndex = firstIndex; + paragraph.characterRun.numberOfCharacters = 1u + index - firstIndex; + + firstIndex += paragraph.characterRun.numberOfCharacters; } -} -void LogicalModel::ReplaceVisualToLogicalMap( CharacterIndex characterIndex, - Length numberOfCharactersToRemove, - const BidirectionalLineInfoRun* const bidirectionalInfo, - Length numberOfCharactersToInsert ) -{ -} -CharacterIndex LogicalModel::GetVisualCharacterIndex( CharacterIndex logicalCharacterIndex ) const -{ - if( 0u == mLogicalToVisualMap.Count() ) + // Insert the new paragraphs. + if( updateCurrentParagraphs ) { - // If there is no logical to visual info is because the whole text is left to right. - // Return the identity. - return logicalCharacterIndex; - } + mParagraphInfo.Insert( mParagraphInfo.Begin() + paragraphIndex, + newParagraphs.Begin(), + newParagraphs.End() ); - return *( mLogicalToVisualMap.Begin() + logicalCharacterIndex ); -} + mParagraphInfo.Resize( totalNumberOfParagraphs ); -CharacterIndex LogicalModel::GetLogicalCharacterIndex( CharacterIndex visualCharacterIndex ) const -{ - if( 0u == mVisualToLogicalMap.Count() ) - { - // If there is no visual to logical info is because the whole text is left to right. - // Return the identity. - return visualCharacterIndex; - } + // Update the next paragraph indices. + for( Vector::Iterator it = mParagraphInfo.Begin() + paragraphIndex + newParagraphs.Count(), + endIt = mParagraphInfo.End(); + it != endIt; + ++it ) + { + ParagraphRun& paragraph( *it ); - return *( mVisualToLogicalMap.Begin() + visualCharacterIndex ); + paragraph.characterRun.characterIndex += numberOfCharacters; + } + } } -void LogicalModel::GetLogicalToVisualMap( CharacterIndex* logicalToVisualMap, - CharacterIndex characterIndex, - Length numberOfCharacters ) const +void LogicalModel::FindParagraphs( CharacterIndex index, + Length numberOfCharacters, + Vector& paragraphs ) { - memcpy( logicalToVisualMap, mLogicalToVisualMap.Begin() + characterIndex, numberOfCharacters * sizeof( CharacterIndex ) ); -} + // Reserve som space for the paragraph indices. + paragraphs.Reserve( mParagraphInfo.Count() ); -void LogicalModel::GetVisualToLogicalMap( CharacterIndex* visualToLogicalMap, - CharacterIndex characterIndex, - Length numberOfCharacters ) const -{ - memcpy( visualToLogicalMap, mVisualToLogicalMap.Begin() + characterIndex, numberOfCharacters * sizeof( CharacterIndex ) ); + // Traverse the paragraphs to find which ones contain the given characters. + ParagraphRunIndex paragraphIndex = 0u; + for( Vector::ConstIterator it = mParagraphInfo.Begin(), + endIt = mParagraphInfo.End(); + it != endIt; + ++it, ++paragraphIndex ) + { + const ParagraphRun& paragraph( *it ); + + if( ( paragraph.characterRun.characterIndex + paragraph.characterRun.numberOfCharacters > index ) && + ( paragraph.characterRun.characterIndex < index + numberOfCharacters ) ) + { + paragraphs.PushBack( paragraphIndex ); + } + } } LogicalModel::~LogicalModel() { + ClearFontDescriptionRuns(); } LogicalModel::LogicalModel()