Dali-Text: Keyboard Shortcuts
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / logical-model-impl.cpp
old mode 100644 (file)
new mode 100755 (executable)
index 0d8cf5a..3d9440e
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -38,12 +38,26 @@ void FreeFontFamilyNames( Vector<FontDescriptionRun>& fontDescriptionRuns )
        it != endIt;
        ++it )
   {
-    delete (*it).familyName;
+    delete[] (*it).familyName;
   }
 
   fontDescriptionRuns.Clear();
 }
 
+void FreeEmbeddedItems( Vector<EmbeddedItem>& embeddedItem )
+{
+  for( Vector<EmbeddedItem>::Iterator it = embeddedItem.Begin(),
+         endIt = embeddedItem.End();
+       it != endIt;
+       ++it )
+  {
+    EmbeddedItem& item = *it;
+    delete[] item.url;
+  }
+
+  embeddedItem.Clear();
+}
+
 LogicalModelPtr LogicalModel::New()
 {
   return LogicalModelPtr( new LogicalModel() );
@@ -53,9 +67,10 @@ Script LogicalModel::GetScript( CharacterIndex characterIndex ) const
 {
   // If this operation is too slow, consider a binary search.
 
+  const ScriptRun* const scriptRunBuffer = mScriptRuns.Begin();
   for( Length index = 0u, length = mScriptRuns.Count(); index < length; ++index )
   {
-    const ScriptRun* const scriptRun = mScriptRuns.Begin() + index;
+    const ScriptRun* const scriptRun = scriptRunBuffer + index;
 
     if( ( scriptRun->characterRun.characterIndex <= characterIndex ) &&
         ( characterIndex < scriptRun->characterRun.characterIndex + scriptRun->characterRun.numberOfCharacters ) )
@@ -80,16 +95,6 @@ CharacterDirection LogicalModel::GetCharacterDirection( CharacterIndex character
 
 CharacterIndex LogicalModel::GetLogicalCursorIndex( CharacterIndex visualCursorIndex )
 {
-  // The total number of characters.
-  const Length numberOfCharacters = mText.Count();
-
-  const bool fetch = FetchBidirectionalLineInfo( visualCursorIndex );
-  if( !fetch )
-  {
-    // The character is not inside a bidi line.
-    return visualCursorIndex;
-  }
-
   // The character's directions buffer.
   const CharacterDirection* const modelCharacterDirections = mCharacterDirections.Begin();
 
@@ -99,28 +104,31 @@ CharacterIndex LogicalModel::GetLogicalCursorIndex( CharacterIndex visualCursorI
   // Whether the paragraph starts with a right to left character.
   const bool isRightToLeftParagraph = bidirectionalLineInfo->direction;
 
+  // The total number of characters of the line.
+  const Length lastCharacterIndex = bidirectionalLineInfo->characterRun.characterIndex + bidirectionalLineInfo->characterRun.numberOfCharacters;
+
   CharacterIndex logicalCursorIndex = 0u;
 
-  if( 0u == visualCursorIndex )
+  if( bidirectionalLineInfo->characterRun.characterIndex == visualCursorIndex )
   {
     if( isRightToLeftParagraph )
     {
-      logicalCursorIndex = numberOfCharacters;
+      logicalCursorIndex = lastCharacterIndex;
     }
-    else // else logical position is zero.
+    else // else logical position is the first of the line.
     {
-      logicalCursorIndex = 0u;
+      logicalCursorIndex = bidirectionalLineInfo->characterRun.characterIndex;
     }
   }
-  else if( numberOfCharacters == visualCursorIndex )
+  else if( lastCharacterIndex == visualCursorIndex )
   {
     if( isRightToLeftParagraph )
     {
-      logicalCursorIndex = 0u;
+      logicalCursorIndex = bidirectionalLineInfo->characterRun.characterIndex;
     }
     else // else logical position is the number of characters.
     {
-      logicalCursorIndex = numberOfCharacters;
+      logicalCursorIndex = lastCharacterIndex;
     }
   }
   else
@@ -180,13 +188,6 @@ CharacterIndex LogicalModel::GetLogicalCursorIndex( CharacterIndex visualCursorI
 
 CharacterIndex LogicalModel::GetLogicalCharacterIndex( CharacterIndex visualCharacterIndex )
 {
-  const bool fetch = FetchBidirectionalLineInfo( visualCharacterIndex );
-  if( !fetch )
-  {
-    // The character is not inside a bidi line.
-    return visualCharacterIndex;
-  }
-
   // The bidirectional line info.
   const BidirectionalLineInfoRun* const bidirectionalLineInfo = mBidirectionalLineInfo.Begin() + mBidirectionalLineIndex;
 
@@ -216,12 +217,9 @@ bool LogicalModel::FetchBidirectionalLineInfo( CharacterIndex characterIndex )
   {
     const BidirectionalLineInfoRun& bidiLineRun = *( bidirectionalLineInfoBuffer + mBidirectionalLineIndex );
 
-    // Whether the character index is just after the last one. i.e The cursor position after the last character.
-    const bool isLastIndex = characterIndex == mText.Count();
-
     const CharacterIndex lastCharacterOfRunPlusOne = bidiLineRun.characterRun.characterIndex + bidiLineRun.characterRun.numberOfCharacters;
     if( ( bidiLineRun.characterRun.characterIndex <= characterIndex ) &&
-        ( ( characterIndex < lastCharacterOfRunPlusOne ) || ( isLastIndex && ( characterIndex == lastCharacterOfRunPlusOne ) ) ) )
+        ( characterIndex < lastCharacterOfRunPlusOne ) )
     {
       // The character is in the previously fetched bidi line.
       return true;
@@ -229,22 +227,6 @@ bool LogicalModel::FetchBidirectionalLineInfo( CharacterIndex characterIndex )
     else
     {
       // The character is not in the previously fetched line.
-
-      if( isLastIndex )
-      {
-        // The given index is one after the last character, so it's not in a bidi line.
-        // Check if it's just after the last bidi line.
-        const BidirectionalLineRunIndex lastBidiLineIndex = numberOfBidirectionalLines - 1u;
-        const BidirectionalLineInfoRun& bidiLineRun = *( bidirectionalLineInfoBuffer + lastBidiLineIndex );
-
-        if( characterIndex == bidiLineRun.characterRun.characterIndex + bidiLineRun.characterRun.numberOfCharacters )
-        {
-          // The character is in the last bidi line.
-          mBidirectionalLineIndex = lastBidiLineIndex;
-          return true;
-        }
-      }
-
       // Set the bidi line index from where to start the fetch.
 
       if( characterIndex < bidiLineRun.characterRun.characterIndex )
@@ -269,7 +251,8 @@ bool LogicalModel::FetchBidirectionalLineInfo( CharacterIndex characterIndex )
   {
     const BidirectionalLineInfoRun& bidiLineRun = *it;
 
-    if( ( lastCharacterOfRightToLeftRun < characterIndex ) && ( characterIndex < bidiLineRun.characterRun.characterIndex ) )
+    if( ( lastCharacterOfRightToLeftRun < characterIndex ) &&
+        ( characterIndex < bidiLineRun.characterRun.characterIndex ) )
     {
       // The character is not inside a bidi line.
       return false;
@@ -306,6 +289,14 @@ void LogicalModel::UpdateTextStyleRuns( CharacterIndex index, int numberOfCharac
                                  mColorRuns,
                                  removedColorRuns );
 
+  // Process the background color runs.
+  Vector<ColorRun> removedBackgroundColorRuns;
+  UpdateCharacterRuns<ColorRun>( index,
+                                 numberOfCharacters,
+                                 totalNumberOfCharacters,
+                                 mBackgroundColorRuns,
+                                 removedBackgroundColorRuns );
+
   // Process the font description runs.
   Vector<FontDescriptionRun> removedFontDescriptionRuns;
   UpdateCharacterRuns<FontDescriptionRun>( index,
@@ -411,7 +402,7 @@ void LogicalModel::RetrieveStyle( CharacterIndex index, InputStyle& style )
     const FontDescriptionRun& fontDescriptionRun = *( fontDescriptionRunsBuffer + nameIndex );
 
     style.familyName = std::string( fontDescriptionRun.familyName, fontDescriptionRun.familyLength );
-    style.familyDefined = true;
+    style.isFamilyDefined = true;
   }
 
   // Set the font's weight if it's overriden.
@@ -420,7 +411,7 @@ void LogicalModel::RetrieveStyle( CharacterIndex index, InputStyle& style )
     const FontDescriptionRun& fontDescriptionRun = *( fontDescriptionRunsBuffer + weightIndex );
 
     style.weight = fontDescriptionRun.weight;
-    style.weightDefined = true;
+    style.isWeightDefined = true;
   }
 
   // Set the font's width if it's overriden.
@@ -429,7 +420,7 @@ void LogicalModel::RetrieveStyle( CharacterIndex index, InputStyle& style )
     const FontDescriptionRun& fontDescriptionRun = *( fontDescriptionRunsBuffer + widthIndex );
 
     style.width = fontDescriptionRun.width;
-    style.widthDefined = true;
+    style.isWidthDefined = true;
   }
 
   // Set the font's slant if it's overriden.
@@ -438,7 +429,7 @@ void LogicalModel::RetrieveStyle( CharacterIndex index, InputStyle& style )
     const FontDescriptionRun& fontDescriptionRun = *( fontDescriptionRunsBuffer + slantIndex );
 
     style.slant = fontDescriptionRun.slant;
-    style.slantDefined = true;
+    style.isSlantDefined = true;
   }
 
   // Set the font's size if it's overriden.
@@ -447,7 +438,7 @@ void LogicalModel::RetrieveStyle( CharacterIndex index, InputStyle& style )
     const FontDescriptionRun& fontDescriptionRun = *( fontDescriptionRunsBuffer + sizeIndex );
 
     style.size = static_cast<float>( fontDescriptionRun.size ) / 64.f;
-    style.sizeDefined = true;
+    style.isSizeDefined = true;
   }
 }
 
@@ -581,9 +572,15 @@ void LogicalModel::FindParagraphs( CharacterIndex index,
   }
 }
 
+void LogicalModel::ClearEmbeddedImages()
+{
+  FreeEmbeddedItems( mEmbeddedItems );
+}
+
 LogicalModel::~LogicalModel()
 {
   ClearFontDescriptionRuns();
+  ClearEmbeddedImages();
 }
 
 LogicalModel::LogicalModel()