Merge "Fixed an incorrect ellipsis" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / rendering / text-backend-impl.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/internal/text/rendering/text-backend-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/integration-api/debug.h>
23 #include <dali/devel-api/adaptor-framework/singleton-service.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/public-api/text/rendering-backend.h>
27 #include <dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.h>
28 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
29 #include <dali-toolkit/internal/text/rendering/vector-based/vector-based-renderer.h>
30 #endif
31
32 namespace Dali
33 {
34
35 namespace Toolkit
36 {
37
38 namespace Text
39 {
40
41 namespace Internal
42 {
43
44 struct Backend::Impl
45 {
46   int temp; // placeholder for future backend implemenations
47 };
48
49 Backend::Backend()
50 : mImpl( NULL )
51 {
52   mImpl = new Impl();
53 }
54
55 Backend::~Backend()
56 {
57   delete mImpl;
58 }
59
60 Dali::Toolkit::Text::Backend Backend::Get()
61 {
62   Dali::Toolkit::Text::Backend backendHandle;
63
64   Dali::SingletonService service( SingletonService::Get() );
65   if ( service )
66   {
67     // Check whether the singleton is already created
68     Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::Toolkit::Text::Backend ) );
69     if(handle)
70     {
71       // If so, downcast the handle
72       Backend* impl = dynamic_cast< Dali::Toolkit::Text::Internal::Backend* >( handle.GetObjectPtr() );
73       backendHandle = Dali::Toolkit::Text::Backend( impl );
74     }
75     else // create and register the object
76     {
77       backendHandle = Dali::Toolkit::Text::Backend( new Backend );
78       service.Register( typeid( backendHandle ), backendHandle );
79     }
80   }
81
82   return backendHandle;
83 }
84
85 RendererPtr Backend::NewRenderer( unsigned int renderingType )
86 {
87   RendererPtr renderer;
88
89   switch( renderingType )
90   {
91     case Dali::Toolkit::Text::RENDERING_SHARED_ATLAS:
92     {
93       renderer = Dali::Toolkit::Text::AtlasRenderer::New();
94     }
95     break;
96
97     case Dali::Toolkit::Text::RENDERING_VECTOR_BASED:
98     {
99 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
100       renderer = Dali::Toolkit::Text::VectorBasedRenderer::New();
101 #else
102       renderer = Dali::Toolkit::Text::AtlasRenderer::New(); // Fallback to bitmap-based rendering
103 #endif
104     }
105     break;
106
107     default:
108     {
109       DALI_LOG_WARNING( "Unknown renderer type: %d\n", renderingType );
110       break;
111     }
112   }
113
114   return renderer;
115 }
116
117 } // namespace Internal
118
119 } // namespace Text
120
121 } // namespace Toolkit
122
123 } // namespace Dali