Merge "TextVisual implementation." into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / svg / svg-visual.h
1 #ifndef DALI_TOOLKIT_INTERNAL_SVG_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_SVG_VISUAL_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 //EXTERNAL INCLUDES
22 #include <dali/devel-api/object/weak-handle.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
26
27 struct NSVGimage;
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 namespace Internal
36 {
37
38 /**
39  * The visual which renders a svg image
40  *
41  * The following property is essential
42  *
43  * | %Property Name           | Type             |
44  * |--------------------------|------------------|
45  * | url                      | STRING           |
46  *
47  */
48 class SvgVisual: public Visual::Base
49 {
50 public:
51
52   /**
53    * @brief Constructor.
54    *
55    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
56    */
57   SvgVisual( VisualFactoryCache& factoryCache );
58
59   /**
60    * @brief Constructor which creates the SVG Visual using the image URL.
61    *
62    * The visual will parse the SVG image once it is set.
63    * And rasterize it into BufferImage synchronously when the associated actor is put on stage, and destroy the BufferImage when it is off stage
64    *
65    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
66    * @param[in] imageUrl The URL to svg resource to use
67    */
68   SvgVisual( VisualFactoryCache& factoryCache, const std::string& imageUrl, ImageDimensions size = ImageDimensions() );
69
70   /**
71    * @brief A reference counted object may only be deleted by calling Unreference().
72    */
73   ~SvgVisual();
74
75 public:  // from Visual
76
77   /**
78    * @copydoc Visual::Base::GetNaturalSize
79    */
80   virtual void GetNaturalSize( Vector2& naturalSize ) const;
81
82   /**
83    * @copydoc Visual::Base::SetSize
84    */
85   virtual void SetSize( const Vector2& size );
86
87   /**
88    * @copydoc Visual::Base::CreatePropertyMap
89    */
90   virtual void DoCreatePropertyMap( Property::Map& map ) const;
91
92   /**
93    * @copydoc Visual::Base::DoSetProperty
94    */
95   virtual void DoSetProperty( Dali::Property::Index index, const Dali::Property::Value& propertyValue );
96
97   /**
98    * @copydoc Visual::Base::DoGetProperty
99    */
100   virtual Dali::Property::Value DoGetProperty( Dali::Property::Index index );
101
102 protected:
103
104   /**
105    * @copydoc Visual::Base::DoInitialize
106    */
107   virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap );
108
109   /**
110    * @copydoc Visual::Base::DoSetOnStage
111    */
112   virtual void DoSetOnStage( Actor& actor );
113
114   /**
115    * @copydoc Visual::Base::DoSetOffStage
116    */
117   virtual void DoSetOffStage( Actor& actor );
118
119 public:
120
121   /**
122    * @bried Apply the rasterized image to the visual.
123    *
124    * @param[in] rasterizedPixelData The pixel buffer with the rasterized pixels
125    */
126   void ApplyRasterizedImage( PixelData rasterizedPixelData );
127
128 private:
129
130   /**
131    * @brief Parses the SVG Image from the set URL.
132    *
133    * @param[in] imageUrl The URL of the image to parse the SVG from.
134    * @param[in] size The required size of the SVG
135    */
136   void ParseFromUrl( const std::string& imageUrl, ImageDimensions size = ImageDimensions() );
137
138   /**
139    * @bried Rasterize the svg with the given size, and add it to the visual.
140    *
141    * @param[in] size The target size of the SVG rasterization.
142    */
143   void AddRasterizationTask( const Vector2& size );
144
145
146   // Undefined
147   SvgVisual( const SvgVisual& svgRenderer );
148
149   // Undefined
150   SvgVisual& operator=( const SvgVisual& svgRenderer );
151
152 private:
153   Vector4              mAtlasRect;
154   std::string          mImageUrl;
155   NSVGimage*           mParsedImage;
156   WeakHandle<Actor>    mPlacementActor;
157
158 };
159
160 } // namespace Internal
161
162 } // namespace Toolkit
163
164 } // namespace Dali
165
166 #endif /* DALI_TOOLKIT_INTERNAL_SVG_VISUAL_H */