X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Fmulti-language-support-impl.cpp;h=990d0cee26f06657e5df27b3fe02bfa21f2e7956;hp=020a5cbe38d9a2b9385029c6d694d4d62b8b6606;hb=a40939e617ca1a0b79aeb6af999cda7c70418be1;hpb=56eaa070094d7a0fc04e9c75b272f1cd3ceb9dc8 diff --git a/dali-toolkit/internal/text/multi-language-support-impl.cpp b/dali-toolkit/internal/text/multi-language-support-impl.cpp index 020a5cb..990d0ce 100644 --- a/dali-toolkit/internal/text/multi-language-support-impl.cpp +++ b/dali-toolkit/internal/text/multi-language-support-impl.cpp @@ -451,10 +451,6 @@ void MultilanguageSupport::ValidateFonts( const Vector& text, FontId previousFontId = 0u; bool isPreviousEmojiScript = false; - // Whether it's the first set of characters to be validated. - // Used in case the paragraph starts with characters common to all scripts. - bool isFirstSetToBeValidated = true; - CharacterIndex lastCharacter = startIndex + numberOfCharacters; for( Length index = startIndex; index < lastCharacter; ++index ) { @@ -494,7 +490,7 @@ void MultilanguageSupport::ValidateFonts( const Vector& text, description.path.c_str() ); } #endif - if (script == TextAbstraction::UNKNOWN) + if( script == TextAbstraction::UNKNOWN ) { script = TextAbstraction::LATIN; } @@ -504,10 +500,11 @@ void MultilanguageSupport::ValidateFonts( const Vector& text, // Check first in the cache of default fonts per script and size. - DefaultFonts* defaultFonts = *( defaultFontPerScriptCacheBuffer + script ); FontId cachedDefaultFontId = 0u; + DefaultFonts* defaultFonts = *( defaultFontPerScriptCacheBuffer + script ); if( NULL != defaultFonts ) { + // This cache stores fall-back fonts. cachedDefaultFontId = defaultFonts->FindFont( fontClient, currentFontDescription, currentFontPointSize ); @@ -519,6 +516,12 @@ void MultilanguageSupport::ValidateFonts( const Vector& text, // The font is valid if it matches with the default one for the current script and size and it's different than zero. isValidFont = isValidCachedDefaultFont && ( fontId == cachedDefaultFontId ); + if( isValidFont ) + { + // Check if the font supports the character. + isValidFont = fontClient.IsCharacterSupportedByFont( fontId, character ); + } + bool isCommonScript = false; bool isEmojiScript = TextAbstraction::EMOJI == script; @@ -537,7 +540,6 @@ void MultilanguageSupport::ValidateFonts( const Vector& text, currentFontRun.fontId = fontId; } - // If the given font is not valid, it means either: // - there is no cached font for the current script yet or, // - the user has set a different font than the default one for the current script or, @@ -578,21 +580,31 @@ void MultilanguageSupport::ValidateFonts( const Vector& text, if( NULL != validateFontsPerScript ) { + // This cache stores valid fonts set by the user. isValidFont = validateFontsPerScript->IsValidFont( fontId ); + + // It may happen that a validated font for a script doesn't have all the glyphs for that script. + // i.e a font validated for the CJK script may contain glyphs for the chinese language but not for the Japanese. + if( isValidFont ) + { + // Checks if the current character is supported by the font is needed. + isValidFont = fontClient.IsCharacterSupportedByFont( fontId, character ); + } } if( !isValidFont ) // (2) { - // Use the font client to validate the font. - const GlyphIndex glyphIndex = fontClient.GetGlyphIndex( fontId, character ); + // The selected font is not stored in any cache. - // The font is valid if there is a glyph for that character. - isValidFont = 0u != glyphIndex; + // Checks if the current character is supported by the selected font. + isValidFont = fontClient.IsCharacterSupportedByFont( fontId, character ); // Emojis are present in many monochrome fonts; prefer color by default. if( isValidFont && isEmojiScript ) { + const GlyphIndex glyphIndex = fontClient.GetGlyphIndex( fontId, character ); + // For color emojis, the font is valid if the glyph is a color glyph (the bitmap is RGBA). isValidFont = fontClient.IsColorGlyph( fontId, glyphIndex ); } @@ -610,12 +622,18 @@ void MultilanguageSupport::ValidateFonts( const Vector& text, validateFontsPerScript->mValidFonts.PushBack( fontId ); } - if( !isValidFont ) // (3) + if( !isValidFont && ( fontId != cachedDefaultFontId ) ) // (3) { - // The given font has not been validated. - int validCharacterIndex = fontClient.GetGlyphIndex(cachedDefaultFontId, character ); + // The selected font by the user or the platform's default font has failed to validate the character. + + // Checks if the previously discarted cached default font supports the character. + bool isValidCachedFont = false; + if( isValidCachedDefaultFont ) + { + isValidCachedFont = fontClient.IsCharacterSupportedByFont( cachedDefaultFontId, character ); + } - if( isValidCachedDefaultFont && validCharacterIndex != 0u ) + if( isValidCachedFont ) { // Use the cached default font for the script if there is one. fontId = cachedDefaultFontId; @@ -683,12 +701,6 @@ void MultilanguageSupport::ValidateFonts( const Vector& text, } #endif - if( isFirstSetToBeValidated && !isCommonScript ) - { - currentFontRun.fontId = fontId; - isFirstSetToBeValidated = false; - } - // The font is now validated. if( ( fontId != currentFontRun.fontId ) || isNewParagraphCharacter ) @@ -706,11 +718,6 @@ void MultilanguageSupport::ValidateFonts( const Vector& text, currentFontRun.characterRun.characterIndex = currentFontRun.characterRun.characterIndex + currentFontRun.characterRun.numberOfCharacters; currentFontRun.characterRun.numberOfCharacters = 0u; currentFontRun.fontId = fontId; - - if( isNewParagraphCharacter ) - { - isFirstSetToBeValidated = true; - } } // Add one more character to the run.