2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
18 #include <dali/internal/event/images/emoji-factory.h>
25 #include <dali/integration-api/platform-abstraction.h>
26 #include <dali/internal/event/common/thread-local-storage.h>
36 const std::string U( "u" ); ///<
37 const std::string PNG( ".png" ); ///< Used to build the emoji file name.
38 const std::size_t PNG_SIZE( 4u ); ///<
41 EmojiFactory::EmojiFactory()
43 mMinEmoji( std::numeric_limits<uint32_t>::max() )
45 Internal::ThreadLocalStorage& tls = Internal::ThreadLocalStorage::Get();
47 // Get the color glyphs from the directory.
48 Integration::PlatformAbstraction& platform = tls.GetPlatformAbstraction();
50 std::vector<std::string> fileNames;
51 platform.GetFileNamesFromDirectory( DALI_EMOTICON_DIR, fileNames );
53 for( std::vector<std::string>::const_iterator it = fileNames.begin(), endIt = fileNames.end(); it != endIt; ++it )
55 const std::string& fileName( *it );
56 const std::size_t fileNameSize = fileName.size();
58 if( ( fileNameSize < PNG_SIZE + 1u ) ||
59 ( U != fileName.substr( 0u, 1u ) ) ||
60 ( PNG != fileName.substr( fileNameSize - PNG_SIZE, PNG_SIZE ) ) )
62 // Invalid emoji file name.
66 uint32_t character = 0u;
68 std::istringstream( fileName.substr( 1u, fileNameSize - PNG_SIZE - 1u ) ) >> std::hex >> character;
72 if( character < mMinEmoji )
74 mMinEmoji = character;
77 mColorGlyphs[character] = fileName;
82 EmojiFactory::~EmojiFactory()
86 bool EmojiFactory::IsEmoji( const uint32_t character ) const
88 return ( character >= mMinEmoji ) &&
89 ( mColorGlyphs.find( character ) != mColorGlyphs.end() );
92 std::string EmojiFactory::GetEmojiFileNameFromCharacter( const uint32_t character ) const
96 std::map<uint32_t,std::string>::const_iterator it = mColorGlyphs.find( character );
98 if( it != mColorGlyphs.end() )
100 fileName = it->second;
106 } // namespace Internal