1 #ifndef DALI_TOOLKIT_INTERNAL_SVG_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_SVG_VISUAL_H
5 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/common/intrusive-ptr.h>
23 #include <dali/public-api/object/weak-handle.h>
26 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
27 #include <dali-toolkit/internal/visuals/visual-url.h>
31 #endif /* NO_THORVG */
42 class ImageVisualShaderFactory;
44 typedef IntrusivePtr< SvgVisual > SvgVisualPtr;
47 * The visual which renders a svg image
49 * The following property is essential
51 * | %Property Name | Type |
52 * |--------------------------|------------------|
56 class SvgVisual: public Visual::Base
61 * @brief Create the SVG Visual using the image URL.
63 * The visual will parse the SVG image once it is set.
64 * And rasterize it into BufferImage synchronously when the associated actor is put on stage, and destroy the BufferImage when it is off stage
66 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
67 * @param[in] shaderFactory The ImageVisualShaderFactory object
68 * @param[in] imageUrl The URL to svg resource to use
69 * @param[in] properties A Property::Map containing settings for this visual
70 * @return A smart-pointer to the newly allocated visual.
72 static SvgVisualPtr New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties );
75 * @brief Create the SVG Visual using the image URL.
77 * The visual will parse the SVG image once it is set.
78 * And rasterize it into BufferImage synchronously when the associated actor is put on stage, and destroy the BufferImage when it is off stage
80 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
81 * @param[in] shaderFactory The ImageVisualShaderFactory object
82 * @param[in] imageUrl The URL to svg resource to use
83 * @return A smart-pointer to the newly allocated visual.
85 static SvgVisualPtr New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl );
87 public: // from Visual
90 * @copydoc Visual::Base::GetNaturalSize
92 void GetNaturalSize( Vector2& naturalSize ) override;
95 * @copydoc Visual::Base::CreatePropertyMap
97 void DoCreatePropertyMap( Property::Map& map ) const override;
100 * @copydoc Visual::Base::CreateInstancePropertyMap
102 void DoCreateInstancePropertyMap( Property::Map& map ) const override;
107 * @brief Constructor.
109 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
110 * @param[in] shaderFactory The ImageVisualShaderFactory object
111 * @param[in] imageUrl The URL to svg resource to use
113 SvgVisual( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl );
116 * @brief A reference counted object may only be deleted by calling Unreference().
118 virtual ~SvgVisual();
121 * @copydoc Visual::Base::DoSetProperties
123 void DoSetProperties( const Property::Map& propertyMap ) override;
126 * @copydoc Visual::Base::DoSetOnScene
128 void DoSetOnScene( Actor& actor ) override;
131 * @copydoc Visual::Base::DoSetOffScene
133 void DoSetOffScene( Actor& actor ) override;
136 * @copydoc Visual::Base::OnSetTransform
138 void OnSetTransform() override;
141 * @copydoc Visual::Base::IsResourceReady
143 bool IsResourceReady() const override;
149 * @bried Apply the rasterized image to the visual.
151 * @param[in] parsedSvg The data of parsed image.
152 * @param[in] rasterizedPixelData The pixel buffer with the rasterized pixels
154 void ApplyRasterizedImage( NSVGimage* parsedSvg, PixelData rasterizedPixelData );
155 #else /* NO_THORVG */
157 * @bried Apply the rasterized image to the visual.
159 * @param[in] vectorImage The data of vector image.
160 * @param[in] rasterizedPixelData The pixel buffer with the rasterized pixels
161 * @param[in] bool Whether the resource is loaded
163 void ApplyRasterizedImage( VectorImageRenderer vectorImage, PixelData rasterizedPixelData, bool isLoaded );
164 #endif /* NO_THORVG */
169 * @brief Parses the SVG Image from the set URL.
171 * @param[in] imageUrl The URL of the image to parse the SVG from.
173 void ParseFromUrl( const VisualUrl& imageUrl );
174 #else /* NO_THORVG */
176 * @brief Load the SVG Image from the set URL.
179 #endif /* NO_THORVG */
182 * @bried Rasterize the svg with the given size, and add it to the visual.
184 * @param[in] size The target size of the SVG rasterization.
186 void AddRasterizationTask( const Vector2& size );
189 * Helper method to set individual values by index key.
190 * @param[in] index The index key of the value
191 * @param[in] value The value
193 void DoSetProperty( Property::Index index, const Property::Value& value );
196 SvgVisual( const SvgVisual& svgRenderer );
199 SvgVisual& operator=( const SvgVisual& svgRenderer );
202 ImageVisualShaderFactory& mImageVisualShaderFactory;
206 NSVGimage* mParsedImage;
207 #else /* NO_THORVG */
208 VectorImageRenderer mVectorRenderer;
209 uint32_t mDefaultWidth;
210 uint32_t mDefaultHeight;
213 #endif /* NO_THORVG */
214 WeakHandle<Actor> mPlacementActor;
216 bool mAttemptAtlasing; ///< If true will attempt atlasing, otherwise create unique texture
219 } // namespace Internal
221 } // namespace Toolkit
225 #endif /* DALI_TOOLKIT_INTERNAL_SVG_VISUAL_H */