Refactor the Text::Controller::ClearFontData. 45/66945/3
authorVictor Cebollada <v.cebollada@samsung.com>
Thu, 21 Apr 2016 14:01:46 +0000 (15:01 +0100)
committerVictor Cebollada <v.cebollada@samsung.com>
Mon, 25 Apr 2016 06:51:26 +0000 (07:51 +0100)
* This method clears completely some buffers of the model.
  Then the Text::Controller::Impl::ClearModelData may access
  the same buffers out of bounds causing a crash.

Change-Id: I1b50135c707354bd3037aabb63cded10ba2e6f2f
Signed-off-by: Victor Cebollada <v.cebollada@samsung.com>
dali-toolkit/internal/text/text-controller.cpp

index b32b20e8a0eb6d37718b7c7609711d69de3c1f84..68247aebe5277cfe887d0bf6af870d999df59637 100644 (file)
@@ -115,7 +115,6 @@ void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
   // Clear the font-specific data
   ClearFontData();
 
-  mImpl->mOperationsPending = ALL_OPERATIONS;
   mImpl->mRecalculateNaturalSize = true;
 
   mImpl->RequestRelayout();
@@ -322,7 +321,6 @@ void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
   // Clear the font-specific data
   ClearFontData();
 
-  mImpl->mOperationsPending = ALL_OPERATIONS;
   mImpl->mRecalculateNaturalSize = true;
 
   mImpl->RequestRelayout();
@@ -371,7 +369,6 @@ void Controller::SetDefaultFontWeight( FontWeight weight )
   // Clear the font-specific data
   ClearFontData();
 
-  mImpl->mOperationsPending = ALL_OPERATIONS;
   mImpl->mRecalculateNaturalSize = true;
 
   mImpl->RequestRelayout();
@@ -400,7 +397,6 @@ void Controller::SetDefaultFontWidth( FontWidth width )
   // Clear the font-specific data
   ClearFontData();
 
-  mImpl->mOperationsPending = ALL_OPERATIONS;
   mImpl->mRecalculateNaturalSize = true;
 
   mImpl->RequestRelayout();
@@ -429,7 +425,6 @@ void Controller::SetDefaultFontSlant( FontSlant slant )
   // Clear the font-specific data
   ClearFontData();
 
-  mImpl->mOperationsPending = ALL_OPERATIONS;
   mImpl->mRecalculateNaturalSize = true;
 
   mImpl->RequestRelayout();
@@ -467,7 +462,6 @@ void Controller::SetDefaultPointSize( float pointSize )
   // Clear the font-specific data
   ClearFontData();
 
-  mImpl->mOperationsPending = ALL_OPERATIONS;
   mImpl->mRecalculateNaturalSize = true;
 
   mImpl->RequestRelayout();
@@ -492,8 +486,6 @@ void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
     DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
     ClearFontData();
     mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
-    mImpl->UpdateModel( ALL_OPERATIONS );
-    mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
     mImpl->mRecalculateNaturalSize = true;
     mImpl->RequestRelayout();
   }
@@ -2579,15 +2571,21 @@ void Controller::ClearFontData()
   {
     mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
   }
-  mImpl->mLogicalModel->mFontRuns.Clear();
-  mImpl->mVisualModel->mGlyphs.Clear();
-  mImpl->mVisualModel->mGlyphsToCharacters.Clear();
-  mImpl->mVisualModel->mCharactersToGlyph.Clear();
-  mImpl->mVisualModel->mCharactersPerGlyph.Clear();
-  mImpl->mVisualModel->mGlyphsPerCharacter.Clear();
-  mImpl->mVisualModel->mGlyphPositions.Clear();
-  mImpl->mVisualModel->mLines.Clear();
   mImpl->mVisualModel->ClearCaches();
+
+  mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
+  mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
+  mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mLogicalModel->mText.Count();
+
+  mImpl->mTextUpdateInfo.mClearAll = true;
+  mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
+                                                           VALIDATE_FONTS            |
+                                                           SHAPE_TEXT                |
+                                                           GET_GLYPH_METRICS         |
+                                                           LAYOUT                    |
+                                                           UPDATE_ACTUAL_SIZE        |
+                                                           REORDER                   |
+                                                           ALIGN );
 }
 
 void Controller::ClearStyleData()