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=fd1d8e48aa57f98ea8bf91ba1be23ca19d0e5413;hp=1a72243d1530b02df7f165e9e9843687546ce298;hb=402679a59170924dd5b18bb5057a4c6c5b7dcbe3;hpb=81a7e08e1bcf2c17cb63921915bf13afc1b94d23 diff --git a/dali-toolkit/internal/text/multi-language-support-impl.cpp b/dali-toolkit/internal/text/multi-language-support-impl.cpp index 1a72243..fd1d8e4 100644 --- a/dali-toolkit/internal/text/multi-language-support-impl.cpp +++ b/dali-toolkit/internal/text/multi-language-support-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -63,23 +63,38 @@ bool ValidateFontsPerScript::IsValidFont( FontId fontId ) const return false; } -FontId DefaultFonts::FindFont( TextAbstraction::FontClient& fontClient, PointSize26Dot6 size ) const +FontId DefaultFonts::FindFont( TextAbstraction::FontClient& fontClient, + const TextAbstraction::FontDescription& description, + PointSize26Dot6 size ) const { - for( Vector::ConstIterator it = mFonts.Begin(), - endIt = mFonts.End(); + for( std::vector::const_iterator it = mFonts.begin(), + endIt = mFonts.end(); it != endIt; ++it ) { - const FontId fontId = *it; - if( size == fontClient.GetPointSize( fontId ) ) + const CacheItem& item = *it; + + if( ( ( TextAbstraction::FontWeight::NONE == description.weight ) || ( description.weight == item.description.weight ) ) && + ( ( TextAbstraction::FontWidth::NONE == description.width ) || ( description.width == item.description.width ) ) && + ( ( TextAbstraction::FontSlant::NONE == description.slant ) || ( description.slant == item.description.slant ) ) && + ( size == fontClient.GetPointSize( item.fontId ) ) && + ( description.family.empty() || ( description.family == item.description.family ) ) ) { - return fontId; + return item.fontId; } } return 0u; } +void DefaultFonts::Cache( const TextAbstraction::FontDescription& description, FontId fontId ) +{ + CacheItem item; + item.description = description; + item.fontId = fontId; + mFonts.push_back( item ); +} + MultilanguageSupport::MultilanguageSupport() : mDefaultFontPerScriptCache(), mValidFontsPerScriptCache() @@ -374,7 +389,8 @@ void MultilanguageSupport::SetScripts( const Vector& text, void MultilanguageSupport::ValidateFonts( const Vector& text, const Vector& scripts, const Vector& fontDescriptions, - FontId defaultFontId, + const TextAbstraction::FontDescription& defaultFontDescription, + TextAbstraction::PointSize26Dot6 defaultFontPointSize, CharacterIndex startIndex, Length numberOfCharacters, Vector& fonts ) @@ -424,36 +440,13 @@ void MultilanguageSupport::ValidateFonts( const Vector& text, // Get the font client. TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get(); - // Get the default font description and default size. - TextAbstraction::FontDescription defaultFontDescription; - TextAbstraction::PointSize26Dot6 defaultPointSize = TextAbstraction::FontClient::DEFAULT_POINT_SIZE; - if( defaultFontId > 0u ) - { - fontClient.GetDescription( defaultFontId, defaultFontDescription ); - defaultPointSize = fontClient.GetPointSize( defaultFontId ); - } - - // Merge font descriptions - Vector fontIds; - fontIds.Resize( numberOfCharacters, defaultFontId ); - Vector isDefaultFont; - isDefaultFont.Resize( numberOfCharacters, true ); - MergeFontDescriptions( fontDescriptions, - fontIds, - isDefaultFont, - defaultFontDescription, - defaultPointSize, - startIndex, - numberOfCharacters ); - const Character* const textBuffer = text.Begin(); - const FontId* const fontIdsBuffer = fontIds.Begin(); - const bool* const isDefaultFontBuffer = isDefaultFont.Begin(); + + // Iterators of the script runs. Vector::ConstIterator scriptRunIt = scripts.Begin(); Vector::ConstIterator scriptRunEndIt = scripts.End(); bool isNewParagraphCharacter = false; - PointSize26Dot6 currentPointSize = defaultPointSize; FontId currentFontId = 0u; FontId previousFontId = 0u; bool isPreviousEmojiScript = false; @@ -468,23 +461,25 @@ void MultilanguageSupport::ValidateFonts( const Vector& text, // Get the current character. const Character character = *( textBuffer + index ); - // Get the font for the current character. - FontId fontId = *( fontIdsBuffer + index - startIndex ); + TextAbstraction::FontDescription currentFontDescription; + TextAbstraction::PointSize26Dot6 currentFontPointSize = defaultFontPointSize; + bool isDefaultFont = true; + MergeFontDescriptions( fontDescriptions, + defaultFontDescription, + defaultFontPointSize, + index, + currentFontDescription, + currentFontPointSize, + isDefaultFont ); - // Whether the font being validated for the current character is a default one not set by the user. - const bool isDefault = *( isDefaultFontBuffer + index - startIndex ); + // Get the font for the current character. + FontId fontId = fontClient.GetFontId( currentFontDescription, currentFontPointSize ); + currentFontId = fontId; // Get the script for the current character. - const Script script = GetScript( index, - scriptRunIt, - scriptRunEndIt ); - - // Get the current point size. - if( currentFontId != fontId ) - { - currentPointSize = fontClient.GetPointSize( fontId ); - currentFontId = fontId; - } + Script script = GetScript( index, + scriptRunIt, + scriptRunEndIt ); #ifdef DEBUG_ENABLED { @@ -499,6 +494,10 @@ void MultilanguageSupport::ValidateFonts( const Vector& text, description.path.c_str() ); } #endif + if (script == TextAbstraction::UNKNOWN) + { + script = TextAbstraction::LATIN; + } // Validate whether the current character is supported by the given font. bool isValidFont = false; @@ -509,7 +508,9 @@ void MultilanguageSupport::ValidateFonts( const Vector& text, FontId cachedDefaultFontId = 0u; if( NULL != defaultFonts ) { - cachedDefaultFontId = defaultFonts->FindFont( fontClient, currentPointSize ); + cachedDefaultFontId = defaultFonts->FindFont( fontClient, + currentFontDescription, + currentFontPointSize ); } // Whether the cached default font is valid. @@ -562,13 +563,12 @@ void MultilanguageSupport::ValidateFonts( const Vector& text, if( isCommonScript ) { if( isValidCachedDefaultFont && - ( isDefault || ( currentFontId == previousFontId ) ) && + ( isDefaultFont || ( currentFontId == previousFontId ) ) && !isEmojiScript ) { // At this point the character common for all scripts has no font assigned. // If there is a valid previously cached default font for it, use that one. fontId = cachedDefaultFontId; - isValidFont = true; } } else @@ -593,10 +593,8 @@ void MultilanguageSupport::ValidateFonts( const Vector& text, if( isValidFont && isEmojiScript ) { - const BufferImage bitmap = fontClient.CreateBitmap( fontId, glyphIndex ); - - // For color emojis, the font is valid if the bitmap is RGBA. - isValidFont = bitmap && ( Pixel::BGRA8888 == bitmap.GetPixelFormat() ); + // For color emojis, the font is valid if the glyph is a color glyph (the bitmap is RGBA). + isValidFont = fontClient.IsColorGlyph( fontId, glyphIndex ); } // If there is a valid font, cache it. @@ -631,7 +629,10 @@ void MultilanguageSupport::ValidateFonts( const Vector& text, const bool preferColor = ( TextAbstraction::EMOJI == script ); // Find a fallback-font. - fontId = fontClient.FindFallbackFont( currentFontId, character, currentPointSize, preferColor ); + fontId = fontClient.FindFallbackFont( character, + currentFontDescription, + currentFontPointSize, + preferColor ); if( 0u == fontId ) { @@ -639,13 +640,15 @@ void MultilanguageSupport::ValidateFonts( const Vector& text, defaultFontsPerScript = *( defaultFontPerScriptCacheBuffer + TextAbstraction::LATIN ); if( NULL != defaultFontsPerScript ) { - fontId = defaultFontsPerScript->FindFont( fontClient, currentPointSize ); + fontId = defaultFontsPerScript->FindFont( fontClient, + currentFontDescription, + currentFontPointSize ); } } if( 0u == fontId ) { - fontId = fontClient.FindDefaultFont( UTF32_A, currentPointSize ); + fontId = fontClient.FindDefaultFont( UTF32_A, currentFontPointSize ); } // Cache the font. @@ -659,7 +662,7 @@ void MultilanguageSupport::ValidateFonts( const Vector& text, *( defaultFontPerScriptCacheBuffer + script ) = defaultFontsPerScript; } } - defaultFontsPerScript->mFonts.PushBack( fontId ); + defaultFontsPerScript->Cache( currentFontDescription, fontId ); } } // !isValidFont (3) } // !isValidFont (2)