Fix the valid condition of text update
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / controller / text-controller-impl-model-updater.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/internal/text/controller/text-controller-impl-model-updater.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/integration-api/debug.h>
23 #include <dali/integration-api/trace.h>
24 #include <dali/public-api/math/math-utils.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/internal/text/bidirectional-support.h>
28 #include <dali-toolkit/internal/text/character-set-conversion.h>
29 #include <dali-toolkit/internal/text/color-segmentation.h>
30 #include <dali-toolkit/internal/text/hyphenator.h>
31 #include <dali-toolkit/internal/text/multi-language-support.h>
32 #include <dali-toolkit/internal/text/segmentation.h>
33 #include <dali-toolkit/internal/text/shaper.h>
34 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
35
36 namespace Dali::Toolkit::Text
37 {
38 namespace
39 {
40 #if defined(DEBUG_ENABLED)
41 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
42 #endif
43
44 DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_TEXT_PERFORMANCE_MARKER, false);
45
46 // The relative luminance of a color is defined as (L = 0.2126 * R + 0.7152 * G + 0.0722 * B)
47 // based on W3C Recommendations (https://www.w3.org/TR/WCAG20/)
48 constexpr float         BRIGHTNESS_THRESHOLD = 0.179f;
49 constexpr float         CONSTANT_R           = 0.2126f;
50 constexpr float         CONSTANT_G           = 0.7152f;
51 constexpr float         CONSTANT_B           = 0.0722f;
52 constexpr Dali::Vector4 BLACK(0.f, 0.f, 0.f, 1.f);
53 constexpr Dali::Vector4 WHITE(1.f, 1.f, 1.f, 1.f);
54 constexpr Dali::Vector4 LIGHT_BLUE(0.75f, 0.96f, 1.f, 1.f);
55 constexpr Dali::Vector4 BACKGROUND_SUB4(0.58f, 0.87f, 0.96f, 1.f);
56 constexpr Dali::Vector4 BACKGROUND_SUB5(0.83f, 0.94f, 0.98f, 1.f);
57 constexpr Dali::Vector4 BACKGROUND_SUB6(1.f, 0.5f, 0.5f, 1.f);
58 constexpr Dali::Vector4 BACKGROUND_SUB7(1.f, 0.8f, 0.8f, 1.f);
59 } // namespace
60
61 bool ControllerImplModelUpdater::Update(Controller::Impl& impl, OperationsMask operationsRequired)
62 {
63   DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::UpdateModel\n");
64
65   // Calculate the operations to be done.
66   const OperationsMask operations = static_cast<OperationsMask>(impl.mOperationsPending & operationsRequired);
67
68   if(Controller::NO_OPERATION == operations)
69   {
70     // Nothing to do if no operations are pending and required.
71     return false;
72   }
73   DALI_TRACE_SCOPE(gTraceFilter, "DALI_TEXT_MODEL_UPDATE");
74
75   Vector<Character>& srcCharacters = impl.mModel->mLogicalModel->mText;
76   Vector<Character>  displayCharacters;
77   bool               useHiddenText = false;
78   if(impl.mHiddenInput && impl.mEventData != nullptr)
79   {
80     if(impl.mEventData->mIsShowingPlaceholderText)
81     {
82       impl.mHiddenInput->InitPreviousTextCount();
83     }
84     else
85     {
86       impl.mHiddenInput->Substitute(srcCharacters, displayCharacters, impl.mEventData->mPrimaryCursorPosition);
87       useHiddenText = true;
88     }
89   }
90
91   Vector<Character>& utf32Characters    = useHiddenText ? displayCharacters : srcCharacters;
92   const Length       numberOfCharacters = utf32Characters.Count();
93
94   // Index to the first character of the first paragraph to be updated.
95   CharacterIndex startIndex = 0u;
96   // Number of characters of the paragraphs to be removed.
97   Length paragraphCharacters = 0u;
98
99   impl.CalculateTextUpdateIndices(paragraphCharacters);
100
101   // Check whether the indices for updating the text is valid
102   if(impl.mTextUpdateInfo.mParagraphCharacterIndex > numberOfCharacters ||
103      impl.mTextUpdateInfo.mRequestedNumberOfCharacters > numberOfCharacters)
104   {
105     if(numberOfCharacters == 0u)
106     {
107       impl.mTextUpdateInfo.Clear();
108       impl.mTextUpdateInfo.mClearAll = true;
109     }
110     else // numberOfCharacters > 0u
111     {
112       std::string currentText;
113       Utf32ToUtf8(impl.mModel->mLogicalModel->mText.Begin(), numberOfCharacters, currentText);
114
115       DALI_LOG_ERROR("Controller::Impl::UpdateModel: mTextUpdateInfo has invalid indices\n");
116       DALI_LOG_ERROR("Number of characters: %d, current text is: %s paragraphCharacters: %d\n", numberOfCharacters, currentText.c_str(), paragraphCharacters);
117
118       // Dump mTextUpdateInfo
119       DALI_LOG_ERROR("Dump mTextUpdateInfo:\n");
120       DALI_LOG_ERROR("     mTextUpdateInfo.mCharacterIndex = %u\n", impl.mTextUpdateInfo.mCharacterIndex);
121       DALI_LOG_ERROR("     mTextUpdateInfo.mNumberOfCharactersToRemove = %u\n", impl.mTextUpdateInfo.mNumberOfCharactersToRemove);
122       DALI_LOG_ERROR("     mTextUpdateInfo.mNumberOfCharactersToAdd = %u\n", impl.mTextUpdateInfo.mNumberOfCharactersToAdd);
123       DALI_LOG_ERROR("     mTextUpdateInfo.mPreviousNumberOfCharacters = %u\n", impl.mTextUpdateInfo.mPreviousNumberOfCharacters);
124       DALI_LOG_ERROR("     mTextUpdateInfo.mParagraphCharacterIndex = %u\n", impl.mTextUpdateInfo.mParagraphCharacterIndex);
125       DALI_LOG_ERROR("     mTextUpdateInfo.mRequestedNumberOfCharacters = %u\n", impl.mTextUpdateInfo.mRequestedNumberOfCharacters);
126       DALI_LOG_ERROR("     mTextUpdateInfo.mStartGlyphIndex = %u\n", impl.mTextUpdateInfo.mStartGlyphIndex);
127       DALI_LOG_ERROR("     mTextUpdateInfo.mStartLineIndex = %u\n", impl.mTextUpdateInfo.mStartLineIndex);
128       DALI_LOG_ERROR("     mTextUpdateInfo.mEstimatedNumberOfLines = %u\n", impl.mTextUpdateInfo.mEstimatedNumberOfLines);
129       DALI_LOG_ERROR("     mTextUpdateInfo.mClearAll = %d\n", impl.mTextUpdateInfo.mClearAll);
130       DALI_LOG_ERROR("     mTextUpdateInfo.mFullRelayoutNeeded = %d\n", impl.mTextUpdateInfo.mFullRelayoutNeeded);
131       DALI_LOG_ERROR("     mTextUpdateInfo.mIsLastCharacterNewParagraph = %d\n", impl.mTextUpdateInfo.mIsLastCharacterNewParagraph);
132
133       return false;
134     }
135   }
136
137   startIndex = impl.mTextUpdateInfo.mParagraphCharacterIndex;
138
139   if(impl.mTextUpdateInfo.mClearAll ||
140      (0u != paragraphCharacters))
141   {
142     impl.ClearModelData(startIndex, startIndex + ((paragraphCharacters > 0u) ? paragraphCharacters - 1u : 0u), operations);
143   }
144
145   impl.mTextUpdateInfo.mClearAll = false;
146
147   // Whether the model is updated.
148   bool updated = false;
149
150   Vector<LineBreakInfo>& lineBreakInfo               = impl.mModel->mLogicalModel->mLineBreakInfo;
151   const Length           requestedNumberOfCharacters = impl.mTextUpdateInfo.mRequestedNumberOfCharacters;
152
153   if(Controller::NO_OPERATION != (Controller::GET_LINE_BREAKS & operations))
154   {
155     // Retrieves the line break info. The line break info is used to split the text in 'paragraphs' to
156     // calculate the bidirectional info for each 'paragraph'.
157     // It's also used to layout the text (where it should be a new line) or to shape the text (text in different lines
158     // is not shaped together).
159     lineBreakInfo.Resize(numberOfCharacters, TextAbstraction::LINE_NO_BREAK);
160
161     SetLineBreakInfo(utf32Characters,
162                      startIndex,
163                      requestedNumberOfCharacters,
164                      lineBreakInfo);
165
166     if(impl.mModel->mLineWrapMode == ((Text::LineWrap::Mode)DevelText::LineWrap::HYPHENATION) ||
167        impl.mModel->mLineWrapMode == ((Text::LineWrap::Mode)DevelText::LineWrap::MIXED))
168     {
169       CharacterIndex end                 = startIndex + requestedNumberOfCharacters;
170       LineBreakInfo* lineBreakInfoBuffer = lineBreakInfo.Begin();
171
172       for(CharacterIndex index = startIndex; index < end; index++)
173       {
174         CharacterIndex wordEnd = index;
175         while((*(lineBreakInfoBuffer + wordEnd) != TextAbstraction::LINE_ALLOW_BREAK) && (*(lineBreakInfoBuffer + wordEnd) != TextAbstraction::LINE_MUST_BREAK))
176         {
177           wordEnd++;
178         }
179
180         if((wordEnd + 1) == end) // add last char
181         {
182           wordEnd++;
183         }
184
185         Vector<bool> hyphens = GetWordHyphens(utf32Characters.Begin() + index, wordEnd - index, nullptr);
186
187         for(CharacterIndex i = 0; i < (wordEnd - index); i++)
188         {
189           if(hyphens[i])
190           {
191             *(lineBreakInfoBuffer + index + i) = TextAbstraction::LINE_HYPHENATION_BREAK;
192           }
193         }
194
195         index = wordEnd;
196       }
197     }
198
199     // Create the paragraph info.
200     impl.mModel->mLogicalModel->CreateParagraphInfo(startIndex,
201                                                     requestedNumberOfCharacters);
202     updated = true;
203   }
204
205   const bool getScripts    = Controller::NO_OPERATION != (Controller::GET_SCRIPTS & operations);
206   const bool validateFonts = Controller::NO_OPERATION != (Controller::VALIDATE_FONTS & operations);
207
208   Vector<ScriptRun>& scripts    = impl.mModel->mLogicalModel->mScriptRuns;
209   Vector<FontRun>&   validFonts = impl.mModel->mLogicalModel->mFontRuns;
210
211   if(getScripts || validateFonts)
212   {
213     // Validates the fonts assigned by the application or assigns default ones.
214     // It makes sure all the characters are going to be rendered by the correct font.
215     MultilanguageSupport multilanguageSupport = MultilanguageSupport::Get();
216
217     if(getScripts)
218     {
219       // Retrieves the scripts used in the text.
220       multilanguageSupport.SetScripts(utf32Characters,
221                                       startIndex,
222                                       requestedNumberOfCharacters,
223                                       scripts);
224     }
225
226     if(validateFonts)
227     {
228       // Validate the fonts set through the mark-up string.
229       Vector<FontDescriptionRun>& fontDescriptionRuns = impl.mModel->mLogicalModel->mFontDescriptionRuns;
230
231       // Get the default font's description.
232       TextAbstraction::FontDescription defaultFontDescription;
233       TextAbstraction::PointSize26Dot6 defaultPointSize = TextAbstraction::FontClient::DEFAULT_POINT_SIZE * impl.GetFontSizeScale();
234
235       //Get the number of points per one unit of point-size
236       uint32_t numberOfPointsPerOneUnitOfPointSize = impl.mFontClient.GetNumberOfPointsPerOneUnitOfPointSize();
237
238       if(impl.IsShowingPlaceholderText() && impl.mEventData && (nullptr != impl.mEventData->mPlaceholderFont))
239       {
240         // If the placeholder font is set specifically, only placeholder font is changed.
241         defaultFontDescription = impl.mEventData->mPlaceholderFont->mFontDescription;
242         if(impl.mEventData->mPlaceholderFont->sizeDefined)
243         {
244           defaultPointSize = impl.mEventData->mPlaceholderFont->mDefaultPointSize * impl.GetFontSizeScale() * numberOfPointsPerOneUnitOfPointSize;
245         }
246       }
247       else if(nullptr != impl.mFontDefaults)
248       {
249         // Set the normal font and the placeholder font.
250         defaultFontDescription = impl.mFontDefaults->mFontDescription;
251
252         if(impl.mTextFitEnabled)
253         {
254           defaultPointSize = impl.mFontDefaults->mFitPointSize * numberOfPointsPerOneUnitOfPointSize;
255         }
256         else
257         {
258           defaultPointSize = impl.mFontDefaults->mDefaultPointSize * impl.GetFontSizeScale() * numberOfPointsPerOneUnitOfPointSize;
259         }
260       }
261
262       // Validates the fonts. If there is a character with no assigned font it sets a default one.
263       // After this call, fonts are validated.
264       multilanguageSupport.ValidateFonts(utf32Characters,
265                                          scripts,
266                                          fontDescriptionRuns,
267                                          defaultFontDescription,
268                                          defaultPointSize,
269                                          startIndex,
270                                          requestedNumberOfCharacters,
271                                          validFonts);
272     }
273     updated = true;
274   }
275
276   Vector<Character> mirroredUtf32Characters;
277   bool              textMirrored       = false;
278   const Length      numberOfParagraphs = impl.mModel->mLogicalModel->mParagraphInfo.Count();
279   if(Controller::NO_OPERATION != (Controller::BIDI_INFO & operations))
280   {
281     Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = impl.mModel->mLogicalModel->mBidirectionalParagraphInfo;
282     bidirectionalInfo.Reserve(numberOfParagraphs);
283
284     // Calculates the bidirectional info for the whole paragraph if it contains right to left scripts.
285     SetBidirectionalInfo(utf32Characters,
286                          scripts,
287                          lineBreakInfo,
288                          startIndex,
289                          requestedNumberOfCharacters,
290                          bidirectionalInfo,
291                          (impl.mModel->mMatchLayoutDirection != DevelText::MatchLayoutDirection::CONTENTS),
292                          impl.mLayoutDirection);
293
294     if(0u != bidirectionalInfo.Count())
295     {
296       // Only set the character directions if there is right to left characters.
297       Vector<CharacterDirection>& directions = impl.mModel->mLogicalModel->mCharacterDirections;
298       GetCharactersDirection(bidirectionalInfo,
299                              numberOfCharacters,
300                              startIndex,
301                              requestedNumberOfCharacters,
302                              directions);
303
304       // This paragraph has right to left text. Some characters may need to be mirrored.
305       // TODO: consider if the mirrored string can be stored as well.
306
307       textMirrored = GetMirroredText(utf32Characters,
308                                      directions,
309                                      bidirectionalInfo,
310                                      startIndex,
311                                      requestedNumberOfCharacters,
312                                      mirroredUtf32Characters);
313     }
314     else
315     {
316       // There is no right to left characters. Clear the directions vector.
317       impl.mModel->mLogicalModel->mCharacterDirections.Clear();
318     }
319     updated = true;
320   }
321
322   Vector<GlyphInfo>&      glyphs                = impl.mModel->mVisualModel->mGlyphs;
323   Vector<CharacterIndex>& glyphsToCharactersMap = impl.mModel->mVisualModel->mGlyphsToCharacters;
324   Vector<Length>&         charactersPerGlyph    = impl.mModel->mVisualModel->mCharactersPerGlyph;
325   Vector<GlyphIndex>      newParagraphGlyphs;
326   newParagraphGlyphs.Reserve(numberOfParagraphs);
327
328   const Length currentNumberOfGlyphs = glyphs.Count();
329   if(Controller::NO_OPERATION != (Controller::SHAPE_TEXT & operations))
330   {
331     const Vector<Character>& textToShape = textMirrored ? mirroredUtf32Characters : utf32Characters;
332     // Shapes the text.
333     ShapeText(textToShape,
334               lineBreakInfo,
335               scripts,
336               validFonts,
337               startIndex,
338               impl.mTextUpdateInfo.mStartGlyphIndex,
339               requestedNumberOfCharacters,
340               glyphs,
341               glyphsToCharactersMap,
342               charactersPerGlyph,
343               newParagraphGlyphs);
344
345     // Create the 'number of glyphs' per character and the glyph to character conversion tables.
346     impl.mModel->mVisualModel->CreateGlyphsPerCharacterTable(startIndex, impl.mTextUpdateInfo.mStartGlyphIndex, requestedNumberOfCharacters);
347     impl.mModel->mVisualModel->CreateCharacterToGlyphTable(startIndex, impl.mTextUpdateInfo.mStartGlyphIndex, requestedNumberOfCharacters);
348
349     updated = true;
350   }
351
352   const Length numberOfGlyphs = static_cast<Length>(glyphs.Count()) - currentNumberOfGlyphs;
353
354   if(Controller::NO_OPERATION != (Controller::GET_GLYPH_METRICS & operations))
355   {
356     GlyphInfo* glyphsBuffer = glyphs.Begin();
357     impl.mMetrics->GetGlyphMetrics(glyphsBuffer + impl.mTextUpdateInfo.mStartGlyphIndex, numberOfGlyphs);
358
359     // Update the width and advance of all new paragraph characters.
360     for(Vector<GlyphIndex>::ConstIterator it = newParagraphGlyphs.Begin(), endIt = newParagraphGlyphs.End(); it != endIt; ++it)
361     {
362       const GlyphIndex index = *it;
363       GlyphInfo&       glyph = *(glyphsBuffer + index);
364
365       glyph.xBearing = 0.f;
366       glyph.width    = 0.f;
367       glyph.advance  = 0.f;
368     }
369     updated = true;
370   }
371
372   if((nullptr != impl.mEventData) &&
373      impl.mEventData->mPreEditFlag &&
374      (0u != impl.mModel->mVisualModel->mCharactersToGlyph.Count()))
375   {
376     Dali::InputMethodContext::PreEditAttributeDataContainer attrs;
377     impl.mEventData->mInputMethodContext.GetPreeditStyle(attrs);
378     Dali::InputMethodContext::PreeditStyle type = Dali::InputMethodContext::PreeditStyle::NONE;
379
380     // Check the type of preedit and run it.
381     for(Dali::InputMethodContext::PreEditAttributeDataContainer::Iterator it = attrs.Begin(), endIt = attrs.End(); it != endIt; it++)
382     {
383       Dali::InputMethodContext::PreeditAttributeData attrData = *it;
384       DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::UpdateModel PreeditStyle type : %d  start %d end %d \n", attrData.preeditType, attrData.startIndex, attrData.endIndex);
385       type = attrData.preeditType;
386
387       // Check the number of commit characters for the start position.
388       unsigned int numberOfCommit  = impl.mEventData->mPrimaryCursorPosition - impl.mEventData->mPreEditLength;
389       Length       numberOfIndices = attrData.endIndex - attrData.startIndex;
390
391       switch(type)
392       {
393         case Dali::InputMethodContext::PreeditStyle::UNDERLINE:
394         {
395           // Add the underline for the pre-edit text.
396           UnderlinedGlyphRun underlineRun;
397           underlineRun.glyphRun.glyphIndex     = attrData.startIndex + numberOfCommit;
398           underlineRun.glyphRun.numberOfGlyphs = numberOfIndices;
399           impl.mModel->mVisualModel->mUnderlineRuns.PushBack(underlineRun);
400
401           //Mark-up processor case
402           if(impl.mModel->mVisualModel->IsMarkupProcessorEnabled() ||
403              impl.mModel->mLogicalModel->mUnderlineRunsUpdated)
404           {
405             impl.CopyUnderlinedFromLogicalToVisualModels(false);
406           }
407           break;
408         }
409         case Dali::InputMethodContext::PreeditStyle::REVERSE:
410         {
411           Vector4  textColor = impl.mModel->mVisualModel->GetTextColor();
412           ColorRun backgroundColorRun;
413           backgroundColorRun.characterRun.characterIndex     = attrData.startIndex + numberOfCommit;
414           backgroundColorRun.characterRun.numberOfCharacters = numberOfIndices;
415           backgroundColorRun.color                           = textColor;
416           impl.mModel->mLogicalModel->mBackgroundColorRuns.PushBack(backgroundColorRun);
417
418           Vector4 backgroundColor = impl.mModel->mVisualModel->GetBackgroundColor();
419           if(Dali::EqualsZero(backgroundColor.a)) // There is no text background color.
420           {
421             // Try use the control's background color.
422             if(nullptr != impl.mEditableControlInterface)
423             {
424               impl.mEditableControlInterface->GetControlBackgroundColor(backgroundColor);
425               if(Dali::EqualsZero(backgroundColor.a)) // There is no control background color.
426               {
427                 // Determines black or white color according to text color.
428                 // Based on W3C Recommendations (https://www.w3.org/TR/WCAG20/)
429                 float L         = CONSTANT_R * textColor.r + CONSTANT_G * textColor.g + CONSTANT_B * textColor.b;
430                 backgroundColor = L > BRIGHTNESS_THRESHOLD ? BLACK : WHITE;
431               }
432             }
433           }
434
435           Vector<ColorRun> colorRuns;
436           colorRuns.Resize(1u);
437           ColorRun& colorRun                       = *(colorRuns.Begin());
438           colorRun.color                           = backgroundColor;
439           colorRun.characterRun.characterIndex     = attrData.startIndex + numberOfCommit;
440           colorRun.characterRun.numberOfCharacters = numberOfIndices;
441           impl.mModel->mLogicalModel->mColorRuns.PushBack(colorRun);
442
443           //Mark-up processor case
444           if(impl.mModel->mVisualModel->IsMarkupProcessorEnabled() ||
445              impl.mModel->mLogicalModel->mUnderlineRunsUpdated)
446           {
447             impl.CopyUnderlinedFromLogicalToVisualModels(false);
448           }
449           break;
450         }
451         case Dali::InputMethodContext::PreeditStyle::HIGHLIGHT:
452         {
453           ColorRun backgroundColorRun;
454           backgroundColorRun.characterRun.characterIndex     = attrData.startIndex + numberOfCommit;
455           backgroundColorRun.characterRun.numberOfCharacters = numberOfIndices;
456           backgroundColorRun.color                           = LIGHT_BLUE;
457           impl.mModel->mLogicalModel->mBackgroundColorRuns.PushBack(backgroundColorRun);
458
459           //Mark-up processor case
460           if(impl.mModel->mVisualModel->IsMarkupProcessorEnabled() ||
461              impl.mModel->mLogicalModel->mUnderlineRunsUpdated)
462           {
463             impl.CopyUnderlinedFromLogicalToVisualModels(false);
464           }
465           break;
466         }
467         case Dali::InputMethodContext::PreeditStyle::CUSTOM_PLATFORM_STYLE_1:
468         {
469           // CUSTOM_PLATFORM_STYLE_1 should be drawn with background and underline together.
470           ColorRun backgroundColorRun;
471           backgroundColorRun.characterRun.characterIndex     = attrData.startIndex + numberOfCommit;
472           backgroundColorRun.characterRun.numberOfCharacters = numberOfIndices;
473           backgroundColorRun.color                           = BACKGROUND_SUB4;
474           impl.mModel->mLogicalModel->mBackgroundColorRuns.PushBack(backgroundColorRun);
475
476           UnderlinedGlyphRun underlineRun;
477           underlineRun.glyphRun.glyphIndex     = attrData.startIndex + numberOfCommit;
478           underlineRun.glyphRun.numberOfGlyphs = numberOfIndices;
479           impl.mModel->mVisualModel->mUnderlineRuns.PushBack(underlineRun);
480
481           //Mark-up processor case
482           if(impl.mModel->mVisualModel->IsMarkupProcessorEnabled() ||
483              impl.mModel->mLogicalModel->mUnderlineRunsUpdated)
484           {
485             impl.CopyUnderlinedFromLogicalToVisualModels(false);
486           }
487           break;
488         }
489         case Dali::InputMethodContext::PreeditStyle::CUSTOM_PLATFORM_STYLE_2:
490         {
491           // CUSTOM_PLATFORM_STYLE_2 should be drawn with background and underline together.
492           ColorRun backgroundColorRun;
493           backgroundColorRun.characterRun.characterIndex     = attrData.startIndex + numberOfCommit;
494           backgroundColorRun.characterRun.numberOfCharacters = numberOfIndices;
495           backgroundColorRun.color                           = BACKGROUND_SUB5;
496           impl.mModel->mLogicalModel->mBackgroundColorRuns.PushBack(backgroundColorRun);
497
498           UnderlinedGlyphRun underlineRun;
499           underlineRun.glyphRun.glyphIndex     = attrData.startIndex + numberOfCommit;
500           underlineRun.glyphRun.numberOfGlyphs = numberOfIndices;
501           impl.mModel->mVisualModel->mUnderlineRuns.PushBack(underlineRun);
502
503           //Mark-up processor case
504           if(impl.mModel->mVisualModel->IsMarkupProcessorEnabled() ||
505              impl.mModel->mLogicalModel->mUnderlineRunsUpdated)
506           {
507             impl.CopyUnderlinedFromLogicalToVisualModels(false);
508           }
509           break;
510         }
511         case Dali::InputMethodContext::PreeditStyle::CUSTOM_PLATFORM_STYLE_3:
512         {
513           // CUSTOM_PLATFORM_STYLE_3 should be drawn with background and underline together.
514           ColorRun backgroundColorRun;
515           backgroundColorRun.characterRun.characterIndex     = attrData.startIndex + numberOfCommit;
516           backgroundColorRun.characterRun.numberOfCharacters = numberOfIndices;
517           backgroundColorRun.color                           = BACKGROUND_SUB6;
518           impl.mModel->mLogicalModel->mBackgroundColorRuns.PushBack(backgroundColorRun);
519
520           UnderlinedGlyphRun underlineRun;
521           underlineRun.glyphRun.glyphIndex     = attrData.startIndex + numberOfCommit;
522           underlineRun.glyphRun.numberOfGlyphs = numberOfIndices;
523           impl.mModel->mVisualModel->mUnderlineRuns.PushBack(underlineRun);
524
525           //Mark-up processor case
526           if(impl.mModel->mVisualModel->IsMarkupProcessorEnabled() ||
527              impl.mModel->mLogicalModel->mUnderlineRunsUpdated)
528           {
529             impl.CopyUnderlinedFromLogicalToVisualModels(false);
530           }
531           break;
532         }
533         case Dali::InputMethodContext::PreeditStyle::CUSTOM_PLATFORM_STYLE_4:
534         {
535           // CUSTOM_PLATFORM_STYLE_4 should be drawn with background and underline together.
536           ColorRun backgroundColorRun;
537           backgroundColorRun.characterRun.characterIndex     = attrData.startIndex + numberOfCommit;
538           backgroundColorRun.characterRun.numberOfCharacters = numberOfIndices;
539           backgroundColorRun.color                           = BACKGROUND_SUB7;
540           impl.mModel->mLogicalModel->mBackgroundColorRuns.PushBack(backgroundColorRun);
541
542           UnderlinedGlyphRun underlineRun;
543           underlineRun.glyphRun.glyphIndex     = attrData.startIndex + numberOfCommit;
544           underlineRun.glyphRun.numberOfGlyphs = numberOfIndices;
545           impl.mModel->mVisualModel->mUnderlineRuns.PushBack(underlineRun);
546
547           //Mark-up processor case
548           if(impl.mModel->mVisualModel->IsMarkupProcessorEnabled() ||
549              impl.mModel->mLogicalModel->mUnderlineRunsUpdated)
550           {
551             impl.CopyUnderlinedFromLogicalToVisualModels(false);
552           }
553           break;
554         }
555         case Dali::InputMethodContext::PreeditStyle::NONE:
556         default:
557         {
558           break;
559         }
560       }
561     }
562     attrs.Clear();
563     updated = true;
564   }
565
566   if(Controller::NO_OPERATION != (Controller::COLOR & operations))
567   {
568     // Set the color runs in glyphs.
569     SetColorSegmentationInfo(impl.mModel->mLogicalModel->mColorRuns,
570                              impl.mModel->mVisualModel->mCharactersToGlyph,
571                              impl.mModel->mVisualModel->mGlyphsPerCharacter,
572                              startIndex,
573                              impl.mTextUpdateInfo.mStartGlyphIndex,
574                              requestedNumberOfCharacters,
575                              impl.mModel->mVisualModel->mColors,
576                              impl.mModel->mVisualModel->mColorIndices);
577
578     // Set the background color runs in glyphs.
579     SetColorSegmentationInfo(impl.mModel->mLogicalModel->mBackgroundColorRuns,
580                              impl.mModel->mVisualModel->mCharactersToGlyph,
581                              impl.mModel->mVisualModel->mGlyphsPerCharacter,
582                              startIndex,
583                              impl.mTextUpdateInfo.mStartGlyphIndex,
584                              requestedNumberOfCharacters,
585                              impl.mModel->mVisualModel->mBackgroundColors,
586                              impl.mModel->mVisualModel->mBackgroundColorIndices);
587
588     updated = true;
589   }
590
591   if((Controller::NO_OPERATION != (Controller::SHAPE_TEXT & operations)) &&
592      !((nullptr != impl.mEventData) &&
593        impl.mEventData->mPreEditFlag &&
594        (0u != impl.mModel->mVisualModel->mCharactersToGlyph.Count())))
595   {
596     //Mark-up processor case
597     if(impl.mModel->mVisualModel->IsMarkupProcessorEnabled() ||
598        impl.mModel->mLogicalModel->mUnderlineRunsUpdated ||
599        impl.mModel->mLogicalModel->mCharacterSpacingRunsUpdated ||
600        impl.mModel->mLogicalModel->mStrikethroughRunsUpdated)
601     {
602       impl.CopyUnderlinedFromLogicalToVisualModels(true);
603       impl.CopyStrikethroughFromLogicalToVisualModels();
604       impl.CopyCharacterSpacingFromLogicalToVisualModels();
605     }
606
607     updated = true;
608   }
609
610   // The estimated number of lines. Used to avoid reallocations when layouting.
611   impl.mTextUpdateInfo.mEstimatedNumberOfLines = std::max(impl.mModel->mVisualModel->mLines.Count(), impl.mModel->mLogicalModel->mParagraphInfo.Count());
612
613   // Set the previous number of characters for the next time the text is updated.
614   impl.mTextUpdateInfo.mPreviousNumberOfCharacters = numberOfCharacters;
615
616   return updated;
617 }
618
619 } // namespace Dali::Toolkit::Text