Optimized shader hash to not allocate memory or perform multiple passes of string...
[platform/core/uifw/dali-core.git] / dali / internal / event / text / font-factory.cpp
index 89af73a..c088d0f 100644 (file)
@@ -1,18 +1,19 @@
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2014 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
 // CLASS HEADER
 #include <dali/internal/event/text/font-factory.h>
@@ -22,9 +23,8 @@
 #include <dali/integration-api/debug.h>
 #include <dali/internal/event/resources/resource-client.h>
 #include <dali/internal/event/text/atlas/glyph-atlas-manager.h>
+#include <dali/internal/common/dali-hash.h>
 
-// EXTERNAL INCLUDES
-#include <boost/functional/hash.hpp>
 
 using namespace Dali::Integration;
 
@@ -55,14 +55,13 @@ FontFactory::~FontFactory()
 FontMetricsIntrusivePtr FontFactory::GetFontMetrics( const std::string& fontFamily, const std::string& fontStyle )
 {
 
-  StringHash hasher;
-  std::size_t hashValue = hasher(fontFamily + fontStyle);
+  std::size_t hashValue = CalculateHash(fontFamily,fontStyle);
   FontMetricsIntrusivePtr metrics;
 
   FontMetricsIter iter = mMetricsCache.find( hashValue );
   if ( iter == mMetricsCache.end() )
   {
-    metrics = FontMetrics::New( Vector2(mHorizontalDpi, mVerticalDpi), hashValue, mFontCount, fontFamily, fontStyle, mResourceClient );
+    metrics = FontMetrics::New( Vector2(mHorizontalDpi, mVerticalDpi), hashValue, mFontCount, fontFamily, fontStyle );
     mFontCount++;
 
     // load the global metrics
@@ -85,8 +84,7 @@ FontMetricsIntrusivePtr FontFactory::GetFontMetrics( const std::string& fontFami
 void FontFactory::RemoveFontMetrics(const std::string& fontFamily,
                                     const std::string& fontStyle)
 {
-  StringHash hasher;
-  std::size_t hashValue = hasher(fontFamily + fontStyle);
+  std::size_t hashValue = CalculateHash(fontFamily, fontStyle);
   FontMetricsIntrusivePtr metrics;
 
   FontMetricsIter iter = mMetricsCache.find( hashValue );
@@ -101,10 +99,10 @@ void FontFactory::RemoveFontMetrics(const std::string& fontFamily,
 
 
 void FontFactory::GetFontInformation( FontId fontId,
-                                  std::string& family,
-                                  std::string& style,
-                                  float& maxGlyphWidth,
-                                  float& maxGlyphHeight) const
+                                      std::string& family,
+                                      std::string& style,
+                                      float& maxGlyphWidth,
+                                      float& maxGlyphHeight) const
 {
   // typically we only have around 4 fonts in the cache,
   // and GetFontInformation is only called a couple of times on startup
@@ -113,7 +111,7 @@ void FontFactory::GetFontInformation( FontId fontId,
 
   for( FontMetricsMap::const_iterator iter =  mMetricsCache.begin(); iter != endIter; ++iter)
   {
-    const FontMetrics* metric( (*iter).second.Get() ) ;
+    const FontMetrics* metric( (*iter).second.Get() );
 
     if( metric->GetFontId() == fontId)
     {