d1437ff907ac40a0390997a826a05447f0f8cbce
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / renderers / svg / svg-renderer.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_SVG_RENDERER_H__
2 #define __DALI_TOOLKIT_INTERNAL_SVG_RENDERER_H__
3
4 /*
5  * Copyright (c) 2016 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-toolkit/internal/controls/renderers/control-renderer-impl.h>
23 #include <dali-toolkit/internal/controls/renderers/image-atlas-manager.h>
24
25 struct NSVGimage;
26
27 namespace Dali
28 {
29
30 namespace Toolkit
31 {
32
33 namespace Internal
34 {
35
36 /**
37  * The renderer which renders a svg image
38  *
39  * The following property is essential
40  *
41  * | %Property Name           | Type             |
42  * |--------------------------|------------------|
43  * | imageUrl                 | STRING           |
44  *
45  */
46 class SvgRenderer: public ControlRenderer
47 {
48 public:
49
50   /**
51    * @brief Constructor.
52    *
53    * @param[in] factoryCache A pointer pointing to the RendererFactoryCache object
54    */
55   SvgRenderer( RendererFactoryCache& factoryCache, ImageAtlasManager& atlasManager );
56
57   /**
58    * @brief A reference counted object may only be deleted by calling Unreference().
59    */
60   ~SvgRenderer();
61
62 public:  // from ControlRenderer
63
64   /**
65    * @copydoc ControlRenderer::GetNaturalSize
66    */
67   virtual void GetNaturalSize( Vector2& naturalSize ) const;
68
69   /**
70    * @copydoc ControlRenderer::SetSize
71    */
72   virtual void SetSize( const Vector2& size );
73
74   /**
75    * @copydoc ControlRenderer::CreatePropertyMap
76    */
77   virtual void DoCreatePropertyMap( Property::Map& map ) const;
78
79 protected:
80
81   /**
82    * @copydoc ControlRenderer::DoInitialize
83    */
84   virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap );
85
86   /**
87    * @copydoc ControlRenderer::DoSetOnStage
88    */
89   virtual void DoSetOnStage( Actor& actor );
90
91   /**
92    * @copydoc ControlRenderer::DoSetOffStage
93    */
94   virtual void DoSetOffStage( Actor& actor );
95
96 public:
97
98   /**
99    * @brief Helper method to determine whether the url indicate that it is a svg image.
100    *
101    * @param [in] url The URL of the image file.
102    * @return true if it is a svg image
103    */
104   static bool IsSvgUrl( const std::string& url );
105
106   /**
107    * @brief Sets the svg image of this renderer to the resource at imageUrl
108    * The renderer will parse the svg image once it is set.
109    * And rasterize it into BufferImage synchronously when the associated actor is put on stage, and destroy the BufferImage when it is off stage
110    *
111    * @param[in] imageUrl The URL to svg resource to use
112    */
113   void SetImage( const std::string& imageUrl, ImageDimensions size = ImageDimensions() );
114
115   /**
116    * @bried Apply the rasterized image to the renderer.
117    *
118    * @param[in] rasterizedPixelData The pixel buffer with the rasterized pixels
119    */
120   void ApplyRasterizedImage( PixelDataPtr rasterizedPixelData );
121
122 private:
123   /**
124    * @bried Rasterize the svg with the given size, and add it to the renderer.
125    *
126    * @param[in] size The target size of the SVG rasterization.
127    */
128   void AddRasterizationTask( const Vector2& size );
129
130
131   // Undefined
132   SvgRenderer( const SvgRenderer& svgRenderer );
133
134   // Undefined
135   SvgRenderer& operator=( const SvgRenderer& svgRenderer );
136
137 private:
138   Vector4              mAtlasRect;
139   ImageAtlasManager&   mAtlasManager;
140   std::string          mImageUrl;
141   NSVGimage*           mParsedImage;
142
143 };
144
145 } // namespace Internal
146
147 } // namespace Toolkit
148
149 } // namespace Dali
150
151 #endif /* __DALI_TOOLKIT_INTERNAL_SVG_RENDERER_H__ */