2 * Copyright (c) 2023 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;
45 // TODO : Customization required for these values.
46 constexpr std::size_t MAX_VALIDATE_FONTS_PER_SCRIPT_CACHE_SIZE = 63;
47 constexpr std::size_t MAX_DEFAULT_FONTS_CACHE_SIZE = 15;
49 constexpr int VALIDATE_FONTS_PER_SCRIPT_REMAIN_COUNT = 8;
50 constexpr int DEFAULT_FONTS_REMAIN_COUNT = 2;
57 bool ValidateFontsPerScript::IsValidFont(FontId fontId) const
59 for(Vector<FontId>::ConstIterator it = mValidFonts.Begin(),
60 endIt = mValidFonts.End();
72 void ValidateFontsPerScript::Cache(FontId fontId)
74 mValidFonts.PushBack(fontId);
75 if(MAX_VALIDATE_FONTS_PER_SCRIPT_CACHE_SIZE < mValidFonts.Count())
77 // Clear cache but remaind some last items.
78 const auto offset = mValidFonts.Count() - VALIDATE_FONTS_PER_SCRIPT_REMAIN_COUNT;
79 for(int i = 0; i < VALIDATE_FONTS_PER_SCRIPT_REMAIN_COUNT; ++i)
81 mValidFonts[i] = std::move(mValidFonts[offset + i]);
83 mValidFonts.Resize(VALIDATE_FONTS_PER_SCRIPT_REMAIN_COUNT);
87 FontId DefaultFonts::FindFont(TextAbstraction::FontClient& fontClient,
88 const TextAbstraction::FontDescription& description,
89 PointSize26Dot6 size) const
91 for(std::vector<CacheItem>::const_iterator it = mFonts.begin(),
96 const CacheItem& item = *it;
98 if(((TextAbstraction::FontWeight::NONE == description.weight) || (description.weight == item.description.weight)) &&
99 ((TextAbstraction::FontWidth::NONE == description.width) || (description.width == item.description.width)) &&
100 ((TextAbstraction::FontSlant::NONE == description.slant) || (description.slant == item.description.slant)) &&
101 (size == fontClient.GetPointSize(item.fontId)) &&
102 (description.family.empty() || (description.family == item.description.family)))
111 void DefaultFonts::Cache(const TextAbstraction::FontDescription& description, FontId fontId)
114 item.description = description;
115 item.fontId = fontId;
116 mFonts.push_back(item);
117 if(MAX_DEFAULT_FONTS_CACHE_SIZE < mFonts.size())
119 // Clear cache but remaind some last items.
120 const auto offset = mFonts.size() - DEFAULT_FONTS_REMAIN_COUNT;
121 for(int i = 0; i < DEFAULT_FONTS_REMAIN_COUNT; ++i)
123 mFonts[i] = std::move(mFonts[offset + i]);
125 mFonts.resize(DEFAULT_FONTS_REMAIN_COUNT);
129 MultilanguageSupport::MultilanguageSupport()
130 : mDefaultFontPerScriptCache(),
131 mValidFontsPerScriptCache()
133 // Initializes the default font cache to zero (invalid font).
134 // Reserves space to cache the default fonts and access them with the script as an index.
135 mDefaultFontPerScriptCache.Resize(TextAbstraction::GetNumberOfScripts(), NULL);
137 // Initializes the valid fonts cache to NULL (no valid fonts).
138 // Reserves space to cache the valid fonts and access them with the script as an index.
139 mValidFontsPerScriptCache.Resize(TextAbstraction::GetNumberOfScripts(), NULL);
142 MultilanguageSupport::~MultilanguageSupport()
144 // Destroy the default font per script cache.
145 for(Vector<DefaultFonts*>::Iterator it = mDefaultFontPerScriptCache.Begin(),
146 endIt = mDefaultFontPerScriptCache.End();
153 // Destroy the valid fonts per script cache.
154 for(Vector<ValidateFontsPerScript*>::Iterator it = mValidFontsPerScriptCache.Begin(),
155 endIt = mValidFontsPerScriptCache.End();
163 Text::MultilanguageSupport MultilanguageSupport::Get()
165 Text::MultilanguageSupport multilanguageSupportHandle;
167 SingletonService service(SingletonService::Get());
170 // Check whether the singleton is already created
171 Dali::BaseHandle handle = service.GetSingleton(typeid(Text::MultilanguageSupport));
174 // If so, downcast the handle
175 MultilanguageSupport* impl = dynamic_cast<Internal::MultilanguageSupport*>(handle.GetObjectPtr());
176 multilanguageSupportHandle = Text::MultilanguageSupport(impl);
178 else // create and register the object
180 multilanguageSupportHandle = Text::MultilanguageSupport(new MultilanguageSupport);
181 service.Register(typeid(multilanguageSupportHandle), multilanguageSupportHandle);
185 return multilanguageSupportHandle;
188 void MultilanguageSupport::SetScripts(const Vector<Character>& text,
189 CharacterIndex startIndex,
190 Length numberOfCharacters,
191 Vector<ScriptRun>& scripts)
193 if(0u == numberOfCharacters)
195 // Nothing to do if there are no characters.
199 // Find the first index where to insert the script.
200 ScriptRunIndex scriptIndex = 0u;
203 for(Vector<ScriptRun>::ConstIterator it = scripts.Begin(),
204 endIt = scripts.End();
208 const ScriptRun& run = *it;
209 if(startIndex < run.characterRun.characterIndex + run.characterRun.numberOfCharacters)
217 // Stores the current script run.
218 ScriptRun currentScriptRun;
219 currentScriptRun.characterRun.characterIndex = startIndex;
220 currentScriptRun.characterRun.numberOfCharacters = 0u;
221 currentScriptRun.script = TextAbstraction::UNKNOWN;
223 // Reserve some space to reduce the number of reallocations.
224 scripts.Reserve(text.Count() << 2u);
226 // Whether the first valid script needs to be set.
227 bool isFirstScriptToBeSet = true;
229 // Whether the first valid script is a right to left script.
230 bool isParagraphRTL = false;
232 // Count the number of characters which are valid for all scripts. i.e. white spaces or '\n'.
233 Length numberOfAllScriptCharacters = 0u;
235 // Pointers to the text buffer.
236 const Character* const textBuffer = text.Begin();
238 // Initialize whether is right to left direction
239 currentScriptRun.isRightToLeft = false;
241 // Traverse all characters and set the scripts.
242 const Length lastCharacter = startIndex + numberOfCharacters - 1u;
244 for(Length index = startIndex; index <= lastCharacter; ++index)
246 Character character = *(textBuffer + index);
248 // Get the script of the character.
249 Script script = TextAbstraction::GetCharacterScript(character);
251 // Some characters (like white spaces) are valid for many scripts. The rules to set a script
253 // - If they are at the begining of a paragraph they get the script of the first character with
254 // a defined script. If they are at the end, they get the script of the last one.
255 // - If they are between two scripts with the same direction, they get the script of the previous
256 // character with a defined script. If the two scripts have different directions, they get the
257 // script of the first character of the paragraph with a defined script.
259 // Skip those characters valid for many scripts like white spaces or '\n'.
260 bool endOfText = index > lastCharacter;
262 //Handle all Emoji Sequence cases
263 if(IsNewSequence(textBuffer, currentScriptRun.script, index, lastCharacter, script))
265 AddCurrentScriptAndCreatNewScript(script,
269 numberOfAllScriptCharacters,
273 else if(IsScriptChangedToFollowSequence(currentScriptRun.script, character, script))
275 currentScriptRun.script = script;
277 else if(IsOneOfEmojiScripts(currentScriptRun.script) && (TextAbstraction::COMMON == script))
279 // Emojis doesn't mix well with characters common to all scripts. Insert the emoji run.
280 AddCurrentScriptAndCreatNewScript(TextAbstraction::UNKNOWN,
284 numberOfAllScriptCharacters,
290 (TextAbstraction::COMMON == script))
292 // Check if whether is right to left markup and Keeps true if the previous value was true.
293 currentScriptRun.isRightToLeft = currentScriptRun.isRightToLeft || TextAbstraction::IsRightToLeftMark(character);
295 // Count all these characters to be added into a script.
296 ++numberOfAllScriptCharacters;
298 if(TextAbstraction::IsNewParagraph(character))
300 // The character is a new paragraph.
301 // To know when there is a new paragraph is needed because if there is a white space
302 // between two scripts with different directions, it is added to the script with
303 // the same direction than the first script of the paragraph.
304 isFirstScriptToBeSet = true;
306 AddCurrentScriptAndCreatNewScript(TextAbstraction::UNKNOWN,
310 numberOfAllScriptCharacters,
315 // Get the next character.
317 endOfText = index > lastCharacter;
320 character = *(textBuffer + index);
321 script = TextAbstraction::GetCharacterScript(character);
323 //Handle all Emoji Sequence cases
324 if(IsNewSequence(textBuffer, currentScriptRun.script, index, lastCharacter, script))
326 AddCurrentScriptAndCreatNewScript(script,
330 numberOfAllScriptCharacters,
334 else if(IsScriptChangedToFollowSequence(currentScriptRun.script, character, script))
336 currentScriptRun.script = script;
339 } // end while( !endOfText && ( TextAbstraction::COMMON == script ) )
343 // Last characters of the text are 'white spaces'.
344 // There is nothing else to do. Just add the remaining characters to the last script after this bucle.
348 // Check if it is the first character of a paragraph.
349 if(isFirstScriptToBeSet &&
350 (TextAbstraction::UNKNOWN != script) &&
351 (TextAbstraction::COMMON != script) &&
352 (TextAbstraction::EMOJI != script) &&
353 (TextAbstraction::EMOJI_TEXT != script) &&
354 (TextAbstraction::EMOJI_COLOR != script) &&
355 (!TextAbstraction::IsSymbolScript(script)))
357 // Sets the direction of the first valid script.
358 isParagraphRTL = currentScriptRun.isRightToLeft || TextAbstraction::IsRightToLeftScript(script);
359 isFirstScriptToBeSet = false;
362 if((script != currentScriptRun.script) &&
363 (TextAbstraction::COMMON != script))
365 // Current run needs to be stored and a new one initialized.
367 if((isParagraphRTL == TextAbstraction::IsRightToLeftScript(currentScriptRun.script)) &&
368 (TextAbstraction::UNKNOWN != currentScriptRun.script))
370 // Previous script has the same direction than the first script of the paragraph.
371 // All the previously skipped characters need to be added to the previous script before it's stored.
372 currentScriptRun.characterRun.numberOfCharacters += numberOfAllScriptCharacters;
373 numberOfAllScriptCharacters = 0u;
375 else if((TextAbstraction::IsRightToLeftScript(currentScriptRun.script) == TextAbstraction::IsRightToLeftScript(script)) &&
376 (TextAbstraction::UNKNOWN != currentScriptRun.script))
378 // Current script and previous one have the same direction.
379 // All the previously skipped characters need to be added to the previous script before it's stored.
380 currentScriptRun.characterRun.numberOfCharacters += numberOfAllScriptCharacters;
381 numberOfAllScriptCharacters = 0u;
383 else if((TextAbstraction::UNKNOWN == currentScriptRun.script) &&
384 (TextAbstraction::IsSymbolOrEmojiOrTextScript(script)))
386 currentScriptRun.characterRun.numberOfCharacters += numberOfAllScriptCharacters;
387 numberOfAllScriptCharacters = 0u;
390 // Adds the white spaces which are at the begining of the script.
391 numberOfAllScriptCharacters++;
392 AddCurrentScriptAndCreatNewScript(script,
393 TextAbstraction::IsRightToLeftScript(script),
396 numberOfAllScriptCharacters,
402 if(TextAbstraction::UNKNOWN != currentScriptRun.script)
404 // Adds white spaces between characters.
405 currentScriptRun.characterRun.numberOfCharacters += numberOfAllScriptCharacters;
406 numberOfAllScriptCharacters = 0u;
409 // Add one more character to the run.
410 ++currentScriptRun.characterRun.numberOfCharacters;
414 // Add remaining characters into the last script.
415 currentScriptRun.characterRun.numberOfCharacters += numberOfAllScriptCharacters;
417 if(0u != currentScriptRun.characterRun.numberOfCharacters)
419 // Store the last run.
420 scripts.Insert(scripts.Begin() + scriptIndex, currentScriptRun);
424 if(scriptIndex < scripts.Count())
426 // Update the indices of the next script runs.
427 const ScriptRun& run = *(scripts.Begin() + scriptIndex - 1u);
428 CharacterIndex nextCharacterIndex = run.characterRun.characterIndex + run.characterRun.numberOfCharacters;
430 for(Vector<ScriptRun>::Iterator it = scripts.Begin() + scriptIndex,
431 endIt = scripts.End();
435 ScriptRun& run = *it;
436 run.characterRun.characterIndex = nextCharacterIndex;
437 nextCharacterIndex += run.characterRun.numberOfCharacters;
442 void MultilanguageSupport::ValidateFonts(const Vector<Character>& text,
443 const Vector<ScriptRun>& scripts,
444 const Vector<FontDescriptionRun>& fontDescriptions,
445 const TextAbstraction::FontDescription& defaultFontDescription,
446 TextAbstraction::PointSize26Dot6 defaultFontPointSize,
448 CharacterIndex startIndex,
449 Length numberOfCharacters,
450 Vector<FontRun>& fonts)
452 DALI_LOG_INFO(gLogFilter, Debug::General, "-->MultilanguageSupport::ValidateFonts\n");
454 if(0u == numberOfCharacters)
456 DALI_LOG_INFO(gLogFilter, Debug::General, "<--MultilanguageSupport::ValidateFonts\n");
457 // Nothing to do if there are no characters.
461 DALI_TRACE_SCOPE(gTraceFilter, "DALI_TEXT_FONTS_VALIDATE");
463 // Find the first index where to insert the font run.
464 FontRunIndex fontIndex = 0u;
467 for(Vector<FontRun>::ConstIterator it = fonts.Begin(),
472 const FontRun& run = *it;
473 if(startIndex < run.characterRun.characterIndex + run.characterRun.numberOfCharacters)
481 // Traverse the characters and validate/set the fonts.
484 DefaultFonts** defaultFontPerScriptCacheBuffer = mDefaultFontPerScriptCache.Begin();
485 ValidateFontsPerScript** validFontsPerScriptCacheBuffer = mValidFontsPerScriptCache.Begin();
487 // Stores the validated font runs.
488 fonts.Reserve(fontDescriptions.Count());
490 // Initializes a validated font run.
491 FontRun currentFontRun;
492 currentFontRun.characterRun.characterIndex = startIndex;
493 currentFontRun.characterRun.numberOfCharacters = 0u;
494 currentFontRun.fontId = 0u;
495 currentFontRun.isBoldRequired = false;
496 currentFontRun.isItalicRequired = false;
498 // Get the font client.
499 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
501 const Character* const textBuffer = text.Begin();
503 // Iterators of the script runs.
504 Vector<ScriptRun>::ConstIterator scriptRunIt = scripts.Begin();
505 Vector<ScriptRun>::ConstIterator scriptRunEndIt = scripts.End();
506 bool isNewParagraphCharacter = false;
508 FontId previousEmojiFontId = 0u;
509 FontId currentFontId = 0u;
510 FontId previousFontId = 0u;
511 TextAbstraction::Script previousScript = TextAbstraction::UNKNOWN;
513 CharacterIndex lastCharacter = startIndex + numberOfCharacters - 1u;
514 for(Length index = startIndex; index <= lastCharacter; ++index)
516 // Get the current character.
517 const Character character = *(textBuffer + index);
518 bool isItalicRequired = false;
519 bool isBoldRequired = false;
521 // new description for current character
522 TextAbstraction::FontDescription currentFontDescription;
523 TextAbstraction::PointSize26Dot6 currentFontPointSize = defaultFontPointSize;
524 bool isDefaultFont = true;
525 MergeFontDescriptions(fontDescriptions,
526 defaultFontDescription,
527 defaultFontPointSize,
530 currentFontDescription,
531 currentFontPointSize,
534 // Get the font for the current character.
535 FontId fontId = fontClient.GetFontId(currentFontDescription, currentFontPointSize);
536 currentFontId = fontId;
538 // Get the script for the current character.
539 Script script = GetScript(index,
544 if(gLogFilter->IsEnabledFor(Debug::Verbose))
546 Dali::TextAbstraction::FontDescription description;
547 fontClient.GetDescription(fontId, description);
549 DALI_LOG_INFO(gLogFilter,
551 " Initial font set\n Character : %x, Script : %s, Font : %s \n",
553 Dali::TextAbstraction::ScriptName[script],
554 description.path.c_str());
558 // Validate whether the current character is supported by the given font.
559 bool isValidFont = false;
561 // Check first in the cache of default fonts per script and size.
563 FontId cachedDefaultFontId = 0u;
564 DefaultFonts* defaultFonts = *(defaultFontPerScriptCacheBuffer + script);
565 if(NULL != defaultFonts)
567 // This cache stores fall-back fonts.
568 cachedDefaultFontId = defaultFonts->FindFont(fontClient,
569 currentFontDescription,
570 currentFontPointSize);
573 // Whether the cached default font is valid.
574 const bool isValidCachedDefaultFont = 0u != cachedDefaultFontId;
576 // The font is valid if it matches with the default one for the current script and size and it's different than zero.
577 isValidFont = isValidCachedDefaultFont && (fontId == cachedDefaultFontId);
581 // Check if the font supports the character.
582 isValidFont = fontClient.IsCharacterSupportedByFont(fontId, character);
585 bool isCommonScript = false;
586 bool isEmojiScript = TextAbstraction::IsOneOfEmojiScripts(script);
588 if(isEmojiScript && (previousScript == script))
590 // Emoji sequence should use the previous emoji font.
591 if(0u != previousEmojiFontId)
593 fontId = previousEmojiFontId;
598 if(TextAbstraction::IsSpace(character) &&
599 TextAbstraction::HasLigatureMustBreak(script) &&
600 isValidCachedDefaultFont &&
601 (isDefaultFont || (currentFontId == previousFontId)))
603 fontId = cachedDefaultFontId;
607 // If the given font is not valid, it means either:
608 // - there is no cached font for the current script yet or,
609 // - the user has set a different font than the default one for the current script or,
610 // - the platform default font is different than the default font for the current script.
612 // Need to check if the given font supports the current character.
613 if(!isValidFont) // (1)
615 // Whether the current character is common for all scripts (i.e. white spaces, ...)
617 // Is not desirable to cache fonts for the common script.
619 // i.e. Consider the text " हिंदी", the 'white space' has assigned the DEVANAGARI script.
620 // The user may have set a font or the platform's default is used.
622 // As the 'white space' is the first character, no font is cached so the font validation
623 // retrieves a glyph from the given font.
625 // Many fonts support 'white spaces' so probably the font set by the user or the platform's default
626 // supports the 'white space'. However, that font may not support the DEVANAGARI script.
627 isCommonScript = TextAbstraction::IsCommonScript(character) || TextAbstraction::IsEmojiPresentationSelector(character);
629 // Check in the valid fonts cache.
630 ValidateFontsPerScript* validateFontsPerScript = *(validFontsPerScriptCacheBuffer + script);
632 if(NULL != validateFontsPerScript)
634 // This cache stores valid fonts set by the user.
635 isValidFont = validateFontsPerScript->IsValidFont(fontId);
637 // It may happen that a validated font for a script doesn't have all the glyphs for that script.
638 // i.e a font validated for the CJK script may contain glyphs for the chinese language but not for the Japanese.
641 // Checks if the current character is supported by the font is needed.
642 isValidFont = fontClient.IsCharacterSupportedByFont(fontId, character);
646 if(!isValidFont) // (2)
648 // The selected font is not stored in any cache.
650 // Checks if the current character is supported by the selected font.
651 isValidFont = fontClient.IsCharacterSupportedByFont(fontId, character);
653 // If there is a valid font, cache it.
654 if(isValidFont && !isCommonScript)
656 if(NULL == validateFontsPerScript)
658 validateFontsPerScript = new ValidateFontsPerScript();
660 *(validFontsPerScriptCacheBuffer + script) = validateFontsPerScript;
663 validateFontsPerScript->Cache(fontId);
666 if(!isValidFont && (fontId != cachedDefaultFontId) && (!TextAbstraction::IsNewParagraph(character))) // (3)
668 // The selected font by the user or the platform's default font has failed to validate the character.
670 // Checks if the previously discarted cached default font supports the character.
671 bool isValidCachedFont = false;
672 if(isValidCachedDefaultFont)
674 isValidCachedFont = fontClient.IsCharacterSupportedByFont(cachedDefaultFontId, character);
677 if(isValidCachedFont)
679 // Use the cached default font for the script if there is one.
680 fontId = cachedDefaultFontId;
685 // There is no valid cached default font for the script.
687 DefaultFonts* defaultFontsPerScript = NULL;
689 // Find a fallback-font.
690 fontId = fontClient.FindFallbackFont(character,
691 currentFontDescription,
692 currentFontPointSize,
697 fontId = fontClient.FindDefaultFont(UTF32_A, currentFontPointSize);
700 if(!isCommonScript && (script != TextAbstraction::UNKNOWN))
702 // Cache the font if it is not an unknown script
703 if(NULL == defaultFontsPerScript)
705 defaultFontsPerScript = *(defaultFontPerScriptCacheBuffer + script);
707 if(NULL == defaultFontsPerScript)
709 defaultFontsPerScript = new DefaultFonts();
710 *(defaultFontPerScriptCacheBuffer + script) = defaultFontsPerScript;
713 defaultFontsPerScript->Cache(currentFontDescription, fontId);
717 } // !isValidFont (3)
718 } // !isValidFont (2)
719 } // !isValidFont (1)
721 if(isEmojiScript && (previousScript != script))
723 //New Emoji sequence should select font according to the variation selector (VS15 or VS16).
724 if(0u != currentFontRun.characterRun.numberOfCharacters)
726 // Store the font run.
727 fonts.Insert(fonts.Begin() + fontIndex, currentFontRun);
731 // Initialize the new one.
732 currentFontRun.characterRun.characterIndex = currentFontRun.characterRun.characterIndex + currentFontRun.characterRun.numberOfCharacters;
733 currentFontRun.characterRun.numberOfCharacters = 0u;
734 currentFontRun.fontId = fontId;
735 currentFontRun.isItalicRequired = false;
736 currentFontRun.isBoldRequired = false;
738 if(TextAbstraction::IsEmojiColorScript(script) || TextAbstraction::IsEmojiTextScript(script))
740 bool isModifiedByVariationSelector = false;
741 GlyphIndex glyphIndexChar = fontClient.GetGlyphIndex(fontId, character);
742 GlyphIndex glyphIndexCharByVS = fontClient.GetGlyphIndex(fontId, character, Text::GetVariationSelectorByScript(script));
744 isModifiedByVariationSelector = glyphIndexChar != glyphIndexCharByVS;
746 if(isModifiedByVariationSelector)
748 FontId requestedFontId = fontClient.FindDefaultFont(character, currentFontPointSize, IsEmojiColorScript(script));
749 if(0u != requestedFontId)
751 currentFontRun.fontId = fontId = requestedFontId;
758 // Store the font id when the first character is an emoji.
761 if(0u != fontId && previousScript != script)
763 previousEmojiFontId = fontId;
768 previousEmojiFontId = 0u;
772 if(gLogFilter->IsEnabledFor(Debug::Verbose))
774 Dali::TextAbstraction::FontDescription description;
775 fontClient.GetDescription(fontId, description);
776 DALI_LOG_INFO(gLogFilter,
778 " Validated font set\n Character : %x, Script : %s, Font : %s \n",
780 Dali::TextAbstraction::ScriptName[script],
781 description.path.c_str());
784 if(!isValidFont && !isCommonScript)
786 Dali::TextAbstraction::FontDescription descriptionForLog;
787 fontClient.GetDescription(fontId, descriptionForLog);
788 DALI_LOG_RELEASE_INFO("Validated font set fail : Character : %x, Script : %s, Font : %s \n",
790 Dali::TextAbstraction::ScriptName[script],
791 descriptionForLog.path.c_str());
794 // Whether bols style is required.
795 isBoldRequired = (currentFontDescription.weight >= TextAbstraction::FontWeight::BOLD);
797 // Whether italic style is required.
798 isItalicRequired = (currentFontDescription.slant >= TextAbstraction::FontSlant::ITALIC);
800 // The font is now validated.
801 if((fontId != currentFontRun.fontId) ||
802 isNewParagraphCharacter ||
803 // If font id is same as previous but style is diffrent, initialize new one
804 ((fontId == currentFontRun.fontId) && ((isBoldRequired != currentFontRun.isBoldRequired) || (isItalicRequired != currentFontRun.isItalicRequired))))
806 // Current run needs to be stored and a new one initialized.
808 if(0u != currentFontRun.characterRun.numberOfCharacters)
810 // Store the font run.
811 fonts.Insert(fonts.Begin() + fontIndex, currentFontRun);
815 // Initialize the new one.
816 currentFontRun.characterRun.characterIndex = currentFontRun.characterRun.characterIndex + currentFontRun.characterRun.numberOfCharacters;
817 currentFontRun.characterRun.numberOfCharacters = 0u;
818 currentFontRun.fontId = fontId;
819 currentFontRun.isBoldRequired = isBoldRequired;
820 currentFontRun.isItalicRequired = isItalicRequired;
823 // Add one more character to the run.
824 ++currentFontRun.characterRun.numberOfCharacters;
826 // Whether the current character is a new paragraph character.
827 isNewParagraphCharacter = TextAbstraction::IsNewParagraph(character);
828 previousScript = script;
829 previousFontId = currentFontId;
830 } // end traverse characters.
832 if(0u != currentFontRun.characterRun.numberOfCharacters)
834 // Store the last run.
835 fonts.Insert(fonts.Begin() + fontIndex, currentFontRun);
839 if(fontIndex < fonts.Count())
841 // Update the indices of the next font runs.
842 const FontRun& run = *(fonts.Begin() + fontIndex - 1u);
843 CharacterIndex nextCharacterIndex = run.characterRun.characterIndex + run.characterRun.numberOfCharacters;
845 for(Vector<FontRun>::Iterator it = fonts.Begin() + fontIndex,
852 run.characterRun.characterIndex = nextCharacterIndex;
853 nextCharacterIndex += run.characterRun.numberOfCharacters;
857 DALI_LOG_INFO(gLogFilter, Debug::General, "<--MultilanguageSupport::ValidateFonts\n");
860 void MultilanguageSupport::AddCurrentScriptAndCreatNewScript(const Script requestedScript,
861 const bool isRightToLeft,
862 const bool addScriptCharactersToNewScript,
863 ScriptRun& currentScriptRun,
864 Length& numberOfAllScriptCharacters,
865 Vector<ScriptRun>& scripts,
866 ScriptRunIndex& scriptIndex)
868 // Add the pending characters to the current script
869 currentScriptRun.characterRun.numberOfCharacters += (addScriptCharactersToNewScript ? 0u : numberOfAllScriptCharacters);
871 // In-case the current script is empty then no need to add it for scripts
872 if(0u != currentScriptRun.characterRun.numberOfCharacters)
874 // Store the script run.
875 scripts.Insert(scripts.Begin() + scriptIndex, currentScriptRun);
879 // Initialize the new one by the requested script
880 currentScriptRun.characterRun.characterIndex = currentScriptRun.characterRun.characterIndex + currentScriptRun.characterRun.numberOfCharacters;
881 currentScriptRun.characterRun.numberOfCharacters = (addScriptCharactersToNewScript ? numberOfAllScriptCharacters : 0u);
882 currentScriptRun.script = requestedScript;
883 numberOfAllScriptCharacters = 0u;
884 // Initialize whether is right to left direction
885 currentScriptRun.isRightToLeft = isRightToLeft;
888 } // namespace Internal
892 } // namespace Toolkit