2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali-toolkit/internal/text/multi-language-support-impl.h>
22 #include <dali/devel-api/common/singleton-service.h>
23 #include <dali/devel-api/text-abstraction/font-client.h>
24 #include <dali/integration-api/debug.h>
25 #include <dali/integration-api/trace.h>
28 #include <dali-toolkit/internal/text/emoji-helper.h>
29 #include <dali-toolkit/internal/text/multi-language-helper-functions.h>
37 #if defined(DEBUG_ENABLED)
38 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_MULTI_LANGUAGE_SUPPORT");
41 DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_FONT_PERFORMANCE_MARKER, false);
43 const Dali::Toolkit::Text::Character UTF32_A = 0x0041;
50 bool ValidateFontsPerScript::IsValidFont(FontId fontId) const
52 for(Vector<FontId>::ConstIterator it = mValidFonts.Begin(),
53 endIt = mValidFonts.End();
66 FontId DefaultFonts::FindFont(TextAbstraction::FontClient& fontClient,
67 const TextAbstraction::FontDescription& description,
68 PointSize26Dot6 size) const
70 for(std::vector<CacheItem>::const_iterator it = mFonts.begin(),
75 const CacheItem& item = *it;
77 if(((TextAbstraction::FontWeight::NONE == description.weight) || (description.weight == item.description.weight)) &&
78 ((TextAbstraction::FontWidth::NONE == description.width) || (description.width == item.description.width)) &&
79 ((TextAbstraction::FontSlant::NONE == description.slant) || (description.slant == item.description.slant)) &&
80 (size == fontClient.GetPointSize(item.fontId)) &&
81 (description.family.empty() || (description.family == item.description.family)))
90 void DefaultFonts::Cache(const TextAbstraction::FontDescription& description, FontId fontId)
93 item.description = description;
95 mFonts.push_back(item);
98 MultilanguageSupport::MultilanguageSupport()
99 : mDefaultFontPerScriptCache(),
100 mValidFontsPerScriptCache()
102 // Initializes the default font cache to zero (invalid font).
103 // Reserves space to cache the default fonts and access them with the script as an index.
104 mDefaultFontPerScriptCache.Resize(TextAbstraction::GetNumberOfScripts(), NULL);
106 // Initializes the valid fonts cache to NULL (no valid fonts).
107 // Reserves space to cache the valid fonts and access them with the script as an index.
108 mValidFontsPerScriptCache.Resize(TextAbstraction::GetNumberOfScripts(), NULL);
111 MultilanguageSupport::~MultilanguageSupport()
113 // Destroy the default font per script cache.
114 for(Vector<DefaultFonts*>::Iterator it = mDefaultFontPerScriptCache.Begin(),
115 endIt = mDefaultFontPerScriptCache.End();
122 // Destroy the valid fonts per script cache.
123 for(Vector<ValidateFontsPerScript*>::Iterator it = mValidFontsPerScriptCache.Begin(),
124 endIt = mValidFontsPerScriptCache.End();
132 Text::MultilanguageSupport MultilanguageSupport::Get()
134 Text::MultilanguageSupport multilanguageSupportHandle;
136 SingletonService service(SingletonService::Get());
139 // Check whether the singleton is already created
140 Dali::BaseHandle handle = service.GetSingleton(typeid(Text::MultilanguageSupport));
143 // If so, downcast the handle
144 MultilanguageSupport* impl = dynamic_cast<Internal::MultilanguageSupport*>(handle.GetObjectPtr());
145 multilanguageSupportHandle = Text::MultilanguageSupport(impl);
147 else // create and register the object
149 multilanguageSupportHandle = Text::MultilanguageSupport(new MultilanguageSupport);
150 service.Register(typeid(multilanguageSupportHandle), multilanguageSupportHandle);
154 return multilanguageSupportHandle;
157 void MultilanguageSupport::SetScripts(const Vector<Character>& text,
158 CharacterIndex startIndex,
159 Length numberOfCharacters,
160 Vector<ScriptRun>& scripts)
162 if(0u == numberOfCharacters)
164 // Nothing to do if there are no characters.
168 // Find the first index where to insert the script.
169 ScriptRunIndex scriptIndex = 0u;
172 for(Vector<ScriptRun>::ConstIterator it = scripts.Begin(),
173 endIt = scripts.End();
177 const ScriptRun& run = *it;
178 if(startIndex < run.characterRun.characterIndex + run.characterRun.numberOfCharacters)
186 // Stores the current script run.
187 ScriptRun currentScriptRun;
188 currentScriptRun.characterRun.characterIndex = startIndex;
189 currentScriptRun.characterRun.numberOfCharacters = 0u;
190 currentScriptRun.script = TextAbstraction::UNKNOWN;
192 // Reserve some space to reduce the number of reallocations.
193 scripts.Reserve(text.Count() << 2u);
195 // Whether the first valid script needs to be set.
196 bool isFirstScriptToBeSet = true;
198 // Whether the first valid script is a right to left script.
199 bool isParagraphRTL = false;
201 // Count the number of characters which are valid for all scripts. i.e. white spaces or '\n'.
202 Length numberOfAllScriptCharacters = 0u;
204 // Pointers to the text buffer.
205 const Character* const textBuffer = text.Begin();
207 // Initialize whether is right to left direction
208 currentScriptRun.isRightToLeft = false;
210 // Traverse all characters and set the scripts.
211 const Length lastCharacter = startIndex + numberOfCharacters - 1u;
213 for(Length index = startIndex; index <= lastCharacter; ++index)
215 Character character = *(textBuffer + index);
217 // Get the script of the character.
218 Script script = TextAbstraction::GetCharacterScript(character);
220 // Some characters (like white spaces) are valid for many scripts. The rules to set a script
222 // - If they are at the begining of a paragraph they get the script of the first character with
223 // a defined script. If they are at the end, they get the script of the last one.
224 // - If they are between two scripts with the same direction, they get the script of the previous
225 // character with a defined script. If the two scripts have different directions, they get the
226 // script of the first character of the paragraph with a defined script.
228 // Skip those characters valid for many scripts like white spaces or '\n'.
229 bool endOfText = index > lastCharacter;
231 //Handle all Emoji Sequence cases
232 if(IsNewSequence(textBuffer, currentScriptRun.script, index, lastCharacter, script))
234 AddCurrentScriptAndCreatNewScript(script,
238 numberOfAllScriptCharacters,
242 else if(IsScriptChangedToFollowSequence(currentScriptRun.script, character, script))
244 currentScriptRun.script = script;
246 else if(IsOneOfEmojiScripts(currentScriptRun.script) && (TextAbstraction::COMMON == script))
248 // Emojis doesn't mix well with characters common to all scripts. Insert the emoji run.
249 AddCurrentScriptAndCreatNewScript(TextAbstraction::UNKNOWN,
253 numberOfAllScriptCharacters,
259 (TextAbstraction::COMMON == script))
261 // Check if whether is right to left markup and Keeps true if the previous value was true.
262 currentScriptRun.isRightToLeft = currentScriptRun.isRightToLeft || TextAbstraction::IsRightToLeftMark(character);
264 // Count all these characters to be added into a script.
265 ++numberOfAllScriptCharacters;
267 if(TextAbstraction::IsNewParagraph(character))
269 // The character is a new paragraph.
270 // To know when there is a new paragraph is needed because if there is a white space
271 // between two scripts with different directions, it is added to the script with
272 // the same direction than the first script of the paragraph.
273 isFirstScriptToBeSet = true;
275 AddCurrentScriptAndCreatNewScript(TextAbstraction::UNKNOWN,
279 numberOfAllScriptCharacters,
284 // Get the next character.
286 endOfText = index > lastCharacter;
289 character = *(textBuffer + index);
290 script = TextAbstraction::GetCharacterScript(character);
292 //Handle all Emoji Sequence cases
293 if(IsNewSequence(textBuffer, currentScriptRun.script, index, lastCharacter, script))
295 AddCurrentScriptAndCreatNewScript(script,
299 numberOfAllScriptCharacters,
303 else if(IsScriptChangedToFollowSequence(currentScriptRun.script, character, script))
305 currentScriptRun.script = script;
308 } // end while( !endOfText && ( TextAbstraction::COMMON == script ) )
312 // Last characters of the text are 'white spaces'.
313 // There is nothing else to do. Just add the remaining characters to the last script after this bucle.
317 // Check if it is the first character of a paragraph.
318 if(isFirstScriptToBeSet &&
319 (TextAbstraction::UNKNOWN != script) &&
320 (TextAbstraction::COMMON != script) &&
321 (TextAbstraction::EMOJI != script) &&
322 (TextAbstraction::EMOJI_TEXT != script) &&
323 (TextAbstraction::EMOJI_COLOR != script) &&
324 (!TextAbstraction::IsSymbolScript(script)))
326 // Sets the direction of the first valid script.
327 isParagraphRTL = currentScriptRun.isRightToLeft || TextAbstraction::IsRightToLeftScript(script);
328 isFirstScriptToBeSet = false;
331 if((script != currentScriptRun.script) &&
332 (TextAbstraction::COMMON != script))
334 // Current run needs to be stored and a new one initialized.
336 if((isParagraphRTL == TextAbstraction::IsRightToLeftScript(currentScriptRun.script)) &&
337 (TextAbstraction::UNKNOWN != currentScriptRun.script))
339 // Previous script has the same direction than the first script of the paragraph.
340 // All the previously skipped characters need to be added to the previous script before it's stored.
341 currentScriptRun.characterRun.numberOfCharacters += numberOfAllScriptCharacters;
342 numberOfAllScriptCharacters = 0u;
344 else if((TextAbstraction::IsRightToLeftScript(currentScriptRun.script) == TextAbstraction::IsRightToLeftScript(script)) &&
345 (TextAbstraction::UNKNOWN != currentScriptRun.script))
347 // Current script and previous one have the same direction.
348 // All the previously skipped characters need to be added to the previous script before it's stored.
349 currentScriptRun.characterRun.numberOfCharacters += numberOfAllScriptCharacters;
350 numberOfAllScriptCharacters = 0u;
352 else if((TextAbstraction::UNKNOWN == currentScriptRun.script) &&
353 (TextAbstraction::IsSymbolOrEmojiOrTextScript(script)))
355 currentScriptRun.characterRun.numberOfCharacters += numberOfAllScriptCharacters;
356 numberOfAllScriptCharacters = 0u;
359 // Adds the white spaces which are at the begining of the script.
360 numberOfAllScriptCharacters++;
361 AddCurrentScriptAndCreatNewScript(script,
362 TextAbstraction::IsRightToLeftScript(script),
365 numberOfAllScriptCharacters,
371 if(TextAbstraction::UNKNOWN != currentScriptRun.script)
373 // Adds white spaces between characters.
374 currentScriptRun.characterRun.numberOfCharacters += numberOfAllScriptCharacters;
375 numberOfAllScriptCharacters = 0u;
378 // Add one more character to the run.
379 ++currentScriptRun.characterRun.numberOfCharacters;
383 // Add remaining characters into the last script.
384 currentScriptRun.characterRun.numberOfCharacters += numberOfAllScriptCharacters;
386 if(0u != currentScriptRun.characterRun.numberOfCharacters)
388 // Store the last run.
389 scripts.Insert(scripts.Begin() + scriptIndex, currentScriptRun);
393 if(scriptIndex < scripts.Count())
395 // Update the indices of the next script runs.
396 const ScriptRun& run = *(scripts.Begin() + scriptIndex - 1u);
397 CharacterIndex nextCharacterIndex = run.characterRun.characterIndex + run.characterRun.numberOfCharacters;
399 for(Vector<ScriptRun>::Iterator it = scripts.Begin() + scriptIndex,
400 endIt = scripts.End();
404 ScriptRun& run = *it;
405 run.characterRun.characterIndex = nextCharacterIndex;
406 nextCharacterIndex += run.characterRun.numberOfCharacters;
411 void MultilanguageSupport::ValidateFonts(const Vector<Character>& text,
412 const Vector<ScriptRun>& scripts,
413 const Vector<FontDescriptionRun>& fontDescriptions,
414 const TextAbstraction::FontDescription& defaultFontDescription,
415 TextAbstraction::PointSize26Dot6 defaultFontPointSize,
416 CharacterIndex startIndex,
417 Length numberOfCharacters,
418 Vector<FontRun>& fonts)
420 DALI_LOG_INFO(gLogFilter, Debug::General, "-->MultilanguageSupport::ValidateFonts\n");
422 if(0u == numberOfCharacters)
424 DALI_LOG_INFO(gLogFilter, Debug::General, "<--MultilanguageSupport::ValidateFonts\n");
425 // Nothing to do if there are no characters.
429 DALI_TRACE_SCOPE(gTraceFilter, "DALI_TEXT_FONTS_VALIDATE");
431 // Find the first index where to insert the font run.
432 FontRunIndex fontIndex = 0u;
435 for(Vector<FontRun>::ConstIterator it = fonts.Begin(),
440 const FontRun& run = *it;
441 if(startIndex < run.characterRun.characterIndex + run.characterRun.numberOfCharacters)
449 // Traverse the characters and validate/set the fonts.
452 DefaultFonts** defaultFontPerScriptCacheBuffer = mDefaultFontPerScriptCache.Begin();
453 ValidateFontsPerScript** validFontsPerScriptCacheBuffer = mValidFontsPerScriptCache.Begin();
455 // Stores the validated font runs.
456 fonts.Reserve(fontDescriptions.Count());
458 // Initializes a validated font run.
459 FontRun currentFontRun;
460 currentFontRun.characterRun.characterIndex = startIndex;
461 currentFontRun.characterRun.numberOfCharacters = 0u;
462 currentFontRun.fontId = 0u;
463 currentFontRun.isBoldRequired = false;
464 currentFontRun.isItalicRequired = false;
466 // Get the font client.
467 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
469 const Character* const textBuffer = text.Begin();
471 // Iterators of the script runs.
472 Vector<ScriptRun>::ConstIterator scriptRunIt = scripts.Begin();
473 Vector<ScriptRun>::ConstIterator scriptRunEndIt = scripts.End();
474 bool isNewParagraphCharacter = false;
476 FontId previousEmojiFontId = 0u;
477 FontId currentFontId = 0u;
478 FontId previousFontId = 0u;
479 TextAbstraction::Script previousScript = TextAbstraction::UNKNOWN;
481 CharacterIndex lastCharacter = startIndex + numberOfCharacters - 1u;
482 for(Length index = startIndex; index <= lastCharacter; ++index)
484 // Get the current character.
485 const Character character = *(textBuffer + index);
486 bool isItalicRequired = false;
487 bool isBoldRequired = false;
489 // new description for current character
490 TextAbstraction::FontDescription currentFontDescription;
491 TextAbstraction::PointSize26Dot6 currentFontPointSize = defaultFontPointSize;
492 bool isDefaultFont = true;
493 MergeFontDescriptions(fontDescriptions,
494 defaultFontDescription,
495 defaultFontPointSize,
497 currentFontDescription,
498 currentFontPointSize,
501 // Get the font for the current character.
502 FontId fontId = fontClient.GetFontId(currentFontDescription, currentFontPointSize);
503 currentFontId = fontId;
505 // Get the script for the current character.
506 Script script = GetScript(index,
511 if(gLogFilter->IsEnabledFor(Debug::Verbose))
513 Dali::TextAbstraction::FontDescription description;
514 fontClient.GetDescription(fontId, description);
516 DALI_LOG_INFO(gLogFilter,
518 " Initial font set\n Character : %x, Script : %s, Font : %s \n",
520 Dali::TextAbstraction::ScriptName[script],
521 description.path.c_str());
525 // Validate whether the current character is supported by the given font.
526 bool isValidFont = false;
528 // Check first in the cache of default fonts per script and size.
530 FontId cachedDefaultFontId = 0u;
531 DefaultFonts* defaultFonts = *(defaultFontPerScriptCacheBuffer + script);
532 if(NULL != defaultFonts)
534 // This cache stores fall-back fonts.
535 cachedDefaultFontId = defaultFonts->FindFont(fontClient,
536 currentFontDescription,
537 currentFontPointSize);
540 // Whether the cached default font is valid.
541 const bool isValidCachedDefaultFont = 0u != cachedDefaultFontId;
543 // The font is valid if it matches with the default one for the current script and size and it's different than zero.
544 isValidFont = isValidCachedDefaultFont && (fontId == cachedDefaultFontId);
548 // Check if the font supports the character.
549 isValidFont = fontClient.IsCharacterSupportedByFont(fontId, character);
552 bool isCommonScript = false;
553 bool isEmojiScript = TextAbstraction::IsOneOfEmojiScripts(script);
555 if(isEmojiScript && (previousScript == script))
557 // Emoji sequence should use the previous emoji font.
558 if(0u != previousEmojiFontId)
560 fontId = previousEmojiFontId;
565 if(TextAbstraction::IsSpace(character) &&
566 TextAbstraction::HasLigatureMustBreak(script) &&
567 isValidCachedDefaultFont &&
568 (isDefaultFont || (currentFontId == previousFontId)))
570 fontId = cachedDefaultFontId;
574 // If the given font is not valid, it means either:
575 // - there is no cached font for the current script yet or,
576 // - the user has set a different font than the default one for the current script or,
577 // - the platform default font is different than the default font for the current script.
579 // Need to check if the given font supports the current character.
580 if(!isValidFont) // (1)
582 // Whether the current character is common for all scripts (i.e. white spaces, ...)
584 // Is not desirable to cache fonts for the common script.
586 // i.e. Consider the text " हिंदी", the 'white space' has assigned the DEVANAGARI script.
587 // The user may have set a font or the platform's default is used.
589 // As the 'white space' is the first character, no font is cached so the font validation
590 // retrieves a glyph from the given font.
592 // Many fonts support 'white spaces' so probably the font set by the user or the platform's default
593 // supports the 'white space'. However, that font may not support the DEVANAGARI script.
594 isCommonScript = TextAbstraction::IsCommonScript(character) || TextAbstraction::IsEmojiPresentationSelector(character);
596 // Check in the valid fonts cache.
597 ValidateFontsPerScript* validateFontsPerScript = *(validFontsPerScriptCacheBuffer + script);
599 if(NULL != validateFontsPerScript)
601 // This cache stores valid fonts set by the user.
602 isValidFont = validateFontsPerScript->IsValidFont(fontId);
604 // It may happen that a validated font for a script doesn't have all the glyphs for that script.
605 // i.e a font validated for the CJK script may contain glyphs for the chinese language but not for the Japanese.
608 // Checks if the current character is supported by the font is needed.
609 isValidFont = fontClient.IsCharacterSupportedByFont(fontId, character);
613 if(!isValidFont) // (2)
615 // The selected font is not stored in any cache.
617 // Checks if the current character is supported by the selected font.
618 isValidFont = fontClient.IsCharacterSupportedByFont(fontId, character);
620 // If there is a valid font, cache it.
621 if(isValidFont && !isCommonScript)
623 if(NULL == validateFontsPerScript)
625 validateFontsPerScript = new ValidateFontsPerScript();
627 *(validFontsPerScriptCacheBuffer + script) = validateFontsPerScript;
630 validateFontsPerScript->mValidFonts.PushBack(fontId);
633 if(!isValidFont && (fontId != cachedDefaultFontId) && (!TextAbstraction::IsNewParagraph(character))) // (3)
635 // The selected font by the user or the platform's default font has failed to validate the character.
637 // Checks if the previously discarted cached default font supports the character.
638 bool isValidCachedFont = false;
639 if(isValidCachedDefaultFont)
641 isValidCachedFont = fontClient.IsCharacterSupportedByFont(cachedDefaultFontId, character);
644 if(isValidCachedFont)
646 // Use the cached default font for the script if there is one.
647 fontId = cachedDefaultFontId;
652 // There is no valid cached default font for the script.
654 DefaultFonts* defaultFontsPerScript = NULL;
656 // Find a fallback-font.
657 fontId = fontClient.FindFallbackFont(character,
658 currentFontDescription,
659 currentFontPointSize,
664 fontId = fontClient.FindDefaultFont(UTF32_A, currentFontPointSize);
667 if(!isCommonScript && (script != TextAbstraction::UNKNOWN))
669 // Cache the font if it is not an unknown script
670 if(NULL == defaultFontsPerScript)
672 defaultFontsPerScript = *(defaultFontPerScriptCacheBuffer + script);
674 if(NULL == defaultFontsPerScript)
676 defaultFontsPerScript = new DefaultFonts();
677 *(defaultFontPerScriptCacheBuffer + script) = defaultFontsPerScript;
680 defaultFontsPerScript->Cache(currentFontDescription, fontId);
684 } // !isValidFont (3)
685 } // !isValidFont (2)
686 } // !isValidFont (1)
688 if(isEmojiScript && (previousScript != script))
690 //New Emoji sequence should select font according to the variation selector (VS15 or VS16).
691 if(0u != currentFontRun.characterRun.numberOfCharacters)
693 // Store the font run.
694 fonts.Insert(fonts.Begin() + fontIndex, currentFontRun);
698 // Initialize the new one.
699 currentFontRun.characterRun.characterIndex = currentFontRun.characterRun.characterIndex + currentFontRun.characterRun.numberOfCharacters;
700 currentFontRun.characterRun.numberOfCharacters = 0u;
701 currentFontRun.fontId = fontId;
702 currentFontRun.isItalicRequired = false;
703 currentFontRun.isBoldRequired = false;
705 if(TextAbstraction::IsEmojiColorScript(script) || TextAbstraction::IsEmojiTextScript(script))
707 bool isModifiedByVariationSelector = false;
708 GlyphIndex glyphIndexChar = fontClient.GetGlyphIndex(fontId, character);
709 GlyphIndex glyphIndexCharByVS = fontClient.GetGlyphIndex(fontId, character, Text::GetVariationSelectorByScript(script));
711 isModifiedByVariationSelector = glyphIndexChar != glyphIndexCharByVS;
713 if(isModifiedByVariationSelector)
715 FontId requestedFontId = fontClient.FindDefaultFont(character, currentFontPointSize, IsEmojiColorScript(script));
716 if(0u != requestedFontId)
718 currentFontRun.fontId = fontId = requestedFontId;
725 // Store the font id when the first character is an emoji.
728 if(0u != fontId && previousScript != script)
730 previousEmojiFontId = fontId;
735 previousEmojiFontId = 0u;
739 if(gLogFilter->IsEnabledFor(Debug::Verbose))
741 Dali::TextAbstraction::FontDescription description;
742 fontClient.GetDescription(fontId, description);
743 DALI_LOG_INFO(gLogFilter,
745 " Validated font set\n Character : %x, Script : %s, Font : %s \n",
747 Dali::TextAbstraction::ScriptName[script],
748 description.path.c_str());
751 if(!isValidFont && !isCommonScript)
753 Dali::TextAbstraction::FontDescription descriptionForLog;
754 fontClient.GetDescription(fontId, descriptionForLog);
755 DALI_LOG_RELEASE_INFO("Validated font set fail : Character : %x, Script : %s, Font : %s \n",
757 Dali::TextAbstraction::ScriptName[script],
758 descriptionForLog.path.c_str());
761 // Whether bols style is required.
762 isBoldRequired = (currentFontDescription.weight >= TextAbstraction::FontWeight::BOLD);
764 // Whether italic style is required.
765 isItalicRequired = (currentFontDescription.slant >= TextAbstraction::FontSlant::ITALIC);
767 // The font is now validated.
768 if((fontId != currentFontRun.fontId) ||
769 isNewParagraphCharacter ||
770 // If font id is same as previous but style is diffrent, initialize new one
771 ((fontId == currentFontRun.fontId) && ((isBoldRequired != currentFontRun.isBoldRequired) || (isItalicRequired != currentFontRun.isItalicRequired))))
773 // Current run needs to be stored and a new one initialized.
775 if(0u != currentFontRun.characterRun.numberOfCharacters)
777 // Store the font run.
778 fonts.Insert(fonts.Begin() + fontIndex, currentFontRun);
782 // Initialize the new one.
783 currentFontRun.characterRun.characterIndex = currentFontRun.characterRun.characterIndex + currentFontRun.characterRun.numberOfCharacters;
784 currentFontRun.characterRun.numberOfCharacters = 0u;
785 currentFontRun.fontId = fontId;
786 currentFontRun.isBoldRequired = isBoldRequired;
787 currentFontRun.isItalicRequired = isItalicRequired;
790 // Add one more character to the run.
791 ++currentFontRun.characterRun.numberOfCharacters;
793 // Whether the current character is a new paragraph character.
794 isNewParagraphCharacter = TextAbstraction::IsNewParagraph(character);
795 previousScript = script;
796 previousFontId = currentFontId;
797 } // end traverse characters.
799 if(0u != currentFontRun.characterRun.numberOfCharacters)
801 // Store the last run.
802 fonts.Insert(fonts.Begin() + fontIndex, currentFontRun);
806 if(fontIndex < fonts.Count())
808 // Update the indices of the next font runs.
809 const FontRun& run = *(fonts.Begin() + fontIndex - 1u);
810 CharacterIndex nextCharacterIndex = run.characterRun.characterIndex + run.characterRun.numberOfCharacters;
812 for(Vector<FontRun>::Iterator it = fonts.Begin() + fontIndex,
819 run.characterRun.characterIndex = nextCharacterIndex;
820 nextCharacterIndex += run.characterRun.numberOfCharacters;
824 DALI_LOG_INFO(gLogFilter, Debug::General, "<--MultilanguageSupport::ValidateFonts\n");
827 void MultilanguageSupport::AddCurrentScriptAndCreatNewScript(const Script requestedScript,
828 const bool isRightToLeft,
829 const bool addScriptCharactersToNewScript,
830 ScriptRun& currentScriptRun,
831 Length& numberOfAllScriptCharacters,
832 Vector<ScriptRun>& scripts,
833 ScriptRunIndex& scriptIndex)
835 // Add the pending characters to the current script
836 currentScriptRun.characterRun.numberOfCharacters += (addScriptCharactersToNewScript ? 0u : numberOfAllScriptCharacters);
838 // In-case the current script is empty then no need to add it for scripts
839 if(0u != currentScriptRun.characterRun.numberOfCharacters)
841 // Store the script run.
842 scripts.Insert(scripts.Begin() + scriptIndex, currentScriptRun);
846 // Initialize the new one by the requested script
847 currentScriptRun.characterRun.characterIndex = currentScriptRun.characterRun.characterIndex + currentScriptRun.characterRun.numberOfCharacters;
848 currentScriptRun.characterRun.numberOfCharacters = (addScriptCharactersToNewScript ? numberOfAllScriptCharacters : 0u);
849 currentScriptRun.script = requestedScript;
850 numberOfAllScriptCharacters = 0u;
851 // Initialize whether is right to left direction
852 currentScriptRun.isRightToLeft = isRightToLeft;
855 } // namespace Internal
859 } // namespace Toolkit