Merge "modify Samplecode in Header of OverlayPanel and OverlayRegion" into tizen_2.1
[framework/osp/uifw.git] / src / graphics / FGrp_FontRsrcManager.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /*
19  * @file        FGrp_FontRsrcManager.cpp
20  * @brief       This is the cpp file for _FontRsrcManager class.
21  *
22  */
23
24 #include <new>
25 #include <memory>
26
27 #include <unique_ptr.h>
28 #include <pthread.h>
29
30 #include <fontconfig/fontconfig.h>
31
32 #include <FAppApp.h>
33 #include <FBaseColIHashCodeProviderT.h>
34 #include <FBaseUtilStringUtil.h>
35 #include <FIoFile.h>
36 #include <FGrpFontCommon.h>
37 #include <FIoDirectory.h>
38 #include <FBaseUtilStringTokenizer.h>
39
40 #include <FBaseSysLog.h>
41
42 #include "FGrp_Font.h"
43 #include "FGrp_FontRsrcManager.h"
44 #include "FGrp_FontMemoryManager.h"
45 #include "FGrp_FontFt2.h"
46
47 #define USE_REMOVE_ALL_CACHE
48 #define USE_MMAP
49
50 #include "util/FGrp_UtilTemplate.h"
51
52
53 #define IF_NOT_INITIALIZED(code) if (_pImpl == null) \
54         { \
55                 code; \
56         }
57
58 using namespace Tizen::App;
59 using namespace Tizen::Io;
60 using namespace Tizen::Base;
61 using namespace Tizen::Base::Collection;
62 using namespace Tizen::Base::Utility;
63 using namespace Tizen::Graphics;
64 using namespace Tizen::System;
65
66
67 namespace // unnamed
68 {
69
70 const int _DEFAULT_FONT_ENGINE = 0;
71 const int _DEFAULT_FONT_FACE = 0;
72 const char* _DEFAULT_SYSTEM_FONT = "DefaultSystemFont";
73 const char* _DEFAULT_SYSTEM_BOLD_FONT = "DefaultSystemBoldFont";
74 const _Util::FixedPoint26_6 _SYSTEM_DEFAULT_FONT_SIZE(16);
75
76 class _FontNull
77         : public Tizen::Graphics::_IFont
78 {
79 public:
80         virtual bool SetAttrib(const Attrib& fontAttrib)
81         {
82                 return false;
83         }
84
85         virtual bool GetAttrib(Attrib& fontAttrib) const
86         {
87                 return false;
88         }
89
90         virtual bool GetKerning(unsigned long character1, unsigned long character2, long& xVector, long& yVector) const
91         {
92                 return false;
93         }
94
95         virtual bool LoadGlyph(unsigned long character, Glyph** pFontGlyphData)
96         {
97                 return false;
98         }
99
100         virtual bool UnloadGlyph(Glyph** pFontGlyphData)
101         {
102                 return false;
103         }
104
105         virtual unsigned long CheckGlyph(unsigned long character)
106         {
107                 return 0;
108         }
109
110         virtual bool GetGlyphList(const _Util::String& text, Tizen::Base::Collection::IListT<_IFont::Glyph *>& out, int script)
111         {
112                 return false;
113         }
114
115         virtual bool GetFontSizeProperty(SizeProperty& sizeProperty) const
116         {
117                 return false;
118         }
119
120         virtual bool GetFontProperty(Property& property) const
121         {
122                 return false;
123         }
124
125         virtual FontMapT* GetFallbackMap(void)
126         {
127                 return null;
128         }
129
130         virtual bool IsEmoji(void) const
131         {
132                 return false;
133         }
134
135 protected:
136         virtual bool Create(const void* pBuffer, long bufSize, long face = 0)
137         {
138                 return false;
139         }
140
141         virtual bool Create(const char* pFilePath, long face = 0)
142         {
143                 return false;
144         }
145
146         virtual bool CreateStatic(const void* pBuffer, long bufSize, long face = 0)
147         {
148                 return false;
149         }
150
151         virtual bool Reload(const void* pBuffer, long bufSize, long face = 0)
152         {
153                 return false;
154         }
155
156         virtual bool Reload(const char* filePath, long face = 0)
157         {
158                 return false;
159         }
160
161         virtual void Destroy(void) {}
162
163         virtual bool FindCache(unsigned long glyphIndex, _Util::FixedPoint26_6 size, int style, Glyph** pOut)
164         {
165                 return false;
166         }
167
168         virtual bool AddCache(unsigned long glyphIndex, _Util::FixedPoint26_6 size, int style, Glyph* pGlyph)
169         {
170                 return false;
171         }
172
173         virtual bool CleanCache(void)
174         {
175                 return false;
176         }
177 }; // _FontNull
178
179 #ifdef USE_HASHMAP_FOR_FONT
180 template<class T>
181 class _FontHashCodeProvider
182         : public IHashCodeProviderT <T>
183 {
184 public:
185         virtual int GetHashCode(const T& obj) const
186         {
187                 return obj.GetHashCode();
188         }
189 }; // _FontHashCodeProvider
190
191 template<class T>
192 class _FontComparer
193         : public IComparerT <T>
194 {
195 public:
196         virtual result Compare(const T& obj1, const T& obj2, int& cmp) const
197         {
198                 String& objString1 = static_cast <String&>(const_cast <T&>(obj1));
199                 String& objString2 = static_cast <String&>(const_cast <T&>(obj2));
200
201                 cmp = objString1.CompareTo(objString2);
202
203                 return E_SUCCESS;
204         }
205 }; // _FontComparer
206
207 template<class T>
208 class _FontHashCodeProviderEx
209         : public IHashCodeProviderT <T>
210 {
211 public:
212         virtual int GetHashCode(const T& obj) const
213         {
214                 const wchar_t* pText = obj.c_str();
215                 const wchar_t* pTextEnd = pText - 1;
216
217                 while (*(++pTextEnd))
218                         ;
219
220                 int stride = ((pTextEnd - pText + 1) << 16) / 9;
221                 int ix16 = 0;
222
223                 int ret1 = (pText[(ix16 += stride) >> 16] & 0xFF);
224                 ret1 |= ((pText[(ix16 += stride) >> 16] & 0xFF) << 8);
225                 ret1 |= ((pText[(ix16 += stride) >> 16] & 0xFF) << 16);
226                 ret1 |= ((pText[(ix16 += stride) >> 16] & 0xFF) << 24);
227
228                 int ret2 = (pText[(ix16 += stride) >> 16] & 0xFF);
229                 ret2 |= ((pText[(ix16 += stride) >> 16] & 0xFF) << 8);
230                 ret2 |= ((pText[(ix16 += stride) >> 16] & 0xFF) << 16);
231                 ret2 |= ((pText[(ix16 += stride) >> 16] & 0xFF) << 24);
232
233                 return ret1 ^ ret2;
234         }
235 }; // _FontHashCodeProviderEx
236
237 template<class T>
238 class _FontComparerEx
239         : public IComparerT <T>
240 {
241 public:
242         virtual result Compare(const T& obj1, const T& obj2, int& cmp) const
243         {
244                 cmp = wcscmp((wchar_t*)obj1.c_str(), (wchar_t*)obj2.c_str());
245
246                 return E_SUCCESS;
247         }
248 }; // _FontComparerEx
249
250 #endif
251 }
252
253 namespace Tizen { namespace Graphics
254 {
255
256 _FontRsrcManager* _FontRsrcManager::__pTheInstance = null;
257
258 _FontRsrcManager::_FontRsrcManager()
259         : __isAppFontListInitialized(false)
260 {
261 #ifdef USE_HASHMAP_FOR_FONT
262         // are you worry about failing to construct?
263         // but, HashMapT only can give E_SUCCESS/E_INVALID_ARG/E_OUT_OF_MEMORY.
264         // it means, if you ha2ve already verified input param, don't need to concern yourself.
265         // even though you have E_OUT_OF_MEMORY, it's already out of our control,
266         // and surely the other member function can give a error message.
267
268         static _FontHashCodeProviderEx<_Util::WString> fontHashCodeProviderEx;
269         static _FontComparerEx<_Util::WString> fontComparerEx;
270         __fontRsrcMap.Construct(0, 0, fontHashCodeProviderEx, fontComparerEx);
271         __appFontMap.Construct(0, 0, fontHashCodeProviderEx, fontComparerEx);
272 #endif
273
274
275         __defaultSystemFontPath.Clear();
276         __defaultSystemBoldFontPath.Clear();
277         __pDefaultSystemFont = null;
278
279         FcInit();
280
281         const unsigned long cacheMemorySize = 1 * 1024 * 1024;
282         std::unique_ptr<_FontMemoryManager> pMemoryMgr(new (std::nothrow) _FontMemoryManager(_FontMemoryManager::TYPE_SIZE, cacheMemorySize));
283
284         if (pMemoryMgr != null && pMemoryMgr->IsValid())
285         {
286                 __pFontMemoryManager = pMemoryMgr.release();
287         }
288
289         SysAssert(__pFontMemoryManager != null);
290 }
291
292 _FontRsrcManager::~_FontRsrcManager()
293 {
294 #ifdef USE_HASHMAP_FOR_FONT
295         __fontRsrcMap.RemoveAll();
296         __appFontMap.RemoveAll();
297 #else
298         __fontRsrcMap.clear();
299         __appFontMap.clear();
300 #endif
301
302         delete __pDefaultSystemFont;
303         delete __pFontMemoryManager;
304
305         FcFini();
306 }
307
308 result
309 _FontRsrcManager::GetFont(const Tizen::Base::String& fontPath, int style, _Util::FixedPoint26_6 size, SharedFontResource& out)
310 {
311         _Util::WString fontPathTemp(fontPath.GetPointer());
312
313         SharedFontResource sharedFont;
314         _IFont* pFont = null;
315
316         bool rtn = false;
317
318         //--------------------------------------------------------------------------
319         // validation check of input param
320         //
321         // in case input fontPath is indicating folder,
322         // we should return 'E_UNSUPPORTED_FORMAT' as bads 2.0 did.
323         //--------------------------------------------------------------------------
324         {
325                 FileAttributes attr;
326                 result r = File::GetAttributes(fontPath, attr);
327                 if (IsFailed(r))
328                 {
329                         return E_FILE_NOT_FOUND;
330                 }
331                 else if (attr.IsDirectory())
332                 {
333                         return E_UNSUPPORTED_FORMAT;
334                 }
335         }
336
337         //--------------------------------------------------------------------------
338         // step 1
339         //
340         // if we already have specified resoruce,
341         // return it with increasing reference count
342         //--------------------------------------------------------------------------
343         rtn = __SearchFont(fontPathTemp, sharedFont);
344
345         if (rtn)
346         {
347                 out = sharedFont;
348
349                 return E_SUCCESS;
350         }
351
352         //--------------------------------------------------------------------------
353         // step 2
354         //
355         // create new font
356         //--------------------------------------------------------------------------
357         {
358 #ifdef USE_MMAP
359                 ByteBuffer* pBuffer = StringUtil::StringToUtf8N(fontPath);
360                 if (pBuffer == null)
361                 {
362                         return false;
363                 }
364                 std::auto_ptr<ByteBuffer> pathString(pBuffer);
365
366                 rtn = __CreateFont(_DEFAULT_FONT_ENGINE, (char*)pathString->GetPointer(), _DEFAULT_FONT_FACE, &pFont);
367 #else
368                 int fileLength = 0;
369                 int readLength = 0;
370                 File file;
371
372                 result r = file.Construct(fontPath, L"rb");
373                 SysTryReturnResult(NID_GRP, r == E_SUCCESS, E_SYSTEM, "Failed to open file");
374
375                 r = file.Seek(FILESEEKPOSITION_END, 0);
376                 SysTryReturnResult(NID_GRP, r == E_SUCCESS, E_SYSTEM, "Failed to seek file");
377
378                 fileLength = file.Tell();
379                 SysTryReturnResult(NID_GRP, fileLength > 0, E_SYSTEM, "The length of the file is not positive");
380
381                 r = file.Seek(FILESEEKPOSITION_BEGIN, 0);
382                 SysTryReturnResult(NID_GRP, r == E_SUCCESS, E_SYSTEM, "Failed to seek file");
383
384                 std::unique_ptr<unsigned char[]> buffer(new (std::nothrow) unsigned char[fileLength]);
385                 SysTryReturnResult(NID_GRP, buffer, E_OUT_OF_MEMORY, "Failed to create font instance");
386
387                 readLength = file.Read(buffer.get(), fileLength);
388                 SysTryReturnResult(NID_GRP, readLength == fileLength, E_SYSTEM, "Failed to read file");
389
390                 // create font
391                 rtn = __CreateFont(_DEFAULT_FONT_ENGINE, buffer.get(), fileLength, _DEFAULT_FONT_FACE, &pFont);
392 #endif
393                 std::auto_ptr<_IFont> autoPtrFont(pFont);
394                 SysTryReturnResult(NID_GRP, rtn && autoPtrFont.get() != null, E_UNSUPPORTED_FORMAT, "Failed to create _IFont instance");
395
396                 // make shared resource
397                 sharedFont.reset(autoPtrFont.release());
398
399                 _IFont::Attrib fontAttrib;
400                 rtn = pFont->GetAttrib(fontAttrib);
401                 SysTryReturnResult(NID_GRP, rtn, E_SYSTEM, "Failed to get font attribute");
402
403                 fontAttrib.size = size;
404                 fontAttrib.style = 0;
405                 fontAttrib.style |= (style & FONT_STYLE_BOLD) ? _IFont::STYLE_BOLD : 0;
406                 fontAttrib.style |= (style & FONT_STYLE_ITALIC) ? _IFont::STYLE_ITALIC : 0;
407
408                 rtn = pFont->SetAttrib(fontAttrib);
409                 SysTryReturnResult(NID_GRP, rtn, E_SYSTEM, "Failed to set font attribute");
410         }
411
412         //--------------------------------------------------------------------------
413         // step 3
414         //
415         // add newly created font resource to rsrc manager
416         //--------------------------------------------------------------------------
417         rtn = __AddFont(fontPathTemp, sharedFont);
418         SysTryReturnResult(NID_GRP, rtn, E_SYSTEM, "Failed to add font resource into the shared container.");
419
420         // set
421         out = sharedFont;
422
423         //--------------------------------------------------------------------------
424         // step 4
425         //
426         // remove unused font
427         //--------------------------------------------------------------------------
428         __RemoveUnusedFont();
429
430         return E_SUCCESS;
431 }
432
433 result
434 _FontRsrcManager::GetTempFont(const Tizen::Base::String& fontPath, int style, _Util::FixedPoint26_6 size, SharedFontResource& out)
435 {
436         _Util::WString fontPathTemp(fontPath.GetPointer());
437
438         SharedFontResource sharedFont;
439         _IFont* pFont = null;
440         //_FontCache* pFontCache = null;
441         bool rtn = false;
442         //unsigned char* pBuffer = null;
443
444         //--------------------------------------------------------------------------
445         // validation check of input param
446         //
447         // in case input fontPath is indicating folder,
448         // we should return 'E_UNSUPPORTED_FORMAT' as bads 2.0 did.
449         //--------------------------------------------------------------------------
450         {
451                 FileAttributes attr;
452                 result r = File::GetAttributes(fontPath, attr);
453                 if (IsFailed(r))
454                 {
455                         return E_FILE_NOT_FOUND;
456                 }
457                 else if (attr.IsDirectory())
458                 {
459                         return E_UNSUPPORTED_FORMAT;
460                 }
461         }
462
463         //--------------------------------------------------------------------------
464         // step 1
465         //
466         // if we already have specified resoruce,
467         // return it with increasing reference count
468         //--------------------------------------------------------------------------
469         rtn = __SearchFont(fontPathTemp, sharedFont);
470
471         if (rtn)
472         {
473                 out = sharedFont;
474
475                 return E_SUCCESS;
476         }
477
478         //--------------------------------------------------------------------------
479         // step 2
480         //
481         // create new font
482         //--------------------------------------------------------------------------
483         {
484                 ByteBuffer* pBuffer = StringUtil::StringToUtf8N(fontPath);
485                 if (pBuffer == null)
486                 {
487                         return false;
488                 }
489                 std::auto_ptr<ByteBuffer> pathString(pBuffer);
490
491                 rtn = __CreateFont(_DEFAULT_FONT_ENGINE, (char*)pathString->GetPointer(), _DEFAULT_FONT_FACE, &pFont);
492
493                 std::auto_ptr<_IFont> autoPtrFont(pFont);
494                 SysTryReturnResult(NID_GRP, rtn && autoPtrFont.get() != null, E_UNSUPPORTED_FORMAT, "Failed to create _IFont instance");
495
496                 // make shared resource
497                 sharedFont.reset(autoPtrFont.release());
498
499                 _IFont::Attrib fontAttrib;
500                 rtn = pFont->GetAttrib(fontAttrib);
501                 SysTryReturnResult(NID_GRP, rtn, E_SYSTEM, "Failed to get font attribute");
502
503                 fontAttrib.size = size;
504                 fontAttrib.style = 0;
505                 fontAttrib.style |= (style & FONT_STYLE_BOLD) ? _IFont::STYLE_BOLD : 0;
506                 fontAttrib.style |= (style & FONT_STYLE_ITALIC) ? _IFont::STYLE_ITALIC : 0;
507
508                 rtn = pFont->SetAttrib(fontAttrib);
509                 SysTryReturnResult(NID_GRP, rtn, E_SYSTEM, "Failed to set font attribute");
510         }
511
512         // set
513         out = sharedFont;
514
515         return E_SUCCESS;
516 }
517
518 result
519 _FontRsrcManager::AddFont(const _Util::WString& fontPath, SharedFontResource& out)
520 {
521         bool rtn = false;
522
523         rtn = __AddFont(fontPath, out);
524         SysTryReturnResult(NID_GRP, rtn, E_SYSTEM, "Failed to add font resource into the shared container.");
525
526         return E_SUCCESS;
527 }
528
529
530 bool
531 _FontRsrcManager::SearchFont(const _Util::WString& fontName)
532 {
533         SharedFontResource sharedFont;
534
535         return (__SearchFont(fontName, sharedFont) == true);
536 }
537
538 result
539 _FontRsrcManager::GetFont(const byte* pFontData, int fontDataSize, int style, _Util::FixedPoint26_6 size, SharedFontResource& out)
540 {
541         SharedFontResource sharedFont;
542         _IFont* pFont = null;
543
544         //--------------------------------------------------------------------------
545         // step 1
546         //
547         // create new font with user resource.
548         //--------------------------------------------------------------------------
549         bool rtn = __CreateFont(_DEFAULT_FONT_ENGINE, pFontData, fontDataSize, _DEFAULT_FONT_FACE, &pFont);
550         std::auto_ptr<_IFont> autoPtrFont(pFont);
551         SysTryReturnResult(NID_GRP, rtn && autoPtrFont.get() != null, E_UNSUPPORTED_FORMAT, "Failed to create _IFont");
552
553         // make shared resource
554         sharedFont.reset(autoPtrFont.release());
555
556         _IFont::Attrib fontAttrib;
557         rtn = pFont->GetAttrib(fontAttrib);
558         SysTryReturnResult(NID_GRP, rtn, E_SYSTEM, "Failed to get font attribute");
559
560         fontAttrib.size = size;
561         fontAttrib.style = 0;
562         fontAttrib.style |= (style & FONT_STYLE_BOLD) ? _IFont::STYLE_BOLD : 0;
563         fontAttrib.style |= (style & FONT_STYLE_ITALIC) ? _IFont::STYLE_ITALIC : 0;
564
565         rtn = pFont->SetAttrib(fontAttrib);
566         SysTryReturnResult(NID_GRP, rtn, E_SYSTEM, "Failed to set font attribute");
567
568         //--------------------------------------------------------------------------
569         // step 2
570         //
571         // add newly created font resource to rsrc manager
572         //--------------------------------------------------------------------------
573         static long long idx = 0;
574
575         String fontName(L"UserMemoryFont");
576         fontName.Append(idx++);
577
578         _Util::WString fontNameTemp(fontName.GetPointer());
579
580         rtn = __AddFont(fontNameTemp, sharedFont);
581         SysTryReturnResult(NID_GRP, rtn, E_SYSTEM, "Failed to add font resrouce into the shared container.");
582
583         // set
584         out = sharedFont;
585
586         //--------------------------------------------------------------------------
587         // step 3
588         //
589         // remove unused font
590         //--------------------------------------------------------------------------
591         __RemoveUnusedFont();
592
593         return E_SUCCESS;
594 }
595
596 result
597 _FontRsrcManager::GetFont(int style, _Util::FixedPoint26_6 size, SharedFontResource& out)
598 {
599         SharedFontResource sharedFont;
600         bool isBold = (style & FONT_STYLE_BOLD) ? true : false;
601
602         String systemFontName = isBold ? _DEFAULT_SYSTEM_BOLD_FONT : _DEFAULT_SYSTEM_FONT;
603
604         _Util::WString systemFontNameTemp(systemFontName.GetPointer());
605
606         _IFont* pFont = null;
607         bool rtn = false;
608
609         //--------------------------------------------------------------------------
610         // step 1
611         //
612         // if we already have specified resoruce,
613         // return it with increasing reference count
614         //--------------------------------------------------------------------------
615         rtn = __SearchFont(systemFontNameTemp, sharedFont);
616
617         if (rtn)
618         {
619                 out = sharedFont;
620
621                 return E_SUCCESS;
622         }
623
624         //--------------------------------------------------------------------------
625         // step 2
626         //
627         // create new font with default font resource.
628         //--------------------------------------------------------------------------
629
630         isBold ? __defaultSystemBoldFontPath.Clear() : __defaultSystemFontPath.Clear();
631
632         const String& defaultSystemFontPath = __GetDefaultSystemFontPath(isBold);
633         SysTryReturnResult(NID_GRP, defaultSystemFontPath.IsEmpty() == false, E_SYSTEM, "Failed to get default system font path");
634
635         {
636 #ifdef USE_MMAP
637                 ByteBuffer* pBuffer = StringUtil::StringToUtf8N(defaultSystemFontPath);
638                 if (pBuffer == null)
639                 {
640                         return false;
641                 }
642                 std::auto_ptr<ByteBuffer> pathString(pBuffer);
643
644                 rtn = __CreateFont(_DEFAULT_FONT_ENGINE, (char*)pathString->GetPointer(), _DEFAULT_FONT_FACE, &pFont);
645 #else
646                 int fileLength = 0;
647                 File file;
648
649                 result r = file.Construct(defaultSystemFontPath, L"rb");
650                 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Failed to open file", GetErrorMessage(r));
651
652                 r = file.Seek(FILESEEKPOSITION_END, 0);
653                 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Failed to seek file", GetErrorMessage(r));
654
655                 fileLength = file.Tell();
656                 SysTryReturn(NID_GRP, fileLength > 0, r, r, "[%s] The length of the file is not positive", GetErrorMessage(r));
657
658                 r = file.Seek(FILESEEKPOSITION_BEGIN, 0);
659                 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Failed to seek file", GetErrorMessage(r));
660
661                 std::unique_ptr<unsigned char[]> autoPtrBuffer(new (std::nothrow) unsigned char[fileLength]);
662                 SysTryReturn(NID_GRP, autoPtrBuffer, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to create buffer of the file length");
663
664                 file.Read(autoPtrBuffer.get(), fileLength);
665
666                 rtn = __CreateFont(_DEFAULT_FONT_ENGINE, autoPtrBuffer.get(), fileLength, _DEFAULT_FONT_FACE, &pFont);
667 #endif
668                 std::auto_ptr<_IFont> autoPtrFont(pFont);
669                 SysTryReturnResult(NID_GRP, rtn && autoPtrFont.get() != null, E_UNSUPPORTED_FORMAT, "Failed to create _IFont instance");
670
671                 // make shared resource
672                 sharedFont.reset(autoPtrFont.release());
673
674                 _IFont::Attrib fontAttrib;
675                 rtn = pFont->GetAttrib(fontAttrib);
676                 SysTryReturnResult(NID_GRP, rtn, E_SYSTEM, "Failed to get font attribute");
677
678                 fontAttrib.size = size;
679                 fontAttrib.style = 0;
680                 fontAttrib.style |= (style & FONT_STYLE_BOLD) ? _IFont::STYLE_BOLD : 0;
681                 fontAttrib.style |= (style & FONT_STYLE_ITALIC) ? _IFont::STYLE_ITALIC : 0;
682
683                 rtn = pFont->SetAttrib(fontAttrib);
684                 SysTryReturnResult(NID_GRP, rtn, E_SYSTEM, "Failed to set font attribute");
685         }
686
687         //--------------------------------------------------------------------------
688         // step 3
689         //
690         // add newly created font resource to rsrc manager
691         //--------------------------------------------------------------------------
692         rtn = __AddFont(systemFontNameTemp, sharedFont);
693         SysTryReturnResult(NID_GRP, rtn, E_SYSTEM, "Failed to add font resource into the shared container");
694
695         // set
696         out = sharedFont;
697
698         //--------------------------------------------------------------------------
699         // step 4
700         //
701         // remove unused font
702         //--------------------------------------------------------------------------
703         __RemoveUnusedFont();
704
705         return E_SUCCESS;
706 }
707
708 result
709 _FontRsrcManager::GetSystemFont(const Tizen::Base::String& fontName, int style, _Util::FixedPoint26_6 size, SharedFontResource& out)
710 {
711         FcPattern *pFontPattern = null;
712         FcFontSet *pFontSet = null;
713         FcResult res = FcResultNoMatch;
714         FcChar8* pPath = null;
715         const char* fcStyle = (style & FONT_STYLE_BOLD) ? "Bold" : "Regular";
716         result r = E_SYSTEM;
717
718         ByteBuffer* pBuffer = StringUtil::StringToUtf8N(fontName);
719         if (pBuffer == null)
720         {
721                 return E_SYSTEM;
722         }
723         std::auto_ptr<ByteBuffer> utfString(pBuffer);
724
725         //FcBool rtn = FcInitReinitialize();
726         //SysTryCatch(NID_GRP, rtn != FcFalse, , r, "[E_SYSTEM] Failed to init fontconfig");
727
728         pFontPattern = FcPatternBuild(NULL, FC_STYLE, FcTypeString, (FcChar8*)fcStyle, NULL);
729         SysTryCatch(NID_GRP, pFontPattern, , r, "[E_SYSTEM] Failed to FcPatternBuild()");
730
731         FcPatternAddString(pFontPattern, FC_FAMILY, (FcChar8*)utfString->GetPointer());
732         FcConfigSubstitute(NULL, pFontPattern, FcMatchPattern);
733         FcDefaultSubstitute(pFontPattern);
734
735         pFontSet = FcFontSort(NULL, pFontPattern, FcTrue, NULL, &res);
736         SysTryCatch(NID_GRP, pFontSet, , r, "[E_SYSTEM] Failed to FcFontSort()");
737
738         res = FcPatternGetString(pFontSet->fonts[0], FC_FILE, 0, &pPath);
739         SysTryCatch(NID_GRP, res == FcResultMatch, , r, "[E_SYSTEM] Failed to get path of system font");
740
741         r = this->GetFont(String((char*)pPath), style, size, out);
742         SysTryCatch(NID_GRP, r == E_SUCCESS, , r, "[%s] Failed to get font", GetErrorMessage(r));
743
744         // destroy
745         FcPatternDestroy(pFontPattern);
746         FcFontSetDestroy(pFontSet);
747         //FcFini();
748
749         return E_SUCCESS;
750
751 CATCH:
752         if (pFontSet)
753         {
754                 FcFontSetDestroy(pFontSet);
755         }
756
757         if (pFontPattern)
758         {
759                 FcPatternDestroy(pFontPattern);
760         }
761
762         //FcFini();
763
764         return r;
765 }
766
767 void
768 _FontRsrcManager::__InitFontRsrcManager(void)
769 {
770         static _FontRsrcManager instance;
771         __pTheInstance = &instance;
772 }
773
774 _FontRsrcManager&
775 _FontRsrcManager::GetInstance(void)
776 {
777         static pthread_once_t once_block = PTHREAD_ONCE_INIT;
778
779         if (!__pTheInstance)
780         {
781                 pthread_once(&once_block, __InitFontRsrcManager);
782         }
783
784         return (*__pTheInstance);
785 }
786
787 bool
788 _FontRsrcManager::__CreateFont(int fontEngine, const void* pBuffer, long bufSize, long face, _IFont** ppOut)
789 {
790         // check input param
791         SysTryReturn(NID_GRP, ppOut, false, E_INVALID_ARG, "[E_INVALID_ARG] Invalid out param is given");
792
793         std::auto_ptr<_IFont> autoPtrFont;
794
795         switch (fontEngine)
796         {
797         case 0:
798                 autoPtrFont.reset(new (std::nothrow) _FontFt2);
799                 break;
800
801         default:
802                 autoPtrFont.reset(new (std::nothrow) _FontNull);
803                 break;
804         }
805
806         SysTryReturn(NID_GRP, autoPtrFont.get() != null, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory");
807
808         bool rtn = autoPtrFont->Create(pBuffer, bufSize, face);
809         SysTryReturn(NID_GRP, rtn, false, E_SYSTEM, "[E_SYSTEM] Failed to create font resource");
810
811         // set out param
812         *ppOut = autoPtrFont.release();
813
814         return true;
815 }
816
817 bool
818 _FontRsrcManager::__CreateFont(int fontEngine, const char* filePath, const long face, _IFont** ppOut)
819 {
820         // check input param
821         SysTryReturn(NID_GRP, ppOut, false, E_INVALID_ARG, "[E_INVALID_ARG] Invalid out param is given");
822
823         std::auto_ptr<_IFont> autoPtrFont;
824
825         switch (fontEngine)
826         {
827         case 0:
828                 autoPtrFont.reset(new (std::nothrow) _FontFt2);
829                 break;
830
831         default:
832                 autoPtrFont.reset(new (std::nothrow) _FontNull);
833                 break;
834         }
835
836         SysTryReturn(NID_GRP, autoPtrFont.get() != null, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory");
837
838         bool rtn = autoPtrFont->Create(filePath, face);
839         SysTryReturn(NID_GRP, rtn, false, E_SYSTEM, "[E_SYSTEM] Failed to create font resource");
840
841         // set out param
842         *ppOut = autoPtrFont.release();
843
844         return true;
845 }
846
847 bool
848 _FontRsrcManager::__CreateStaticFont(int fontEngine, const void* pBuffer, long bufSize, long face, _IFont** ppOut)
849 {
850         // check input param
851         SysTryReturn(NID_GRP, ppOut, false, E_INVALID_ARG, "[E_INVALID_ARG] Invalid out param is given");
852
853         std::auto_ptr<_IFont> autoPtrFont;
854
855         switch (fontEngine)
856         {
857         case 0:
858                 autoPtrFont.reset(new (std::nothrow) _FontFt2);
859                 break;
860
861         default:
862                 autoPtrFont.reset(new (std::nothrow) _FontNull);
863                 break;
864         }
865
866         SysTryReturn(NID_GRP, autoPtrFont.get() != null, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory");
867
868         bool rtn = autoPtrFont->CreateStatic(pBuffer, bufSize, face);
869         SysTryReturn(NID_GRP, rtn, false, E_SYSTEM, "[E_SYSTEM] Failed to create font resource");
870
871         // set out param
872         *ppOut = autoPtrFont.release();
873
874         return true;
875 }
876
877 bool
878 _FontRsrcManager::__SearchFont(const _Util::WString& fontPath, SharedFontResource& out) const
879 {
880         // check input param
881         SysTryReturn(NID_GRP, out.get() == null, false, E_INVALID_ARG, "[E_INVALID_ARG] Invalid out param is given");
882
883 #ifdef USE_HASHMAP_FOR_FONT
884         return (__fontRsrcMap.GetValue(fontPath, out) == E_SUCCESS);
885 #else
886         FontMapT::const_iterator fontIterator = __fontRsrcMap.find(fontPath);
887
888         if (fontIterator != __fontRsrcMap.end())
889         {
890                 out = fontIterator->second;
891                 return true;
892         }
893
894         return false;
895 #endif
896 }
897
898 bool
899 _FontRsrcManager::__AddFont(const _Util::WString& key, const SharedFontResource& font)
900 {
901         // check input param
902         SysTryReturn(NID_GRP, font.get() != null, false, E_INVALID_ARG, "[E_INVALID_ARG] Invalid input param is given");
903
904 #ifdef USE_HASHMAP_FOR_FONT
905         result r = __fontRsrcMap.Add(key, font);
906
907         SysTryReturn(NID_GRP, r == E_SUCCESS || r == E_OBJ_ALREADY_EXIST, false, false, "[%s] Failed to add font into resource pool", GetErrorMessage(r));
908 #else
909         __fontRsrcMap[key] = font;
910 #endif
911
912         return true;
913 }
914
915 void
916 _FontRsrcManager::__RemoveUnusedFont(void)
917 {
918         ArrayListT<_Util::WString> keys;
919         String systemFontName(_DEFAULT_SYSTEM_FONT);
920         String systemBoldFontName(_DEFAULT_SYSTEM_BOLD_FONT);
921
922         _Util::WString systemFontNameTemp(systemFontName.GetPointer());
923         _Util::WString systemBoldFontNameTemp(systemBoldFontName.GetPointer());
924
925         // find out unused font
926
927 #ifdef USE_HASHMAP_FOR_FONT
928         {
929                 std::auto_ptr<IMapEnumeratorT<_Util::WString, SharedFontResource> > enumerator(__fontRsrcMap.GetMapEnumeratorN());
930                 result r = GetLastResult();
931                 SysTryReturnVoidResult(NID_GRP, enumerator.get() != null, r, "[%s] Propagating.", GetErrorMessage(r));
932
933                 while (enumerator->MoveNext() == E_SUCCESS)
934                 {
935                         SharedFontResource font;
936                         r = enumerator->GetValue(font);
937
938                         if (r == E_SUCCESS && font.use_count() == 2)
939                         {
940                                 _Util::WString key(L"");
941                                 r = enumerator->GetKey(key);
942
943                                 if (r == E_SUCCESS && (key != systemFontNameTemp && key != systemBoldFontNameTemp))
944                                 {
945                                         keys.Add(key);
946                                 }
947                         }
948                 }
949         }
950 #else
951         {
952                 for (FontMapT::iterator fontIterator = __fontRsrcMap.begin(); fontIterator != __fontRsrcMap.end(); ++fontIterator)
953                 {
954                         SharedFontResource font(fontIterator->second);
955
956                         if (font != null && font.use_count() == 2)
957                         {
958                                 _Util::WString key(fontIterator->first);
959
960                                 if (key != systemFontNameTemp && key != systemBoldFontNameTemp)
961                                 {
962                                         keys.Add(key);
963                                 }
964                         }
965                 }
966         }
967 #endif
968
969         // remove
970         if (keys.GetCount() > 0)
971         {
972                 std::auto_ptr<IEnumeratorT<_Util::WString> > enumerator(keys.GetEnumeratorN());
973                 result r = GetLastResult();
974                 SysTryReturnVoidResult(NID_GRP, enumerator.get() != null, r, "[%s] Propagating.", GetErrorMessage(r));
975
976                 while (enumerator->MoveNext() == E_SUCCESS)
977                 {
978                         _Util::WString key(L"");
979                         r = enumerator->GetCurrent(key);
980
981                         if (r == E_SUCCESS)
982                         {
983 #ifdef USE_HASHMAP_FOR_FONT
984                                 __fontRsrcMap.Remove(key);
985 #else
986                                 __fontRsrcMap.erase(key);
987 #endif
988                         }
989                 }
990         }
991
992         return;
993 }
994
995 bool
996 _FontRsrcManager::__ReloadFont(String fontName, bool isBold)
997 {
998         SharedFontResource sharedFont;
999         _Util::WString systemFontName(fontName.GetPointer());
1000
1001         _IFont* pFont = null;
1002         bool rtn = false;
1003
1004         // Check if there is default system font in font resource manager
1005         // If there isn't default system font, we can't reload font resource
1006         rtn = __SearchFont(systemFontName, sharedFont);
1007         SysTryReturn(NID_GRP, rtn, false, E_SYSTEM, "[E_SYSTEM] Failed to search default system font");
1008
1009         // Get default system font interface instance
1010         pFont = sharedFont.get();
1011
1012         // Reload system font resource in font interface
1013         {
1014 #ifdef USE_MMAP
1015                 isBold ? __defaultSystemBoldFontPath.Clear() : __defaultSystemFontPath.Clear();
1016                 const String& fontPath = __GetDefaultSystemFontPath(isBold);
1017
1018                 ByteBuffer* pBuffer = StringUtil::StringToUtf8N(fontPath);
1019                 if (pBuffer == null)
1020                 {
1021                         return false;
1022                 }
1023                 std::auto_ptr<ByteBuffer> pathString(pBuffer);
1024
1025                 rtn = pFont->Reload((char*)pathString->GetPointer(), _DEFAULT_FONT_FACE);
1026                 SysTryReturn(NID_GRP, rtn, false, E_SYSTEM, "[E_SYSTEM] Failed to reload font");
1027 #else
1028                 int fileLength = 0;
1029                 File file;
1030
1031                 isBold ? __defaultSystemBoldFontPath.Clear() : __defaultSystemFontPath.Clear();
1032
1033                 result r = file.Construct(__GetDefaultSystemFontPath(isBold), L"rb");
1034                 SysTryReturn(NID_GRP, r == E_SUCCESS, false, r, "[%s] Failed to open file", GetErrorMessage(r));
1035
1036                 r = file.Seek(FILESEEKPOSITION_END, 0);
1037                 SysTryReturn(NID_GRP, r == E_SUCCESS, false, r, "[%s] Failed to seek file", GetErrorMessage(r));
1038
1039                 fileLength = file.Tell();
1040                 SysTryReturn(NID_GRP, fileLength > 0, false, r, "[%s] The length of the file is not positive", GetErrorMessage(r));
1041
1042                 r = file.Seek(FILESEEKPOSITION_BEGIN, 0);
1043                 SysTryReturn(NID_GRP, r == E_SUCCESS, false, r, "[%s] Failed to seek file", GetErrorMessage(r));
1044
1045                 std::unique_ptr<unsigned char[]> autoPtrBuffer(new (std::nothrow) unsigned char[fileLength]);
1046                 SysTryReturn(NID_GRP, autoPtrBuffer, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to create buffer of the file length");
1047
1048                 file.Read(autoPtrBuffer.get(), fileLength);
1049                 rtn = pFont->Reload(autoPtrBuffer.get(), fileLength, _DEFAULT_FONT_FACE);
1050                 SysTryReturn(NID_GRP, rtn, false, E_SYSTEM, "[E_SYSTEM] Failed to reload font");
1051 #endif
1052
1053                 pFont->CleanCache();
1054         }
1055
1056         return true;
1057 }
1058
1059 bool
1060 _FontRsrcManager::ReloadDefaultSystemFont(void)
1061 {
1062         // reinitialize fontconfig library
1063         FcInitReinitialize();
1064
1065         String systemFontName;
1066
1067         systemFontName = _DEFAULT_SYSTEM_FONT;
1068         __ReloadFont(systemFontName, false);
1069
1070         systemFontName = _DEFAULT_SYSTEM_BOLD_FONT;
1071         __ReloadFont(systemFontName, true);
1072
1073         return true;
1074 }
1075
1076 _FontMemoryManager&
1077 _FontRsrcManager::GetMemoryManager(void)
1078 {
1079         return *__pFontMemoryManager;
1080 }
1081
1082
1083 _Font&
1084 _FontRsrcManager::GetDefaultSystemFont(void)
1085 {
1086         if (__pDefaultSystemFont == null)
1087         {
1088                 std::auto_ptr<_Font> font(new (std::nothrow) _Font);
1089
1090                 if (font.get())
1091                 {
1092                         result r = font->Construct(FONT_STYLE_PLAIN, _SYSTEM_DEFAULT_FONT_SIZE);
1093
1094                         if (r == E_SUCCESS)
1095                         {
1096                                 __pDefaultSystemFont = font.release();
1097                         }
1098                 }
1099         }
1100
1101         SysAssert(__pDefaultSystemFont != null);
1102
1103         return *__pDefaultSystemFont;
1104 }
1105
1106
1107 long
1108 _FontRsrcManager::__GetMaxFontEngine(void) const
1109 {
1110         return 1;
1111 }
1112
1113 String
1114 _FontRsrcManager::__GetFontPath(bool isBold)
1115 {
1116         String fontPath(L"");
1117
1118         FcFontSet* pFontSet = null;
1119         FcPattern* pFontPattern = null;
1120         const char* fcStyle = isBold ? "Bold" : "Regular";
1121         // initialize fontconfig library
1122         //FcBool rtn = FcInitReinitialize();
1123         //SysTryCatch(NID_GRP, rtn != FcFalse, , E_SYSTEM, "[E_SYSTEM] Failed to init fontconfig");
1124
1125         // create pattern
1126         pFontPattern = FcPatternCreate();
1127         SysTryCatch(NID_GRP, pFontPattern, , E_SYSTEM, "[E_SYSTEM] Failed to create font pattern");
1128
1129         FcPatternAddString(pFontPattern, FC_FAMILY, (FcChar8*)"Tizen");
1130         FcPatternAddString(pFontPattern, FC_STYLE, (FcChar8*)fcStyle);
1131         FcConfigSubstitute(0, pFontPattern, FcMatchPattern);
1132         FcDefaultSubstitute(pFontPattern);
1133
1134         // create fontset
1135         pFontSet = FcFontSetCreate();
1136         SysTryCatch(NID_GRP, pFontSet, , E_SYSTEM, "[E_SYSTEM] Failed to create fontset");
1137
1138         {
1139                 FcPattern* pMatchedPattern = null;
1140                 FcResult result = FcResultNoMatch;
1141                 pMatchedPattern = FcFontMatch(NULL, pFontPattern, &result);
1142
1143                 if (/*result == FcResultMatch && */pMatchedPattern)
1144                 {
1145                         FcFontSetAdd(pFontSet, pMatchedPattern);
1146                 }
1147
1148                 // check if we have a system font info
1149                 SysTryCatch(NID_GRP, pFontSet->nfont >= 1, , E_SYSTEM, "[E_SYSTEM] Default system count is %d", pFontSet->nfont);
1150
1151                 FcChar8* pPath = null;
1152                 result = FcPatternGetString(pFontSet->fonts[0], FC_FILE, 0, &pPath);
1153                 SysTryCatch(NID_GRP, result == FcResultMatch, , E_SYSTEM, "[E_SYSTEM] Failed to create fontset");
1154                 fontPath.Clear();
1155                 fontPath.Append(String((char*)pPath));
1156         }
1157
1158         // destroy
1159         FcPatternDestroy(pFontPattern);
1160         FcFontSetDestroy(pFontSet);
1161         //FcFini();
1162
1163         return fontPath;
1164
1165 CATCH:
1166         if (pFontSet != null)
1167         {
1168                 FcFontSetDestroy(pFontSet);
1169         }
1170
1171         if (pFontPattern != null)
1172         {
1173                 FcPatternDestroy(pFontPattern);
1174         }
1175
1176         return fontPath;
1177 }
1178
1179 const String&
1180 _FontRsrcManager::__GetDefaultSystemFontPath(bool isBold)
1181 {
1182         String& defaultPath = (isBold) ? __defaultSystemBoldFontPath : __defaultSystemFontPath;
1183
1184         if (!defaultPath.IsEmpty())
1185         {
1186                 return defaultPath;
1187         }
1188         else
1189         {
1190                 String path = __GetFontPath(isBold);
1191
1192                 if (isBold)
1193                 {
1194                         if (path.IsEmpty())
1195                         {
1196                                 path = __GetFontPath(false);
1197                                 // [ykahn] Is 'path' always not NULL ?
1198                         }
1199
1200                         __defaultSystemBoldFontPath.Clear();
1201                         __defaultSystemBoldFontPath.Append(path);
1202
1203                         return __defaultSystemBoldFontPath;
1204                 }
1205                 else
1206                 {
1207                         __defaultSystemFontPath.Clear();
1208                         __defaultSystemFontPath.Append(path);
1209
1210                         return __defaultSystemFontPath;
1211                 }
1212         }
1213 }
1214
1215 bool
1216 _FontRsrcManager::RemoveMemory(unsigned long requestedSize)
1217 {
1218 #ifdef USE_REMOVE_ALL_CACHE
1219
1220 #ifdef USE_HASHMAP_FOR_FONT
1221         result r = E_SUCCESS;
1222         std::auto_ptr<IMapEnumeratorT<_Util::WString, SharedFontResource > > enumerator(__fontRsrcMap.GetMapEnumeratorN());
1223
1224         while (enumerator->MoveNext() == E_SUCCESS)
1225         {
1226                 SharedFontResource fontRsrc;
1227                 r = enumerator->GetValue(fontRsrc);
1228
1229                 fontRsrc.get()->CleanCache();
1230         }
1231
1232         return true;
1233 #else
1234         for (FontMapT::iterator fontIterator = __fontRsrcMap.begin(); fontIterator != __fontRsrcMap.end(); ++fontIterator)
1235         {
1236                 SharedFontResource fontRsrc(fontIterator->second);
1237
1238                 fontRsrc.get()->CleanCache();
1239         }
1240
1241         return true;
1242 #endif
1243
1244 #else
1245         unsigned long remainedMemory = 0;
1246         result r = E_SUCCESS;
1247         bool isComplete = false;
1248
1249         ArrayListT<String> keys;
1250         String systemFontName(_DEFAULT_SYSTEM_FONT);
1251         _Util::WString systemFontNameTemp(systemFontName.GetPointer());
1252
1253         std::auto_ptr<IMapEnumeratorT<_Util::WString, SharedFontResource > > enumerator(__fontRsrcMap.GetMapEnumeratorN());
1254
1255         while (enumerator->MoveNext() == E_SUCCESS)
1256         {
1257                 if (isComplete)
1258                 {
1259                         break;
1260                 }
1261
1262                 _Util::WString key;
1263                 r = enumerator->GetKey(key);
1264                 if (r == E_SUCCESS/* && key != systemFontNameTemp*/)
1265                 {
1266                         SharedFontResource fontRsrc;
1267                         r = enumerator->GetValue(fontRsrc);
1268
1269                         while (!fontRsrc.get()->second->IsEmpty())
1270                         {
1271                                 fontRsrc.get()->second->RemoveFirst();
1272
1273                                 remainedMemory = __pFontMemoryManager->GetRemainedMemory();
1274
1275                                 if (remainedMemory > requestedSize)
1276                                 {
1277                                                 isComplete = true;
1278                                                 break;
1279                                 }
1280                         }
1281                 }
1282         }
1283
1284         return isComplete;
1285 #endif
1286 }
1287
1288 _Util::WString
1289 _FontRsrcManager::FindAppFontName(const _Util::WString& fontName)
1290 {
1291         _Util::WString fontPath(L"");
1292
1293         if (!__isAppFontListInitialized)
1294         {
1295                 String dirName;
1296                 Directory dir;
1297                 DirEnumerator* pDirEnum;
1298
1299                 //dirName = L"/usr/share/app_font";
1300                 dirName = Tizen::App::App::GetInstance()->GetAppResourcePath() + L"font";
1301
1302                 // Open the directory
1303                 if (IsFailed(dir.Construct(dirName)))
1304                 {
1305                         return fontPath;
1306                 }
1307
1308                 // Reads all the directory entries
1309                 pDirEnum = dir.ReadN();
1310
1311                 if (!pDirEnum)
1312                 {
1313                         return fontPath;
1314                 }
1315
1316                 // Loops through all the directory entries
1317                 while (pDirEnum->MoveNext() == E_SUCCESS)
1318                 {
1319                         SharedFontResource sharedFont;
1320                         String faceName;
1321                         String name;
1322                         String token;
1323                         DirEntry entry = pDirEnum->GetCurrentDirEntry();
1324                         Tizen::Base::Utility::StringTokenizer formatTok(entry.GetName(), L".");
1325
1326                         while (formatTok.GetTokenCount())
1327                         {
1328                                 formatTok.GetNextToken(token);
1329                         }
1330
1331                         if (entry.IsDirectory() == false)
1332                         {
1333                                 name.Append(dirName);
1334                                 name.Append(L"/");
1335                                 name.Append(entry.GetName());
1336
1337                                 faceName = _Font::GetFaceName(name);
1338
1339                                 _Util::WString faceNameTemp(faceName.GetPointer());
1340                                 _Util::WString nameTemp(name.GetPointer());
1341 #ifdef USE_HASHMAP_FOR_FONT
1342                                 __appFontMap.Add(faceNameTemp, nameTemp);
1343 #else
1344                                 __appFontMap[faceNameTemp] = nameTemp;
1345 #endif
1346                         }
1347                 }
1348
1349                 delete pDirEnum;
1350                 pDirEnum = null;
1351
1352                 __isAppFontListInitialized = true;
1353         }
1354
1355 #ifdef USE_HASHMAP_FOR_FONT
1356         __appFontMap.GetValue(fontName, fontPath);
1357 #else
1358         AppFontMapT::const_iterator appFontIterator = __appFontMap.find(fontName);
1359
1360         if (appFontIterator != __appFontMap.end())
1361         {
1362                 fontPath = appFontIterator->second;
1363         }
1364 #endif
1365
1366         return fontPath;
1367 }
1368
1369 }} // Tizen::Graphics