// Open Service Platform
// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
//
-// Licensed under the Flora License, Version 1.0 (the License);
+// 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://floralicense.org/license/
+// 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,
+// 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.
const char* _DEFAULT_SYSTEM_FONT = "DefaultSystemFont";
const char* _DEFAULT_SYSTEM_BOLD_FONT = "DefaultSystemBoldFont";
const _Util::FixedPoint26_6 _SYSTEM_DEFAULT_FONT_SIZE(16);
+const int _BLACK_LIST_MAX_COUNT = 1000;
class _FontNull
: public Tizen::Graphics::_IFont
virtual void Destroy(void) {}
- virtual bool FindCache(unsigned long character, _Util::FixedPoint26_6 size, int style, Glyph** pOut)
+ virtual bool FindCache(unsigned long glyphIndex, _Util::FixedPoint26_6 size, int style, Glyph** pOut)
{
return false;
}
- virtual bool AddCache(unsigned long character, _Util::FixedPoint26_6 size, int style, Glyph* pGlyph)
+ virtual bool AddCache(unsigned long glyphIndex, _Util::FixedPoint26_6 size, int style, Glyph* pGlyph)
{
return false;
}
}
}; // _FontNull
+#ifdef USE_HASHMAP_FOR_FONT
template<class T>
class _FontHashCodeProvider
: public IHashCodeProviderT <T>
}
}; // _FontComparer
-#ifdef USE_HASHMAP_FOR_FONT
template<class T>
class _FontHashCodeProviderEx
: public IHashCodeProviderT <T>
public:
virtual int GetHashCode(const T& obj) const
{
- return reinterpret_cast<int>(obj.c_str());
+ const wchar_t* pText = obj.c_str();
+ const wchar_t* pTextEnd = pText - 1;
+
+ while (*(++pTextEnd))
+ ;
+
+ int stride = ((pTextEnd - pText + 1) << 16) / 9;
+ int ix16 = 0;
+
+ int ret1 = (pText[(ix16 += stride) >> 16] & 0xFF);
+ ret1 |= ((pText[(ix16 += stride) >> 16] & 0xFF) << 8);
+ ret1 |= ((pText[(ix16 += stride) >> 16] & 0xFF) << 16);
+ ret1 |= ((pText[(ix16 += stride) >> 16] & 0xFF) << 24);
+
+ int ret2 = (pText[(ix16 += stride) >> 16] & 0xFF);
+ ret2 |= ((pText[(ix16 += stride) >> 16] & 0xFF) << 8);
+ ret2 |= ((pText[(ix16 += stride) >> 16] & 0xFF) << 16);
+ ret2 |= ((pText[(ix16 += stride) >> 16] & 0xFF) << 24);
+
+ return ret1 ^ ret2;
}
}; // _FontHashCodeProviderEx
public:
virtual result Compare(const T& obj1, const T& obj2, int& cmp) const
{
- cmp = wcscmp((wchar_t*)obj1.c_str(), (wchar_t*)obj1.c_str());
+ cmp = wcscmp((wchar_t*)obj1.c_str(), (wchar_t*)obj2.c_str());
return E_SUCCESS;
}
}; // _FontComparerEx
+
+#else
+
+class _FindValueByString
+{
+public:
+ _FindValueByString(const _Util::WString& key)
+ : __key(key)
+ {
+ }
+
+ bool operator()(const std::pair<_Util::WString, Tizen::Graphics::_FontRsrcManager::SharedFontResource> pairValue)
+ {
+ return (__key == pairValue.first);
+ }
+
+ bool operator()(const std::pair<_Util::WString, _Util::WString> pairValue)
+ {
+ return (__key == pairValue.first);
+ }
+
+ const _Util::WString& __key;
+}; // _FindValueByString
+
#endif
}
_FontRsrcManager::_FontRsrcManager()
: __isAppFontListInitialized(false)
{
- static _FontHashCodeProvider<String> fontHashCodeProvider;
- static _FontComparer<String> fontComparer;
-
+#ifdef USE_HASHMAP_FOR_FONT
// are you worry about failing to construct?
// but, HashMapT only can give E_SUCCESS/E_INVALID_ARG/E_OUT_OF_MEMORY.
// it means, if you ha2ve already verified input param, don't need to concern yourself.
// even though you have E_OUT_OF_MEMORY, it's already out of our control,
// and surely the other member function can give a error message.
-#ifdef USE_HASHMAP_FOR_FONT
+
static _FontHashCodeProviderEx<_Util::WString> fontHashCodeProviderEx;
static _FontComparerEx<_Util::WString> fontComparerEx;
__fontRsrcMap.Construct(0, 0, fontHashCodeProviderEx, fontComparerEx);
+ __appFontMap.Construct(0, 0, fontHashCodeProviderEx, fontComparerEx);
#endif
- __appFontMap.Construct(0, 0, fontHashCodeProvider, fontComparer);
__defaultSystemFontPath.Clear();
__defaultSystemBoldFontPath.Clear();
{
#ifdef USE_HASHMAP_FOR_FONT
__fontRsrcMap.RemoveAll();
+ __appFontMap.RemoveAll();
#else
__fontRsrcMap.clear();
+ __appFontMap.clear();
#endif
- __appFontMap.RemoveAll();
-
delete __pDefaultSystemFont;
delete __pFontMemoryManager;
return E_SUCCESS;
}
-
bool
_FontRsrcManager::SearchFont(const _Util::WString& fontName)
{
return (__SearchFont(fontName, sharedFont) == true);
}
+void
+_FontRsrcManager::AddBlackList(const wchar_t unicode)
+{
+ if (__blackListUnicodeSet.size() > _BLACK_LIST_MAX_COUNT)
+ {
+ this->ClearBlackList();
+ }
+
+ __blackListUnicodeSet.insert(unicode);
+}
+
+bool
+_FontRsrcManager::SearchBlackList(const wchar_t unicode) const
+{
+ BlackListSetT::const_iterator blackListIterator = __blackListUnicodeSet.find(unicode);
+
+ return (blackListIterator != __blackListUnicodeSet.end());
+}
+
+void
+_FontRsrcManager::ClearBlackList()
+{
+ __blackListUnicodeSet.clear();
+}
+
result
_FontRsrcManager::GetFont(const byte* pFontData, int fontDataSize, int style, _Util::FixedPoint26_6 size, SharedFontResource& out)
{
FcFontSet *pFontSet = null;
FcResult res = FcResultNoMatch;
FcChar8* pPath = null;
- const char* fcStyle = (style & FONT_STYLE_BOLD) ? "Bold" : "Regular";
+ const int fcWeight = (style & FONT_STYLE_BOLD) ? FC_WEIGHT_BOLD : FC_WEIGHT_REGULAR;
result r = E_SYSTEM;
ByteBuffer* pBuffer = StringUtil::StringToUtf8N(fontName);
//FcBool rtn = FcInitReinitialize();
//SysTryCatch(NID_GRP, rtn != FcFalse, , r, "[E_SYSTEM] Failed to init fontconfig");
- pFontPattern = FcPatternBuild(NULL, FC_STYLE, FcTypeString, (FcChar8*)fcStyle, NULL);
+ pFontPattern = FcPatternBuild(NULL, FC_WEIGHT, FcTypeInteger, fcWeight, NULL);
SysTryCatch(NID_GRP, pFontPattern, , r, "[E_SYSTEM] Failed to FcPatternBuild()");
FcPatternAddString(pFontPattern, FC_FAMILY, (FcChar8*)utfString->GetPointer());
#ifdef USE_HASHMAP_FOR_FONT
return (__fontRsrcMap.GetValue(fontPath, out) == E_SUCCESS);
#else
- FontMapT::const_iterator fontIterator = __fontRsrcMap.find(fontPath);
+ FontMapT::const_iterator fontIterator = std::find_if(__fontRsrcMap.begin(), __fontRsrcMap.end(), _FindValueByString(fontPath));
if (fontIterator != __fontRsrcMap.end())
{
out = fontIterator->second;
+
return true;
}
SysTryReturn(NID_GRP, r == E_SUCCESS || r == E_OBJ_ALREADY_EXIST, false, false, "[%s] Failed to add font into resource pool", GetErrorMessage(r));
#else
- __fontRsrcMap[key] = font;
+ __fontRsrcMap.push_back(std::make_pair(key, font));
#endif
return true;
#ifdef USE_HASHMAP_FOR_FONT
__fontRsrcMap.Remove(key);
#else
- __fontRsrcMap.erase(key);
+ for (FontMapT::iterator fontMapIter = __fontRsrcMap.begin(); fontMapIter != __fontRsrcMap.end(); ++fontMapIter)
+ {
+ if (fontMapIter->first == key)
+ {
+ __fontRsrcMap.erase(fontMapIter);
+ break;
+ }
+ }
#endif
}
}
#endif
pFont->CleanCache();
+ this->ClearBlackList();
}
return true;
FcFontSet* pFontSet = null;
FcPattern* pFontPattern = null;
- const char* fcStyle = isBold ? "Bold" : "Regular";
+ const int fcWeight = isBold ? FC_WEIGHT_BOLD : FC_WEIGHT_REGULAR;
+
// initialize fontconfig library
//FcBool rtn = FcInitReinitialize();
//SysTryCatch(NID_GRP, rtn != FcFalse, , E_SYSTEM, "[E_SYSTEM] Failed to init fontconfig");
pFontPattern = FcPatternCreate();
SysTryCatch(NID_GRP, pFontPattern, , E_SYSTEM, "[E_SYSTEM] Failed to create font pattern");
+ FcPatternAddInteger(pFontPattern, FC_WEIGHT, fcWeight);
FcPatternAddString(pFontPattern, FC_FAMILY, (FcChar8*)"Tizen");
- FcPatternAddString(pFontPattern, FC_STYLE, (FcChar8*)fcStyle);
FcConfigSubstitute(0, pFontPattern, FcMatchPattern);
FcDefaultSubstitute(pFontPattern);
#endif
}
-Tizen::Base::String
-_FontRsrcManager::FindAppFontName(const Tizen::Base::String& fontName)
+_Util::WString
+_FontRsrcManager::FindAppFontName(const _Util::WString& fontName)
{
- String fontPath(L"");
-
- if (__isAppFontListInitialized)
- {
- __appFontMap.GetValue(fontName, fontPath);
+ _Util::WString fontPath(L"");
- return fontPath;
- }
- else
+ if (!__isAppFontListInitialized)
{
String dirName;
Directory dir;
faceName = _Font::GetFaceName(name);
- __appFontMap.Add(faceName, name);
+ _Util::WString faceNameTemp(faceName.GetPointer());
+ _Util::WString nameTemp(name.GetPointer());
+#ifdef USE_HASHMAP_FOR_FONT
+ __appFontMap.Add(faceNameTemp, nameTemp);
+#else
+ __appFontMap.push_back(std::make_pair(faceNameTemp, nameTemp));
+#endif
}
}
pDirEnum = null;
__isAppFontListInitialized = true;
+ }
- __appFontMap.GetValue(fontName, fontPath);
+#ifdef USE_HASHMAP_FOR_FONT
+ __appFontMap.GetValue(fontName, fontPath);
+#else
+ AppFontMapT::const_iterator appFontIterator = std::find_if(__appFontMap.begin(), __appFontMap.end(), _FindValueByString(fontName));
- return fontPath;
+ if (appFontIterator != __appFontMap.end())
+ {
+ fontPath = appFontIterator->second;
}
+#endif
+
+ return fontPath;
}
-}} // Tizen::Graphics
+}} // Tizen::Graphics
\ No newline at end of file