[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / rendering / text-backend-impl.cpp
1 /*
2  * Copyright (c) 2021 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/devel-api/common/singleton-service.h>
23 #include <dali/integration-api/debug.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/devel-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 namespace Toolkit
35 {
36 namespace Text
37 {
38 namespace Internal
39 {
40 struct Backend::Impl
41 {
42   int temp; // placeholder for future backend implemenations
43 };
44
45 Backend::Backend()
46 : mImpl(NULL)
47 {
48   mImpl = new Impl();
49 }
50
51 Backend::~Backend()
52 {
53   delete mImpl;
54 }
55
56 Dali::Toolkit::Text::Backend Backend::Get()
57 {
58   Dali::Toolkit::Text::Backend backendHandle;
59
60   Dali::SingletonService service(SingletonService::Get());
61   if(service)
62   {
63     // Check whether the singleton is already created
64     Dali::BaseHandle handle = service.GetSingleton(typeid(Dali::Toolkit::Text::Backend));
65     if(handle)
66     {
67       // If so, downcast the handle
68       Backend* impl = dynamic_cast<Dali::Toolkit::Text::Internal::Backend*>(handle.GetObjectPtr());
69       backendHandle = Dali::Toolkit::Text::Backend(impl);
70     }
71     else // create and register the object
72     {
73       backendHandle = Dali::Toolkit::Text::Backend(new Backend);
74       service.Register(typeid(backendHandle), backendHandle);
75     }
76   }
77
78   return backendHandle;
79 }
80
81 RendererPtr Backend::NewRenderer(unsigned int renderingType)
82 {
83   RendererPtr renderer;
84
85   switch(renderingType)
86   {
87     case Dali::Toolkit::DevelText::RENDERING_SHARED_ATLAS:
88     {
89       renderer = Dali::Toolkit::Text::AtlasRenderer::New();
90     }
91     break;
92
93     case Dali::Toolkit::DevelText::RENDERING_VECTOR_BASED:
94     {
95 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
96       renderer = Dali::Toolkit::Text::VectorBasedRenderer::New();
97 #else
98       renderer = Dali::Toolkit::Text::AtlasRenderer::New(); // Fallback to bitmap-based rendering
99 #endif
100     }
101     break;
102
103     default:
104     {
105       DALI_LOG_WARNING("Unknown renderer type: %d\n", renderingType);
106       break;
107     }
108   }
109
110   return renderer;
111 }
112
113 } // namespace Internal
114
115 } // namespace Text
116
117 } // namespace Toolkit
118
119 } // namespace Dali