Merge remote-tracking branch 'origin/tizen' into new_text
[platform/core/uifw/dali-adaptor.git] / text / dali / internal / text-abstraction / font-client-plugin-impl.h
1 #ifndef __DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_PLUGIN_IMPL_H__
2 #define __DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_PLUGIN_IMPL_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/text-abstraction/font-metrics.h>
23 #include <dali/internal/text-abstraction/font-client-impl.h>
24
25 // EXTERNAL INCLUDES
26 #include <ft2build.h>
27 #include FT_FREETYPE_H
28 #include FT_GLYPH_H
29 #include <fontconfig/fontconfig.h>
30
31 namespace Dali
32 {
33
34 namespace TextAbstraction
35 {
36
37 namespace Internal
38 {
39
40 struct FontClient::Plugin
41 {
42   struct CacheItem
43   {
44     CacheItem( FontId id, FT_Face ftFace, const std::string& path, PointSize26Dot6 pointSize, FaceIndex face, const FontMetrics& metrics );
45
46     FT_Face mFreeTypeFace;
47     std::string mPath;
48     PointSize26Dot6 mPointSize;
49     FaceIndex mFaceIndex;
50     FontMetrics mMetrics;
51   };
52
53   Plugin( unsigned int horizontalDpi, unsigned int verticalDpi );
54
55   ~Plugin();
56
57   void Initialize();
58
59   void SetDpi( unsigned int horizontalDpi, unsigned int verticalDpi );
60
61   void GetSystemFonts( FontList& systemFonts );
62
63   void InitSystemFonts();
64
65   _FcFontSet* GetFcFontSet() const;
66
67   bool GetFcString( const FcPattern* pattern, const char* n, std::string& string );
68
69   void GetDescription( FontId id, FontDescription& fontDescription ) const;
70
71   PointSize26Dot6 GetPointSize( FontId id );
72
73   FontId FindDefaultFont( Character charcode, PointSize26Dot6 pointSize );
74
75   FontId GetFontId( const std::string& path, PointSize26Dot6 pointSize, FaceIndex faceIndex );
76
77   FontId GetFontId( const FontFamily& fontFamily,
78                     const FontStyle& fontStyle,
79                     PointSize26Dot6 pointSize,
80                     FaceIndex faceIndex );
81
82   GlyphIndex GetGlyphIndex( FontId fontId, Character charcode );
83
84   FontId CreateFont( const std::string& path, PointSize26Dot6 pointSize, FaceIndex faceIndex );
85
86   void GetFontMetrics( FontId fontId, FontMetrics& metrics );
87
88   bool GetGlyphMetrics( GlyphInfo* array, uint32_t size, bool horizontal );
89
90   BitmapImage CreateBitmap( FontId fontId, GlyphIndex glyphIndex );
91
92   void ConvertBitmap( BitmapImage& destBitmap, FT_Bitmap srcBitmap );
93
94 private:
95
96   bool FindFont( const std::string& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, FontId& found ) const;
97
98   FT_Library mFreeTypeLibrary;
99
100   FontList mSystemFonts;
101
102   std::vector<CacheItem> mFontCache;
103
104   unsigned int mDpiHorizontal;
105   unsigned int mDpiVertical;
106 };
107
108 } // namespace Internal
109
110 } // namespace TextAbstraction
111
112 } // namespace Dali
113
114 #endif // __DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_PLUGIN_IMPL_H__