Merge "Add log for font load validation" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-scene-loader / public-api / dli-loader.h
1 #ifndef DALI_SCENE_LOADER_DLI_LOADER_H
2 #define DALI_SCENE_LOADER_DLI_LOADER_H
3 /*
4  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 // INTERNAL INCLUDES
21 #include "dali-scene-loader/public-api/animation-definition.h"
22 #include "dali-scene-loader/public-api/api.h"
23 #include "dali-scene-loader/public-api/customization.h"
24 #include "dali-scene-loader/public-api/index.h"
25 #include "dali-scene-loader/public-api/string-callback.h"
26
27 // EXTERNAL INCLUDES
28 #include "dali/public-api/common/vector-wrapper.h"
29
30 namespace Dali
31 {
32 namespace SceneLoader
33 {
34 typedef std::pair<std::string, std::string> Metadata;
35
36 // Forward declarations
37 struct LoadResult;
38 struct CameraParameters;
39 struct LightParameters;
40 struct TextParameters;
41
42 class ResourceBundle;
43 struct NodeDefinition;
44 class SceneDefinition;
45
46 class DALI_SCENE_LOADER_API DliLoader
47 {
48 public:
49   using ConvertFontCode  = void (*)(const std::string& code, std::string& fontFamily, std::string& slant, std::string& weight, float& size);
50   using ConvertColorCode = Vector4 (*)(const std::string& code);
51
52   using CategoryProcessor       = std::function<void(Property::Array&& categoryData, StringCallback onError)>;
53   using CategoryProcessorVector = std::vector<std::pair<std::string /*name*/, CategoryProcessor>>;
54
55   using NodeProcessor = std::function<void(const NodeDefinition& nodeDef,
56                                            Property::Map&&       nodeData,
57                                            StringCallback        onError)>;
58
59   using AnimationProcessor = std::function<void(const AnimationDefinition& animDef,
60                                                 Property::Map&&            animData,
61                                                 StringCallback             onError)>;
62
63   struct InputParams
64   {
65     /**
66      * @brief The absolute path of animation binaries referenced in the .dli.
67      */
68     std::string mAnimationsPath;
69
70     /**
71      * @brief Provides a facility to determine a color from a code instead of RGB(A) values.
72      */
73     ConvertColorCode mConvertColorCode;
74
75     /**
76      * @brief A collection of handlers, mapped to the names of the top level (i.e. below
77      *  root) element, whom they will attempt to process. This will take place before
78      *  the parsing of scene Nodes and Animations, but after skeletons, environment, mesh,
79      *  shader and material resources.
80      */
81     CategoryProcessorVector mPreNodeCategoryProcessors;
82
83     /**
84      * @brief A collection of handlers, mapped to the names of the top level (i.e. below
85      *  root) element, whom they will attempt to process. This will take place after
86      *  the parsing of the scene Nodes and Animations.
87      */
88     CategoryProcessorVector mPostNodeCategoryProcessors;
89
90     /**
91      * @brief Provides an extension point to nodes. If provided, this function will be
92      *  called with each JSON element and definition, of a scene node.
93      * @note Constraints rely on ID resolution (from .dli to scene definition), which
94      *  takes place after the parsing of the nodes; therefore AT THIS POINT the node
95      *  IDs seen in constraints will still be the .dli IDs - NOT to be relied on for
96      *  indexing into mScene.
97      */
98     NodeProcessor mNodePropertyProcessor;
99
100     /**
101      * @brief Provides an extension point to animations. If provided, this function will be
102      *  called with each JSON element and fully processed definition, of an animation.
103      */
104     AnimationProcessor mAnimationPropertyProcessor;
105   };
106
107   struct LoadParams
108   {
109     InputParams const& input;
110     LoadResult&        output;
111   };
112
113   DliLoader();
114   ~DliLoader();
115
116   /**
117    * @brief Sets the callback that messages from non-fatal errors get posted to.
118    *  Uses DefaultErrorCallback by default.
119    */
120   void SetErrorCallback(StringCallback onError);
121
122   /**
123    * @brief Attempts to load and parse a .dli document into a DOM tree.
124    * @return Whether the operation was successful.
125    */
126   bool LoadScene(const std::string& uri, LoadParams& params);
127
128   /**
129    * @return The error string describing how the parse has failed, if any.
130    */
131   std::string GetParseError() const;
132
133 private:
134   struct Impl;
135   const std::unique_ptr<Impl> mImpl;
136 };
137
138 } // namespace SceneLoader
139 } // namespace Dali
140
141 #endif // DALI_SCENE_LOADER_DLI_LOADER_H