2 * Copyright (c) 2014 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/internal/event/images/emoji-factory.h>
26 #include <dali/integration-api/platform-abstraction.h>
27 #include <dali/internal/event/common/thread-local-storage.h>
37 const std::string U( "u" ); ///<
38 const std::string PNG( ".png" ); ///< Used to build the emoji file name.
39 const std::size_t PNG_SIZE( 4u ); ///<
42 EmojiFactory::EmojiFactory()
44 mMinEmoji( std::numeric_limits<uint32_t>::max() )
46 Internal::ThreadLocalStorage& tls = Internal::ThreadLocalStorage::Get();
48 // Get the color glyphs from the directory.
49 Integration::PlatformAbstraction& platform = tls.GetPlatformAbstraction();
51 std::vector<std::string> fileNames;
52 platform.GetFileNamesFromDirectory( DALI_EMOTICON_DIR, fileNames );
54 for( std::vector<std::string>::const_iterator it = fileNames.begin(), endIt = fileNames.end(); it != endIt; ++it )
56 const std::string& fileName( *it );
57 const std::size_t fileNameSize = fileName.size();
59 if( ( fileNameSize < PNG_SIZE + 1u ) ||
60 ( U != fileName.substr( 0u, 1u ) ) ||
61 ( PNG != fileName.substr( fileNameSize - PNG_SIZE, PNG_SIZE ) ) )
63 // Invalid emoji file name.
67 uint32_t character = 0u;
69 std::istringstream( fileName.substr( 1u, fileNameSize - PNG_SIZE - 1u ) ) >> std::hex >> character;
73 if( character < mMinEmoji )
75 mMinEmoji = character;
78 mColorGlyphs[character] = fileName;
83 EmojiFactory::~EmojiFactory()
87 bool EmojiFactory::IsEmoji( const uint32_t character ) const
89 return ( character >= mMinEmoji ) &&
90 ( mColorGlyphs.find( character ) != mColorGlyphs.end() );
93 std::string EmojiFactory::GetEmojiFileNameFromCharacter( const uint32_t character ) const
97 std::map<uint32_t,std::string>::const_iterator it = mColorGlyphs.find( character );
99 if( it != mColorGlyphs.end() )
101 fileName = it->second;
107 } // namespace Internal